blob: 8a63d3547464f20387f0926b55a61bfbed9a5a89 [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
Richard Smithee579842017-01-30 20:39:26 +0000310 /// \brief Transform a type that is permitted to produce a
311 /// DeducedTemplateSpecializationType.
312 ///
313 /// This is used in the (relatively rare) contexts where it is acceptable
314 /// for transformation to produce a class template type with deduced
315 /// template arguments.
316 /// @{
317 QualType TransformTypeWithDeducedTST(QualType T);
318 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
319 /// @}
320
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000321 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000322 ///
Mike Stump11289f42009-09-09 15:08:12 +0000323 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 /// appropriate TransformXXXStmt function to transform a specific kind of
325 /// statement or the TransformExpr() function to transform an expression.
326 /// Subclasses may override this function to transform statements using some
327 /// other mechanism.
328 ///
329 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000330 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000331
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000332 /// \brief Transform the given statement.
333 ///
334 /// By default, this routine transforms a statement by delegating to the
335 /// appropriate TransformOMPXXXClause function to transform a specific kind
336 /// of clause. Subclasses may override this function to transform statements
337 /// using some other mechanism.
338 ///
339 /// \returns the transformed OpenMP clause.
340 OMPClause *TransformOMPClause(OMPClause *S);
341
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000342 /// \brief Transform the given attribute.
343 ///
344 /// By default, this routine transforms a statement by delegating to the
345 /// appropriate TransformXXXAttr function to transform a specific kind
346 /// of attribute. Subclasses may override this function to transform
347 /// attributed statements using some other mechanism.
348 ///
349 /// \returns the transformed attribute
350 const Attr *TransformAttr(const Attr *S);
351
352/// \brief Transform the specified attribute.
353///
354/// Subclasses should override the transformation of attributes with a pragma
355/// spelling to transform expressions stored within the attribute.
356///
357/// \returns the transformed attribute.
358#define ATTR(X)
359#define PRAGMA_SPELLING_ATTR(X) \
360 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
361#include "clang/Basic/AttrList.inc"
362
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000363 /// \brief Transform the given expression.
364 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000365 /// By default, this routine transforms an expression by delegating to the
366 /// appropriate TransformXXXExpr function to build a new expression.
367 /// Subclasses may override this function to transform expressions using some
368 /// other mechanism.
369 ///
370 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000371 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Richard Smithd59b8322012-12-19 01:39:02 +0000373 /// \brief Transform the given initializer.
374 ///
375 /// By default, this routine transforms an initializer by stripping off the
376 /// semantic nodes added by initialization, then passing the result to
377 /// TransformExpr or TransformExprs.
378 ///
379 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000380 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000381
Douglas Gregora3efea12011-01-03 19:04:46 +0000382 /// \brief Transform the given list of expressions.
383 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// This routine transforms a list of expressions by invoking
385 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000386 /// support for variadic templates by expanding any pack expansions (if the
387 /// derived class permits such expansion) along the way. When pack expansions
388 /// are present, the number of outputs may not equal the number of inputs.
389 ///
390 /// \param Inputs The set of expressions to be transformed.
391 ///
392 /// \param NumInputs The number of expressions in \c Inputs.
393 ///
394 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000395 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000396 /// be.
397 ///
398 /// \param Outputs The transformed input expressions will be added to this
399 /// vector.
400 ///
401 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
402 /// due to transformation.
403 ///
404 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000405 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000406 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000407 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409 /// \brief Transform the given declaration, which is referenced from a type
410 /// or expression.
411 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000412 /// By default, acts as the identity function on declarations, unless the
413 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000414 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000415 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000416 llvm::DenseMap<Decl *, Decl *>::iterator Known
417 = TransformedLocalDecls.find(D);
418 if (Known != TransformedLocalDecls.end())
419 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000420
421 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000423
Richard Smith03a4aa32016-06-23 19:02:52 +0000424 /// \brief Transform the specified condition.
425 ///
426 /// By default, this transforms the variable and expression and rebuilds
427 /// the condition.
428 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
429 Expr *Expr,
430 Sema::ConditionKind Kind);
431
Chad Rosier1dcde962012-08-08 18:46:20 +0000432 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000433 /// place them on the new declaration.
434 ///
435 /// By default, this operation does nothing. Subclasses may override this
436 /// behavior to transform attributes.
437 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000439 /// \brief Note that a local declaration has been transformed by this
440 /// transformer.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000443 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
444 /// the transformer itself has to transform the declarations. This routine
445 /// can be overridden by a subclass that keeps track of such mappings.
446 void transformedLocalDecl(Decl *Old, Decl *New) {
447 TransformedLocalDecls[Old] = New;
448 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000449
Douglas Gregorebe10102009-08-20 07:17:43 +0000450 /// \brief Transform the definition of the given declaration.
451 ///
Mike Stump11289f42009-09-09 15:08:12 +0000452 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000453 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000454 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
455 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000456 }
Mike Stump11289f42009-09-09 15:08:12 +0000457
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000458 /// \brief Transform the given declaration, which was the first part of a
459 /// nested-name-specifier in a member access expression.
460 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000461 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000462 /// identifier in a nested-name-specifier of a member access expression, e.g.,
463 /// the \c T in \c x->T::member
464 ///
465 /// By default, invokes TransformDecl() to transform the declaration.
466 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000467 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
468 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000469 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000470
Richard Smith151c4562016-12-20 21:35:28 +0000471 /// Transform the set of declarations in an OverloadExpr.
472 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
473 LookupResult &R);
474
Douglas Gregor14454802011-02-25 02:25:35 +0000475 /// \brief Transform the given nested-name-specifier with source-location
476 /// information.
477 ///
478 /// By default, transforms all of the types and declarations within the
479 /// nested-name-specifier. Subclasses may override this function to provide
480 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000481 NestedNameSpecifierLoc
482 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
483 QualType ObjectType = QualType(),
484 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000485
Douglas Gregorf816bd72009-09-03 22:13:48 +0000486 /// \brief Transform the given declaration name.
487 ///
488 /// By default, transforms the types of conversion function, constructor,
489 /// and destructor names and then (if needed) rebuilds the declaration name.
490 /// Identifiers and selectors are returned unmodified. Sublcasses may
491 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000492 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000493 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000494
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000496 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000497 /// \param SS The nested-name-specifier that qualifies the template
498 /// name. This nested-name-specifier must already have been transformed.
499 ///
500 /// \param Name The template name to transform.
501 ///
502 /// \param NameLoc The source location of the template name.
503 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000504 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000505 /// access expression, this is the type of the object whose member template
506 /// is being referenced.
507 ///
508 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
509 /// also refers to a name within the current (lexical) scope, this is the
510 /// declaration it refers to.
511 ///
512 /// By default, transforms the template name by transforming the declarations
513 /// and nested-name-specifiers that occur within the template name.
514 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000515 TemplateName
516 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
517 SourceLocation NameLoc,
518 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000519 NamedDecl *FirstQualifierInScope = nullptr,
520 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000521
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// \brief Transform the given template argument.
523 ///
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// By default, this operation transforms the type, expression, or
525 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000526 /// new template argument from the transformed result. Subclasses may
527 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000528 ///
529 /// Returns true if there was an error.
530 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000531 TemplateArgumentLoc &Output,
532 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000533
Douglas Gregor62e06f22010-12-20 17:31:10 +0000534 /// \brief Transform the given set of template arguments.
535 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000537 /// in the input set using \c TransformTemplateArgument(), and appends
538 /// the transformed arguments to the output list.
539 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000540 /// Note that this overload of \c TransformTemplateArguments() is merely
541 /// a convenience function. Subclasses that wish to override this behavior
542 /// should override the iterator-based member template version.
543 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000544 /// \param Inputs The set of template arguments to be transformed.
545 ///
546 /// \param NumInputs The number of template arguments in \p Inputs.
547 ///
548 /// \param Outputs The set of transformed template arguments output by this
549 /// routine.
550 ///
551 /// Returns true if an error occurred.
552 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
553 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000554 TemplateArgumentListInfo &Outputs,
555 bool Uneval = false) {
556 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
557 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000559
560 /// \brief Transform the given set of template arguments.
561 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000562 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000565 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000566 /// \param First An iterator to the first template argument.
567 ///
568 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000569 ///
570 /// \param Outputs The set of transformed template arguments output by this
571 /// routine.
572 ///
573 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000574 template<typename InputIterator>
575 bool TransformTemplateArguments(InputIterator First,
576 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000577 TemplateArgumentListInfo &Outputs,
578 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000579
John McCall0ad16662009-10-29 08:12:44 +0000580 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
581 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
582 TemplateArgumentLoc &ArgLoc);
583
John McCallbcd03502009-12-07 02:54:59 +0000584 /// \brief Fakes up a TypeSourceInfo for a type.
585 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
586 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000587 getDerived().getBaseLocation());
588 }
Mike Stump11289f42009-09-09 15:08:12 +0000589
John McCall550e0c22009-10-21 00:40:46 +0000590#define ABSTRACT_TYPELOC(CLASS, PARENT)
591#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000592 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000593#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594
Richard Smith2e321552014-11-12 02:00:47 +0000595 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000596 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
597 FunctionProtoTypeLoc TL,
598 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000599 unsigned ThisTypeQuals,
600 Fn TransformExceptionSpec);
601
602 bool TransformExceptionSpec(SourceLocation Loc,
603 FunctionProtoType::ExceptionSpecInfo &ESI,
604 SmallVectorImpl<QualType> &Exceptions,
605 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000606
David Majnemerfad8f482013-10-15 09:33:02 +0000607 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000608
Chad Rosier1dcde962012-08-08 18:46:20 +0000609 QualType
John McCall31f82722010-11-12 08:19:04 +0000610 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
611 TemplateSpecializationTypeLoc TL,
612 TemplateName Template);
613
Chad Rosier1dcde962012-08-08 18:46:20 +0000614 QualType
John McCall31f82722010-11-12 08:19:04 +0000615 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
616 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000617 TemplateName Template,
618 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000619
Nico Weberc153d242014-07-28 00:02:09 +0000620 QualType TransformDependentTemplateSpecializationType(
621 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
622 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000623
John McCall58f10c32010-03-11 09:03:00 +0000624 /// \brief Transforms the parameters of a function type into the
625 /// given vectors.
626 ///
627 /// The result vectors should be kept in sync; null entries in the
628 /// variables vector are acceptable.
629 ///
630 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000631 bool TransformFunctionTypeParams(
632 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
633 const QualType *ParamTypes,
634 const FunctionProtoType::ExtParameterInfo *ParamInfos,
635 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
636 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000637
638 /// \brief Transforms a single function-type parameter. Return null
639 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000640 ///
641 /// \param indexAdjustment - A number to add to the parameter's
642 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000643 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000644 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000645 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000646 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000647
John McCall31f82722010-11-12 08:19:04 +0000648 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000649
John McCalldadc5752010-08-24 06:29:42 +0000650 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
651 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000652
Faisal Vali2cba1332013-10-23 06:44:28 +0000653 TemplateParameterList *TransformTemplateParameterList(
654 TemplateParameterList *TPL) {
655 return TPL;
656 }
657
Richard Smithdb2630f2012-10-21 03:28:35 +0000658 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000659
Richard Smithdb2630f2012-10-21 03:28:35 +0000660 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000661 bool IsAddressOfOperand,
662 TypeSourceInfo **RecoveryTSI);
663
664 ExprResult TransformParenDependentScopeDeclRefExpr(
665 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
666 TypeSourceInfo **RecoveryTSI);
667
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000668 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000669
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000670// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
671// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000672#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000673 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000674 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000675#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000676 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000677 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000678#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000679#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000680
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000681#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000682 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000683 OMPClause *Transform ## Class(Class *S);
684#include "clang/Basic/OpenMPKinds.def"
685
Richard Smithee579842017-01-30 20:39:26 +0000686 /// \brief Build a new qualified type given its unqualified type and type
687 /// qualifiers.
688 ///
689 /// By default, this routine adds type qualifiers only to types that can
690 /// have qualifiers, and silently suppresses those qualifiers that are not
691 /// permitted. Subclasses may override this routine to provide different
692 /// behavior.
693 QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
694 Qualifiers Quals);
695
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 /// \brief Build a new pointer type given its pointee type.
697 ///
698 /// By default, performs semantic analysis when building the pointer type.
699 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000700 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701
702 /// \brief Build a new block pointer type given its pointee type.
703 ///
Mike Stump11289f42009-09-09 15:08:12 +0000704 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000705 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000706 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000707
John McCall70dd5f62009-10-30 00:06:24 +0000708 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000709 ///
John McCall70dd5f62009-10-30 00:06:24 +0000710 /// By default, performs semantic analysis when building the
711 /// reference type. Subclasses may override this routine to provide
712 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000713 ///
John McCall70dd5f62009-10-30 00:06:24 +0000714 /// \param LValue whether the type was written with an lvalue sigil
715 /// or an rvalue sigil.
716 QualType RebuildReferenceType(QualType ReferentType,
717 bool LValue,
718 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000719
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 /// \brief Build a new member pointer type given the pointee type and the
721 /// class type it refers into.
722 ///
723 /// By default, performs semantic analysis when building the member pointer
724 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000725 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
726 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Manman Rene6be26c2016-09-13 17:25:08 +0000728 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
729 SourceLocation ProtocolLAngleLoc,
730 ArrayRef<ObjCProtocolDecl *> Protocols,
731 ArrayRef<SourceLocation> ProtocolLocs,
732 SourceLocation ProtocolRAngleLoc);
733
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000734 /// \brief Build an Objective-C object type.
735 ///
736 /// By default, performs semantic analysis when building the object type.
737 /// Subclasses may override this routine to provide different behavior.
738 QualType RebuildObjCObjectType(QualType BaseType,
739 SourceLocation Loc,
740 SourceLocation TypeArgsLAngleLoc,
741 ArrayRef<TypeSourceInfo *> TypeArgs,
742 SourceLocation TypeArgsRAngleLoc,
743 SourceLocation ProtocolLAngleLoc,
744 ArrayRef<ObjCProtocolDecl *> Protocols,
745 ArrayRef<SourceLocation> ProtocolLocs,
746 SourceLocation ProtocolRAngleLoc);
747
748 /// \brief Build a new Objective-C object pointer type given the pointee type.
749 ///
750 /// By default, directly builds the pointer type, with no additional semantic
751 /// analysis.
752 QualType RebuildObjCObjectPointerType(QualType PointeeType,
753 SourceLocation Star);
754
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 /// \brief Build a new array type given the element type, size
756 /// modifier, size of the array (if known), size expression, and index type
757 /// qualifiers.
758 ///
759 /// By default, performs semantic analysis when building the array type.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 QualType RebuildArrayType(QualType ElementType,
763 ArrayType::ArraySizeModifier SizeMod,
764 const llvm::APInt *Size,
765 Expr *SizeExpr,
766 unsigned IndexTypeQuals,
767 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregord6ff3322009-08-04 16:50:30 +0000769 /// \brief Build a new constant array type given the element type, size
770 /// modifier, (known) size of the array, and index type qualifiers.
771 ///
772 /// By default, performs semantic analysis when building the array type.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000774 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 ArrayType::ArraySizeModifier SizeMod,
776 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000777 unsigned IndexTypeQuals,
778 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780 /// \brief Build a new incomplete array type given the element type, size
781 /// modifier, and index type qualifiers.
782 ///
783 /// By default, performs semantic analysis when building the array type.
784 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000785 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000786 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000789
Mike Stump11289f42009-09-09 15:08:12 +0000790 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// size modifier, size expression, and index type qualifiers.
792 ///
793 /// By default, performs semantic analysis when building the array type.
794 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000795 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000797 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000798 unsigned IndexTypeQuals,
799 SourceRange BracketsRange);
800
Mike Stump11289f42009-09-09 15:08:12 +0000801 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000802 /// size modifier, size expression, and index type qualifiers.
803 ///
804 /// By default, performs semantic analysis when building the array type.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000806 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000808 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 unsigned IndexTypeQuals,
810 SourceRange BracketsRange);
811
812 /// \brief Build a new vector type given the element type and
813 /// number of elements.
814 ///
815 /// By default, performs semantic analysis when building the vector type.
816 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000817 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000818 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000819
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// \brief Build a new extended vector type given the element type and
821 /// number of elements.
822 ///
823 /// By default, performs semantic analysis when building the vector type.
824 /// Subclasses may override this routine to provide different behavior.
825 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
826 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000827
828 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000829 /// given the element type and number of elements.
830 ///
831 /// By default, performs semantic analysis when building the vector type.
832 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000833 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000834 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000836
Douglas Gregord6ff3322009-08-04 16:50:30 +0000837 /// \brief Build a new function type.
838 ///
839 /// By default, performs semantic analysis when building the function type.
840 /// Subclasses may override this routine to provide different behavior.
841 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000842 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000843 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000844
John McCall550e0c22009-10-21 00:40:46 +0000845 /// \brief Build a new unprototyped function type.
846 QualType RebuildFunctionNoProtoType(QualType ResultType);
847
John McCallb96ec562009-12-04 22:46:56 +0000848 /// \brief Rebuild an unresolved typename type, given the decl that
849 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000850 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000851
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000853 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000854 return SemaRef.Context.getTypeDeclType(Typedef);
855 }
856
857 /// \brief Build a new class/struct/union type.
858 QualType RebuildRecordType(RecordDecl *Record) {
859 return SemaRef.Context.getTypeDeclType(Record);
860 }
861
862 /// \brief Build a new Enum type.
863 QualType RebuildEnumType(EnumDecl *Enum) {
864 return SemaRef.Context.getTypeDeclType(Enum);
865 }
John McCallfcc33b02009-09-05 00:15:47 +0000866
Mike Stump11289f42009-09-09 15:08:12 +0000867 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868 ///
869 /// By default, performs semantic analysis when building the typeof type.
870 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000871 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000872
Mike Stump11289f42009-09-09 15:08:12 +0000873 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000874 ///
875 /// By default, builds a new TypeOfType with the given underlying type.
876 QualType RebuildTypeOfType(QualType Underlying);
877
Alexis Hunte852b102011-05-24 22:41:36 +0000878 /// \brief Build a new unary transform type.
879 QualType RebuildUnaryTransformType(QualType BaseType,
880 UnaryTransformType::UTTKind UKind,
881 SourceLocation Loc);
882
Richard Smith74aeef52013-04-26 16:15:35 +0000883 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884 ///
885 /// By default, performs semantic analysis when building the decltype type.
886 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000887 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000888
Richard Smith74aeef52013-04-26 16:15:35 +0000889 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000890 ///
891 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000892 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000893 // Note, IsDependent is always false here: we implicitly convert an 'auto'
894 // which has been deduced to a dependent type into an undeduced 'auto', so
895 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000896 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000897 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000898 }
899
Richard Smith600b5262017-01-26 20:40:47 +0000900 /// By default, builds a new DeducedTemplateSpecializationType with the given
901 /// deduced type.
902 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
903 QualType Deduced) {
904 return SemaRef.Context.getDeducedTemplateSpecializationType(
905 Template, Deduced, /*IsDependent*/ false);
906 }
907
Douglas Gregord6ff3322009-08-04 16:50:30 +0000908 /// \brief Build a new template specialization type.
909 ///
910 /// By default, performs semantic analysis when building the template
911 /// specialization type. Subclasses may override this routine to provide
912 /// different behavior.
913 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000914 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000915 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000916
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000917 /// \brief Build a new parenthesized type.
918 ///
919 /// By default, builds a new ParenType type from the inner type.
920 /// Subclasses may override this routine to provide different behavior.
921 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000922 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000923 }
924
Douglas Gregord6ff3322009-08-04 16:50:30 +0000925 /// \brief Build a new qualified name type.
926 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000927 /// By default, builds a new ElaboratedType type from the keyword,
928 /// the nested-name-specifier and the named type.
929 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000930 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
931 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000932 NestedNameSpecifierLoc QualifierLoc,
933 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000934 return SemaRef.Context.getElaboratedType(Keyword,
935 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000936 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000937 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000938
939 /// \brief Build a new typename type that refers to a template-id.
940 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000941 /// By default, builds a new DependentNameType type from the
942 /// nested-name-specifier and the given type. Subclasses may override
943 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000944 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000945 ElaboratedTypeKeyword Keyword,
946 NestedNameSpecifierLoc QualifierLoc,
947 const IdentifierInfo *Name,
948 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000949 TemplateArgumentListInfo &Args,
950 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000951 // Rebuild the template name.
952 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000953 CXXScopeSpec SS;
954 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000955 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000956 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000957 nullptr, AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000958
Douglas Gregora7a795b2011-03-01 20:11:18 +0000959 if (InstName.isNull())
960 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000961
Douglas Gregora7a795b2011-03-01 20:11:18 +0000962 // If it's still dependent, make a dependent specialization.
963 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000964 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
965 QualifierLoc.getNestedNameSpecifier(),
966 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000967 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000968
Douglas Gregora7a795b2011-03-01 20:11:18 +0000969 // Otherwise, make an elaborated type wrapping a non-dependent
970 // specialization.
971 QualType T =
972 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
973 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000974
Craig Topperc3ec1492014-05-26 06:22:03 +0000975 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000976 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
978 return SemaRef.Context.getElaboratedType(Keyword,
979 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000980 T);
981 }
982
Douglas Gregord6ff3322009-08-04 16:50:30 +0000983 /// \brief Build a new typename type that refers to an identifier.
984 ///
985 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000986 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000987 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000988 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000989 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000990 NestedNameSpecifierLoc QualifierLoc,
991 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +0000992 SourceLocation IdLoc,
993 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000994 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000995 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000996
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000997 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000998 // If the name is still dependent, just build a new dependent name type.
999 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001000 return SemaRef.Context.getDependentNameType(Keyword,
1001 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001002 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001003 }
1004
Richard Smithee579842017-01-30 20:39:26 +00001005 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1006 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1007 *Id, IdLoc);
1008 // If a dependent name resolves to a deduced template specialization type,
1009 // check that we're in one of the syntactic contexts permitting it.
1010 if (!DeducedTSTContext) {
1011 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1012 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1013 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1014 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1015 Deduced->getTemplateName())
1016 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1017 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1018 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1019 return QualType();
1020 }
1021 }
1022 return T;
1023 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001024
1025 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1026
Abramo Bagnarad7548482010-05-19 21:37:53 +00001027 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001028 // into a non-dependent elaborated-type-specifier. Find the tag we're
1029 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001030 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001031 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1032 if (!DC)
1033 return QualType();
1034
John McCallbf8c5192010-05-27 06:40:31 +00001035 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1036 return QualType();
1037
Craig Topperc3ec1492014-05-26 06:22:03 +00001038 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001039 SemaRef.LookupQualifiedName(Result, DC);
1040 switch (Result.getResultKind()) {
1041 case LookupResult::NotFound:
1042 case LookupResult::NotFoundInCurrentInstantiation:
1043 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001044
Douglas Gregore677daf2010-03-31 22:19:08 +00001045 case LookupResult::Found:
1046 Tag = Result.getAsSingle<TagDecl>();
1047 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001048
Douglas Gregore677daf2010-03-31 22:19:08 +00001049 case LookupResult::FoundOverloaded:
1050 case LookupResult::FoundUnresolvedValue:
1051 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001052
Douglas Gregore677daf2010-03-31 22:19:08 +00001053 case LookupResult::Ambiguous:
1054 // Let the LookupResult structure handle ambiguities.
1055 return QualType();
1056 }
1057
1058 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001059 // Check where the name exists but isn't a tag type and use that to emit
1060 // better diagnostics.
1061 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1062 SemaRef.LookupQualifiedName(Result, DC);
1063 switch (Result.getResultKind()) {
1064 case LookupResult::Found:
1065 case LookupResult::FoundOverloaded:
1066 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001067 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001068 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1069 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1070 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001071 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1072 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001073 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001074 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001075 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001076 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001077 break;
1078 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001079 return QualType();
1080 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001081
Richard Trieucaa33d32011-06-10 03:11:26 +00001082 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001083 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001084 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001085 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1086 return QualType();
1087 }
1088
1089 // Build the elaborated-type-specifier type.
1090 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001091 return SemaRef.Context.getElaboratedType(Keyword,
1092 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001093 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Douglas Gregor822d0302011-01-12 17:07:58 +00001096 /// \brief Build a new pack expansion type.
1097 ///
1098 /// By default, builds a new PackExpansionType type from the given pattern.
1099 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001100 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001101 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001102 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001103 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001104 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1105 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001106 }
1107
Eli Friedman0dfb8892011-10-06 23:00:33 +00001108 /// \brief Build a new atomic type given its value type.
1109 ///
1110 /// By default, performs semantic analysis when building the atomic type.
1111 /// Subclasses may override this routine to provide different behavior.
1112 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1113
Xiuli Pan9c14e282016-01-09 12:53:17 +00001114 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001115 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1116 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001117
Douglas Gregor71dc5092009-08-06 06:41:21 +00001118 /// \brief Build a new template name given a nested name specifier, a flag
1119 /// indicating whether the "template" keyword was provided, and the template
1120 /// that the template name refers to.
1121 ///
1122 /// By default, builds the new template name directly. Subclasses may override
1123 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001124 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001125 bool TemplateKW,
1126 TemplateDecl *Template);
1127
Douglas Gregor71dc5092009-08-06 06:41:21 +00001128 /// \brief Build a new template name given a nested name specifier and the
1129 /// name that is referred to as a template.
1130 ///
1131 /// By default, performs semantic analysis to determine whether the name can
1132 /// be resolved to a specific template, then builds the appropriate kind of
1133 /// template name. Subclasses may override this routine to provide different
1134 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001135 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1136 const IdentifierInfo &Name,
1137 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001138 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001139 NamedDecl *FirstQualifierInScope,
1140 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001141
Douglas Gregor71395fa2009-11-04 00:56:37 +00001142 /// \brief Build a new template name given a nested name specifier and the
1143 /// overloaded operator name that is referred to as a template.
1144 ///
1145 /// By default, performs semantic analysis to determine whether the name can
1146 /// be resolved to a specific template, then builds the appropriate kind of
1147 /// template name. Subclasses may override this routine to provide different
1148 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001149 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001150 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001151 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00001152 QualType ObjectType,
1153 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001154
1155 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001156 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001157 ///
1158 /// By default, performs semantic analysis to determine whether the name can
1159 /// be resolved to a specific template, then builds the appropriate kind of
1160 /// template name. Subclasses may override this routine to provide different
1161 /// behavior.
1162 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1163 const TemplateArgument &ArgPack) {
1164 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1165 }
1166
Douglas Gregorebe10102009-08-20 07:17:43 +00001167 /// \brief Build a new compound statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001171 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001172 MultiStmtArg Statements,
1173 SourceLocation RBraceLoc,
1174 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001175 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001176 IsStmtExpr);
1177 }
1178
1179 /// \brief Build a new case statement.
1180 ///
1181 /// By default, performs semantic analysis to build the new statement.
1182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001183 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001184 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001186 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 ColonLoc);
1190 }
Mike Stump11289f42009-09-09 15:08:12 +00001191
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 /// \brief Attach the body to a new case statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001197 getSema().ActOnCaseStmtBody(S, Body);
1198 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 }
Mike Stump11289f42009-09-09 15:08:12 +00001200
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 /// \brief Build a new default statement.
1202 ///
1203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001205 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001207 Stmt *SubStmt) {
1208 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001209 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 }
Mike Stump11289f42009-09-09 15:08:12 +00001211
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 /// \brief Build a new label statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001216 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1217 SourceLocation ColonLoc, Stmt *SubStmt) {
1218 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Richard Smithc202b282012-04-14 00:33:13 +00001221 /// \brief Build a new label statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001225 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1226 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001227 Stmt *SubStmt) {
1228 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1229 }
1230
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 /// \brief Build a new "if" statement.
1232 ///
1233 /// By default, performs semantic analysis to build the new statement.
1234 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001235 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001236 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001237 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001238 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001239 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 /// \brief Start building a new switch statement.
1243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001246 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001247 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001248 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 /// \brief Attach the body to the switch statement.
1252 ///
1253 /// By default, performs semantic analysis to build the new statement.
1254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001255 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001256 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001257 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new while statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001264 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1265 Sema::ConditionResult Cond, Stmt *Body) {
1266 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001267 }
Mike Stump11289f42009-09-09 15:08:12 +00001268
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 /// \brief Build a new do-while statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001273 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001274 SourceLocation WhileLoc, SourceLocation LParenLoc,
1275 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001276 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1277 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001278 }
1279
1280 /// \brief Build a new for statement.
1281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001284 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001285 Stmt *Init, Sema::ConditionResult Cond,
1286 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1287 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001288 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001289 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001290 }
Mike Stump11289f42009-09-09 15:08:12 +00001291
Douglas Gregorebe10102009-08-20 07:17:43 +00001292 /// \brief Build a new goto statement.
1293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001296 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1297 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001298 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001299 }
1300
1301 /// \brief Build a new indirect goto statement.
1302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001305 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001306 SourceLocation StarLoc,
1307 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001308 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregorebe10102009-08-20 07:17:43 +00001311 /// \brief Build a new return statement.
1312 ///
1313 /// By default, performs semantic analysis to build the new statement.
1314 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001315 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001316 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregorebe10102009-08-20 07:17:43 +00001319 /// \brief Build a new declaration statement.
1320 ///
1321 /// By default, performs semantic analysis to build the new statement.
1322 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001323 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001324 SourceLocation StartLoc, SourceLocation EndLoc) {
1325 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001326 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001327 }
Mike Stump11289f42009-09-09 15:08:12 +00001328
Anders Carlssonaaeef072010-01-24 05:50:09 +00001329 /// \brief Build a new inline asm statement.
1330 ///
1331 /// By default, performs semantic analysis to build the new statement.
1332 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001333 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1334 bool IsVolatile, unsigned NumOutputs,
1335 unsigned NumInputs, IdentifierInfo **Names,
1336 MultiExprArg Constraints, MultiExprArg Exprs,
1337 Expr *AsmString, MultiExprArg Clobbers,
1338 SourceLocation RParenLoc) {
1339 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1340 NumInputs, Names, Constraints, Exprs,
1341 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001342 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001343
Chad Rosier32503022012-06-11 20:47:18 +00001344 /// \brief Build a new MS style inline asm statement.
1345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001348 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001349 ArrayRef<Token> AsmToks,
1350 StringRef AsmString,
1351 unsigned NumOutputs, unsigned NumInputs,
1352 ArrayRef<StringRef> Constraints,
1353 ArrayRef<StringRef> Clobbers,
1354 ArrayRef<Expr*> Exprs,
1355 SourceLocation EndLoc) {
1356 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1357 NumOutputs, NumInputs,
1358 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001359 }
1360
Richard Smith9f690bd2015-10-27 06:02:45 +00001361 /// \brief Build a new co_return statement.
1362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
1365 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result) {
1366 return getSema().BuildCoreturnStmt(CoreturnLoc, Result);
1367 }
1368
1369 /// \brief Build a new co_await expression.
1370 ///
1371 /// By default, performs semantic analysis to build the new expression.
1372 /// Subclasses may override this routine to provide different behavior.
1373 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result) {
1374 return getSema().BuildCoawaitExpr(CoawaitLoc, Result);
1375 }
1376
1377 /// \brief Build a new co_yield expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
1381 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1382 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1383 }
1384
James Dennett2a4d13c2012-06-15 07:13:21 +00001385 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001389 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001390 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001391 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001392 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001393 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001394 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001395 }
1396
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001397 /// \brief Rebuild an Objective-C exception declaration.
1398 ///
1399 /// By default, performs semantic analysis to build the new declaration.
1400 /// Subclasses may override this routine to provide different behavior.
1401 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1402 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001403 return getSema().BuildObjCExceptionDecl(TInfo, T,
1404 ExceptionDecl->getInnerLocStart(),
1405 ExceptionDecl->getLocation(),
1406 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001407 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001408
James Dennett2a4d13c2012-06-15 07:13:21 +00001409 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001410 ///
1411 /// By default, performs semantic analysis to build the new statement.
1412 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001413 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001414 SourceLocation RParenLoc,
1415 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001416 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001417 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001418 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001419 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001420
James Dennett2a4d13c2012-06-15 07:13:21 +00001421 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001422 ///
1423 /// By default, performs semantic analysis to build the new statement.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001426 Stmt *Body) {
1427 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001428 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001429
James Dennett2a4d13c2012-06-15 07:13:21 +00001430 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001431 ///
1432 /// By default, performs semantic analysis to build the new statement.
1433 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001434 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001435 Expr *Operand) {
1436 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001437 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001438
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001439 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001440 ///
1441 /// By default, performs semantic analysis to build the new statement.
1442 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001443 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001444 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001445 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001446 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001447 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001448 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001449 return getSema().ActOnOpenMPExecutableDirective(
1450 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001451 }
1452
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001453 /// \brief Build a new OpenMP 'if' clause.
1454 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001455 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001456 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001457 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1458 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001459 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001460 SourceLocation NameModifierLoc,
1461 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001462 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001463 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1464 LParenLoc, NameModifierLoc, ColonLoc,
1465 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001466 }
1467
Alexey Bataev3778b602014-07-17 07:32:53 +00001468 /// \brief Build a new OpenMP 'final' clause.
1469 ///
1470 /// By default, performs semantic analysis to build the new OpenMP clause.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1473 SourceLocation LParenLoc,
1474 SourceLocation EndLoc) {
1475 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1476 EndLoc);
1477 }
1478
Alexey Bataev568a8332014-03-06 06:15:19 +00001479 /// \brief Build a new OpenMP 'num_threads' clause.
1480 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001481 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001482 /// Subclasses may override this routine to provide different behavior.
1483 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1484 SourceLocation StartLoc,
1485 SourceLocation LParenLoc,
1486 SourceLocation EndLoc) {
1487 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1488 LParenLoc, EndLoc);
1489 }
1490
Alexey Bataev62c87d22014-03-21 04:51:18 +00001491 /// \brief Build a new OpenMP 'safelen' clause.
1492 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001493 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001494 /// Subclasses may override this routine to provide different behavior.
1495 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation EndLoc) {
1498 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1499 }
1500
Alexey Bataev66b15b52015-08-21 11:14:16 +00001501 /// \brief Build a new OpenMP 'simdlen' clause.
1502 ///
1503 /// By default, performs semantic analysis to build the new OpenMP clause.
1504 /// Subclasses may override this routine to provide different behavior.
1505 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1506 SourceLocation LParenLoc,
1507 SourceLocation EndLoc) {
1508 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1509 }
1510
Alexander Musman8bd31e62014-05-27 15:12:19 +00001511 /// \brief Build a new OpenMP 'collapse' clause.
1512 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001513 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001514 /// Subclasses may override this routine to provide different behavior.
1515 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1516 SourceLocation LParenLoc,
1517 SourceLocation EndLoc) {
1518 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1519 EndLoc);
1520 }
1521
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001522 /// \brief Build a new OpenMP 'default' clause.
1523 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001524 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001525 /// Subclasses may override this routine to provide different behavior.
1526 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1527 SourceLocation KindKwLoc,
1528 SourceLocation StartLoc,
1529 SourceLocation LParenLoc,
1530 SourceLocation EndLoc) {
1531 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1532 StartLoc, LParenLoc, EndLoc);
1533 }
1534
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001535 /// \brief Build a new OpenMP 'proc_bind' clause.
1536 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001537 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001538 /// Subclasses may override this routine to provide different behavior.
1539 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1540 SourceLocation KindKwLoc,
1541 SourceLocation StartLoc,
1542 SourceLocation LParenLoc,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1545 StartLoc, LParenLoc, EndLoc);
1546 }
1547
Alexey Bataev56dafe82014-06-20 07:16:17 +00001548 /// \brief Build a new OpenMP 'schedule' clause.
1549 ///
1550 /// By default, performs semantic analysis to build the new OpenMP clause.
1551 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001552 OMPClause *RebuildOMPScheduleClause(
1553 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1554 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1555 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1556 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001557 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001558 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1559 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001560 }
1561
Alexey Bataev10e775f2015-07-30 11:36:16 +00001562 /// \brief Build a new OpenMP 'ordered' clause.
1563 ///
1564 /// By default, performs semantic analysis to build the new OpenMP clause.
1565 /// Subclasses may override this routine to provide different behavior.
1566 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1567 SourceLocation EndLoc,
1568 SourceLocation LParenLoc, Expr *Num) {
1569 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1570 }
1571
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001572 /// \brief Build a new OpenMP 'private' clause.
1573 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001574 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001575 /// Subclasses may override this routine to provide different behavior.
1576 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1577 SourceLocation StartLoc,
1578 SourceLocation LParenLoc,
1579 SourceLocation EndLoc) {
1580 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1581 EndLoc);
1582 }
1583
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001584 /// \brief Build a new OpenMP 'firstprivate' clause.
1585 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001586 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001587 /// Subclasses may override this routine to provide different behavior.
1588 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1589 SourceLocation StartLoc,
1590 SourceLocation LParenLoc,
1591 SourceLocation EndLoc) {
1592 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1593 EndLoc);
1594 }
1595
Alexander Musman1bb328c2014-06-04 13:06:39 +00001596 /// \brief Build a new OpenMP 'lastprivate' clause.
1597 ///
1598 /// By default, performs semantic analysis to build the new OpenMP clause.
1599 /// Subclasses may override this routine to provide different behavior.
1600 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1601 SourceLocation StartLoc,
1602 SourceLocation LParenLoc,
1603 SourceLocation EndLoc) {
1604 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1605 EndLoc);
1606 }
1607
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001608 /// \brief Build a new OpenMP 'shared' clause.
1609 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001610 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001611 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001612 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1613 SourceLocation StartLoc,
1614 SourceLocation LParenLoc,
1615 SourceLocation EndLoc) {
1616 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1617 EndLoc);
1618 }
1619
Alexey Bataevc5e02582014-06-16 07:08:35 +00001620 /// \brief Build a new OpenMP 'reduction' clause.
1621 ///
1622 /// By default, performs semantic analysis to build the new statement.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1625 SourceLocation StartLoc,
1626 SourceLocation LParenLoc,
1627 SourceLocation ColonLoc,
1628 SourceLocation EndLoc,
1629 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001630 const DeclarationNameInfo &ReductionId,
1631 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001632 return getSema().ActOnOpenMPReductionClause(
1633 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001634 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001635 }
1636
Alexander Musman8dba6642014-04-22 13:09:42 +00001637 /// \brief Build a new OpenMP 'linear' clause.
1638 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001639 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001640 /// Subclasses may override this routine to provide different behavior.
1641 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001644 OpenMPLinearClauseKind Modifier,
1645 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001646 SourceLocation ColonLoc,
1647 SourceLocation EndLoc) {
1648 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001649 Modifier, ModifierLoc, ColonLoc,
1650 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001651 }
1652
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001653 /// \brief Build a new OpenMP 'aligned' clause.
1654 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001655 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001656 /// Subclasses may override this routine to provide different behavior.
1657 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1658 SourceLocation StartLoc,
1659 SourceLocation LParenLoc,
1660 SourceLocation ColonLoc,
1661 SourceLocation EndLoc) {
1662 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1663 LParenLoc, ColonLoc, EndLoc);
1664 }
1665
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001666 /// \brief Build a new OpenMP 'copyin' clause.
1667 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001668 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001669 /// Subclasses may override this routine to provide different behavior.
1670 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1671 SourceLocation StartLoc,
1672 SourceLocation LParenLoc,
1673 SourceLocation EndLoc) {
1674 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1675 EndLoc);
1676 }
1677
Alexey Bataevbae9a792014-06-27 10:37:06 +00001678 /// \brief Build a new OpenMP 'copyprivate' clause.
1679 ///
1680 /// By default, performs semantic analysis to build the new OpenMP clause.
1681 /// Subclasses may override this routine to provide different behavior.
1682 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1683 SourceLocation StartLoc,
1684 SourceLocation LParenLoc,
1685 SourceLocation EndLoc) {
1686 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1687 EndLoc);
1688 }
1689
Alexey Bataev6125da92014-07-21 11:26:11 +00001690 /// \brief Build a new OpenMP 'flush' pseudo clause.
1691 ///
1692 /// By default, performs semantic analysis to build the new OpenMP clause.
1693 /// Subclasses may override this routine to provide different behavior.
1694 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1695 SourceLocation StartLoc,
1696 SourceLocation LParenLoc,
1697 SourceLocation EndLoc) {
1698 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1699 EndLoc);
1700 }
1701
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001702 /// \brief Build a new OpenMP 'depend' pseudo clause.
1703 ///
1704 /// By default, performs semantic analysis to build the new OpenMP clause.
1705 /// Subclasses may override this routine to provide different behavior.
1706 OMPClause *
1707 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1708 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1709 SourceLocation StartLoc, SourceLocation LParenLoc,
1710 SourceLocation EndLoc) {
1711 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1712 StartLoc, LParenLoc, EndLoc);
1713 }
1714
Michael Wonge710d542015-08-07 16:16:36 +00001715 /// \brief Build a new OpenMP 'device' clause.
1716 ///
1717 /// By default, performs semantic analysis to build the new statement.
1718 /// Subclasses may override this routine to provide different behavior.
1719 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1720 SourceLocation LParenLoc,
1721 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001722 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001723 EndLoc);
1724 }
1725
Kelvin Li0bff7af2015-11-23 05:32:03 +00001726 /// \brief Build a new OpenMP 'map' clause.
1727 ///
1728 /// By default, performs semantic analysis to build the new OpenMP clause.
1729 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001730 OMPClause *
1731 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1732 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1733 SourceLocation MapLoc, SourceLocation ColonLoc,
1734 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1735 SourceLocation LParenLoc, SourceLocation EndLoc) {
1736 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1737 IsMapTypeImplicit, MapLoc, ColonLoc,
1738 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001739 }
1740
Kelvin Li099bb8c2015-11-24 20:50:12 +00001741 /// \brief Build a new OpenMP 'num_teams' clause.
1742 ///
1743 /// By default, performs semantic analysis to build the new statement.
1744 /// Subclasses may override this routine to provide different behavior.
1745 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1746 SourceLocation LParenLoc,
1747 SourceLocation EndLoc) {
1748 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1749 EndLoc);
1750 }
1751
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001752 /// \brief Build a new OpenMP 'thread_limit' clause.
1753 ///
1754 /// By default, performs semantic analysis to build the new statement.
1755 /// Subclasses may override this routine to provide different behavior.
1756 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1757 SourceLocation StartLoc,
1758 SourceLocation LParenLoc,
1759 SourceLocation EndLoc) {
1760 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1761 LParenLoc, EndLoc);
1762 }
1763
Alexey Bataeva0569352015-12-01 10:17:31 +00001764 /// \brief Build a new OpenMP 'priority' clause.
1765 ///
1766 /// By default, performs semantic analysis to build the new statement.
1767 /// Subclasses may override this routine to provide different behavior.
1768 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1769 SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1772 EndLoc);
1773 }
1774
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001775 /// \brief Build a new OpenMP 'grainsize' clause.
1776 ///
1777 /// By default, performs semantic analysis to build the new statement.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1783 EndLoc);
1784 }
1785
Alexey Bataev382967a2015-12-08 12:06:20 +00001786 /// \brief Build a new OpenMP 'num_tasks' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new statement.
1789 /// Subclasses may override this routine to provide different behavior.
1790 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
Alexey Bataev28c75412015-12-15 08:19:24 +00001797 /// \brief Build a new OpenMP 'hint' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new statement.
1800 /// Subclasses may override this routine to provide different behavior.
1801 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1805 }
1806
Carlo Bertollib4adf552016-01-15 18:50:31 +00001807 /// \brief Build a new OpenMP 'dist_schedule' clause.
1808 ///
1809 /// By default, performs semantic analysis to build the new OpenMP clause.
1810 /// Subclasses may override this routine to provide different behavior.
1811 OMPClause *
1812 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1813 Expr *ChunkSize, SourceLocation StartLoc,
1814 SourceLocation LParenLoc, SourceLocation KindLoc,
1815 SourceLocation CommaLoc, SourceLocation EndLoc) {
1816 return getSema().ActOnOpenMPDistScheduleClause(
1817 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1818 }
1819
Samuel Antao661c0902016-05-26 17:39:58 +00001820 /// \brief Build a new OpenMP 'to' clause.
1821 ///
1822 /// By default, performs semantic analysis to build the new statement.
1823 /// Subclasses may override this routine to provide different behavior.
1824 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1825 SourceLocation StartLoc,
1826 SourceLocation LParenLoc,
1827 SourceLocation EndLoc) {
1828 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1829 }
1830
Samuel Antaoec172c62016-05-26 17:49:04 +00001831 /// \brief Build a new OpenMP 'from' clause.
1832 ///
1833 /// By default, performs semantic analysis to build the new statement.
1834 /// Subclasses may override this routine to provide different behavior.
1835 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1836 SourceLocation StartLoc,
1837 SourceLocation LParenLoc,
1838 SourceLocation EndLoc) {
1839 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1840 EndLoc);
1841 }
1842
Carlo Bertolli2404b172016-07-13 15:37:16 +00001843 /// Build a new OpenMP 'use_device_ptr' clause.
1844 ///
1845 /// By default, performs semantic analysis to build the new OpenMP clause.
1846 /// Subclasses may override this routine to provide different behavior.
1847 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1848 SourceLocation StartLoc,
1849 SourceLocation LParenLoc,
1850 SourceLocation EndLoc) {
1851 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1852 EndLoc);
1853 }
1854
Carlo Bertolli70594e92016-07-13 17:16:49 +00001855 /// Build a new OpenMP 'is_device_ptr' clause.
1856 ///
1857 /// By default, performs semantic analysis to build the new OpenMP clause.
1858 /// Subclasses may override this routine to provide different behavior.
1859 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1860 SourceLocation StartLoc,
1861 SourceLocation LParenLoc,
1862 SourceLocation EndLoc) {
1863 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1864 EndLoc);
1865 }
1866
James Dennett2a4d13c2012-06-15 07:13:21 +00001867 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001868 ///
1869 /// By default, performs semantic analysis to build the new statement.
1870 /// Subclasses may override this routine to provide different behavior.
1871 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1872 Expr *object) {
1873 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1874 }
1875
James Dennett2a4d13c2012-06-15 07:13:21 +00001876 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001877 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001878 /// By default, performs semantic analysis to build the new statement.
1879 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001880 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001881 Expr *Object, Stmt *Body) {
1882 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001883 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001884
James Dennett2a4d13c2012-06-15 07:13:21 +00001885 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001886 ///
1887 /// By default, performs semantic analysis to build the new statement.
1888 /// Subclasses may override this routine to provide different behavior.
1889 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1890 Stmt *Body) {
1891 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1892 }
John McCall53848232011-07-27 01:07:15 +00001893
Douglas Gregorf68a5082010-04-22 23:10:45 +00001894 /// \brief Build a new Objective-C fast enumeration statement.
1895 ///
1896 /// By default, performs semantic analysis to build the new statement.
1897 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001898 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001899 Stmt *Element,
1900 Expr *Collection,
1901 SourceLocation RParenLoc,
1902 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001903 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001904 Element,
John McCallb268a282010-08-23 23:25:46 +00001905 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001906 RParenLoc);
1907 if (ForEachStmt.isInvalid())
1908 return StmtError();
1909
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001910 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001911 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001912
Douglas Gregorebe10102009-08-20 07:17:43 +00001913 /// \brief Build a new C++ exception declaration.
1914 ///
1915 /// By default, performs semantic analysis to build the new decaration.
1916 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001917 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001918 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001919 SourceLocation StartLoc,
1920 SourceLocation IdLoc,
1921 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001922 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001923 StartLoc, IdLoc, Id);
1924 if (Var)
1925 getSema().CurContext->addDecl(Var);
1926 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001927 }
1928
1929 /// \brief Build a new C++ catch statement.
1930 ///
1931 /// By default, performs semantic analysis to build the new statement.
1932 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001933 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001934 VarDecl *ExceptionDecl,
1935 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001936 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1937 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001938 }
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregorebe10102009-08-20 07:17:43 +00001940 /// \brief Build a new C++ try statement.
1941 ///
1942 /// By default, performs semantic analysis to build the new statement.
1943 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001944 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1945 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001946 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001947 }
Mike Stump11289f42009-09-09 15:08:12 +00001948
Richard Smith02e85f32011-04-14 22:09:26 +00001949 /// \brief Build a new C++0x range-based for statement.
1950 ///
1951 /// By default, performs semantic analysis to build the new statement.
1952 /// Subclasses may override this routine to provide different behavior.
1953 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001954 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001955 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001956 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001957 Expr *Cond, Expr *Inc,
1958 Stmt *LoopVar,
1959 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001960 // If we've just learned that the range is actually an Objective-C
1961 // collection, treat this as an Objective-C fast enumeration loop.
1962 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1963 if (RangeStmt->isSingleDecl()) {
1964 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001965 if (RangeVar->isInvalidDecl())
1966 return StmtError();
1967
Douglas Gregorf7106af2013-04-08 18:40:13 +00001968 Expr *RangeExpr = RangeVar->getInit();
1969 if (!RangeExpr->isTypeDependent() &&
1970 RangeExpr->getType()->isObjCObjectPointerType())
1971 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1972 RParenLoc);
1973 }
1974 }
1975 }
1976
Richard Smithcfd53b42015-10-22 06:13:50 +00001977 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001978 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001979 Cond, Inc, LoopVar, RParenLoc,
1980 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001981 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001982
1983 /// \brief Build a new C++0x range-based for statement.
1984 ///
1985 /// By default, performs semantic analysis to build the new statement.
1986 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001987 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001988 bool IsIfExists,
1989 NestedNameSpecifierLoc QualifierLoc,
1990 DeclarationNameInfo NameInfo,
1991 Stmt *Nested) {
1992 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1993 QualifierLoc, NameInfo, Nested);
1994 }
1995
Richard Smith02e85f32011-04-14 22:09:26 +00001996 /// \brief Attach body to a C++0x range-based for statement.
1997 ///
1998 /// By default, performs semantic analysis to finish the new statement.
1999 /// Subclasses may override this routine to provide different behavior.
2000 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2001 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2002 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002003
David Majnemerfad8f482013-10-15 09:33:02 +00002004 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002005 Stmt *TryBlock, Stmt *Handler) {
2006 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002007 }
2008
David Majnemerfad8f482013-10-15 09:33:02 +00002009 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002010 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002011 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002012 }
2013
David Majnemerfad8f482013-10-15 09:33:02 +00002014 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002015 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002016 }
2017
Alexey Bataevec474782014-10-09 08:45:04 +00002018 /// \brief Build a new predefined expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
2022 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2023 PredefinedExpr::IdentType IT) {
2024 return getSema().BuildPredefinedExpr(Loc, IT);
2025 }
2026
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 /// \brief Build a new expression that references a declaration.
2028 ///
2029 /// By default, performs semantic analysis to build the new expression.
2030 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002031 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002032 LookupResult &R,
2033 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002034 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2035 }
2036
2037
2038 /// \brief Build a new expression that references a declaration.
2039 ///
2040 /// By default, performs semantic analysis to build the new expression.
2041 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002042 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002043 ValueDecl *VD,
2044 const DeclarationNameInfo &NameInfo,
2045 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002046 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002047 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002048
2049 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002050
2051 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002052 }
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregora16548e2009-08-11 05:31:07 +00002054 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002055 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002056 /// By default, performs semantic analysis to build the new expression.
2057 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002058 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002060 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 }
2062
Douglas Gregorad8a3362009-09-04 17:36:40 +00002063 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002064 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002065 /// By default, performs semantic analysis to build the new expression.
2066 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002067 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002068 SourceLocation OperatorLoc,
2069 bool isArrow,
2070 CXXScopeSpec &SS,
2071 TypeSourceInfo *ScopeType,
2072 SourceLocation CCLoc,
2073 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002074 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002075
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// By default, performs semantic analysis to build the new expression.
2079 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002080 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002081 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002082 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002083 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregor882211c2010-04-28 22:16:22 +00002086 /// \brief Build a new builtin offsetof expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002090 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002091 TypeSourceInfo *Type,
2092 ArrayRef<Sema::OffsetOfComponent> Components,
2093 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002094 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002095 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002097
2098 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002099 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002103 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2104 SourceLocation OpLoc,
2105 UnaryExprOrTypeTrait ExprKind,
2106 SourceRange R) {
2107 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 }
2109
Peter Collingbournee190dee2011-03-11 19:24:49 +00002110 /// \brief Build a new sizeof, alignof or vec step expression with an
2111 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002113 /// By default, performs semantic analysis to build the new expression.
2114 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002115 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2116 UnaryExprOrTypeTrait ExprKind,
2117 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002118 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002119 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002122
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002123 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002124 }
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// By default, performs semantic analysis to build the new expression.
2129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002130 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002132 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002134 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002135 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 RBracketLoc);
2137 }
2138
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002139 /// \brief Build a new array section expression.
2140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
2143 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2144 Expr *LowerBound,
2145 SourceLocation ColonLoc, Expr *Length,
2146 SourceLocation RBracketLoc) {
2147 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2148 ColonLoc, Length, RBracketLoc);
2149 }
2150
Douglas Gregora16548e2009-08-11 05:31:07 +00002151 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002152 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 /// By default, performs semantic analysis to build the new expression.
2154 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002155 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002157 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002158 Expr *ExecConfig = nullptr) {
2159 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002160 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 }
2162
2163 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002164 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002167 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002168 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002169 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002170 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002171 const DeclarationNameInfo &MemberNameInfo,
2172 ValueDecl *Member,
2173 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002174 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002175 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002176 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2177 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002178 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002179 // We have a reference to an unnamed field. This is always the
2180 // base of an anonymous struct/union member access, i.e. the
2181 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002182 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002183 assert(Member->getType()->isRecordType() &&
2184 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002185
Richard Smithcab9a7d2011-10-26 19:06:56 +00002186 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002187 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002188 QualifierLoc.getNestedNameSpecifier(),
2189 FoundDecl, Member);
2190 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002191 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002192 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002193 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002194 MemberExpr *ME = new (getSema().Context)
2195 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2196 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002197 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002200 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002201 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002202
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002203 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002204 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002205
John McCall16df1e52010-03-30 21:47:33 +00002206 // FIXME: this involves duplicating earlier analysis in a lot of
2207 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002208 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002209 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002210 R.resolveKind();
2211
John McCallb268a282010-08-23 23:25:46 +00002212 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002213 SS, TemplateKWLoc,
2214 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002215 R, ExplicitTemplateArgs,
2216 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 }
Mike Stump11289f42009-09-09 15:08:12 +00002218
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002220 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002223 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002224 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002225 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002226 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002227 }
2228
2229 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002230 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002233 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002234 SourceLocation QuestionLoc,
2235 Expr *LHS,
2236 SourceLocation ColonLoc,
2237 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002238 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2239 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 }
2241
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002243 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 /// By default, performs semantic analysis to build the new expression.
2245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002246 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002247 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002249 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002250 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002251 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 }
Mike Stump11289f42009-09-09 15:08:12 +00002253
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002255 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002258 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002259 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002261 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002262 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002263 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002264 }
Mike Stump11289f42009-09-09 15:08:12 +00002265
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002267 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002270 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 SourceLocation OpLoc,
2272 SourceLocation AccessorLoc,
2273 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002274
John McCall10eae182009-11-30 22:42:35 +00002275 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002276 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002277 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002278 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002279 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002280 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002281 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002282 /* TemplateArgs */ nullptr,
2283 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
Mike Stump11289f42009-09-09 15:08:12 +00002285
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002287 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002290 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002291 MultiExprArg Inits,
2292 SourceLocation RBraceLoc,
2293 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002294 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002295 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002296 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002297 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002298
Douglas Gregord3d93062009-11-09 17:16:50 +00002299 // Patch in the result type we were given, which may have been computed
2300 // when the initial InitListExpr was built.
2301 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2302 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002303 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 }
Mike Stump11289f42009-09-09 15:08:12 +00002305
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002307 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002310 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 MultiExprArg ArrayExprs,
2312 SourceLocation EqualOrColonLoc,
2313 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002314 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002315 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002316 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002317 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002319 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002320
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002321 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregora16548e2009-08-11 05:31:07 +00002324 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002325 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 /// By default, builds the implicit value initialization without performing
2327 /// any semantic analysis. Subclasses may override this routine to provide
2328 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002330 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 }
Mike Stump11289f42009-09-09 15:08:12 +00002332
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002334 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 /// By default, performs semantic analysis to build the new expression.
2336 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002337 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002338 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002339 SourceLocation RParenLoc) {
2340 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002341 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002342 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 }
2344
2345 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002346 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 /// By default, performs semantic analysis to build the new expression.
2348 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002349 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002350 MultiExprArg SubExprs,
2351 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002352 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 }
Mike Stump11289f42009-09-09 15:08:12 +00002354
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002356 ///
2357 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 /// rather than attempting to map the label statement itself.
2359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002361 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002362 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 }
Mike Stump11289f42009-09-09 15:08:12 +00002364
Douglas Gregora16548e2009-08-11 05:31:07 +00002365 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002366 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002369 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002370 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002372 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002373 }
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 /// \brief Build a new __builtin_choose_expr expression.
2376 ///
2377 /// By default, performs semantic analysis to build the new expression.
2378 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002379 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002380 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 SourceLocation RParenLoc) {
2382 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002383 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 RParenLoc);
2385 }
Mike Stump11289f42009-09-09 15:08:12 +00002386
Peter Collingbourne91147592011-04-15 00:35:48 +00002387 /// \brief Build a new generic selection expression.
2388 ///
2389 /// By default, performs semantic analysis to build the new expression.
2390 /// Subclasses may override this routine to provide different behavior.
2391 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2392 SourceLocation DefaultLoc,
2393 SourceLocation RParenLoc,
2394 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002395 ArrayRef<TypeSourceInfo *> Types,
2396 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002397 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002398 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002399 }
2400
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 /// \brief Build a new overloaded operator call expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// The semantic analysis provides the behavior of template instantiation,
2405 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002406 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 /// argument-dependent lookup, etc. Subclasses may override this routine to
2408 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002409 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002411 Expr *Callee,
2412 Expr *First,
2413 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002414
2415 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 /// reinterpret_cast.
2417 ///
2418 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002419 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002421 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 Stmt::StmtClass Class,
2423 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002424 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 SourceLocation RAngleLoc,
2426 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002427 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 SourceLocation RParenLoc) {
2429 switch (Class) {
2430 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002431 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002432 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002433 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002434
2435 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002436 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002437 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002438 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002441 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002442 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002443 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002445
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002447 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002448 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002449 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002450
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002452 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002453 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 }
Mike Stump11289f42009-09-09 15:08:12 +00002455
Douglas Gregora16548e2009-08-11 05:31:07 +00002456 /// \brief Build a new C++ static_cast expression.
2457 ///
2458 /// By default, performs semantic analysis to build the new expression.
2459 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002460 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002462 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 SourceLocation RAngleLoc,
2464 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002465 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002467 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002468 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002469 SourceRange(LAngleLoc, RAngleLoc),
2470 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 }
2472
2473 /// \brief Build a new C++ dynamic_cast expression.
2474 ///
2475 /// By default, performs semantic analysis to build the new expression.
2476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002479 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 SourceLocation RAngleLoc,
2481 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002482 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002484 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002485 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002486 SourceRange(LAngleLoc, RAngleLoc),
2487 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
2489
2490 /// \brief Build a new C++ reinterpret_cast expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002494 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002496 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 SourceLocation RAngleLoc,
2498 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002499 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002501 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002502 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002503 SourceRange(LAngleLoc, RAngleLoc),
2504 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 }
2506
2507 /// \brief Build a new C++ const_cast expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002511 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002513 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 SourceLocation RAngleLoc,
2515 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002516 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002517 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002518 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002519 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002520 SourceRange(LAngleLoc, RAngleLoc),
2521 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
Mike Stump11289f42009-09-09 15:08:12 +00002523
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 /// \brief Build a new C++ functional-style cast expression.
2525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002528 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2529 SourceLocation LParenLoc,
2530 Expr *Sub,
2531 SourceLocation RParenLoc) {
2532 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002533 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 RParenLoc);
2535 }
Mike Stump11289f42009-09-09 15:08:12 +00002536
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 /// \brief Build a new C++ typeid(type) expression.
2538 ///
2539 /// By default, performs semantic analysis to build the new expression.
2540 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002541 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002542 SourceLocation TypeidLoc,
2543 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002545 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002546 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002547 }
Mike Stump11289f42009-09-09 15:08:12 +00002548
Francois Pichet9f4f2072010-09-08 12:20:18 +00002549
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 /// \brief Build a new C++ typeid(expr) expression.
2551 ///
2552 /// By default, performs semantic analysis to build the new expression.
2553 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002554 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002555 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002556 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002558 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002559 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002560 }
2561
Francois Pichet9f4f2072010-09-08 12:20:18 +00002562 /// \brief Build a new C++ __uuidof(type) expression.
2563 ///
2564 /// By default, performs semantic analysis to build the new expression.
2565 /// Subclasses may override this routine to provide different behavior.
2566 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2567 SourceLocation TypeidLoc,
2568 TypeSourceInfo *Operand,
2569 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002570 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002571 RParenLoc);
2572 }
2573
2574 /// \brief Build a new C++ __uuidof(expr) expression.
2575 ///
2576 /// By default, performs semantic analysis to build the new expression.
2577 /// Subclasses may override this routine to provide different behavior.
2578 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2579 SourceLocation TypeidLoc,
2580 Expr *Operand,
2581 SourceLocation RParenLoc) {
2582 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2583 RParenLoc);
2584 }
2585
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 /// \brief Build a new C++ "this" expression.
2587 ///
2588 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002589 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002591 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002592 QualType ThisType,
2593 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002594 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002595 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002596 }
2597
2598 /// \brief Build a new C++ throw expression.
2599 ///
2600 /// By default, performs semantic analysis to build the new expression.
2601 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002602 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2603 bool IsThrownVariableInScope) {
2604 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 }
2606
2607 /// \brief Build a new C++ default-argument expression.
2608 ///
2609 /// By default, builds a new default-argument expression, which does not
2610 /// require any semantic analysis. Subclasses may override this routine to
2611 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002612 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002613 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002614 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002615 }
2616
Richard Smith852c9db2013-04-20 22:23:05 +00002617 /// \brief Build a new C++11 default-initialization expression.
2618 ///
2619 /// By default, builds a new default field initialization expression, which
2620 /// does not require any semantic analysis. Subclasses may override this
2621 /// routine to provide different behavior.
2622 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2623 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002624 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002625 }
2626
Douglas Gregora16548e2009-08-11 05:31:07 +00002627 /// \brief Build a new C++ zero-initialization expression.
2628 ///
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002631 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2632 SourceLocation LParenLoc,
2633 SourceLocation RParenLoc) {
2634 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002635 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002636 }
Mike Stump11289f42009-09-09 15:08:12 +00002637
Douglas Gregora16548e2009-08-11 05:31:07 +00002638 /// \brief Build a new C++ "new" expression.
2639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002642 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002643 bool UseGlobal,
2644 SourceLocation PlacementLParen,
2645 MultiExprArg PlacementArgs,
2646 SourceLocation PlacementRParen,
2647 SourceRange TypeIdParens,
2648 QualType AllocatedType,
2649 TypeSourceInfo *AllocatedTypeInfo,
2650 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002651 SourceRange DirectInitRange,
2652 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002653 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002654 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002655 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002656 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002657 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002658 AllocatedType,
2659 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002660 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002661 DirectInitRange,
2662 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002663 }
Mike Stump11289f42009-09-09 15:08:12 +00002664
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 /// \brief Build a new C++ "delete" expression.
2666 ///
2667 /// By default, performs semantic analysis to build the new expression.
2668 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002669 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002670 bool IsGlobalDelete,
2671 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002672 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002674 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 }
Mike Stump11289f42009-09-09 15:08:12 +00002676
Douglas Gregor29c42f22012-02-24 07:38:34 +00002677 /// \brief Build a new type trait expression.
2678 ///
2679 /// By default, performs semantic analysis to build the new expression.
2680 /// Subclasses may override this routine to provide different behavior.
2681 ExprResult RebuildTypeTrait(TypeTrait Trait,
2682 SourceLocation StartLoc,
2683 ArrayRef<TypeSourceInfo *> Args,
2684 SourceLocation RParenLoc) {
2685 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2686 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002687
John Wiegley6242b6a2011-04-28 00:16:57 +00002688 /// \brief Build a new array type trait expression.
2689 ///
2690 /// By default, performs semantic analysis to build the new expression.
2691 /// Subclasses may override this routine to provide different behavior.
2692 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2693 SourceLocation StartLoc,
2694 TypeSourceInfo *TSInfo,
2695 Expr *DimExpr,
2696 SourceLocation RParenLoc) {
2697 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2698 }
2699
John Wiegleyf9f65842011-04-25 06:54:41 +00002700 /// \brief Build a new expression trait expression.
2701 ///
2702 /// By default, performs semantic analysis to build the new expression.
2703 /// Subclasses may override this routine to provide different behavior.
2704 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2705 SourceLocation StartLoc,
2706 Expr *Queried,
2707 SourceLocation RParenLoc) {
2708 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2709 }
2710
Mike Stump11289f42009-09-09 15:08:12 +00002711 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002712 /// expression.
2713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002716 ExprResult RebuildDependentScopeDeclRefExpr(
2717 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002718 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002719 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002720 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002721 bool IsAddressOfOperand,
2722 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002724 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002725
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002726 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002727 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2728 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002729
Reid Kleckner32506ed2014-06-12 23:03:48 +00002730 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002731 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 }
2733
2734 /// \brief Build a new template-id expression.
2735 ///
2736 /// By default, performs semantic analysis to build the new expression.
2737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002738 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002739 SourceLocation TemplateKWLoc,
2740 LookupResult &R,
2741 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002742 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002743 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2744 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002745 }
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.
John McCalldadc5752010-08-24 06:29:42 +00002751 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002752 SourceLocation Loc,
2753 CXXConstructorDecl *Constructor,
2754 bool IsElidable,
2755 MultiExprArg Args,
2756 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002757 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002758 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002759 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002760 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002761 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002762 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002763 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002764 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002765 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002766
Richard Smithc83bf822016-06-10 00:58:19 +00002767 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002768 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002769 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002770 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002771 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002772 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002773 RequiresZeroInit, ConstructKind,
2774 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 }
2776
Richard Smith5179eb72016-06-28 19:03:57 +00002777 /// \brief Build a new implicit construction via inherited constructor
2778 /// expression.
2779 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2780 CXXConstructorDecl *Constructor,
2781 bool ConstructsVBase,
2782 bool InheritedFromVBase) {
2783 return new (getSema().Context) CXXInheritedCtorInitExpr(
2784 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2785 }
2786
Douglas Gregora16548e2009-08-11 05:31:07 +00002787 /// \brief Build a new object-construction expression.
2788 ///
2789 /// By default, performs semantic analysis to build the new expression.
2790 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002791 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2792 SourceLocation LParenLoc,
2793 MultiExprArg Args,
2794 SourceLocation RParenLoc) {
2795 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002796 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002797 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002798 RParenLoc);
2799 }
2800
2801 /// \brief Build a new object-construction expression.
2802 ///
2803 /// By default, performs semantic analysis to build the new expression.
2804 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002805 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2806 SourceLocation LParenLoc,
2807 MultiExprArg Args,
2808 SourceLocation RParenLoc) {
2809 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002810 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002811 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002812 RParenLoc);
2813 }
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregora16548e2009-08-11 05:31:07 +00002815 /// \brief Build a new member reference expression.
2816 ///
2817 /// By default, performs semantic analysis to build the new expression.
2818 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002819 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002820 QualType BaseType,
2821 bool IsArrow,
2822 SourceLocation OperatorLoc,
2823 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002824 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002825 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002826 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002827 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002828 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002829 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002830
John McCallb268a282010-08-23 23:25:46 +00002831 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002832 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002833 SS, TemplateKWLoc,
2834 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002835 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002836 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002837 }
2838
John McCall10eae182009-11-30 22:42:35 +00002839 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002840 ///
2841 /// By default, performs semantic analysis to build the new expression.
2842 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002843 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2844 SourceLocation OperatorLoc,
2845 bool IsArrow,
2846 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002847 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002848 NamedDecl *FirstQualifierInScope,
2849 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002850 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002851 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002852 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002853
John McCallb268a282010-08-23 23:25:46 +00002854 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002855 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002856 SS, TemplateKWLoc,
2857 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002858 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002859 }
Mike Stump11289f42009-09-09 15:08:12 +00002860
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002861 /// \brief Build a new noexcept expression.
2862 ///
2863 /// By default, performs semantic analysis to build the new expression.
2864 /// Subclasses may override this routine to provide different behavior.
2865 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2866 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2867 }
2868
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002869 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002870 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2871 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002872 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002873 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002874 Optional<unsigned> Length,
2875 ArrayRef<TemplateArgument> PartialArgs) {
2876 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2877 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002878 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002879
Patrick Beard0caa3942012-04-19 00:25:12 +00002880 /// \brief Build a new Objective-C boxed expression.
2881 ///
2882 /// By default, performs semantic analysis to build the new expression.
2883 /// Subclasses may override this routine to provide different behavior.
2884 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2885 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2886 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002887
Ted Kremeneke65b0862012-03-06 20:05:56 +00002888 /// \brief Build a new Objective-C array literal.
2889 ///
2890 /// By default, performs semantic analysis to build the new expression.
2891 /// Subclasses may override this routine to provide different behavior.
2892 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2893 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002894 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002895 MultiExprArg(Elements, NumElements));
2896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002897
2898 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002899 Expr *Base, Expr *Key,
2900 ObjCMethodDecl *getterMethod,
2901 ObjCMethodDecl *setterMethod) {
2902 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2903 getterMethod, setterMethod);
2904 }
2905
2906 /// \brief Build a new Objective-C dictionary literal.
2907 ///
2908 /// By default, performs semantic analysis to build the new expression.
2909 /// Subclasses may override this routine to provide different behavior.
2910 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002911 MutableArrayRef<ObjCDictionaryElement> Elements) {
2912 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002913 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
James Dennett2a4d13c2012-06-15 07:13:21 +00002915 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002916 ///
2917 /// By default, performs semantic analysis to build the new expression.
2918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002919 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002920 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002921 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002922 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002923 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002924
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002925 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002926 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002927 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002928 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002929 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002930 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002931 MultiExprArg Args,
2932 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002933 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2934 ReceiverTypeInfo->getType(),
2935 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002936 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002937 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002938 }
2939
2940 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002941 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002942 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002943 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002944 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002945 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002946 MultiExprArg Args,
2947 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002948 return SemaRef.BuildInstanceMessage(Receiver,
2949 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002950 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002951 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002952 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002953 }
2954
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002955 /// \brief Build a new Objective-C instance/class message to 'super'.
2956 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2957 Selector Sel,
2958 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002959 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002960 ObjCMethodDecl *Method,
2961 SourceLocation LBracLoc,
2962 MultiExprArg Args,
2963 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002964 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002965 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002966 SuperLoc,
2967 Sel, Method, LBracLoc, SelectorLocs,
2968 RBracLoc, Args)
2969 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002970 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002971 SuperLoc,
2972 Sel, Method, LBracLoc, SelectorLocs,
2973 RBracLoc, Args);
2974
2975
2976 }
2977
Douglas Gregord51d90d2010-04-26 20:11:03 +00002978 /// \brief Build a new Objective-C ivar reference 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 RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002983 SourceLocation IvarLoc,
2984 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002985 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002986 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00002987 ExprResult Result = getSema().BuildMemberReferenceExpr(
2988 BaseArg, BaseArg->getType(),
2989 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
2990 /*FirstQualifierInScope=*/nullptr, NameInfo,
2991 /*TemplateArgs=*/nullptr,
2992 /*S=*/nullptr);
2993 if (IsFreeIvar && Result.isUsable())
2994 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
2995 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002996 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002997
2998 /// \brief Build a new Objective-C property reference expression.
2999 ///
3000 /// By default, performs semantic analysis to build the new expression.
3001 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003002 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003003 ObjCPropertyDecl *Property,
3004 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003005 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003006 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3007 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3008 /*FIXME:*/PropertyLoc,
3009 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003010 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003011 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003012 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003013 /*TemplateArgs=*/nullptr,
3014 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003016
John McCallb7bd14f2010-12-02 01:19:52 +00003017 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003018 ///
3019 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003020 /// Subclasses may override this routine to provide different behavior.
3021 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3022 ObjCMethodDecl *Getter,
3023 ObjCMethodDecl *Setter,
3024 SourceLocation PropertyLoc) {
3025 // Since these expressions can only be value-dependent, we do not
3026 // need to perform semantic analysis again.
3027 return Owned(
3028 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3029 VK_LValue, OK_ObjCProperty,
3030 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003031 }
3032
Douglas Gregord51d90d2010-04-26 20:11:03 +00003033 /// \brief Build a new Objective-C "isa" expression.
3034 ///
3035 /// By default, performs semantic analysis to build the new expression.
3036 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003037 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003038 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003039 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003040 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3041 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003042 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003043 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003044 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003045 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003046 /*TemplateArgs=*/nullptr,
3047 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003048 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003049
Douglas Gregora16548e2009-08-11 05:31:07 +00003050 /// \brief Build a new shuffle vector expression.
3051 ///
3052 /// By default, performs semantic analysis to build the new expression.
3053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003054 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003055 MultiExprArg SubExprs,
3056 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003057 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003058 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003059 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3060 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3061 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003062 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003063
Douglas Gregora16548e2009-08-11 05:31:07 +00003064 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003065 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003066 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3067 SemaRef.Context.BuiltinFnTy,
3068 VK_RValue, BuiltinLoc);
3069 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3070 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003071 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003072
3073 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003074 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003075 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003076 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003077
Douglas Gregora16548e2009-08-11 05:31:07 +00003078 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003079 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003080 }
John McCall31f82722010-11-12 08:19:04 +00003081
Hal Finkelc4d7c822013-09-18 03:29:45 +00003082 /// \brief Build a new convert vector expression.
3083 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3084 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3085 SourceLocation RParenLoc) {
3086 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3087 BuiltinLoc, RParenLoc);
3088 }
3089
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003090 /// \brief Build a new template argument pack expansion.
3091 ///
3092 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003093 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003094 /// different behavior.
3095 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003096 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003097 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003098 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003099 case TemplateArgument::Expression: {
3100 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003101 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3102 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003103 if (Result.isInvalid())
3104 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003105
Douglas Gregor98318c22011-01-03 21:37:45 +00003106 return TemplateArgumentLoc(Result.get(), Result.get());
3107 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003108
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003109 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003110 return TemplateArgumentLoc(TemplateArgument(
3111 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003112 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003113 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003114 Pattern.getTemplateNameLoc(),
3115 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003117 case TemplateArgument::Null:
3118 case TemplateArgument::Integral:
3119 case TemplateArgument::Declaration:
3120 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003121 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003122 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003123 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003125 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003126 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003127 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003128 EllipsisLoc,
3129 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003130 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3131 Expansion);
3132 break;
3133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003134
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003135 return TemplateArgumentLoc();
3136 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003137
Douglas Gregor968f23a2011-01-03 19:31:53 +00003138 /// \brief Build a new expression pack expansion.
3139 ///
3140 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003141 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003142 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003143 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003144 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003145 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003146 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003147
Richard Smith0f0af192014-11-08 05:07:16 +00003148 /// \brief Build a new C++1z fold-expression.
3149 ///
3150 /// By default, performs semantic analysis in order to build a new fold
3151 /// expression.
3152 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3153 BinaryOperatorKind Operator,
3154 SourceLocation EllipsisLoc, Expr *RHS,
3155 SourceLocation RParenLoc) {
3156 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3157 RHS, RParenLoc);
3158 }
3159
3160 /// \brief Build an empty C++1z fold-expression with the given operator.
3161 ///
3162 /// By default, produces the fallback value for the fold-expression, or
3163 /// produce an error if there is no fallback value.
3164 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3165 BinaryOperatorKind Operator) {
3166 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3167 }
3168
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003169 /// \brief Build a new atomic operation expression.
3170 ///
3171 /// By default, performs semantic analysis to build the new expression.
3172 /// Subclasses may override this routine to provide different behavior.
3173 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3174 MultiExprArg SubExprs,
3175 QualType RetTy,
3176 AtomicExpr::AtomicOp Op,
3177 SourceLocation RParenLoc) {
3178 // Just create the expression; there is not any interesting semantic
3179 // analysis here because we can't actually build an AtomicExpr until
3180 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003181 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003182 RParenLoc);
3183 }
3184
John McCall31f82722010-11-12 08:19:04 +00003185private:
Douglas Gregor14454802011-02-25 02:25:35 +00003186 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3187 QualType ObjectType,
3188 NamedDecl *FirstQualifierInScope,
3189 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003190
3191 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3192 QualType ObjectType,
3193 NamedDecl *FirstQualifierInScope,
3194 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003195
3196 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3197 NamedDecl *FirstQualifierInScope,
3198 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003199
3200 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3201 DependentNameTypeLoc TL,
3202 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203};
Douglas Gregora16548e2009-08-11 05:31:07 +00003204
Douglas Gregorebe10102009-08-20 07:17:43 +00003205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003206StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003207 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003208 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003209
Douglas Gregorebe10102009-08-20 07:17:43 +00003210 switch (S->getStmtClass()) {
3211 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregorebe10102009-08-20 07:17:43 +00003213 // Transform individual statement nodes
3214#define STMT(Node, Parent) \
3215 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003216#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003217#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003218#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003219
Douglas Gregorebe10102009-08-20 07:17:43 +00003220 // Transform expressions by calling TransformExpr.
3221#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003222#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003223#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003224#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003225 {
John McCalldadc5752010-08-24 06:29:42 +00003226 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003227 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003228 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003229
Richard Smith945f8d32013-01-14 22:39:08 +00003230 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003231 }
Mike Stump11289f42009-09-09 15:08:12 +00003232 }
3233
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003234 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003235}
Mike Stump11289f42009-09-09 15:08:12 +00003236
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003237template<typename Derived>
3238OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3239 if (!S)
3240 return S;
3241
3242 switch (S->getClauseKind()) {
3243 default: break;
3244 // Transform individual clause nodes
3245#define OPENMP_CLAUSE(Name, Class) \
3246 case OMPC_ ## Name : \
3247 return getDerived().Transform ## Class(cast<Class>(S));
3248#include "clang/Basic/OpenMPKinds.def"
3249 }
3250
3251 return S;
3252}
3253
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregore922c772009-08-04 22:27:00 +00003255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003256ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003257 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003258 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003259
3260 switch (E->getStmtClass()) {
3261 case Stmt::NoStmtClass: break;
3262#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003263#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003264#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003265 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003266#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003267 }
3268
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003269 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003270}
3271
3272template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003273ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003274 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003275 // Initializers are instantiated like expressions, except that various outer
3276 // layers are stripped.
3277 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003278 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003279
3280 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3281 Init = ExprTemp->getSubExpr();
3282
Richard Smith410306b2016-12-12 02:53:20 +00003283 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3284 Init = AIL->getCommonExpr();
3285
Richard Smithe6ca4752013-05-30 22:40:16 +00003286 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3287 Init = MTE->GetTemporaryExpr();
3288
Richard Smithd59b8322012-12-19 01:39:02 +00003289 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3290 Init = Binder->getSubExpr();
3291
3292 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3293 Init = ICE->getSubExprAsWritten();
3294
Richard Smithcc1b96d2013-06-12 22:31:48 +00003295 if (CXXStdInitializerListExpr *ILE =
3296 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003297 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003298
Richard Smithc6abd962014-07-25 01:12:44 +00003299 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003300 // InitListExprs. Other forms of copy-initialization will be a no-op if
3301 // the initializer is already the right type.
3302 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003303 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003304 return getDerived().TransformExpr(Init);
3305
3306 // Revert value-initialization back to empty parens.
3307 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3308 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003309 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003310 Parens.getEnd());
3311 }
3312
3313 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3314 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003315 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003316 SourceLocation());
3317
3318 // Revert initialization by constructor back to a parenthesized or braced list
3319 // of expressions. Any other form of initializer can just be reused directly.
3320 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003321 return getDerived().TransformExpr(Init);
3322
Richard Smithf8adcdc2014-07-17 05:12:35 +00003323 // If the initialization implicitly converted an initializer list to a
3324 // std::initializer_list object, unwrap the std::initializer_list too.
3325 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003326 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003327
Richard Smithd59b8322012-12-19 01:39:02 +00003328 SmallVector<Expr*, 8> NewArgs;
3329 bool ArgChanged = false;
3330 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003331 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003332 return ExprError();
3333
3334 // If this was list initialization, revert to list form.
3335 if (Construct->isListInitialization())
3336 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3337 Construct->getLocEnd(),
3338 Construct->getType());
3339
Richard Smithd59b8322012-12-19 01:39:02 +00003340 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003341 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003342 if (Parens.isInvalid()) {
3343 // This was a variable declaration's initialization for which no initializer
3344 // was specified.
3345 assert(NewArgs.empty() &&
3346 "no parens or braces but have direct init with arguments?");
3347 return ExprEmpty();
3348 }
Richard Smithd59b8322012-12-19 01:39:02 +00003349 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3350 Parens.getEnd());
3351}
3352
3353template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003354bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003355 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003356 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003357 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003358 bool *ArgChanged) {
3359 for (unsigned I = 0; I != NumInputs; ++I) {
3360 // If requested, drop call arguments that need to be dropped.
3361 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3362 if (ArgChanged)
3363 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003364
Douglas Gregora3efea12011-01-03 19:04:46 +00003365 break;
3366 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003367
Douglas Gregor968f23a2011-01-03 19:31:53 +00003368 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3369 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003370
Chris Lattner01cf8db2011-07-20 06:58:45 +00003371 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003372 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3373 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003374
Douglas Gregor968f23a2011-01-03 19:31:53 +00003375 // Determine whether the set of unexpanded parameter packs can and should
3376 // be expanded.
3377 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003378 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003379 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3380 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003381 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3382 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003383 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003384 Expand, RetainExpansion,
3385 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003386 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor968f23a2011-01-03 19:31:53 +00003388 if (!Expand) {
3389 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003390 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003391 // expansion.
3392 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3393 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3394 if (OutPattern.isInvalid())
3395 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003396
3397 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003398 Expansion->getEllipsisLoc(),
3399 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003400 if (Out.isInvalid())
3401 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor968f23a2011-01-03 19:31:53 +00003403 if (ArgChanged)
3404 *ArgChanged = true;
3405 Outputs.push_back(Out.get());
3406 continue;
3407 }
John McCall542e7c62011-07-06 07:30:07 +00003408
3409 // Record right away that the argument was changed. This needs
3410 // to happen even if the array expands to nothing.
3411 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003412
Douglas Gregor968f23a2011-01-03 19:31:53 +00003413 // The transform has determined that we should perform an elementwise
3414 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003415 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003416 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3417 ExprResult Out = getDerived().TransformExpr(Pattern);
3418 if (Out.isInvalid())
3419 return true;
3420
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003421 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003422 Out = getDerived().RebuildPackExpansion(
3423 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003424 if (Out.isInvalid())
3425 return true;
3426 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003427
Douglas Gregor968f23a2011-01-03 19:31:53 +00003428 Outputs.push_back(Out.get());
3429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003430
Richard Smith9467be42014-06-06 17:33:35 +00003431 // If we're supposed to retain a pack expansion, do so by temporarily
3432 // forgetting the partially-substituted parameter pack.
3433 if (RetainExpansion) {
3434 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3435
3436 ExprResult Out = getDerived().TransformExpr(Pattern);
3437 if (Out.isInvalid())
3438 return true;
3439
3440 Out = getDerived().RebuildPackExpansion(
3441 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3442 if (Out.isInvalid())
3443 return true;
3444
3445 Outputs.push_back(Out.get());
3446 }
3447
Douglas Gregor968f23a2011-01-03 19:31:53 +00003448 continue;
3449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Richard Smithd59b8322012-12-19 01:39:02 +00003451 ExprResult Result =
3452 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3453 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003454 if (Result.isInvalid())
3455 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregora3efea12011-01-03 19:04:46 +00003457 if (Result.get() != Inputs[I] && ArgChanged)
3458 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
3460 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003461 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregora3efea12011-01-03 19:04:46 +00003463 return false;
3464}
3465
Richard Smith03a4aa32016-06-23 19:02:52 +00003466template <typename Derived>
3467Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3468 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3469 if (Var) {
3470 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3471 getDerived().TransformDefinition(Var->getLocation(), Var));
3472
3473 if (!ConditionVar)
3474 return Sema::ConditionError();
3475
3476 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3477 }
3478
3479 if (Expr) {
3480 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3481
3482 if (CondExpr.isInvalid())
3483 return Sema::ConditionError();
3484
3485 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3486 }
3487
3488 return Sema::ConditionResult();
3489}
3490
Douglas Gregora3efea12011-01-03 19:04:46 +00003491template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003492NestedNameSpecifierLoc
3493TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3494 NestedNameSpecifierLoc NNS,
3495 QualType ObjectType,
3496 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003497 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003499 Qualifier = Qualifier.getPrefix())
3500 Qualifiers.push_back(Qualifier);
3501
3502 CXXScopeSpec SS;
3503 while (!Qualifiers.empty()) {
3504 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3505 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003506
Douglas Gregor14454802011-02-25 02:25:35 +00003507 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003508 case NestedNameSpecifier::Identifier: {
3509 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3510 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3511 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3512 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003513 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003514 }
Douglas Gregor14454802011-02-25 02:25:35 +00003515 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Douglas Gregor14454802011-02-25 02:25:35 +00003517 case NestedNameSpecifier::Namespace: {
3518 NamespaceDecl *NS
3519 = cast_or_null<NamespaceDecl>(
3520 getDerived().TransformDecl(
3521 Q.getLocalBeginLoc(),
3522 QNNS->getAsNamespace()));
3523 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3524 break;
3525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003526
Douglas Gregor14454802011-02-25 02:25:35 +00003527 case NestedNameSpecifier::NamespaceAlias: {
3528 NamespaceAliasDecl *Alias
3529 = cast_or_null<NamespaceAliasDecl>(
3530 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3531 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003532 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003533 Q.getLocalEndLoc());
3534 break;
3535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Douglas Gregor14454802011-02-25 02:25:35 +00003537 case NestedNameSpecifier::Global:
3538 // There is no meaningful transformation that one could perform on the
3539 // global scope.
3540 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3541 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Nikola Smiljanic67860242014-09-26 00:28:20 +00003543 case NestedNameSpecifier::Super: {
3544 CXXRecordDecl *RD =
3545 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3546 SourceLocation(), QNNS->getAsRecordDecl()));
3547 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3548 break;
3549 }
3550
Douglas Gregor14454802011-02-25 02:25:35 +00003551 case NestedNameSpecifier::TypeSpecWithTemplate:
3552 case NestedNameSpecifier::TypeSpec: {
3553 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3554 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003555
Douglas Gregor14454802011-02-25 02:25:35 +00003556 if (!TL)
3557 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003558
Douglas Gregor14454802011-02-25 02:25:35 +00003559 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003560 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003561 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003562 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003563 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003564 if (TL.getType()->isEnumeralType())
3565 SemaRef.Diag(TL.getBeginLoc(),
3566 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003567 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3568 Q.getLocalEndLoc());
3569 break;
3570 }
Richard Trieude756fb2011-05-07 01:36:37 +00003571 // If the nested-name-specifier is an invalid type def, don't emit an
3572 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003573 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3574 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003575 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003576 << TL.getType() << SS.getRange();
3577 }
Douglas Gregor14454802011-02-25 02:25:35 +00003578 return NestedNameSpecifierLoc();
3579 }
Douglas Gregore16af532011-02-28 18:50:33 +00003580 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003581
Douglas Gregore16af532011-02-28 18:50:33 +00003582 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003583 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003584 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003585 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003586
Douglas Gregor14454802011-02-25 02:25:35 +00003587 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003588 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003589 !getDerived().AlwaysRebuild())
3590 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
3592 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003593 // nested-name-specifier, do so.
3594 if (SS.location_size() == NNS.getDataLength() &&
3595 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3596 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3597
3598 // Allocate new nested-name-specifier location information.
3599 return SS.getWithLocInContext(SemaRef.Context);
3600}
3601
3602template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003603DeclarationNameInfo
3604TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003605::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003606 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003607 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003608 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003609
3610 switch (Name.getNameKind()) {
3611 case DeclarationName::Identifier:
3612 case DeclarationName::ObjCZeroArgSelector:
3613 case DeclarationName::ObjCOneArgSelector:
3614 case DeclarationName::ObjCMultiArgSelector:
3615 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003616 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003617 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003618 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003619
Richard Smith35845152017-02-07 01:37:30 +00003620 case DeclarationName::CXXDeductionGuideName: {
3621 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3622 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3623 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3624 if (!NewTemplate)
3625 return DeclarationNameInfo();
3626
3627 DeclarationNameInfo NewNameInfo(NameInfo);
3628 NewNameInfo.setName(
3629 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3630 return NewNameInfo;
3631 }
3632
Douglas Gregorf816bd72009-09-03 22:13:48 +00003633 case DeclarationName::CXXConstructorName:
3634 case DeclarationName::CXXDestructorName:
3635 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003636 TypeSourceInfo *NewTInfo;
3637 CanQualType NewCanTy;
3638 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003639 NewTInfo = getDerived().TransformType(OldTInfo);
3640 if (!NewTInfo)
3641 return DeclarationNameInfo();
3642 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003643 }
3644 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003645 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003646 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003647 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003648 if (NewT.isNull())
3649 return DeclarationNameInfo();
3650 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3651 }
Mike Stump11289f42009-09-09 15:08:12 +00003652
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003653 DeclarationName NewName
3654 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3655 NewCanTy);
3656 DeclarationNameInfo NewNameInfo(NameInfo);
3657 NewNameInfo.setName(NewName);
3658 NewNameInfo.setNamedTypeInfo(NewTInfo);
3659 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003660 }
Mike Stump11289f42009-09-09 15:08:12 +00003661 }
3662
David Blaikie83d382b2011-09-23 05:06:16 +00003663 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003664}
3665
3666template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003667TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003668TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3669 TemplateName Name,
3670 SourceLocation NameLoc,
3671 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003672 NamedDecl *FirstQualifierInScope,
3673 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003674 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3675 TemplateDecl *Template = QTN->getTemplateDecl();
3676 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
Douglas Gregor9db53502011-03-02 18:07:45 +00003678 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003679 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003680 Template));
3681 if (!TransTemplate)
3682 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003683
Douglas Gregor9db53502011-03-02 18:07:45 +00003684 if (!getDerived().AlwaysRebuild() &&
3685 SS.getScopeRep() == QTN->getQualifier() &&
3686 TransTemplate == Template)
3687 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor9db53502011-03-02 18:07:45 +00003689 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3690 TransTemplate);
3691 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregor9db53502011-03-02 18:07:45 +00003693 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3694 if (SS.getScopeRep()) {
3695 // These apply to the scope specifier, not the template.
3696 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003697 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698 }
3699
Douglas Gregor9db53502011-03-02 18:07:45 +00003700 if (!getDerived().AlwaysRebuild() &&
3701 SS.getScopeRep() == DTN->getQualifier() &&
3702 ObjectType.isNull())
3703 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003704
Douglas Gregor9db53502011-03-02 18:07:45 +00003705 if (DTN->isIdentifier()) {
3706 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003707 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003708 NameLoc,
3709 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003710 FirstQualifierInScope,
3711 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003713
Douglas Gregor9db53502011-03-02 18:07:45 +00003714 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003715 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor9db53502011-03-02 18:07:45 +00003718 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3719 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003720 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003721 Template));
3722 if (!TransTemplate)
3723 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
Douglas Gregor9db53502011-03-02 18:07:45 +00003725 if (!getDerived().AlwaysRebuild() &&
3726 TransTemplate == Template)
3727 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregor9db53502011-03-02 18:07:45 +00003729 return TemplateName(TransTemplate);
3730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003731
Douglas Gregor9db53502011-03-02 18:07:45 +00003732 if (SubstTemplateTemplateParmPackStorage *SubstPack
3733 = Name.getAsSubstTemplateTemplateParmPack()) {
3734 TemplateTemplateParmDecl *TransParam
3735 = cast_or_null<TemplateTemplateParmDecl>(
3736 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3737 if (!TransParam)
3738 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
Douglas Gregor9db53502011-03-02 18:07:45 +00003740 if (!getDerived().AlwaysRebuild() &&
3741 TransParam == SubstPack->getParameterPack())
3742 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
3744 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003745 SubstPack->getArgumentPack());
3746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003747
Douglas Gregor9db53502011-03-02 18:07:45 +00003748 // These should be getting filtered out before they reach the AST.
3749 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003750}
3751
3752template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003753void TreeTransform<Derived>::InventTemplateArgumentLoc(
3754 const TemplateArgument &Arg,
3755 TemplateArgumentLoc &Output) {
3756 SourceLocation Loc = getDerived().getBaseLocation();
3757 switch (Arg.getKind()) {
3758 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003759 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003760 break;
3761
3762 case TemplateArgument::Type:
3763 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003764 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003765
John McCall0ad16662009-10-29 08:12:44 +00003766 break;
3767
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003768 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003769 case TemplateArgument::TemplateExpansion: {
3770 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003771 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003772 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3773 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3774 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3775 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
Douglas Gregor9d802122011-03-02 17:09:35 +00003777 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003778 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003779 Builder.getWithLocInContext(SemaRef.Context),
3780 Loc);
3781 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003782 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003783 Builder.getWithLocInContext(SemaRef.Context),
3784 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003785
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003786 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003787 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003788
John McCall0ad16662009-10-29 08:12:44 +00003789 case TemplateArgument::Expression:
3790 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3791 break;
3792
3793 case TemplateArgument::Declaration:
3794 case TemplateArgument::Integral:
3795 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003796 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003797 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003798 break;
3799 }
3800}
3801
3802template<typename Derived>
3803bool TreeTransform<Derived>::TransformTemplateArgument(
3804 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003805 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003806 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003807 switch (Arg.getKind()) {
3808 case TemplateArgument::Null:
3809 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003810 case TemplateArgument::Pack:
3811 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003812 case TemplateArgument::NullPtr:
3813 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003814
Douglas Gregore922c772009-08-04 22:27:00 +00003815 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003816 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003817 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003818 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003819
3820 DI = getDerived().TransformType(DI);
3821 if (!DI) return true;
3822
3823 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3824 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003825 }
Mike Stump11289f42009-09-09 15:08:12 +00003826
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003827 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003828 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3829 if (QualifierLoc) {
3830 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3831 if (!QualifierLoc)
3832 return true;
3833 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003834
Douglas Gregordf846d12011-03-02 18:46:51 +00003835 CXXScopeSpec SS;
3836 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003837 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003838 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3839 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003840 if (Template.isNull())
3841 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003842
Douglas Gregor9d802122011-03-02 17:09:35 +00003843 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003844 Input.getTemplateNameLoc());
3845 return false;
3846 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003847
3848 case TemplateArgument::TemplateExpansion:
3849 llvm_unreachable("Caller should expand pack expansions");
3850
Douglas Gregore922c772009-08-04 22:27:00 +00003851 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003852 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003853 EnterExpressionEvaluationContext Unevaluated(
3854 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003855
John McCall0ad16662009-10-29 08:12:44 +00003856 Expr *InputExpr = Input.getSourceExpression();
3857 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3858
Chris Lattnercdb591a2011-04-25 20:37:58 +00003859 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003860 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003861 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003862 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003863 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003864 }
Douglas Gregore922c772009-08-04 22:27:00 +00003865 }
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregore922c772009-08-04 22:27:00 +00003867 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003868 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003869}
3870
Douglas Gregorfe921a72010-12-20 23:36:19 +00003871/// \brief Iterator adaptor that invents template argument location information
3872/// for each of the template arguments in its underlying iterator.
3873template<typename Derived, typename InputIterator>
3874class TemplateArgumentLocInventIterator {
3875 TreeTransform<Derived> &Self;
3876 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregorfe921a72010-12-20 23:36:19 +00003878public:
3879 typedef TemplateArgumentLoc value_type;
3880 typedef TemplateArgumentLoc reference;
3881 typedef typename std::iterator_traits<InputIterator>::difference_type
3882 difference_type;
3883 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003884
Douglas Gregorfe921a72010-12-20 23:36:19 +00003885 class pointer {
3886 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003887
Douglas Gregorfe921a72010-12-20 23:36:19 +00003888 public:
3889 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003890
Douglas Gregorfe921a72010-12-20 23:36:19 +00003891 const TemplateArgumentLoc *operator->() const { return &Arg; }
3892 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003893
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003894 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
Douglas Gregorfe921a72010-12-20 23:36:19 +00003896 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3897 InputIterator Iter)
3898 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Douglas Gregorfe921a72010-12-20 23:36:19 +00003900 TemplateArgumentLocInventIterator &operator++() {
3901 ++Iter;
3902 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003904
Douglas Gregorfe921a72010-12-20 23:36:19 +00003905 TemplateArgumentLocInventIterator operator++(int) {
3906 TemplateArgumentLocInventIterator Old(*this);
3907 ++(*this);
3908 return Old;
3909 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003910
Douglas Gregorfe921a72010-12-20 23:36:19 +00003911 reference operator*() const {
3912 TemplateArgumentLoc Result;
3913 Self.InventTemplateArgumentLoc(*Iter, Result);
3914 return Result;
3915 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003916
Douglas Gregorfe921a72010-12-20 23:36:19 +00003917 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003918
Douglas Gregorfe921a72010-12-20 23:36:19 +00003919 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3920 const TemplateArgumentLocInventIterator &Y) {
3921 return X.Iter == Y.Iter;
3922 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003923
Douglas Gregorfe921a72010-12-20 23:36:19 +00003924 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3925 const TemplateArgumentLocInventIterator &Y) {
3926 return X.Iter != Y.Iter;
3927 }
3928};
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregor42cafa82010-12-20 17:42:22 +00003930template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003931template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003932bool TreeTransform<Derived>::TransformTemplateArguments(
3933 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3934 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003935 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003936 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003937 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003938
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003939 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3940 // Unpack argument packs, which we translate them into separate
3941 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003942 // FIXME: We could do much better if we could guarantee that the
3943 // TemplateArgumentLocInfo for the pack expansion would be usable for
3944 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003945 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003946 TemplateArgument::pack_iterator>
3947 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003948 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003949 In.getArgument().pack_begin()),
3950 PackLocIterator(*this,
3951 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003952 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003953 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003954
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003955 continue;
3956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003958 if (In.getArgument().isPackExpansion()) {
3959 // We have a pack expansion, for which we will be substituting into
3960 // the pattern.
3961 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003962 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003963 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003964 = getSema().getTemplateArgumentPackExpansionPattern(
3965 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Chris Lattner01cf8db2011-07-20 06:58:45 +00003967 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003968 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3969 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003971 // Determine whether the set of unexpanded parameter packs can and should
3972 // be expanded.
3973 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003974 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003975 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003976 if (getDerived().TryExpandParameterPacks(Ellipsis,
3977 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003978 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003979 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003980 RetainExpansion,
3981 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003982 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003983
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003984 if (!Expand) {
3985 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003986 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003987 // expansion.
3988 TemplateArgumentLoc OutPattern;
3989 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003990 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003991 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003992
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003993 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3994 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003995 if (Out.getArgument().isNull())
3996 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003997
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003998 Outputs.addArgument(Out);
3999 continue;
4000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004001
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004002 // The transform has determined that we should perform an elementwise
4003 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004004 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004005 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4006
Richard Smithd784e682015-09-23 21:41:42 +00004007 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004008 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004009
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004010 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004011 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4012 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004013 if (Out.getArgument().isNull())
4014 return true;
4015 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004016
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004017 Outputs.addArgument(Out);
4018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004019
Douglas Gregor48d24112011-01-10 20:53:55 +00004020 // If we're supposed to retain a pack expansion, do so by temporarily
4021 // forgetting the partially-substituted parameter pack.
4022 if (RetainExpansion) {
4023 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004024
Richard Smithd784e682015-09-23 21:41:42 +00004025 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004026 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004027
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004028 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4029 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004030 if (Out.getArgument().isNull())
4031 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004032
Douglas Gregor48d24112011-01-10 20:53:55 +00004033 Outputs.addArgument(Out);
4034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004036 continue;
4037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
4039 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004040 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004041 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004042
Douglas Gregor42cafa82010-12-20 17:42:22 +00004043 Outputs.addArgument(Out);
4044 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004045
Douglas Gregor42cafa82010-12-20 17:42:22 +00004046 return false;
4047
4048}
4049
Douglas Gregord6ff3322009-08-04 16:50:30 +00004050//===----------------------------------------------------------------------===//
4051// Type transformation
4052//===----------------------------------------------------------------------===//
4053
4054template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004055QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004056 if (getDerived().AlreadyTransformed(T))
4057 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004058
John McCall550e0c22009-10-21 00:40:46 +00004059 // Temporary workaround. All of these transformations should
4060 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004061 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4062 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004063
John McCall31f82722010-11-12 08:19:04 +00004064 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004065
John McCall550e0c22009-10-21 00:40:46 +00004066 if (!NewDI)
4067 return QualType();
4068
4069 return NewDI->getType();
4070}
4071
4072template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004073TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004074 // Refine the base location to the type's location.
4075 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4076 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004077 if (getDerived().AlreadyTransformed(DI->getType()))
4078 return DI;
4079
4080 TypeLocBuilder TLB;
4081
4082 TypeLoc TL = DI->getTypeLoc();
4083 TLB.reserve(TL.getFullDataSize());
4084
John McCall31f82722010-11-12 08:19:04 +00004085 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004086 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004087 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004088
John McCallbcd03502009-12-07 02:54:59 +00004089 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004090}
4091
4092template<typename Derived>
4093QualType
John McCall31f82722010-11-12 08:19:04 +00004094TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004095 switch (T.getTypeLocClass()) {
4096#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004097#define TYPELOC(CLASS, PARENT) \
4098 case TypeLoc::CLASS: \
4099 return getDerived().Transform##CLASS##Type(TLB, \
4100 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004101#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004102 }
Mike Stump11289f42009-09-09 15:08:12 +00004103
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004104 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004105}
4106
Richard Smithee579842017-01-30 20:39:26 +00004107template<typename Derived>
4108QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4109 if (!isa<DependentNameType>(T))
4110 return TransformType(T);
4111
4112 if (getDerived().AlreadyTransformed(T))
4113 return T;
4114 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4115 getDerived().getBaseLocation());
4116 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4117 return NewDI ? NewDI->getType() : QualType();
4118}
4119
4120template<typename Derived>
4121TypeSourceInfo *
4122TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4123 if (!isa<DependentNameType>(DI->getType()))
4124 return TransformType(DI);
4125
4126 // Refine the base location to the type's location.
4127 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4128 getDerived().getBaseEntity());
4129 if (getDerived().AlreadyTransformed(DI->getType()))
4130 return DI;
4131
4132 TypeLocBuilder TLB;
4133
4134 TypeLoc TL = DI->getTypeLoc();
4135 TLB.reserve(TL.getFullDataSize());
4136
4137 Qualifiers Quals;
4138 auto QTL = TL.getAs<QualifiedTypeLoc>();
4139 if (QTL)
4140 TL = QTL.getUnqualifiedLoc();
4141
4142 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4143
4144 QualType Result = getDerived().TransformDependentNameType(
4145 TLB, DNTL, /*DeducedTSTContext*/true);
4146 if (Result.isNull())
4147 return nullptr;
4148
4149 if (QTL) {
4150 Result = getDerived().RebuildQualifiedType(
4151 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4152 TLB.TypeWasModifiedSafely(Result);
4153 }
4154
4155 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4156}
4157
John McCall550e0c22009-10-21 00:40:46 +00004158template<typename Derived>
4159QualType
4160TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004161 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004162 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004163
John McCall31f82722010-11-12 08:19:04 +00004164 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004165 if (Result.isNull())
4166 return QualType();
4167
Richard Smithee579842017-01-30 20:39:26 +00004168 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4169
4170 // RebuildQualifiedType might have updated the type, but not in a way
4171 // that invalidates the TypeLoc. (There's no location information for
4172 // qualifiers.)
4173 TLB.TypeWasModifiedSafely(Result);
4174
4175 return Result;
4176}
4177
4178template<typename Derived>
4179QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4180 SourceLocation Loc,
4181 Qualifiers Quals) {
4182 // C++ [dcl.fct]p7:
4183 // [When] adding cv-qualifications on top of the function type [...] the
4184 // cv-qualifiers are ignored.
4185 // C++ [dcl.ref]p1:
4186 // when the cv-qualifiers are introduced through the use of a typedef-name
4187 // or decltype-specifier [...] the cv-qualifiers are ignored.
4188 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4189 // applied to a reference type.
4190 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4191 if (T->isFunctionType() || T->isReferenceType())
4192 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004193
John McCall31168b02011-06-15 23:02:42 +00004194 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004195 // resulting type.
4196 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004197 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004198 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004199 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004200 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004201 // A lifetime qualifier applied to a substituted template parameter
4202 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004203 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004204 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004205 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004206 QualType Replacement = SubstTypeParam->getReplacementType();
4207 Qualifiers Qs = Replacement.getQualifiers();
4208 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004209 Replacement = SemaRef.Context.getQualifiedType(
4210 Replacement.getUnqualifiedType(), Qs);
4211 T = SemaRef.Context.getSubstTemplateTypeParmType(
4212 SubstTypeParam->getReplacedParameter(), Replacement);
4213 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004214 // 'auto' types behave the same way as template parameters.
4215 QualType Deduced = AutoTy->getDeducedType();
4216 Qualifiers Qs = Deduced.getQualifiers();
4217 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004218 Deduced =
4219 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4220 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4221 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004222 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004223 // Otherwise, complain about the addition of a qualifier to an
4224 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004225 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4226 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004227 Quals.removeObjCLifetime();
4228 }
4229 }
4230 }
John McCall550e0c22009-10-21 00:40:46 +00004231
Richard Smithee579842017-01-30 20:39:26 +00004232 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004233}
4234
Douglas Gregor14454802011-02-25 02:25:35 +00004235template<typename Derived>
4236TypeLoc
4237TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4238 QualType ObjectType,
4239 NamedDecl *UnqualLookup,
4240 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004241 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004242 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004243
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004244 TypeSourceInfo *TSI =
4245 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4246 if (TSI)
4247 return TSI->getTypeLoc();
4248 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004249}
4250
Douglas Gregor579c15f2011-03-02 18:32:08 +00004251template<typename Derived>
4252TypeSourceInfo *
4253TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4254 QualType ObjectType,
4255 NamedDecl *UnqualLookup,
4256 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004257 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004258 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004259
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004260 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4261 UnqualLookup, SS);
4262}
4263
4264template <typename Derived>
4265TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4266 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4267 CXXScopeSpec &SS) {
4268 QualType T = TL.getType();
4269 assert(!getDerived().AlreadyTransformed(T));
4270
Douglas Gregor579c15f2011-03-02 18:32:08 +00004271 TypeLocBuilder TLB;
4272 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004273
Douglas Gregor579c15f2011-03-02 18:32:08 +00004274 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004275 TemplateSpecializationTypeLoc SpecTL =
4276 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004277
Richard Smithfd3dae02017-01-20 00:20:39 +00004278 TemplateName Template = getDerived().TransformTemplateName(
4279 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4280 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004281 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004282 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004283
4284 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004285 Template);
4286 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004287 DependentTemplateSpecializationTypeLoc SpecTL =
4288 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004289
Douglas Gregor579c15f2011-03-02 18:32:08 +00004290 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004291 = getDerived().RebuildTemplateName(SS,
4292 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004293 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004294 ObjectType, UnqualLookup,
4295 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004296 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004297 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004298
4299 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004300 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004301 Template,
4302 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004303 } else {
4304 // Nothing special needs to be done for these.
4305 Result = getDerived().TransformType(TLB, TL);
4306 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004307
4308 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004309 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregor579c15f2011-03-02 18:32:08 +00004311 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4312}
4313
John McCall550e0c22009-10-21 00:40:46 +00004314template <class TyLoc> static inline
4315QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4316 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4317 NewT.setNameLoc(T.getNameLoc());
4318 return T.getType();
4319}
4320
John McCall550e0c22009-10-21 00:40:46 +00004321template<typename Derived>
4322QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004323 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004324 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4325 NewT.setBuiltinLoc(T.getBuiltinLoc());
4326 if (T.needsExtraLocalData())
4327 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4328 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregord6ff3322009-08-04 16:50:30 +00004331template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004332QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004333 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004334 // FIXME: recurse?
4335 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004336}
Mike Stump11289f42009-09-09 15:08:12 +00004337
Reid Kleckner0503a872013-12-05 01:23:43 +00004338template <typename Derived>
4339QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4340 AdjustedTypeLoc TL) {
4341 // Adjustments applied during transformation are handled elsewhere.
4342 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4343}
4344
Douglas Gregord6ff3322009-08-04 16:50:30 +00004345template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004346QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4347 DecayedTypeLoc TL) {
4348 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4349 if (OriginalType.isNull())
4350 return QualType();
4351
4352 QualType Result = TL.getType();
4353 if (getDerived().AlwaysRebuild() ||
4354 OriginalType != TL.getOriginalLoc().getType())
4355 Result = SemaRef.Context.getDecayedType(OriginalType);
4356 TLB.push<DecayedTypeLoc>(Result);
4357 // Nothing to set for DecayedTypeLoc.
4358 return Result;
4359}
4360
4361template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004362QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004363 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004364 QualType PointeeType
4365 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004366 if (PointeeType.isNull())
4367 return QualType();
4368
4369 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004370 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004371 // A dependent pointer type 'T *' has is being transformed such
4372 // that an Objective-C class type is being replaced for 'T'. The
4373 // resulting pointer type is an ObjCObjectPointerType, not a
4374 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004375 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004376
John McCall8b07ec22010-05-15 11:32:37 +00004377 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4378 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004379 return Result;
4380 }
John McCall31f82722010-11-12 08:19:04 +00004381
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004382 if (getDerived().AlwaysRebuild() ||
4383 PointeeType != TL.getPointeeLoc().getType()) {
4384 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4385 if (Result.isNull())
4386 return QualType();
4387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004388
John McCall31168b02011-06-15 23:02:42 +00004389 // Objective-C ARC can add lifetime qualifiers to the type that we're
4390 // pointing to.
4391 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004392
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004393 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4394 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004395 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
4398template<typename Derived>
4399QualType
John McCall550e0c22009-10-21 00:40:46 +00004400TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004401 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004402 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004403 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4404 if (PointeeType.isNull())
4405 return QualType();
4406
4407 QualType Result = TL.getType();
4408 if (getDerived().AlwaysRebuild() ||
4409 PointeeType != TL.getPointeeLoc().getType()) {
4410 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004411 TL.getSigilLoc());
4412 if (Result.isNull())
4413 return QualType();
4414 }
4415
Douglas Gregor049211a2010-04-22 16:50:51 +00004416 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004417 NewT.setSigilLoc(TL.getSigilLoc());
4418 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004419}
4420
John McCall70dd5f62009-10-30 00:06:24 +00004421/// Transforms a reference type. Note that somewhat paradoxically we
4422/// don't care whether the type itself is an l-value type or an r-value
4423/// type; we only care if the type was *written* as an l-value type
4424/// or an r-value type.
4425template<typename Derived>
4426QualType
4427TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004428 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004429 const ReferenceType *T = TL.getTypePtr();
4430
4431 // Note that this works with the pointee-as-written.
4432 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4433 if (PointeeType.isNull())
4434 return QualType();
4435
4436 QualType Result = TL.getType();
4437 if (getDerived().AlwaysRebuild() ||
4438 PointeeType != T->getPointeeTypeAsWritten()) {
4439 Result = getDerived().RebuildReferenceType(PointeeType,
4440 T->isSpelledAsLValue(),
4441 TL.getSigilLoc());
4442 if (Result.isNull())
4443 return QualType();
4444 }
4445
John McCall31168b02011-06-15 23:02:42 +00004446 // Objective-C ARC can add lifetime qualifiers to the type that we're
4447 // referring to.
4448 TLB.TypeWasModifiedSafely(
4449 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4450
John McCall70dd5f62009-10-30 00:06:24 +00004451 // r-value references can be rebuilt as l-value references.
4452 ReferenceTypeLoc NewTL;
4453 if (isa<LValueReferenceType>(Result))
4454 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4455 else
4456 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4457 NewTL.setSigilLoc(TL.getSigilLoc());
4458
4459 return Result;
4460}
4461
Mike Stump11289f42009-09-09 15:08:12 +00004462template<typename Derived>
4463QualType
John McCall550e0c22009-10-21 00:40:46 +00004464TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 LValueReferenceTypeLoc TL) {
4466 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004467}
4468
Mike Stump11289f42009-09-09 15:08:12 +00004469template<typename Derived>
4470QualType
John McCall550e0c22009-10-21 00:40:46 +00004471TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004472 RValueReferenceTypeLoc TL) {
4473 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004474}
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregord6ff3322009-08-04 16:50:30 +00004476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004477QualType
John McCall550e0c22009-10-21 00:40:46 +00004478TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004479 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004480 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004481 if (PointeeType.isNull())
4482 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004483
Abramo Bagnara509357842011-03-05 14:42:21 +00004484 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004485 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004486 if (OldClsTInfo) {
4487 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4488 if (!NewClsTInfo)
4489 return QualType();
4490 }
4491
4492 const MemberPointerType *T = TL.getTypePtr();
4493 QualType OldClsType = QualType(T->getClass(), 0);
4494 QualType NewClsType;
4495 if (NewClsTInfo)
4496 NewClsType = NewClsTInfo->getType();
4497 else {
4498 NewClsType = getDerived().TransformType(OldClsType);
4499 if (NewClsType.isNull())
4500 return QualType();
4501 }
Mike Stump11289f42009-09-09 15:08:12 +00004502
John McCall550e0c22009-10-21 00:40:46 +00004503 QualType Result = TL.getType();
4504 if (getDerived().AlwaysRebuild() ||
4505 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004506 NewClsType != OldClsType) {
4507 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004508 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004509 if (Result.isNull())
4510 return QualType();
4511 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004512
Reid Kleckner0503a872013-12-05 01:23:43 +00004513 // If we had to adjust the pointee type when building a member pointer, make
4514 // sure to push TypeLoc info for it.
4515 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4516 if (MPT && PointeeType != MPT->getPointeeType()) {
4517 assert(isa<AdjustedType>(MPT->getPointeeType()));
4518 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4519 }
4520
John McCall550e0c22009-10-21 00:40:46 +00004521 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4522 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004523 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004524
4525 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526}
4527
Mike Stump11289f42009-09-09 15:08:12 +00004528template<typename Derived>
4529QualType
John McCall550e0c22009-10-21 00:40:46 +00004530TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004531 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004532 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004533 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004534 if (ElementType.isNull())
4535 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004536
John McCall550e0c22009-10-21 00:40:46 +00004537 QualType Result = TL.getType();
4538 if (getDerived().AlwaysRebuild() ||
4539 ElementType != T->getElementType()) {
4540 Result = getDerived().RebuildConstantArrayType(ElementType,
4541 T->getSizeModifier(),
4542 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004543 T->getIndexTypeCVRQualifiers(),
4544 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004545 if (Result.isNull())
4546 return QualType();
4547 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004548
4549 // We might have either a ConstantArrayType or a VariableArrayType now:
4550 // a ConstantArrayType is allowed to have an element type which is a
4551 // VariableArrayType if the type is dependent. Fortunately, all array
4552 // types have the same location layout.
4553 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004554 NewTL.setLBracketLoc(TL.getLBracketLoc());
4555 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004556
John McCall550e0c22009-10-21 00:40:46 +00004557 Expr *Size = TL.getSizeExpr();
4558 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004559 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4560 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004561 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4562 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004563 }
4564 NewTL.setSizeExpr(Size);
4565
4566 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004567}
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregord6ff3322009-08-04 16:50:30 +00004569template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004570QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004571 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004572 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004573 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004574 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004575 if (ElementType.isNull())
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() ||
4580 ElementType != T->getElementType()) {
4581 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004582 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004583 T->getIndexTypeCVRQualifiers(),
4584 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004585 if (Result.isNull())
4586 return QualType();
4587 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004588
John McCall550e0c22009-10-21 00:40:46 +00004589 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4590 NewTL.setLBracketLoc(TL.getLBracketLoc());
4591 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004592 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004593
4594 return Result;
4595}
4596
4597template<typename Derived>
4598QualType
4599TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004600 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004601 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004602 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4603 if (ElementType.isNull())
4604 return QualType();
4605
Tim Shenb34d0ef2017-02-14 23:46:37 +00004606 ExprResult SizeResult;
4607 {
4608 EnterExpressionEvaluationContext Context(SemaRef,
4609 Sema::PotentiallyEvaluated);
4610 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4611 }
4612 if (SizeResult.isInvalid())
4613 return QualType();
4614 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004615 if (SizeResult.isInvalid())
4616 return QualType();
4617
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004618 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004619
4620 QualType Result = TL.getType();
4621 if (getDerived().AlwaysRebuild() ||
4622 ElementType != T->getElementType() ||
4623 Size != T->getSizeExpr()) {
4624 Result = getDerived().RebuildVariableArrayType(ElementType,
4625 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004626 Size,
John McCall550e0c22009-10-21 00:40:46 +00004627 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004628 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004629 if (Result.isNull())
4630 return QualType();
4631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Serge Pavlov774c6d02014-02-06 03:49:11 +00004633 // We might have constant size array now, but fortunately it has the same
4634 // location layout.
4635 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004636 NewTL.setLBracketLoc(TL.getLBracketLoc());
4637 NewTL.setRBracketLoc(TL.getRBracketLoc());
4638 NewTL.setSizeExpr(Size);
4639
4640 return Result;
4641}
4642
4643template<typename Derived>
4644QualType
4645TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004646 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004647 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004648 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4649 if (ElementType.isNull())
4650 return QualType();
4651
Richard Smith764d2fe2011-12-20 02:08:33 +00004652 // Array bounds are constant expressions.
4653 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4654 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004655
John McCall33ddac02011-01-19 10:06:00 +00004656 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4657 Expr *origSize = TL.getSizeExpr();
4658 if (!origSize) origSize = T->getSizeExpr();
4659
4660 ExprResult sizeResult
4661 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004662 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004663 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004664 return QualType();
4665
John McCall33ddac02011-01-19 10:06:00 +00004666 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004667
4668 QualType Result = TL.getType();
4669 if (getDerived().AlwaysRebuild() ||
4670 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004671 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004672 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4673 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004674 size,
John McCall550e0c22009-10-21 00:40:46 +00004675 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004676 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004677 if (Result.isNull())
4678 return QualType();
4679 }
John McCall550e0c22009-10-21 00:40:46 +00004680
4681 // We might have any sort of array type now, but fortunately they
4682 // all have the same location layout.
4683 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4684 NewTL.setLBracketLoc(TL.getLBracketLoc());
4685 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004686 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004687
4688 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004689}
Mike Stump11289f42009-09-09 15:08:12 +00004690
4691template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004693 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004694 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004695 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004696
4697 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004698 QualType ElementType = getDerived().TransformType(T->getElementType());
4699 if (ElementType.isNull())
4700 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Richard Smith764d2fe2011-12-20 02:08:33 +00004702 // Vector sizes are constant expressions.
4703 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4704 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004705
John McCalldadc5752010-08-24 06:29:42 +00004706 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004707 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708 if (Size.isInvalid())
4709 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004710
John McCall550e0c22009-10-21 00:40:46 +00004711 QualType Result = TL.getType();
4712 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004713 ElementType != T->getElementType() ||
4714 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004715 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004716 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004717 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004718 if (Result.isNull())
4719 return QualType();
4720 }
John McCall550e0c22009-10-21 00:40:46 +00004721
4722 // Result might be dependent or not.
4723 if (isa<DependentSizedExtVectorType>(Result)) {
4724 DependentSizedExtVectorTypeLoc NewTL
4725 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4726 NewTL.setNameLoc(TL.getNameLoc());
4727 } else {
4728 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4729 NewTL.setNameLoc(TL.getNameLoc());
4730 }
4731
4732 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
4735template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004736QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004737 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004738 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739 QualType ElementType = getDerived().TransformType(T->getElementType());
4740 if (ElementType.isNull())
4741 return QualType();
4742
John McCall550e0c22009-10-21 00:40:46 +00004743 QualType Result = TL.getType();
4744 if (getDerived().AlwaysRebuild() ||
4745 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004746 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004747 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004748 if (Result.isNull())
4749 return QualType();
4750 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004751
John McCall550e0c22009-10-21 00:40:46 +00004752 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4753 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004754
John McCall550e0c22009-10-21 00:40:46 +00004755 return Result;
4756}
4757
4758template<typename Derived>
4759QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004760 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004761 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004762 QualType ElementType = getDerived().TransformType(T->getElementType());
4763 if (ElementType.isNull())
4764 return QualType();
4765
4766 QualType Result = TL.getType();
4767 if (getDerived().AlwaysRebuild() ||
4768 ElementType != T->getElementType()) {
4769 Result = getDerived().RebuildExtVectorType(ElementType,
4770 T->getNumElements(),
4771 /*FIXME*/ SourceLocation());
4772 if (Result.isNull())
4773 return QualType();
4774 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004775
John McCall550e0c22009-10-21 00:40:46 +00004776 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4777 NewTL.setNameLoc(TL.getNameLoc());
4778
4779 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004780}
Mike Stump11289f42009-09-09 15:08:12 +00004781
David Blaikie05785d12013-02-20 22:23:23 +00004782template <typename Derived>
4783ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4784 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4785 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004786 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004787 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004788
Douglas Gregor715e4612011-01-14 22:40:04 +00004789 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004790 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004791 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004792 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004793 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004794
Douglas Gregor715e4612011-01-14 22:40:04 +00004795 TypeLocBuilder TLB;
4796 TypeLoc NewTL = OldDI->getTypeLoc();
4797 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004798
4799 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004800 OldExpansionTL.getPatternLoc());
4801 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004802 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004803
4804 Result = RebuildPackExpansionType(Result,
4805 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004806 OldExpansionTL.getEllipsisLoc(),
4807 NumExpansions);
4808 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004809 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004810
Douglas Gregor715e4612011-01-14 22:40:04 +00004811 PackExpansionTypeLoc NewExpansionTL
4812 = TLB.push<PackExpansionTypeLoc>(Result);
4813 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4814 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4815 } else
4816 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004817 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004818 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004819
John McCall8fb0d9d2011-05-01 22:35:37 +00004820 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004821 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004822
4823 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4824 OldParm->getDeclContext(),
4825 OldParm->getInnerLocStart(),
4826 OldParm->getLocation(),
4827 OldParm->getIdentifier(),
4828 NewDI->getType(),
4829 NewDI,
4830 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004831 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004832 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4833 OldParm->getFunctionScopeIndex() + indexAdjustment);
4834 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004835}
4836
David Majnemer59f77922016-06-24 04:05:48 +00004837template <typename Derived>
4838bool TreeTransform<Derived>::TransformFunctionTypeParams(
4839 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4840 const QualType *ParamTypes,
4841 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4842 SmallVectorImpl<QualType> &OutParamTypes,
4843 SmallVectorImpl<ParmVarDecl *> *PVars,
4844 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004845 int indexAdjustment = 0;
4846
David Majnemer59f77922016-06-24 04:05:48 +00004847 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004848 for (unsigned i = 0; i != NumParams; ++i) {
4849 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004850 assert(OldParm->getFunctionScopeIndex() == i);
4851
David Blaikie05785d12013-02-20 22:23:23 +00004852 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004853 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004854 if (OldParm->isParameterPack()) {
4855 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004856 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004857
Douglas Gregor5499af42011-01-05 23:12:31 +00004858 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004859 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004860 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004861 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4862 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004863 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4864
Douglas Gregor5499af42011-01-05 23:12:31 +00004865 // Determine whether we should expand the parameter packs.
4866 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004867 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004868 Optional<unsigned> OrigNumExpansions =
4869 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004870 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004871 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4872 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004873 Unexpanded,
4874 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004875 RetainExpansion,
4876 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004877 return true;
4878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004879
Douglas Gregor5499af42011-01-05 23:12:31 +00004880 if (ShouldExpand) {
4881 // Expand the function parameter pack into multiple, separate
4882 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004883 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004884 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004885 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004886 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004887 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004888 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004889 OrigNumExpansions,
4890 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004891 if (!NewParm)
4892 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004893
John McCallc8e321d2016-03-01 02:09:25 +00004894 if (ParamInfos)
4895 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004896 OutParamTypes.push_back(NewParm->getType());
4897 if (PVars)
4898 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004899 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004900
4901 // If we're supposed to retain a pack expansion, do so by temporarily
4902 // forgetting the partially-substituted parameter pack.
4903 if (RetainExpansion) {
4904 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004905 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004906 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004907 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004908 OrigNumExpansions,
4909 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004910 if (!NewParm)
4911 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
John McCallc8e321d2016-03-01 02:09:25 +00004913 if (ParamInfos)
4914 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004915 OutParamTypes.push_back(NewParm->getType());
4916 if (PVars)
4917 PVars->push_back(NewParm);
4918 }
4919
John McCall8fb0d9d2011-05-01 22:35:37 +00004920 // The next parameter should have the same adjustment as the
4921 // last thing we pushed, but we post-incremented indexAdjustment
4922 // on every push. Also, if we push nothing, the adjustment should
4923 // go down by one.
4924 indexAdjustment--;
4925
Douglas Gregor5499af42011-01-05 23:12:31 +00004926 // We're done with the pack expansion.
4927 continue;
4928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004929
4930 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004931 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004932 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4933 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004934 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004935 NumExpansions,
4936 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004937 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004938 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004939 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004940 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004941
John McCall58f10c32010-03-11 09:03:00 +00004942 if (!NewParm)
4943 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004944
John McCallc8e321d2016-03-01 02:09:25 +00004945 if (ParamInfos)
4946 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004947 OutParamTypes.push_back(NewParm->getType());
4948 if (PVars)
4949 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004950 continue;
4951 }
John McCall58f10c32010-03-11 09:03:00 +00004952
4953 // Deal with the possibility that we don't have a parameter
4954 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004955 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004956 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004957 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004958 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004959 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004960 = dyn_cast<PackExpansionType>(OldType)) {
4961 // We have a function parameter pack that may need to be expanded.
4962 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004963 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004964 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
Douglas Gregor5499af42011-01-05 23:12:31 +00004966 // Determine whether we should expand the parameter packs.
4967 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004968 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004969 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004970 Unexpanded,
4971 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004972 RetainExpansion,
4973 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004974 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004976
Douglas Gregor5499af42011-01-05 23:12:31 +00004977 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004978 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004979 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004980 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004981 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4982 QualType NewType = getDerived().TransformType(Pattern);
4983 if (NewType.isNull())
4984 return true;
John McCall58f10c32010-03-11 09:03:00 +00004985
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00004986 if (NewType->containsUnexpandedParameterPack()) {
4987 NewType =
4988 getSema().getASTContext().getPackExpansionType(NewType, None);
4989
4990 if (NewType.isNull())
4991 return true;
4992 }
4993
John McCallc8e321d2016-03-01 02:09:25 +00004994 if (ParamInfos)
4995 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004996 OutParamTypes.push_back(NewType);
4997 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004998 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004999 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005000
Douglas Gregor5499af42011-01-05 23:12:31 +00005001 // We're done with the pack expansion.
5002 continue;
5003 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005004
Douglas Gregor48d24112011-01-10 20:53:55 +00005005 // If we're supposed to retain a pack expansion, do so by temporarily
5006 // forgetting the partially-substituted parameter pack.
5007 if (RetainExpansion) {
5008 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5009 QualType NewType = getDerived().TransformType(Pattern);
5010 if (NewType.isNull())
5011 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005012
John McCallc8e321d2016-03-01 02:09:25 +00005013 if (ParamInfos)
5014 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005015 OutParamTypes.push_back(NewType);
5016 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005017 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005018 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005019
Chad Rosier1dcde962012-08-08 18:46:20 +00005020 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005021 // expansion.
5022 OldType = Expansion->getPattern();
5023 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5025 NewType = getDerived().TransformType(OldType);
5026 } else {
5027 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005029
Douglas Gregor5499af42011-01-05 23:12:31 +00005030 if (NewType.isNull())
5031 return true;
5032
5033 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005034 NewType = getSema().Context.getPackExpansionType(NewType,
5035 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005036
John McCallc8e321d2016-03-01 02:09:25 +00005037 if (ParamInfos)
5038 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005039 OutParamTypes.push_back(NewType);
5040 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005041 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005042 }
5043
John McCall8fb0d9d2011-05-01 22:35:37 +00005044#ifndef NDEBUG
5045 if (PVars) {
5046 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5047 if (ParmVarDecl *parm = (*PVars)[i])
5048 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005049 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005050#endif
5051
5052 return false;
5053}
John McCall58f10c32010-03-11 09:03:00 +00005054
5055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005056QualType
John McCall550e0c22009-10-21 00:40:46 +00005057TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005058 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005059 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005060 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005061 return getDerived().TransformFunctionProtoType(
5062 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005063 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5064 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5065 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005066 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005067}
5068
Richard Smith2e321552014-11-12 02:00:47 +00005069template<typename Derived> template<typename Fn>
5070QualType TreeTransform<Derived>::TransformFunctionProtoType(
5071 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5072 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005073
Douglas Gregor4afc2362010-08-31 00:26:14 +00005074 // Transform the parameters and return type.
5075 //
Richard Smithf623c962012-04-17 00:58:00 +00005076 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005077 // When the function has a trailing return type, we instantiate the
5078 // parameters before the return type, since the return type can then refer
5079 // to the parameters themselves (via decltype, sizeof, etc.).
5080 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005081 SmallVector<QualType, 4> ParamTypes;
5082 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005083 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005084 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005085
Douglas Gregor7fb25412010-10-01 18:44:50 +00005086 QualType ResultType;
5087
Richard Smith1226c602012-08-14 22:51:13 +00005088 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005089 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005090 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005091 TL.getTypePtr()->param_type_begin(),
5092 T->getExtParameterInfosOrNull(),
5093 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005094 return QualType();
5095
Douglas Gregor3024f072012-04-16 07:05:22 +00005096 {
5097 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005098 // If a declaration declares a member function or member function
5099 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005100 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005101 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005102 // declarator.
5103 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005104
Alp Toker42a16a62014-01-25 23:51:36 +00005105 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005106 if (ResultType.isNull())
5107 return QualType();
5108 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005109 }
5110 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005111 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005112 if (ResultType.isNull())
5113 return QualType();
5114
Alp Toker9cacbab2014-01-20 20:26:09 +00005115 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005116 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005117 TL.getTypePtr()->param_type_begin(),
5118 T->getExtParameterInfosOrNull(),
5119 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005120 return QualType();
5121 }
5122
Richard Smith2e321552014-11-12 02:00:47 +00005123 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5124
5125 bool EPIChanged = false;
5126 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5127 return QualType();
5128
John McCallc8e321d2016-03-01 02:09:25 +00005129 // Handle extended parameter information.
5130 if (auto NewExtParamInfos =
5131 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5132 if (!EPI.ExtParameterInfos ||
5133 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5134 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5135 EPIChanged = true;
5136 }
5137 EPI.ExtParameterInfos = NewExtParamInfos;
5138 } else if (EPI.ExtParameterInfos) {
5139 EPIChanged = true;
5140 EPI.ExtParameterInfos = nullptr;
5141 }
Richard Smithf623c962012-04-17 00:58:00 +00005142
John McCall550e0c22009-10-21 00:40:46 +00005143 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005144 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005145 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005146 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005147 if (Result.isNull())
5148 return QualType();
5149 }
Mike Stump11289f42009-09-09 15:08:12 +00005150
John McCall550e0c22009-10-21 00:40:46 +00005151 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005152 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005153 NewTL.setLParenLoc(TL.getLParenLoc());
5154 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005155 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005156 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005157 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5158 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005159
5160 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005161}
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005164bool TreeTransform<Derived>::TransformExceptionSpec(
5165 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5166 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5167 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5168
5169 // Instantiate a dynamic noexcept expression, if any.
5170 if (ESI.Type == EST_ComputedNoexcept) {
5171 EnterExpressionEvaluationContext Unevaluated(getSema(),
5172 Sema::ConstantEvaluated);
5173 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5174 if (NoexceptExpr.isInvalid())
5175 return true;
5176
Richard Smith03a4aa32016-06-23 19:02:52 +00005177 // FIXME: This is bogus, a noexcept expression is not a condition.
5178 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005179 if (NoexceptExpr.isInvalid())
5180 return true;
5181
5182 if (!NoexceptExpr.get()->isValueDependent()) {
5183 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5184 NoexceptExpr.get(), nullptr,
5185 diag::err_noexcept_needs_constant_expression,
5186 /*AllowFold*/false);
5187 if (NoexceptExpr.isInvalid())
5188 return true;
5189 }
5190
5191 if (ESI.NoexceptExpr != NoexceptExpr.get())
5192 Changed = true;
5193 ESI.NoexceptExpr = NoexceptExpr.get();
5194 }
5195
5196 if (ESI.Type != EST_Dynamic)
5197 return false;
5198
5199 // Instantiate a dynamic exception specification's type.
5200 for (QualType T : ESI.Exceptions) {
5201 if (const PackExpansionType *PackExpansion =
5202 T->getAs<PackExpansionType>()) {
5203 Changed = true;
5204
5205 // We have a pack expansion. Instantiate it.
5206 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5207 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5208 Unexpanded);
5209 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5210
5211 // Determine whether the set of unexpanded parameter packs can and
5212 // should
5213 // be expanded.
5214 bool Expand = false;
5215 bool RetainExpansion = false;
5216 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5217 // FIXME: Track the location of the ellipsis (and track source location
5218 // information for the types in the exception specification in general).
5219 if (getDerived().TryExpandParameterPacks(
5220 Loc, SourceRange(), Unexpanded, Expand,
5221 RetainExpansion, NumExpansions))
5222 return true;
5223
5224 if (!Expand) {
5225 // We can't expand this pack expansion into separate arguments yet;
5226 // just substitute into the pattern and create a new pack expansion
5227 // type.
5228 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5229 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5230 if (U.isNull())
5231 return true;
5232
5233 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5234 Exceptions.push_back(U);
5235 continue;
5236 }
5237
5238 // Substitute into the pack expansion pattern for each slice of the
5239 // pack.
5240 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5241 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5242
5243 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5244 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5245 return true;
5246
5247 Exceptions.push_back(U);
5248 }
5249 } else {
5250 QualType U = getDerived().TransformType(T);
5251 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5252 return true;
5253 if (T != U)
5254 Changed = true;
5255
5256 Exceptions.push_back(U);
5257 }
5258 }
5259
5260 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005261 if (ESI.Exceptions.empty())
5262 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005263 return false;
5264}
5265
5266template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005268 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005269 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005270 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005271 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005272 if (ResultType.isNull())
5273 return QualType();
5274
5275 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005276 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005277 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5278
5279 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005280 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005281 NewTL.setLParenLoc(TL.getLParenLoc());
5282 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005283 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005284
5285 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286}
Mike Stump11289f42009-09-09 15:08:12 +00005287
John McCallb96ec562009-12-04 22:46:56 +00005288template<typename Derived> QualType
5289TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005290 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005291 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005292 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005293 if (!D)
5294 return QualType();
5295
5296 QualType Result = TL.getType();
5297 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005298 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005299 if (Result.isNull())
5300 return QualType();
5301 }
5302
5303 // We might get an arbitrary type spec type back. We should at
5304 // least always get a type spec type, though.
5305 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5306 NewTL.setNameLoc(TL.getNameLoc());
5307
5308 return Result;
5309}
5310
Douglas Gregord6ff3322009-08-04 16:50:30 +00005311template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005312QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005313 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005314 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005315 TypedefNameDecl *Typedef
5316 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5317 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005318 if (!Typedef)
5319 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005320
John McCall550e0c22009-10-21 00:40:46 +00005321 QualType Result = TL.getType();
5322 if (getDerived().AlwaysRebuild() ||
5323 Typedef != T->getDecl()) {
5324 Result = getDerived().RebuildTypedefType(Typedef);
5325 if (Result.isNull())
5326 return QualType();
5327 }
Mike Stump11289f42009-09-09 15:08:12 +00005328
John McCall550e0c22009-10-21 00:40:46 +00005329 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5330 NewTL.setNameLoc(TL.getNameLoc());
5331
5332 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005333}
Mike Stump11289f42009-09-09 15:08:12 +00005334
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005336QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005337 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005338 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00005339 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5340 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005341
John McCalldadc5752010-08-24 06:29:42 +00005342 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005343 if (E.isInvalid())
5344 return QualType();
5345
Eli Friedmane4f22df2012-02-29 04:03:55 +00005346 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5347 if (E.isInvalid())
5348 return QualType();
5349
John McCall550e0c22009-10-21 00:40:46 +00005350 QualType Result = TL.getType();
5351 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005352 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005353 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005354 if (Result.isNull())
5355 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005356 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005357 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005358
John McCall550e0c22009-10-21 00:40:46 +00005359 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005360 NewTL.setTypeofLoc(TL.getTypeofLoc());
5361 NewTL.setLParenLoc(TL.getLParenLoc());
5362 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005363
5364 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005365}
Mike Stump11289f42009-09-09 15:08:12 +00005366
5367template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005368QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005369 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005370 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5371 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5372 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005373 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005374
John McCall550e0c22009-10-21 00:40:46 +00005375 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005376 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5377 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005378 if (Result.isNull())
5379 return QualType();
5380 }
Mike Stump11289f42009-09-09 15:08:12 +00005381
John McCall550e0c22009-10-21 00:40:46 +00005382 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005383 NewTL.setTypeofLoc(TL.getTypeofLoc());
5384 NewTL.setLParenLoc(TL.getLParenLoc());
5385 NewTL.setRParenLoc(TL.getRParenLoc());
5386 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005387
5388 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005389}
Mike Stump11289f42009-09-09 15:08:12 +00005390
5391template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005392QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005393 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005394 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005395
Douglas Gregore922c772009-08-04 22:27:00 +00005396 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5398 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005399
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005401 if (E.isInvalid())
5402 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005403
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005404 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005405 if (E.isInvalid())
5406 return QualType();
5407
John McCall550e0c22009-10-21 00:40:46 +00005408 QualType Result = TL.getType();
5409 if (getDerived().AlwaysRebuild() ||
5410 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005411 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005412 if (Result.isNull())
5413 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005414 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005415 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005416
John McCall550e0c22009-10-21 00:40:46 +00005417 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5418 NewTL.setNameLoc(TL.getNameLoc());
5419
5420 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421}
5422
5423template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005424QualType TreeTransform<Derived>::TransformUnaryTransformType(
5425 TypeLocBuilder &TLB,
5426 UnaryTransformTypeLoc TL) {
5427 QualType Result = TL.getType();
5428 if (Result->isDependentType()) {
5429 const UnaryTransformType *T = TL.getTypePtr();
5430 QualType NewBase =
5431 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5432 Result = getDerived().RebuildUnaryTransformType(NewBase,
5433 T->getUTTKind(),
5434 TL.getKWLoc());
5435 if (Result.isNull())
5436 return QualType();
5437 }
5438
5439 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5440 NewTL.setKWLoc(TL.getKWLoc());
5441 NewTL.setParensRange(TL.getParensRange());
5442 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5443 return Result;
5444}
5445
5446template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005447QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5448 AutoTypeLoc TL) {
5449 const AutoType *T = TL.getTypePtr();
5450 QualType OldDeduced = T->getDeducedType();
5451 QualType NewDeduced;
5452 if (!OldDeduced.isNull()) {
5453 NewDeduced = getDerived().TransformType(OldDeduced);
5454 if (NewDeduced.isNull())
5455 return QualType();
5456 }
5457
5458 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005459 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5460 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005461 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005462 if (Result.isNull())
5463 return QualType();
5464 }
5465
5466 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5467 NewTL.setNameLoc(TL.getNameLoc());
5468
5469 return Result;
5470}
5471
5472template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005473QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5474 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5475 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5476
5477 CXXScopeSpec SS;
5478 TemplateName TemplateName = getDerived().TransformTemplateName(
5479 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5480 if (TemplateName.isNull())
5481 return QualType();
5482
5483 QualType OldDeduced = T->getDeducedType();
5484 QualType NewDeduced;
5485 if (!OldDeduced.isNull()) {
5486 NewDeduced = getDerived().TransformType(OldDeduced);
5487 if (NewDeduced.isNull())
5488 return QualType();
5489 }
5490
5491 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5492 TemplateName, NewDeduced);
5493 if (Result.isNull())
5494 return QualType();
5495
5496 DeducedTemplateSpecializationTypeLoc NewTL =
5497 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5498 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5499
5500 return Result;
5501}
5502
5503template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005504QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005505 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005506 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005507 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005508 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5509 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005510 if (!Record)
5511 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005512
John McCall550e0c22009-10-21 00:40:46 +00005513 QualType Result = TL.getType();
5514 if (getDerived().AlwaysRebuild() ||
5515 Record != T->getDecl()) {
5516 Result = getDerived().RebuildRecordType(Record);
5517 if (Result.isNull())
5518 return QualType();
5519 }
Mike Stump11289f42009-09-09 15:08:12 +00005520
John McCall550e0c22009-10-21 00:40:46 +00005521 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5522 NewTL.setNameLoc(TL.getNameLoc());
5523
5524 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005525}
Mike Stump11289f42009-09-09 15:08:12 +00005526
5527template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005528QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005529 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005530 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005531 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005532 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5533 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005534 if (!Enum)
5535 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005536
John McCall550e0c22009-10-21 00:40:46 +00005537 QualType Result = TL.getType();
5538 if (getDerived().AlwaysRebuild() ||
5539 Enum != T->getDecl()) {
5540 Result = getDerived().RebuildEnumType(Enum);
5541 if (Result.isNull())
5542 return QualType();
5543 }
Mike Stump11289f42009-09-09 15:08:12 +00005544
John McCall550e0c22009-10-21 00:40:46 +00005545 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5546 NewTL.setNameLoc(TL.getNameLoc());
5547
5548 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005549}
John McCallfcc33b02009-09-05 00:15:47 +00005550
John McCalle78aac42010-03-10 03:28:59 +00005551template<typename Derived>
5552QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5553 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005554 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005555 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5556 TL.getTypePtr()->getDecl());
5557 if (!D) return QualType();
5558
5559 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5560 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5561 return T;
5562}
5563
Douglas Gregord6ff3322009-08-04 16:50:30 +00005564template<typename Derived>
5565QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005566 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005567 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005568 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005569}
5570
Mike Stump11289f42009-09-09 15:08:12 +00005571template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005572QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005573 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005574 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005575 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005576
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005577 // Substitute into the replacement type, which itself might involve something
5578 // that needs to be transformed. This only tends to occur with default
5579 // template arguments of template template parameters.
5580 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5581 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5582 if (Replacement.isNull())
5583 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005584
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005585 // Always canonicalize the replacement type.
5586 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5587 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005588 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005589 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005590
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005591 // Propagate type-source information.
5592 SubstTemplateTypeParmTypeLoc NewTL
5593 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5594 NewTL.setNameLoc(TL.getNameLoc());
5595 return Result;
5596
John McCallcebee162009-10-18 09:09:24 +00005597}
5598
5599template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005600QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5601 TypeLocBuilder &TLB,
5602 SubstTemplateTypeParmPackTypeLoc TL) {
5603 return TransformTypeSpecType(TLB, TL);
5604}
5605
5606template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005607QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005608 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005609 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005610 const TemplateSpecializationType *T = TL.getTypePtr();
5611
Douglas Gregordf846d12011-03-02 18:46:51 +00005612 // The nested-name-specifier never matters in a TemplateSpecializationType,
5613 // because we can't have a dependent nested-name-specifier anyway.
5614 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005615 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005616 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5617 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618 if (Template.isNull())
5619 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCall31f82722010-11-12 08:19:04 +00005621 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5622}
5623
Eli Friedman0dfb8892011-10-06 23:00:33 +00005624template<typename Derived>
5625QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5626 AtomicTypeLoc TL) {
5627 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5628 if (ValueType.isNull())
5629 return QualType();
5630
5631 QualType Result = TL.getType();
5632 if (getDerived().AlwaysRebuild() ||
5633 ValueType != TL.getValueLoc().getType()) {
5634 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5635 if (Result.isNull())
5636 return QualType();
5637 }
5638
5639 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5640 NewTL.setKWLoc(TL.getKWLoc());
5641 NewTL.setLParenLoc(TL.getLParenLoc());
5642 NewTL.setRParenLoc(TL.getRParenLoc());
5643
5644 return Result;
5645}
5646
Xiuli Pan9c14e282016-01-09 12:53:17 +00005647template <typename Derived>
5648QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5649 PipeTypeLoc TL) {
5650 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5651 if (ValueType.isNull())
5652 return QualType();
5653
5654 QualType Result = TL.getType();
5655 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005656 const PipeType *PT = Result->getAs<PipeType>();
5657 bool isReadPipe = PT->isReadOnly();
5658 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005659 if (Result.isNull())
5660 return QualType();
5661 }
5662
5663 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5664 NewTL.setKWLoc(TL.getKWLoc());
5665
5666 return Result;
5667}
5668
Chad Rosier1dcde962012-08-08 18:46:20 +00005669 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005670 /// container that provides a \c getArgLoc() member function.
5671 ///
5672 /// This iterator is intended to be used with the iterator form of
5673 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5674 template<typename ArgLocContainer>
5675 class TemplateArgumentLocContainerIterator {
5676 ArgLocContainer *Container;
5677 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005678
Douglas Gregorfe921a72010-12-20 23:36:19 +00005679 public:
5680 typedef TemplateArgumentLoc value_type;
5681 typedef TemplateArgumentLoc reference;
5682 typedef int difference_type;
5683 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005684
Douglas Gregorfe921a72010-12-20 23:36:19 +00005685 class pointer {
5686 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005687
Douglas Gregorfe921a72010-12-20 23:36:19 +00005688 public:
5689 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005690
Douglas Gregorfe921a72010-12-20 23:36:19 +00005691 const TemplateArgumentLoc *operator->() const {
5692 return &Arg;
5693 }
5694 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005695
5696
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005697 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005698
Douglas Gregorfe921a72010-12-20 23:36:19 +00005699 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5700 unsigned Index)
5701 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005702
Douglas Gregorfe921a72010-12-20 23:36:19 +00005703 TemplateArgumentLocContainerIterator &operator++() {
5704 ++Index;
5705 return *this;
5706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005707
Douglas Gregorfe921a72010-12-20 23:36:19 +00005708 TemplateArgumentLocContainerIterator operator++(int) {
5709 TemplateArgumentLocContainerIterator Old(*this);
5710 ++(*this);
5711 return Old;
5712 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005713
Douglas Gregorfe921a72010-12-20 23:36:19 +00005714 TemplateArgumentLoc operator*() const {
5715 return Container->getArgLoc(Index);
5716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005717
Douglas Gregorfe921a72010-12-20 23:36:19 +00005718 pointer operator->() const {
5719 return pointer(Container->getArgLoc(Index));
5720 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005721
Douglas Gregorfe921a72010-12-20 23:36:19 +00005722 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005723 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005724 return X.Container == Y.Container && X.Index == Y.Index;
5725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Douglas Gregorfe921a72010-12-20 23:36:19 +00005727 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005728 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005729 return !(X == Y);
5730 }
5731 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005732
5733
John McCall31f82722010-11-12 08:19:04 +00005734template <typename Derived>
5735QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5736 TypeLocBuilder &TLB,
5737 TemplateSpecializationTypeLoc TL,
5738 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005739 TemplateArgumentListInfo NewTemplateArgs;
5740 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5741 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005742 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5743 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005744 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005745 ArgIterator(TL, TL.getNumArgs()),
5746 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005747 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005748
John McCall0ad16662009-10-29 08:12:44 +00005749 // FIXME: maybe don't rebuild if all the template arguments are the same.
5750
5751 QualType Result =
5752 getDerived().RebuildTemplateSpecializationType(Template,
5753 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005754 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005755
5756 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005757 // Specializations of template template parameters are represented as
5758 // TemplateSpecializationTypes, and substitution of type alias templates
5759 // within a dependent context can transform them into
5760 // DependentTemplateSpecializationTypes.
5761 if (isa<DependentTemplateSpecializationType>(Result)) {
5762 DependentTemplateSpecializationTypeLoc NewTL
5763 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005764 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005765 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005766 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005767 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005768 NewTL.setLAngleLoc(TL.getLAngleLoc());
5769 NewTL.setRAngleLoc(TL.getRAngleLoc());
5770 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5771 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5772 return Result;
5773 }
5774
John McCall0ad16662009-10-29 08:12:44 +00005775 TemplateSpecializationTypeLoc NewTL
5776 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005777 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005778 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5779 NewTL.setLAngleLoc(TL.getLAngleLoc());
5780 NewTL.setRAngleLoc(TL.getRAngleLoc());
5781 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5782 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005783 }
Mike Stump11289f42009-09-09 15:08:12 +00005784
John McCall0ad16662009-10-29 08:12:44 +00005785 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005786}
Mike Stump11289f42009-09-09 15:08:12 +00005787
Douglas Gregor5a064722011-02-28 17:23:35 +00005788template <typename Derived>
5789QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5790 TypeLocBuilder &TLB,
5791 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005792 TemplateName Template,
5793 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005794 TemplateArgumentListInfo NewTemplateArgs;
5795 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5796 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5797 typedef TemplateArgumentLocContainerIterator<
5798 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005799 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005800 ArgIterator(TL, TL.getNumArgs()),
5801 NewTemplateArgs))
5802 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005803
Douglas Gregor5a064722011-02-28 17:23:35 +00005804 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005805
Douglas Gregor5a064722011-02-28 17:23:35 +00005806 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5807 QualType Result
5808 = getSema().Context.getDependentTemplateSpecializationType(
5809 TL.getTypePtr()->getKeyword(),
5810 DTN->getQualifier(),
5811 DTN->getIdentifier(),
5812 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
Douglas Gregor5a064722011-02-28 17:23:35 +00005814 DependentTemplateSpecializationTypeLoc NewTL
5815 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005816 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005817 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005818 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005819 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005820 NewTL.setLAngleLoc(TL.getLAngleLoc());
5821 NewTL.setRAngleLoc(TL.getRAngleLoc());
5822 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5823 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5824 return Result;
5825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
5827 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005828 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005829 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005830 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005831
Douglas Gregor5a064722011-02-28 17:23:35 +00005832 if (!Result.isNull()) {
5833 /// FIXME: Wrap this in an elaborated-type-specifier?
5834 TemplateSpecializationTypeLoc NewTL
5835 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005836 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005837 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005838 NewTL.setLAngleLoc(TL.getLAngleLoc());
5839 NewTL.setRAngleLoc(TL.getRAngleLoc());
5840 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5841 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5842 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005843
Douglas Gregor5a064722011-02-28 17:23:35 +00005844 return Result;
5845}
5846
Mike Stump11289f42009-09-09 15:08:12 +00005847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005848QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005849TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005850 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005851 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005852
Douglas Gregor844cb502011-03-01 18:12:44 +00005853 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005854 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005855 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005856 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005857 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5858 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005859 return QualType();
5860 }
Mike Stump11289f42009-09-09 15:08:12 +00005861
John McCall31f82722010-11-12 08:19:04 +00005862 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5863 if (NamedT.isNull())
5864 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005865
Richard Smith3f1b5d02011-05-05 21:57:07 +00005866 // C++0x [dcl.type.elab]p2:
5867 // If the identifier resolves to a typedef-name or the simple-template-id
5868 // resolves to an alias template specialization, the
5869 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005870 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5871 if (const TemplateSpecializationType *TST =
5872 NamedT->getAs<TemplateSpecializationType>()) {
5873 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005874 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5875 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005876 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005877 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005878 << TAT << Sema::NTK_TypeAliasTemplate
5879 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005880 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5881 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005882 }
5883 }
5884
John McCall550e0c22009-10-21 00:40:46 +00005885 QualType Result = TL.getType();
5886 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005887 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005888 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005889 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005890 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005891 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005892 if (Result.isNull())
5893 return QualType();
5894 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005895
Abramo Bagnara6150c882010-05-11 21:36:43 +00005896 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005897 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005898 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005899 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005900}
Mike Stump11289f42009-09-09 15:08:12 +00005901
5902template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005903QualType TreeTransform<Derived>::TransformAttributedType(
5904 TypeLocBuilder &TLB,
5905 AttributedTypeLoc TL) {
5906 const AttributedType *oldType = TL.getTypePtr();
5907 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5908 if (modifiedType.isNull())
5909 return QualType();
5910
5911 QualType result = TL.getType();
5912
5913 // FIXME: dependent operand expressions?
5914 if (getDerived().AlwaysRebuild() ||
5915 modifiedType != oldType->getModifiedType()) {
5916 // TODO: this is really lame; we should really be rebuilding the
5917 // equivalent type from first principles.
5918 QualType equivalentType
5919 = getDerived().TransformType(oldType->getEquivalentType());
5920 if (equivalentType.isNull())
5921 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005922
5923 // Check whether we can add nullability; it is only represented as
5924 // type sugar, and therefore cannot be diagnosed in any other way.
5925 if (auto nullability = oldType->getImmediateNullability()) {
5926 if (!modifiedType->canHaveNullability()) {
5927 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005928 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005929 return QualType();
5930 }
5931 }
5932
John McCall81904512011-01-06 01:58:22 +00005933 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5934 modifiedType,
5935 equivalentType);
5936 }
5937
5938 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5939 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5940 if (TL.hasAttrOperand())
5941 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5942 if (TL.hasAttrExprOperand())
5943 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5944 else if (TL.hasAttrEnumOperand())
5945 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5946
5947 return result;
5948}
5949
5950template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005951QualType
5952TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5953 ParenTypeLoc TL) {
5954 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5955 if (Inner.isNull())
5956 return QualType();
5957
5958 QualType Result = TL.getType();
5959 if (getDerived().AlwaysRebuild() ||
5960 Inner != TL.getInnerLoc().getType()) {
5961 Result = getDerived().RebuildParenType(Inner);
5962 if (Result.isNull())
5963 return QualType();
5964 }
5965
5966 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5967 NewTL.setLParenLoc(TL.getLParenLoc());
5968 NewTL.setRParenLoc(TL.getRParenLoc());
5969 return Result;
5970}
5971
5972template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00005973QualType TreeTransform<Derived>::TransformDependentNameType(
5974 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
5975 return TransformDependentNameType(TLB, TL, false);
5976}
5977
5978template<typename Derived>
5979QualType TreeTransform<Derived>::TransformDependentNameType(
5980 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00005981 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005982
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005983 NestedNameSpecifierLoc QualifierLoc
5984 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5985 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005986 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005987
John McCallc392f372010-06-11 00:33:02 +00005988 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005989 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005990 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005991 QualifierLoc,
5992 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00005993 TL.getNameLoc(),
5994 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00005995 if (Result.isNull())
5996 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005997
Abramo Bagnarad7548482010-05-19 21:37:53 +00005998 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5999 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006000 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6001
Abramo Bagnarad7548482010-05-19 21:37:53 +00006002 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006003 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006004 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006005 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006006 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006007 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006008 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006009 NewTL.setNameLoc(TL.getNameLoc());
6010 }
John McCall550e0c22009-10-21 00:40:46 +00006011 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006012}
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregord6ff3322009-08-04 16:50:30 +00006014template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006015QualType TreeTransform<Derived>::
6016 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006017 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006018 NestedNameSpecifierLoc QualifierLoc;
6019 if (TL.getQualifierLoc()) {
6020 QualifierLoc
6021 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6022 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006023 return QualType();
6024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006025
John McCall31f82722010-11-12 08:19:04 +00006026 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006027 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006028}
6029
6030template<typename Derived>
6031QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006032TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6033 DependentTemplateSpecializationTypeLoc TL,
6034 NestedNameSpecifierLoc QualifierLoc) {
6035 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006036
Douglas Gregora7a795b2011-03-01 20:11:18 +00006037 TemplateArgumentListInfo NewTemplateArgs;
6038 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6039 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006040
Douglas Gregora7a795b2011-03-01 20:11:18 +00006041 typedef TemplateArgumentLocContainerIterator<
6042 DependentTemplateSpecializationTypeLoc> ArgIterator;
6043 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6044 ArgIterator(TL, TL.getNumArgs()),
6045 NewTemplateArgs))
6046 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006047
Richard Smithfd3dae02017-01-20 00:20:39 +00006048 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6049 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6050 TL.getTemplateNameLoc(), NewTemplateArgs,
6051 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006052 if (Result.isNull())
6053 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006054
Douglas Gregora7a795b2011-03-01 20:11:18 +00006055 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6056 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006057
Douglas Gregora7a795b2011-03-01 20:11:18 +00006058 // Copy information relevant to the template specialization.
6059 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006060 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006061 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006062 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006063 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6064 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006065 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006066 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006067
Douglas Gregora7a795b2011-03-01 20:11:18 +00006068 // Copy information relevant to the elaborated type.
6069 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006070 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006071 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006072 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6073 DependentTemplateSpecializationTypeLoc SpecTL
6074 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006075 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006076 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006077 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006078 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006079 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6080 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006081 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006082 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006083 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006084 TemplateSpecializationTypeLoc SpecTL
6085 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006086 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006087 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006088 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6089 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006090 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006091 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006092 }
6093 return Result;
6094}
6095
6096template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006097QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6098 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006099 QualType Pattern
6100 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006101 if (Pattern.isNull())
6102 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006103
6104 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006105 if (getDerived().AlwaysRebuild() ||
6106 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006107 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006108 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006109 TL.getEllipsisLoc(),
6110 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006111 if (Result.isNull())
6112 return QualType();
6113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006114
Douglas Gregor822d0302011-01-12 17:07:58 +00006115 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6116 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6117 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006118}
6119
6120template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006121QualType
6122TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006123 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006124 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006125 TLB.pushFullCopy(TL);
6126 return TL.getType();
6127}
6128
6129template<typename Derived>
6130QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006131TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6132 ObjCTypeParamTypeLoc TL) {
6133 const ObjCTypeParamType *T = TL.getTypePtr();
6134 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6135 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6136 if (!OTP)
6137 return QualType();
6138
6139 QualType Result = TL.getType();
6140 if (getDerived().AlwaysRebuild() ||
6141 OTP != T->getDecl()) {
6142 Result = getDerived().RebuildObjCTypeParamType(OTP,
6143 TL.getProtocolLAngleLoc(),
6144 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6145 TL.getNumProtocols()),
6146 TL.getProtocolLocs(),
6147 TL.getProtocolRAngleLoc());
6148 if (Result.isNull())
6149 return QualType();
6150 }
6151
6152 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6153 if (TL.getNumProtocols()) {
6154 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6155 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6156 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6157 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6158 }
6159 return Result;
6160}
6161
6162template<typename Derived>
6163QualType
John McCall8b07ec22010-05-15 11:32:37 +00006164TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006165 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006166 // Transform base type.
6167 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6168 if (BaseType.isNull())
6169 return QualType();
6170
6171 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6172
6173 // Transform type arguments.
6174 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6175 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6176 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6177 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6178 QualType TypeArg = TypeArgInfo->getType();
6179 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6180 AnyChanged = true;
6181
6182 // We have a pack expansion. Instantiate it.
6183 const auto *PackExpansion = PackExpansionLoc.getType()
6184 ->castAs<PackExpansionType>();
6185 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6186 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6187 Unexpanded);
6188 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6189
6190 // Determine whether the set of unexpanded parameter packs can
6191 // and should be expanded.
6192 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6193 bool Expand = false;
6194 bool RetainExpansion = false;
6195 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6196 if (getDerived().TryExpandParameterPacks(
6197 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6198 Unexpanded, Expand, RetainExpansion, NumExpansions))
6199 return QualType();
6200
6201 if (!Expand) {
6202 // We can't expand this pack expansion into separate arguments yet;
6203 // just substitute into the pattern and create a new pack expansion
6204 // type.
6205 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6206
6207 TypeLocBuilder TypeArgBuilder;
6208 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6209 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6210 PatternLoc);
6211 if (NewPatternType.isNull())
6212 return QualType();
6213
6214 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6215 NewPatternType, NumExpansions);
6216 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6217 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6218 NewTypeArgInfos.push_back(
6219 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6220 continue;
6221 }
6222
6223 // Substitute into the pack expansion pattern for each slice of the
6224 // pack.
6225 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6226 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6227
6228 TypeLocBuilder TypeArgBuilder;
6229 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6230
6231 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6232 PatternLoc);
6233 if (NewTypeArg.isNull())
6234 return QualType();
6235
6236 NewTypeArgInfos.push_back(
6237 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6238 }
6239
6240 continue;
6241 }
6242
6243 TypeLocBuilder TypeArgBuilder;
6244 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6245 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6246 if (NewTypeArg.isNull())
6247 return QualType();
6248
6249 // If nothing changed, just keep the old TypeSourceInfo.
6250 if (NewTypeArg == TypeArg) {
6251 NewTypeArgInfos.push_back(TypeArgInfo);
6252 continue;
6253 }
6254
6255 NewTypeArgInfos.push_back(
6256 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6257 AnyChanged = true;
6258 }
6259
6260 QualType Result = TL.getType();
6261 if (getDerived().AlwaysRebuild() || AnyChanged) {
6262 // Rebuild the type.
6263 Result = getDerived().RebuildObjCObjectType(
6264 BaseType,
6265 TL.getLocStart(),
6266 TL.getTypeArgsLAngleLoc(),
6267 NewTypeArgInfos,
6268 TL.getTypeArgsRAngleLoc(),
6269 TL.getProtocolLAngleLoc(),
6270 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6271 TL.getNumProtocols()),
6272 TL.getProtocolLocs(),
6273 TL.getProtocolRAngleLoc());
6274
6275 if (Result.isNull())
6276 return QualType();
6277 }
6278
6279 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006280 NewT.setHasBaseTypeAsWritten(true);
6281 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6282 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6283 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6284 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6285 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6286 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6287 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6288 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
6292template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006293QualType
6294TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006295 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006296 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6297 if (PointeeType.isNull())
6298 return QualType();
6299
6300 QualType Result = TL.getType();
6301 if (getDerived().AlwaysRebuild() ||
6302 PointeeType != TL.getPointeeLoc().getType()) {
6303 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6304 TL.getStarLoc());
6305 if (Result.isNull())
6306 return QualType();
6307 }
6308
6309 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6310 NewT.setStarLoc(TL.getStarLoc());
6311 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006312}
6313
Douglas Gregord6ff3322009-08-04 16:50:30 +00006314//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006315// Statement transformation
6316//===----------------------------------------------------------------------===//
6317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006318StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006319TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006320 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006321}
6322
6323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006324StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006325TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6326 return getDerived().TransformCompoundStmt(S, false);
6327}
6328
6329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006330StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006331TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006332 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006333 Sema::CompoundScopeRAII CompoundScope(getSema());
6334
John McCall1ababa62010-08-27 19:56:05 +00006335 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006336 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006337 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006338 for (auto *B : S->body()) {
6339 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006340 if (Result.isInvalid()) {
6341 // Immediately fail if this was a DeclStmt, since it's very
6342 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006343 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006344 return StmtError();
6345
6346 // Otherwise, just keep processing substatements and fail later.
6347 SubStmtInvalid = true;
6348 continue;
6349 }
Mike Stump11289f42009-09-09 15:08:12 +00006350
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006351 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006352 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 }
Mike Stump11289f42009-09-09 15:08:12 +00006354
John McCall1ababa62010-08-27 19:56:05 +00006355 if (SubStmtInvalid)
6356 return StmtError();
6357
Douglas Gregorebe10102009-08-20 07:17:43 +00006358 if (!getDerived().AlwaysRebuild() &&
6359 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006360 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006361
6362 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006363 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006364 S->getRBracLoc(),
6365 IsStmtExpr);
6366}
Mike Stump11289f42009-09-09 15:08:12 +00006367
Douglas Gregorebe10102009-08-20 07:17:43 +00006368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006370TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006371 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006372 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00006373 EnterExpressionEvaluationContext Unevaluated(SemaRef,
6374 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006375
Eli Friedman06577382009-11-19 03:14:00 +00006376 // Transform the left-hand case value.
6377 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006378 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006379 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006380 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006381
Eli Friedman06577382009-11-19 03:14:00 +00006382 // Transform the right-hand case value (for the GNU case-range extension).
6383 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006384 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006385 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006386 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006387 }
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregorebe10102009-08-20 07:17:43 +00006389 // Build the case statement.
6390 // Case statements are always rebuilt so that they will attached to their
6391 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006392 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006393 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006394 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006395 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006396 S->getColonLoc());
6397 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006398 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006399
Douglas Gregorebe10102009-08-20 07:17:43 +00006400 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006401 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006402 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006403 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregorebe10102009-08-20 07:17:43 +00006405 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006406 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006407}
6408
6409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006410StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006411TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006412 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006413 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006414 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006415 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregorebe10102009-08-20 07:17:43 +00006417 // Default statements are always rebuilt
6418 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006419 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006420}
Mike Stump11289f42009-09-09 15:08:12 +00006421
Douglas Gregorebe10102009-08-20 07:17:43 +00006422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006423StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006424TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006425 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006426 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006427 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006428
Chris Lattnercab02a62011-02-17 20:34:02 +00006429 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6430 S->getDecl());
6431 if (!LD)
6432 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006433
6434
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006436 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006437 cast<LabelDecl>(LD), SourceLocation(),
6438 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006439}
Mike Stump11289f42009-09-09 15:08:12 +00006440
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006441template <typename Derived>
6442const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6443 if (!R)
6444 return R;
6445
6446 switch (R->getKind()) {
6447// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6448#define ATTR(X)
6449#define PRAGMA_SPELLING_ATTR(X) \
6450 case attr::X: \
6451 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6452#include "clang/Basic/AttrList.inc"
6453 default:
6454 return R;
6455 }
6456}
6457
6458template <typename Derived>
6459StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6460 bool AttrsChanged = false;
6461 SmallVector<const Attr *, 1> Attrs;
6462
6463 // Visit attributes and keep track if any are transformed.
6464 for (const auto *I : S->getAttrs()) {
6465 const Attr *R = getDerived().TransformAttr(I);
6466 AttrsChanged |= (I != R);
6467 Attrs.push_back(R);
6468 }
6469
Richard Smithc202b282012-04-14 00:33:13 +00006470 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6471 if (SubStmt.isInvalid())
6472 return StmtError();
6473
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006474 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006475 return S;
6476
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006477 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006478 SubStmt.get());
6479}
6480
6481template<typename Derived>
6482StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006483TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006484 // Transform the initialization statement
6485 StmtResult Init = getDerived().TransformStmt(S->getInit());
6486 if (Init.isInvalid())
6487 return StmtError();
6488
Douglas Gregorebe10102009-08-20 07:17:43 +00006489 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006490 Sema::ConditionResult Cond = getDerived().TransformCondition(
6491 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006492 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6493 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006494 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006495 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006496
Richard Smithb130fe72016-06-23 19:16:49 +00006497 // If this is a constexpr if, determine which arm we should instantiate.
6498 llvm::Optional<bool> ConstexprConditionValue;
6499 if (S->isConstexpr())
6500 ConstexprConditionValue = Cond.getKnownValue();
6501
Douglas Gregorebe10102009-08-20 07:17:43 +00006502 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006503 StmtResult Then;
6504 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6505 Then = getDerived().TransformStmt(S->getThen());
6506 if (Then.isInvalid())
6507 return StmtError();
6508 } else {
6509 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6510 }
Mike Stump11289f42009-09-09 15:08:12 +00006511
Douglas Gregorebe10102009-08-20 07:17:43 +00006512 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006513 StmtResult Else;
6514 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6515 Else = getDerived().TransformStmt(S->getElse());
6516 if (Else.isInvalid())
6517 return StmtError();
6518 }
Mike Stump11289f42009-09-09 15:08:12 +00006519
Douglas Gregorebe10102009-08-20 07:17:43 +00006520 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006521 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006522 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006523 Then.get() == S->getThen() &&
6524 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006525 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006526
Richard Smithb130fe72016-06-23 19:16:49 +00006527 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006528 Init.get(), Then.get(), S->getElseLoc(),
6529 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006530}
6531
6532template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006533StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006534TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006535 // Transform the initialization statement
6536 StmtResult Init = getDerived().TransformStmt(S->getInit());
6537 if (Init.isInvalid())
6538 return StmtError();
6539
Douglas Gregorebe10102009-08-20 07:17:43 +00006540 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006541 Sema::ConditionResult Cond = getDerived().TransformCondition(
6542 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6543 Sema::ConditionKind::Switch);
6544 if (Cond.isInvalid())
6545 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006546
Douglas Gregorebe10102009-08-20 07:17:43 +00006547 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006548 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006549 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6550 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006551 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006552 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006553
Douglas Gregorebe10102009-08-20 07:17:43 +00006554 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006555 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006556 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006557 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregorebe10102009-08-20 07:17:43 +00006559 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006560 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6561 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
Douglas Gregorebe10102009-08-20 07:17:43 +00006564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006565StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006566TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006567 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006568 Sema::ConditionResult Cond = getDerived().TransformCondition(
6569 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6570 Sema::ConditionKind::Boolean);
6571 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006572 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006573
Douglas Gregorebe10102009-08-20 07:17:43 +00006574 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006575 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006576 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregorebe10102009-08-20 07:17:43 +00006579 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006580 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006581 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006582 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006583
Richard Smith03a4aa32016-06-23 19:02:52 +00006584 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006585}
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregorebe10102009-08-20 07:17:43 +00006587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006588StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006589TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006590 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006591 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006592 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006594
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006595 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006596 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006597 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006598 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006599
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 if (!getDerived().AlwaysRebuild() &&
6601 Cond.get() == S->getCond() &&
6602 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006603 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006604
John McCallb268a282010-08-23 23:25:46 +00006605 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6606 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006607 S->getRParenLoc());
6608}
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregorebe10102009-08-20 07:17:43 +00006610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006612TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006614 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006615 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006617
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006618 // In OpenMP loop region loop control variable must be captured and be
6619 // private. Perform analysis of first part (if any).
6620 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6621 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6622
Douglas Gregorebe10102009-08-20 07:17:43 +00006623 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006624 Sema::ConditionResult Cond = getDerived().TransformCondition(
6625 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6626 Sema::ConditionKind::Boolean);
6627 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006628 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006629
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006631 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006632 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006634
Richard Smith945f8d32013-01-14 22:39:08 +00006635 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006636 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006640 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006641 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006642 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006643
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 if (!getDerived().AlwaysRebuild() &&
6645 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006646 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006647 Inc.get() == S->getInc() &&
6648 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006649 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006650
Douglas Gregorebe10102009-08-20 07:17:43 +00006651 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006652 Init.get(), Cond, FullInc,
6653 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006654}
6655
6656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006657StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006658TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006659 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6660 S->getLabel());
6661 if (!LD)
6662 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006663
Douglas Gregorebe10102009-08-20 07:17:43 +00006664 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006665 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006666 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006667}
6668
6669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006670StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006671TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006672 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006673 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006674 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006675 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregorebe10102009-08-20 07:17:43 +00006677 if (!getDerived().AlwaysRebuild() &&
6678 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006679 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006680
6681 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006682 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006683}
6684
6685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006686StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006687TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006688 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006689}
Mike Stump11289f42009-09-09 15:08:12 +00006690
Douglas Gregorebe10102009-08-20 07:17:43 +00006691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006692StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006693TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006694 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006695}
Mike Stump11289f42009-09-09 15:08:12 +00006696
Douglas Gregorebe10102009-08-20 07:17:43 +00006697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006698StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006699TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006700 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6701 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006702 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006704
Mike Stump11289f42009-09-09 15:08:12 +00006705 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006706 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006707 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006708}
Mike Stump11289f42009-09-09 15:08:12 +00006709
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006713 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006714 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006715 for (auto *D : S->decls()) {
6716 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006717 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006718 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006719
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006720 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006721 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregorebe10102009-08-20 07:17:43 +00006723 Decls.push_back(Transformed);
6724 }
Mike Stump11289f42009-09-09 15:08:12 +00006725
Douglas Gregorebe10102009-08-20 07:17:43 +00006726 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006727 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006728
Rafael Espindolaab417692013-07-09 12:05:01 +00006729 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006730}
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregorebe10102009-08-20 07:17:43 +00006732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006733StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006734TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006735
Benjamin Kramerf0623432012-08-23 22:51:59 +00006736 SmallVector<Expr*, 8> Constraints;
6737 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006738 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006739
John McCalldadc5752010-08-24 06:29:42 +00006740 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006741 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006742
6743 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006744
Anders Carlssonaaeef072010-01-24 05:50:09 +00006745 // Go through the outputs.
6746 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006747 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006748
Anders Carlssonaaeef072010-01-24 05:50:09 +00006749 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006750 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006751
Anders Carlssonaaeef072010-01-24 05:50:09 +00006752 // Transform the output expr.
6753 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006754 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006755 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006756 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006757
Anders Carlssonaaeef072010-01-24 05:50:09 +00006758 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
John McCallb268a282010-08-23 23:25:46 +00006760 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006761 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006762
Anders Carlssonaaeef072010-01-24 05:50:09 +00006763 // Go through the inputs.
6764 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006765 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
Anders Carlssonaaeef072010-01-24 05:50:09 +00006767 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006768 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Anders Carlssonaaeef072010-01-24 05:50:09 +00006770 // Transform the input expr.
6771 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006772 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006773 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Anders Carlssonaaeef072010-01-24 05:50:09 +00006776 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006777
John McCallb268a282010-08-23 23:25:46 +00006778 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006779 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
Anders Carlssonaaeef072010-01-24 05:50:09 +00006781 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006782 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006783
6784 // Go through the clobbers.
6785 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006786 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006787
6788 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006789 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006790 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6791 S->isVolatile(), S->getNumOutputs(),
6792 S->getNumInputs(), Names.data(),
6793 Constraints, Exprs, AsmString.get(),
6794 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006795}
6796
Chad Rosier32503022012-06-11 20:47:18 +00006797template<typename Derived>
6798StmtResult
6799TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006800 ArrayRef<Token> AsmToks =
6801 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006802
John McCallf413f5e2013-05-03 00:10:13 +00006803 bool HadError = false, HadChange = false;
6804
6805 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6806 SmallVector<Expr*, 8> TransformedExprs;
6807 TransformedExprs.reserve(SrcExprs.size());
6808 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6809 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6810 if (!Result.isUsable()) {
6811 HadError = true;
6812 } else {
6813 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006814 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006815 }
6816 }
6817
6818 if (HadError) return StmtError();
6819 if (!HadChange && !getDerived().AlwaysRebuild())
6820 return Owned(S);
6821
Chad Rosierb6f46c12012-08-15 16:53:30 +00006822 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006823 AsmToks, S->getAsmString(),
6824 S->getNumOutputs(), S->getNumInputs(),
6825 S->getAllConstraints(), S->getClobbers(),
6826 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006827}
Douglas Gregorebe10102009-08-20 07:17:43 +00006828
Richard Smith9f690bd2015-10-27 06:02:45 +00006829// C++ Coroutines TS
6830
6831template<typename Derived>
6832StmtResult
6833TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
6834 // The coroutine body should be re-formed by the caller if necessary.
Eric Fiselier709d1b32016-10-27 07:30:31 +00006835 // FIXME: The coroutine body is always rebuilt by ActOnFinishFunctionBody
Richard Smith9f690bd2015-10-27 06:02:45 +00006836 return getDerived().TransformStmt(S->getBody());
6837}
6838
6839template<typename Derived>
6840StmtResult
6841TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6842 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6843 /*NotCopyInit*/false);
6844 if (Result.isInvalid())
6845 return StmtError();
6846
6847 // Always rebuild; we don't know if this needs to be injected into a new
6848 // context or if the promise type has changed.
6849 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get());
6850}
6851
6852template<typename Derived>
6853ExprResult
6854TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6855 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6856 /*NotCopyInit*/false);
6857 if (Result.isInvalid())
6858 return ExprError();
6859
6860 // Always rebuild; we don't know if this needs to be injected into a new
6861 // context or if the promise type has changed.
6862 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get());
6863}
6864
6865template<typename Derived>
6866ExprResult
6867TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
6868 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6869 /*NotCopyInit*/false);
6870 if (Result.isInvalid())
6871 return ExprError();
6872
6873 // Always rebuild; we don't know if this needs to be injected into a new
6874 // context or if the promise type has changed.
6875 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
6876}
6877
6878// Objective-C Statements.
6879
Douglas Gregorebe10102009-08-20 07:17:43 +00006880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006881StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006882TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006883 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006884 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006885 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006886 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006887
Douglas Gregor96c79492010-04-23 22:50:49 +00006888 // Transform the @catch statements (if present).
6889 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006890 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006891 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006892 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006893 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006894 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006895 if (Catch.get() != S->getCatchStmt(I))
6896 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006897 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006899
Douglas Gregor306de2f2010-04-22 23:59:56 +00006900 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006901 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006902 if (S->getFinallyStmt()) {
6903 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6904 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006905 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006906 }
6907
6908 // If nothing changed, just retain this statement.
6909 if (!getDerived().AlwaysRebuild() &&
6910 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006911 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006912 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006913 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006914
Douglas Gregor306de2f2010-04-22 23:59:56 +00006915 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006916 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006917 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006918}
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregorebe10102009-08-20 07:17:43 +00006920template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006921StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006922TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006923 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006924 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006925 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006926 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006927 if (FromVar->getTypeSourceInfo()) {
6928 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6929 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006930 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006932
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006933 QualType T;
6934 if (TSInfo)
6935 T = TSInfo->getType();
6936 else {
6937 T = getDerived().TransformType(FromVar->getType());
6938 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006939 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006941
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006942 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6943 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006944 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006945 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006946
John McCalldadc5752010-08-24 06:29:42 +00006947 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006948 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006949 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006950
6951 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006952 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006953 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006954}
Mike Stump11289f42009-09-09 15:08:12 +00006955
Douglas Gregorebe10102009-08-20 07:17:43 +00006956template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006957StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006958TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006959 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006960 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006961 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006962 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006963
Douglas Gregor306de2f2010-04-22 23:59:56 +00006964 // If nothing changed, just retain this statement.
6965 if (!getDerived().AlwaysRebuild() &&
6966 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006967 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006968
6969 // Build a new statement.
6970 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006971 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006972}
Mike Stump11289f42009-09-09 15:08:12 +00006973
Douglas Gregorebe10102009-08-20 07:17:43 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006976TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006977 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006978 if (S->getThrowExpr()) {
6979 Operand = getDerived().TransformExpr(S->getThrowExpr());
6980 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006981 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006983
Douglas Gregor2900c162010-04-22 21:44:01 +00006984 if (!getDerived().AlwaysRebuild() &&
6985 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006986 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006987
John McCallb268a282010-08-23 23:25:46 +00006988 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006989}
Mike Stump11289f42009-09-09 15:08:12 +00006990
Douglas Gregorebe10102009-08-20 07:17:43 +00006991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006992StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006993TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006994 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006995 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006996 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006997 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006998 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006999 Object =
7000 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7001 Object.get());
7002 if (Object.isInvalid())
7003 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007004
Douglas Gregor6148de72010-04-22 22:01:21 +00007005 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007006 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007007 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007008 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007009
Douglas Gregor6148de72010-04-22 22:01:21 +00007010 // If nothing change, just retain the current statement.
7011 if (!getDerived().AlwaysRebuild() &&
7012 Object.get() == S->getSynchExpr() &&
7013 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007014 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007015
7016 // Build a new statement.
7017 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007018 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007019}
7020
7021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022StmtResult
John McCall31168b02011-06-15 23:02:42 +00007023TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7024 ObjCAutoreleasePoolStmt *S) {
7025 // Transform the body.
7026 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7027 if (Body.isInvalid())
7028 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007029
John McCall31168b02011-06-15 23:02:42 +00007030 // If nothing changed, just retain this statement.
7031 if (!getDerived().AlwaysRebuild() &&
7032 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007033 return S;
John McCall31168b02011-06-15 23:02:42 +00007034
7035 // Build a new statement.
7036 return getDerived().RebuildObjCAutoreleasePoolStmt(
7037 S->getAtLoc(), Body.get());
7038}
7039
7040template<typename Derived>
7041StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007042TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007043 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007044 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007045 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007046 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007047 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007048
Douglas Gregorf68a5082010-04-22 23:10:45 +00007049 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007050 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007051 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007052 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007053
Douglas Gregorf68a5082010-04-22 23:10:45 +00007054 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007055 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007056 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007057 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007058
Douglas Gregorf68a5082010-04-22 23:10:45 +00007059 // If nothing changed, just retain this statement.
7060 if (!getDerived().AlwaysRebuild() &&
7061 Element.get() == S->getElement() &&
7062 Collection.get() == S->getCollection() &&
7063 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007064 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007065
Douglas Gregorf68a5082010-04-22 23:10:45 +00007066 // Build a new statement.
7067 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007068 Element.get(),
7069 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007070 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007071 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007072}
7073
David Majnemer5f7efef2013-10-15 09:50:08 +00007074template <typename Derived>
7075StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007076 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007077 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007078 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7079 TypeSourceInfo *T =
7080 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007081 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007083
David Majnemer5f7efef2013-10-15 09:50:08 +00007084 Var = getDerived().RebuildExceptionDecl(
7085 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7086 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007087 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007088 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007089 }
Mike Stump11289f42009-09-09 15:08:12 +00007090
Douglas Gregorebe10102009-08-20 07:17:43 +00007091 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007092 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007093 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007094 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007095
David Majnemer5f7efef2013-10-15 09:50:08 +00007096 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007097 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007098 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007099
David Majnemer5f7efef2013-10-15 09:50:08 +00007100 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007101}
Mike Stump11289f42009-09-09 15:08:12 +00007102
David Majnemer5f7efef2013-10-15 09:50:08 +00007103template <typename Derived>
7104StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007105 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007106 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007107 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007108 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007109
Douglas Gregorebe10102009-08-20 07:17:43 +00007110 // Transform the handlers.
7111 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007112 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007113 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007114 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007115 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007117
Douglas Gregorebe10102009-08-20 07:17:43 +00007118 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007119 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007120 }
Mike Stump11289f42009-09-09 15:08:12 +00007121
David Majnemer5f7efef2013-10-15 09:50:08 +00007122 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007123 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007124 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007125
John McCallb268a282010-08-23 23:25:46 +00007126 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007127 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007128}
Mike Stump11289f42009-09-09 15:08:12 +00007129
Richard Smith02e85f32011-04-14 22:09:26 +00007130template<typename Derived>
7131StmtResult
7132TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7133 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7134 if (Range.isInvalid())
7135 return StmtError();
7136
Richard Smith01694c32016-03-20 10:33:40 +00007137 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7138 if (Begin.isInvalid())
7139 return StmtError();
7140 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7141 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007142 return StmtError();
7143
7144 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7145 if (Cond.isInvalid())
7146 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007147 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007148 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007149 if (Cond.isInvalid())
7150 return StmtError();
7151 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007152 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007153
7154 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7155 if (Inc.isInvalid())
7156 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007157 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007158 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007159
7160 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7161 if (LoopVar.isInvalid())
7162 return StmtError();
7163
7164 StmtResult NewStmt = S;
7165 if (getDerived().AlwaysRebuild() ||
7166 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007167 Begin.get() != S->getBeginStmt() ||
7168 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007169 Cond.get() != S->getCond() ||
7170 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007171 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007172 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007173 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007174 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007175 Begin.get(), End.get(),
7176 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007177 Inc.get(), LoopVar.get(),
7178 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007179 if (NewStmt.isInvalid())
7180 return StmtError();
7181 }
Richard Smith02e85f32011-04-14 22:09:26 +00007182
7183 StmtResult Body = getDerived().TransformStmt(S->getBody());
7184 if (Body.isInvalid())
7185 return StmtError();
7186
7187 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7188 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007189 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007190 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007191 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007192 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007193 Begin.get(), End.get(),
7194 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007195 Inc.get(), LoopVar.get(),
7196 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007197 if (NewStmt.isInvalid())
7198 return StmtError();
7199 }
Richard Smith02e85f32011-04-14 22:09:26 +00007200
7201 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007202 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007203
7204 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7205}
7206
John Wiegley1c0675e2011-04-28 01:08:34 +00007207template<typename Derived>
7208StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007209TreeTransform<Derived>::TransformMSDependentExistsStmt(
7210 MSDependentExistsStmt *S) {
7211 // Transform the nested-name-specifier, if any.
7212 NestedNameSpecifierLoc QualifierLoc;
7213 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007214 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007215 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7216 if (!QualifierLoc)
7217 return StmtError();
7218 }
7219
7220 // Transform the declaration name.
7221 DeclarationNameInfo NameInfo = S->getNameInfo();
7222 if (NameInfo.getName()) {
7223 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7224 if (!NameInfo.getName())
7225 return StmtError();
7226 }
7227
7228 // Check whether anything changed.
7229 if (!getDerived().AlwaysRebuild() &&
7230 QualifierLoc == S->getQualifierLoc() &&
7231 NameInfo.getName() == S->getNameInfo().getName())
7232 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007233
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007234 // Determine whether this name exists, if we can.
7235 CXXScopeSpec SS;
7236 SS.Adopt(QualifierLoc);
7237 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007238 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007239 case Sema::IER_Exists:
7240 if (S->isIfExists())
7241 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007242
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007243 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7244
7245 case Sema::IER_DoesNotExist:
7246 if (S->isIfNotExists())
7247 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007248
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007249 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007250
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007251 case Sema::IER_Dependent:
7252 Dependent = true;
7253 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007254
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007255 case Sema::IER_Error:
7256 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007258
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007259 // We need to continue with the instantiation, so do so now.
7260 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7261 if (SubStmt.isInvalid())
7262 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007263
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007264 // If we have resolved the name, just transform to the substatement.
7265 if (!Dependent)
7266 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007267
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007268 // The name is still dependent, so build a dependent expression again.
7269 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7270 S->isIfExists(),
7271 QualifierLoc,
7272 NameInfo,
7273 SubStmt.get());
7274}
7275
7276template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007277ExprResult
7278TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7279 NestedNameSpecifierLoc QualifierLoc;
7280 if (E->getQualifierLoc()) {
7281 QualifierLoc
7282 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7283 if (!QualifierLoc)
7284 return ExprError();
7285 }
7286
7287 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7288 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7289 if (!PD)
7290 return ExprError();
7291
7292 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7293 if (Base.isInvalid())
7294 return ExprError();
7295
7296 return new (SemaRef.getASTContext())
7297 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7298 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7299 QualifierLoc, E->getMemberLoc());
7300}
7301
David Majnemerfad8f482013-10-15 09:33:02 +00007302template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007303ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7304 MSPropertySubscriptExpr *E) {
7305 auto BaseRes = getDerived().TransformExpr(E->getBase());
7306 if (BaseRes.isInvalid())
7307 return ExprError();
7308 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7309 if (IdxRes.isInvalid())
7310 return ExprError();
7311
7312 if (!getDerived().AlwaysRebuild() &&
7313 BaseRes.get() == E->getBase() &&
7314 IdxRes.get() == E->getIdx())
7315 return E;
7316
7317 return getDerived().RebuildArraySubscriptExpr(
7318 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7319}
7320
7321template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007322StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007323 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007324 if (TryBlock.isInvalid())
7325 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007326
7327 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007328 if (Handler.isInvalid())
7329 return StmtError();
7330
David Majnemerfad8f482013-10-15 09:33:02 +00007331 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7332 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007333 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007334
Warren Huntf6be4cb2014-07-25 20:52:51 +00007335 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7336 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007337}
7338
David Majnemerfad8f482013-10-15 09:33:02 +00007339template <typename Derived>
7340StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007341 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007342 if (Block.isInvalid())
7343 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007344
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007345 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007346}
7347
David Majnemerfad8f482013-10-15 09:33:02 +00007348template <typename Derived>
7349StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007350 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007351 if (FilterExpr.isInvalid())
7352 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007353
David Majnemer7e755502013-10-15 09:30:14 +00007354 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007355 if (Block.isInvalid())
7356 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007357
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007358 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7359 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007360}
7361
David Majnemerfad8f482013-10-15 09:33:02 +00007362template <typename Derived>
7363StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7364 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007365 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7366 else
7367 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7368}
7369
Nico Weber9b982072014-07-07 00:12:30 +00007370template<typename Derived>
7371StmtResult
7372TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7373 return S;
7374}
7375
Alexander Musman64d33f12014-06-04 07:53:32 +00007376//===----------------------------------------------------------------------===//
7377// OpenMP directive transformation
7378//===----------------------------------------------------------------------===//
7379template <typename Derived>
7380StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7381 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007382
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007383 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007384 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007385 ArrayRef<OMPClause *> Clauses = D->clauses();
7386 TClauses.reserve(Clauses.size());
7387 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7388 I != E; ++I) {
7389 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007390 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007391 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007392 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007393 if (Clause)
7394 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007395 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007396 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007397 }
7398 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007399 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007400 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007401 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7402 /*CurScope=*/nullptr);
7403 StmtResult Body;
7404 {
7405 Sema::CompoundScopeRAII CompoundScope(getSema());
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007406 int ThisCaptureLevel =
7407 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7408 Stmt *CS = D->getAssociatedStmt();
7409 while (--ThisCaptureLevel >= 0)
7410 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7411 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007412 }
7413 AssociatedStmt =
7414 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007415 if (AssociatedStmt.isInvalid()) {
7416 return StmtError();
7417 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007418 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007419 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007420 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007421 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007422
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007423 // Transform directive name for 'omp critical' directive.
7424 DeclarationNameInfo DirName;
7425 if (D->getDirectiveKind() == OMPD_critical) {
7426 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7427 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7428 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007429 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7430 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7431 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007432 } else if (D->getDirectiveKind() == OMPD_cancel) {
7433 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007434 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007435
Alexander Musman64d33f12014-06-04 07:53:32 +00007436 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007437 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7438 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007439}
7440
Alexander Musman64d33f12014-06-04 07:53:32 +00007441template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007442StmtResult
7443TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7444 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007445 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7446 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007447 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7448 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7449 return Res;
7450}
7451
Alexander Musman64d33f12014-06-04 07:53:32 +00007452template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007453StmtResult
7454TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7455 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007456 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7457 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007458 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7459 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007460 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007461}
7462
Alexey Bataevf29276e2014-06-18 04:14:57 +00007463template <typename Derived>
7464StmtResult
7465TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7466 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007467 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7468 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007469 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7470 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7471 return Res;
7472}
7473
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007474template <typename Derived>
7475StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007476TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7477 DeclarationNameInfo DirName;
7478 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7479 D->getLocStart());
7480 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7481 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7482 return Res;
7483}
7484
7485template <typename Derived>
7486StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007487TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7488 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007489 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7490 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007491 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7492 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7493 return Res;
7494}
7495
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007496template <typename Derived>
7497StmtResult
7498TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7499 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007500 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7501 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007502 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7503 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7504 return Res;
7505}
7506
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007507template <typename Derived>
7508StmtResult
7509TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7510 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007511 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7512 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007513 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7514 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7515 return Res;
7516}
7517
Alexey Bataev4acb8592014-07-07 13:01:15 +00007518template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007519StmtResult
7520TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7521 DeclarationNameInfo DirName;
7522 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7523 D->getLocStart());
7524 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7525 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7526 return Res;
7527}
7528
7529template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007530StmtResult
7531TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7532 getDerived().getSema().StartOpenMPDSABlock(
7533 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7534 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7535 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7536 return Res;
7537}
7538
7539template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007540StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7541 OMPParallelForDirective *D) {
7542 DeclarationNameInfo DirName;
7543 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7544 nullptr, D->getLocStart());
7545 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7546 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7547 return Res;
7548}
7549
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007550template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007551StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7552 OMPParallelForSimdDirective *D) {
7553 DeclarationNameInfo DirName;
7554 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7555 nullptr, D->getLocStart());
7556 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7557 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7558 return Res;
7559}
7560
7561template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007562StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7563 OMPParallelSectionsDirective *D) {
7564 DeclarationNameInfo DirName;
7565 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7566 nullptr, D->getLocStart());
7567 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7568 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7569 return Res;
7570}
7571
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007572template <typename Derived>
7573StmtResult
7574TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7575 DeclarationNameInfo DirName;
7576 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7577 D->getLocStart());
7578 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7579 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7580 return Res;
7581}
7582
Alexey Bataev68446b72014-07-18 07:47:19 +00007583template <typename Derived>
7584StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7585 OMPTaskyieldDirective *D) {
7586 DeclarationNameInfo DirName;
7587 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7588 D->getLocStart());
7589 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7590 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7591 return Res;
7592}
7593
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007594template <typename Derived>
7595StmtResult
7596TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7597 DeclarationNameInfo DirName;
7598 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7599 D->getLocStart());
7600 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7601 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7602 return Res;
7603}
7604
Alexey Bataev2df347a2014-07-18 10:17:07 +00007605template <typename Derived>
7606StmtResult
7607TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7608 DeclarationNameInfo DirName;
7609 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7610 D->getLocStart());
7611 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7612 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7613 return Res;
7614}
7615
Alexey Bataev6125da92014-07-21 11:26:11 +00007616template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007617StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7618 OMPTaskgroupDirective *D) {
7619 DeclarationNameInfo DirName;
7620 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7621 D->getLocStart());
7622 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7623 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7624 return Res;
7625}
7626
7627template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007628StmtResult
7629TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7630 DeclarationNameInfo DirName;
7631 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7632 D->getLocStart());
7633 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7634 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7635 return Res;
7636}
7637
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007638template <typename Derived>
7639StmtResult
7640TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7641 DeclarationNameInfo DirName;
7642 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7643 D->getLocStart());
7644 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7645 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7646 return Res;
7647}
7648
Alexey Bataev0162e452014-07-22 10:10:35 +00007649template <typename Derived>
7650StmtResult
7651TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7652 DeclarationNameInfo DirName;
7653 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7654 D->getLocStart());
7655 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7656 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7657 return Res;
7658}
7659
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007660template <typename Derived>
7661StmtResult
7662TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7663 DeclarationNameInfo DirName;
7664 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7665 D->getLocStart());
7666 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7667 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7668 return Res;
7669}
7670
Alexey Bataev13314bf2014-10-09 04:18:56 +00007671template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007672StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7673 OMPTargetDataDirective *D) {
7674 DeclarationNameInfo DirName;
7675 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7676 D->getLocStart());
7677 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7678 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7679 return Res;
7680}
7681
7682template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007683StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7684 OMPTargetEnterDataDirective *D) {
7685 DeclarationNameInfo DirName;
7686 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7687 nullptr, D->getLocStart());
7688 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7689 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7690 return Res;
7691}
7692
7693template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007694StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7695 OMPTargetExitDataDirective *D) {
7696 DeclarationNameInfo DirName;
7697 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7698 nullptr, D->getLocStart());
7699 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7700 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7701 return Res;
7702}
7703
7704template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007705StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7706 OMPTargetParallelDirective *D) {
7707 DeclarationNameInfo DirName;
7708 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7709 nullptr, D->getLocStart());
7710 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7711 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7712 return Res;
7713}
7714
7715template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007716StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7717 OMPTargetParallelForDirective *D) {
7718 DeclarationNameInfo DirName;
7719 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7720 nullptr, D->getLocStart());
7721 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7722 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7723 return Res;
7724}
7725
7726template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007727StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7728 OMPTargetUpdateDirective *D) {
7729 DeclarationNameInfo DirName;
7730 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7731 nullptr, D->getLocStart());
7732 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7733 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7734 return Res;
7735}
7736
7737template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007738StmtResult
7739TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7740 DeclarationNameInfo DirName;
7741 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7742 D->getLocStart());
7743 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7744 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7745 return Res;
7746}
7747
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007748template <typename Derived>
7749StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7750 OMPCancellationPointDirective *D) {
7751 DeclarationNameInfo DirName;
7752 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7753 nullptr, D->getLocStart());
7754 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7755 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7756 return Res;
7757}
7758
Alexey Bataev80909872015-07-02 11:25:17 +00007759template <typename Derived>
7760StmtResult
7761TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7762 DeclarationNameInfo DirName;
7763 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7764 D->getLocStart());
7765 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7766 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7767 return Res;
7768}
7769
Alexey Bataev49f6e782015-12-01 04:18:41 +00007770template <typename Derived>
7771StmtResult
7772TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7773 DeclarationNameInfo DirName;
7774 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7775 D->getLocStart());
7776 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7777 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7778 return Res;
7779}
7780
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007781template <typename Derived>
7782StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7783 OMPTaskLoopSimdDirective *D) {
7784 DeclarationNameInfo DirName;
7785 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7786 nullptr, D->getLocStart());
7787 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7788 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7789 return Res;
7790}
7791
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007792template <typename Derived>
7793StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7794 OMPDistributeDirective *D) {
7795 DeclarationNameInfo DirName;
7796 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7797 D->getLocStart());
7798 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7799 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7800 return Res;
7801}
7802
Carlo Bertolli9925f152016-06-27 14:55:37 +00007803template <typename Derived>
7804StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7805 OMPDistributeParallelForDirective *D) {
7806 DeclarationNameInfo DirName;
7807 getDerived().getSema().StartOpenMPDSABlock(
7808 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7809 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7810 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7811 return Res;
7812}
7813
Kelvin Li4a39add2016-07-05 05:00:15 +00007814template <typename Derived>
7815StmtResult
7816TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7817 OMPDistributeParallelForSimdDirective *D) {
7818 DeclarationNameInfo DirName;
7819 getDerived().getSema().StartOpenMPDSABlock(
7820 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7821 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7822 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7823 return Res;
7824}
7825
Kelvin Li787f3fc2016-07-06 04:45:38 +00007826template <typename Derived>
7827StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7828 OMPDistributeSimdDirective *D) {
7829 DeclarationNameInfo DirName;
7830 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7831 nullptr, D->getLocStart());
7832 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7833 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7834 return Res;
7835}
7836
Kelvin Lia579b912016-07-14 02:54:56 +00007837template <typename Derived>
7838StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7839 OMPTargetParallelForSimdDirective *D) {
7840 DeclarationNameInfo DirName;
7841 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7842 DirName, nullptr,
7843 D->getLocStart());
7844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7846 return Res;
7847}
7848
Kelvin Li986330c2016-07-20 22:57:10 +00007849template <typename Derived>
7850StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7851 OMPTargetSimdDirective *D) {
7852 DeclarationNameInfo DirName;
7853 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7854 D->getLocStart());
7855 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7856 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7857 return Res;
7858}
7859
Kelvin Li02532872016-08-05 14:37:37 +00007860template <typename Derived>
7861StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7862 OMPTeamsDistributeDirective *D) {
7863 DeclarationNameInfo DirName;
7864 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7865 nullptr, D->getLocStart());
7866 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7867 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7868 return Res;
7869}
7870
Kelvin Li4e325f72016-10-25 12:50:55 +00007871template <typename Derived>
7872StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
7873 OMPTeamsDistributeSimdDirective *D) {
7874 DeclarationNameInfo DirName;
7875 getDerived().getSema().StartOpenMPDSABlock(
7876 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7877 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7878 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7879 return Res;
7880}
7881
Kelvin Li579e41c2016-11-30 23:51:03 +00007882template <typename Derived>
7883StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
7884 OMPTeamsDistributeParallelForSimdDirective *D) {
7885 DeclarationNameInfo DirName;
7886 getDerived().getSema().StartOpenMPDSABlock(
7887 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7888 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7889 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7890 return Res;
7891}
7892
Kelvin Li7ade93f2016-12-09 03:24:30 +00007893template <typename Derived>
7894StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
7895 OMPTeamsDistributeParallelForDirective *D) {
7896 DeclarationNameInfo DirName;
7897 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
7898 DirName, nullptr, D->getLocStart());
7899 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7900 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7901 return Res;
7902}
7903
Kelvin Libf594a52016-12-17 05:48:59 +00007904template <typename Derived>
7905StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
7906 OMPTargetTeamsDirective *D) {
7907 DeclarationNameInfo DirName;
7908 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
7909 nullptr, D->getLocStart());
7910 auto Res = getDerived().TransformOMPExecutableDirective(D);
7911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7912 return Res;
7913}
Kelvin Li579e41c2016-11-30 23:51:03 +00007914
Kelvin Li83c451e2016-12-25 04:52:54 +00007915template <typename Derived>
7916StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
7917 OMPTargetTeamsDistributeDirective *D) {
7918 DeclarationNameInfo DirName;
7919 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
7920 DirName, nullptr, D->getLocStart());
7921 auto Res = getDerived().TransformOMPExecutableDirective(D);
7922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7923 return Res;
7924}
7925
Kelvin Li80e8f562016-12-29 22:16:30 +00007926template <typename Derived>
7927StmtResult
7928TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
7929 OMPTargetTeamsDistributeParallelForDirective *D) {
7930 DeclarationNameInfo DirName;
7931 getDerived().getSema().StartOpenMPDSABlock(
7932 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
7933 D->getLocStart());
7934 auto Res = getDerived().TransformOMPExecutableDirective(D);
7935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7936 return Res;
7937}
7938
Kelvin Li1851df52017-01-03 05:23:48 +00007939template <typename Derived>
7940StmtResult TreeTransform<Derived>::
7941 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
7942 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
7943 DeclarationNameInfo DirName;
7944 getDerived().getSema().StartOpenMPDSABlock(
7945 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
7946 D->getLocStart());
7947 auto Res = getDerived().TransformOMPExecutableDirective(D);
7948 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7949 return Res;
7950}
7951
Kelvin Lida681182017-01-10 18:08:18 +00007952template <typename Derived>
7953StmtResult
7954TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
7955 OMPTargetTeamsDistributeSimdDirective *D) {
7956 DeclarationNameInfo DirName;
7957 getDerived().getSema().StartOpenMPDSABlock(
7958 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
7959 auto Res = getDerived().TransformOMPExecutableDirective(D);
7960 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7961 return Res;
7962}
7963
Kelvin Li1851df52017-01-03 05:23:48 +00007964
Alexander Musman64d33f12014-06-04 07:53:32 +00007965//===----------------------------------------------------------------------===//
7966// OpenMP clause transformation
7967//===----------------------------------------------------------------------===//
7968template <typename Derived>
7969OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007970 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7971 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007972 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007973 return getDerived().RebuildOMPIfClause(
7974 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7975 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007976}
7977
Alexander Musman64d33f12014-06-04 07:53:32 +00007978template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007979OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7980 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7981 if (Cond.isInvalid())
7982 return nullptr;
7983 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7984 C->getLParenLoc(), C->getLocEnd());
7985}
7986
7987template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007988OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007989TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7990 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7991 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007992 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007993 return getDerived().RebuildOMPNumThreadsClause(
7994 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007995}
7996
Alexey Bataev62c87d22014-03-21 04:51:18 +00007997template <typename Derived>
7998OMPClause *
7999TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8000 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8001 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008002 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008003 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008004 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008005}
8006
Alexander Musman8bd31e62014-05-27 15:12:19 +00008007template <typename Derived>
8008OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008009TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8010 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8011 if (E.isInvalid())
8012 return nullptr;
8013 return getDerived().RebuildOMPSimdlenClause(
8014 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8015}
8016
8017template <typename Derived>
8018OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008019TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8020 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8021 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008022 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008023 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008024 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008025}
8026
Alexander Musman64d33f12014-06-04 07:53:32 +00008027template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008028OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008029TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008030 return getDerived().RebuildOMPDefaultClause(
8031 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8032 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008033}
8034
Alexander Musman64d33f12014-06-04 07:53:32 +00008035template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008036OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008037TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008038 return getDerived().RebuildOMPProcBindClause(
8039 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8040 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008041}
8042
Alexander Musman64d33f12014-06-04 07:53:32 +00008043template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008044OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008045TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8046 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8047 if (E.isInvalid())
8048 return nullptr;
8049 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008050 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008051 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008052 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008053 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8054}
8055
8056template <typename Derived>
8057OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008058TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008059 ExprResult E;
8060 if (auto *Num = C->getNumForLoops()) {
8061 E = getDerived().TransformExpr(Num);
8062 if (E.isInvalid())
8063 return nullptr;
8064 }
8065 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8066 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008067}
8068
8069template <typename Derived>
8070OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008071TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8072 // No need to rebuild this clause, no template-dependent parameters.
8073 return C;
8074}
8075
8076template <typename Derived>
8077OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008078TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8079 // No need to rebuild this clause, no template-dependent parameters.
8080 return C;
8081}
8082
8083template <typename Derived>
8084OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008085TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8086 // No need to rebuild this clause, no template-dependent parameters.
8087 return C;
8088}
8089
8090template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008091OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8092 // No need to rebuild this clause, no template-dependent parameters.
8093 return C;
8094}
8095
8096template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008097OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8098 // No need to rebuild this clause, no template-dependent parameters.
8099 return C;
8100}
8101
8102template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008103OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008104TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8105 // No need to rebuild this clause, no template-dependent parameters.
8106 return C;
8107}
8108
8109template <typename Derived>
8110OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008111TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8112 // No need to rebuild this clause, no template-dependent parameters.
8113 return C;
8114}
8115
8116template <typename Derived>
8117OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008118TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8119 // No need to rebuild this clause, no template-dependent parameters.
8120 return C;
8121}
8122
8123template <typename Derived>
8124OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008125TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8126 // No need to rebuild this clause, no template-dependent parameters.
8127 return C;
8128}
8129
8130template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008131OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8132 // No need to rebuild this clause, no template-dependent parameters.
8133 return C;
8134}
8135
8136template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008137OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008138TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8139 // No need to rebuild this clause, no template-dependent parameters.
8140 return C;
8141}
8142
8143template <typename Derived>
8144OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008145TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008146 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008147 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008148 for (auto *VE : C->varlists()) {
8149 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008150 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008151 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008152 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008153 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008154 return getDerived().RebuildOMPPrivateClause(
8155 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008156}
8157
Alexander Musman64d33f12014-06-04 07:53:32 +00008158template <typename Derived>
8159OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8160 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008161 llvm::SmallVector<Expr *, 16> Vars;
8162 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008163 for (auto *VE : C->varlists()) {
8164 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008165 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008166 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008167 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008168 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008169 return getDerived().RebuildOMPFirstprivateClause(
8170 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008171}
8172
Alexander Musman64d33f12014-06-04 07:53:32 +00008173template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008174OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008175TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8176 llvm::SmallVector<Expr *, 16> Vars;
8177 Vars.reserve(C->varlist_size());
8178 for (auto *VE : C->varlists()) {
8179 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8180 if (EVar.isInvalid())
8181 return nullptr;
8182 Vars.push_back(EVar.get());
8183 }
8184 return getDerived().RebuildOMPLastprivateClause(
8185 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8186}
8187
8188template <typename Derived>
8189OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008190TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8191 llvm::SmallVector<Expr *, 16> Vars;
8192 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008193 for (auto *VE : C->varlists()) {
8194 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008195 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008196 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008197 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008198 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008199 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8200 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008201}
8202
Alexander Musman64d33f12014-06-04 07:53:32 +00008203template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008204OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008205TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8206 llvm::SmallVector<Expr *, 16> Vars;
8207 Vars.reserve(C->varlist_size());
8208 for (auto *VE : C->varlists()) {
8209 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8210 if (EVar.isInvalid())
8211 return nullptr;
8212 Vars.push_back(EVar.get());
8213 }
8214 CXXScopeSpec ReductionIdScopeSpec;
8215 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8216
8217 DeclarationNameInfo NameInfo = C->getNameInfo();
8218 if (NameInfo.getName()) {
8219 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8220 if (!NameInfo.getName())
8221 return nullptr;
8222 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008223 // Build a list of all UDR decls with the same names ranged by the Scopes.
8224 // The Scope boundary is a duplication of the previous decl.
8225 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8226 for (auto *E : C->reduction_ops()) {
8227 // Transform all the decls.
8228 if (E) {
8229 auto *ULE = cast<UnresolvedLookupExpr>(E);
8230 UnresolvedSet<8> Decls;
8231 for (auto *D : ULE->decls()) {
8232 NamedDecl *InstD =
8233 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8234 Decls.addDecl(InstD, InstD->getAccess());
8235 }
8236 UnresolvedReductions.push_back(
8237 UnresolvedLookupExpr::Create(
8238 SemaRef.Context, /*NamingClass=*/nullptr,
8239 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8240 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8241 Decls.begin(), Decls.end()));
8242 } else
8243 UnresolvedReductions.push_back(nullptr);
8244 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008245 return getDerived().RebuildOMPReductionClause(
8246 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008247 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008248}
8249
8250template <typename Derived>
8251OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008252TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8253 llvm::SmallVector<Expr *, 16> Vars;
8254 Vars.reserve(C->varlist_size());
8255 for (auto *VE : C->varlists()) {
8256 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8257 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008258 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008259 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008260 }
8261 ExprResult Step = getDerived().TransformExpr(C->getStep());
8262 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008263 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008264 return getDerived().RebuildOMPLinearClause(
8265 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8266 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008267}
8268
Alexander Musman64d33f12014-06-04 07:53:32 +00008269template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008270OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008271TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *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 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8281 if (Alignment.isInvalid())
8282 return nullptr;
8283 return getDerived().RebuildOMPAlignedClause(
8284 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8285 C->getColonLoc(), C->getLocEnd());
8286}
8287
Alexander Musman64d33f12014-06-04 07:53:32 +00008288template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008289OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008290TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8291 llvm::SmallVector<Expr *, 16> Vars;
8292 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008293 for (auto *VE : C->varlists()) {
8294 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008295 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008296 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008297 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008298 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008299 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8300 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008301}
8302
Alexey Bataevbae9a792014-06-27 10:37:06 +00008303template <typename Derived>
8304OMPClause *
8305TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8306 llvm::SmallVector<Expr *, 16> Vars;
8307 Vars.reserve(C->varlist_size());
8308 for (auto *VE : C->varlists()) {
8309 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8310 if (EVar.isInvalid())
8311 return nullptr;
8312 Vars.push_back(EVar.get());
8313 }
8314 return getDerived().RebuildOMPCopyprivateClause(
8315 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8316}
8317
Alexey Bataev6125da92014-07-21 11:26:11 +00008318template <typename Derived>
8319OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8320 llvm::SmallVector<Expr *, 16> Vars;
8321 Vars.reserve(C->varlist_size());
8322 for (auto *VE : C->varlists()) {
8323 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8324 if (EVar.isInvalid())
8325 return nullptr;
8326 Vars.push_back(EVar.get());
8327 }
8328 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8329 C->getLParenLoc(), C->getLocEnd());
8330}
8331
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008332template <typename Derived>
8333OMPClause *
8334TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8335 llvm::SmallVector<Expr *, 16> Vars;
8336 Vars.reserve(C->varlist_size());
8337 for (auto *VE : C->varlists()) {
8338 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8339 if (EVar.isInvalid())
8340 return nullptr;
8341 Vars.push_back(EVar.get());
8342 }
8343 return getDerived().RebuildOMPDependClause(
8344 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8345 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8346}
8347
Michael Wonge710d542015-08-07 16:16:36 +00008348template <typename Derived>
8349OMPClause *
8350TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8351 ExprResult E = getDerived().TransformExpr(C->getDevice());
8352 if (E.isInvalid())
8353 return nullptr;
8354 return getDerived().RebuildOMPDeviceClause(
8355 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8356}
8357
Kelvin Li0bff7af2015-11-23 05:32:03 +00008358template <typename Derived>
8359OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8360 llvm::SmallVector<Expr *, 16> Vars;
8361 Vars.reserve(C->varlist_size());
8362 for (auto *VE : C->varlists()) {
8363 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8364 if (EVar.isInvalid())
8365 return nullptr;
8366 Vars.push_back(EVar.get());
8367 }
8368 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008369 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8370 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8371 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008372}
8373
Kelvin Li099bb8c2015-11-24 20:50:12 +00008374template <typename Derived>
8375OMPClause *
8376TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8377 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8378 if (E.isInvalid())
8379 return nullptr;
8380 return getDerived().RebuildOMPNumTeamsClause(
8381 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8382}
8383
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008384template <typename Derived>
8385OMPClause *
8386TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8387 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8388 if (E.isInvalid())
8389 return nullptr;
8390 return getDerived().RebuildOMPThreadLimitClause(
8391 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8392}
8393
Alexey Bataeva0569352015-12-01 10:17:31 +00008394template <typename Derived>
8395OMPClause *
8396TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8397 ExprResult E = getDerived().TransformExpr(C->getPriority());
8398 if (E.isInvalid())
8399 return nullptr;
8400 return getDerived().RebuildOMPPriorityClause(
8401 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8402}
8403
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008404template <typename Derived>
8405OMPClause *
8406TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8407 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8408 if (E.isInvalid())
8409 return nullptr;
8410 return getDerived().RebuildOMPGrainsizeClause(
8411 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8412}
8413
Alexey Bataev382967a2015-12-08 12:06:20 +00008414template <typename Derived>
8415OMPClause *
8416TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8417 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8418 if (E.isInvalid())
8419 return nullptr;
8420 return getDerived().RebuildOMPNumTasksClause(
8421 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8422}
8423
Alexey Bataev28c75412015-12-15 08:19:24 +00008424template <typename Derived>
8425OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8426 ExprResult E = getDerived().TransformExpr(C->getHint());
8427 if (E.isInvalid())
8428 return nullptr;
8429 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8430 C->getLParenLoc(), C->getLocEnd());
8431}
8432
Carlo Bertollib4adf552016-01-15 18:50:31 +00008433template <typename Derived>
8434OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8435 OMPDistScheduleClause *C) {
8436 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8437 if (E.isInvalid())
8438 return nullptr;
8439 return getDerived().RebuildOMPDistScheduleClause(
8440 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8441 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8442}
8443
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008444template <typename Derived>
8445OMPClause *
8446TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8447 return C;
8448}
8449
Samuel Antao661c0902016-05-26 17:39:58 +00008450template <typename Derived>
8451OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8452 llvm::SmallVector<Expr *, 16> Vars;
8453 Vars.reserve(C->varlist_size());
8454 for (auto *VE : C->varlists()) {
8455 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8456 if (EVar.isInvalid())
8457 return 0;
8458 Vars.push_back(EVar.get());
8459 }
8460 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8461 C->getLParenLoc(), C->getLocEnd());
8462}
8463
Samuel Antaoec172c62016-05-26 17:49:04 +00008464template <typename Derived>
8465OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8466 llvm::SmallVector<Expr *, 16> Vars;
8467 Vars.reserve(C->varlist_size());
8468 for (auto *VE : C->varlists()) {
8469 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8470 if (EVar.isInvalid())
8471 return 0;
8472 Vars.push_back(EVar.get());
8473 }
8474 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8475 C->getLParenLoc(), C->getLocEnd());
8476}
8477
Carlo Bertolli2404b172016-07-13 15:37:16 +00008478template <typename Derived>
8479OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8480 OMPUseDevicePtrClause *C) {
8481 llvm::SmallVector<Expr *, 16> Vars;
8482 Vars.reserve(C->varlist_size());
8483 for (auto *VE : C->varlists()) {
8484 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8485 if (EVar.isInvalid())
8486 return nullptr;
8487 Vars.push_back(EVar.get());
8488 }
8489 return getDerived().RebuildOMPUseDevicePtrClause(
8490 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8491}
8492
Carlo Bertolli70594e92016-07-13 17:16:49 +00008493template <typename Derived>
8494OMPClause *
8495TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8496 llvm::SmallVector<Expr *, 16> Vars;
8497 Vars.reserve(C->varlist_size());
8498 for (auto *VE : C->varlists()) {
8499 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8500 if (EVar.isInvalid())
8501 return nullptr;
8502 Vars.push_back(EVar.get());
8503 }
8504 return getDerived().RebuildOMPIsDevicePtrClause(
8505 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8506}
8507
Douglas Gregorebe10102009-08-20 07:17:43 +00008508//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008509// Expression transformation
8510//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008511template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008512ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008513TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008514 if (!E->isTypeDependent())
8515 return E;
8516
8517 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8518 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008519}
Mike Stump11289f42009-09-09 15:08:12 +00008520
8521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008523TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008524 NestedNameSpecifierLoc QualifierLoc;
8525 if (E->getQualifierLoc()) {
8526 QualifierLoc
8527 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8528 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008529 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008530 }
John McCallce546572009-12-08 09:08:17 +00008531
8532 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008533 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8534 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008535 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008536 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008537
John McCall815039a2010-08-17 21:27:17 +00008538 DeclarationNameInfo NameInfo = E->getNameInfo();
8539 if (NameInfo.getName()) {
8540 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8541 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008542 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008543 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008544
8545 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008546 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008547 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008548 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008549 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008550
8551 // Mark it referenced in the new context regardless.
8552 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008553 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008554
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008555 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008556 }
John McCallce546572009-12-08 09:08:17 +00008557
Craig Topperc3ec1492014-05-26 06:22:03 +00008558 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008559 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008560 TemplateArgs = &TransArgs;
8561 TransArgs.setLAngleLoc(E->getLAngleLoc());
8562 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008563 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8564 E->getNumTemplateArgs(),
8565 TransArgs))
8566 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008567 }
8568
Chad Rosier1dcde962012-08-08 18:46:20 +00008569 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008570 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008571}
Mike Stump11289f42009-09-09 15:08:12 +00008572
Douglas Gregora16548e2009-08-11 05:31:07 +00008573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008575TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008576 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008577}
Mike Stump11289f42009-09-09 15:08:12 +00008578
Douglas Gregora16548e2009-08-11 05:31:07 +00008579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008581TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008582 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008583}
Mike Stump11289f42009-09-09 15:08:12 +00008584
Douglas Gregora16548e2009-08-11 05:31:07 +00008585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008586ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008587TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008588 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008589}
Mike Stump11289f42009-09-09 15:08:12 +00008590
Douglas Gregora16548e2009-08-11 05:31:07 +00008591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008594 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008595}
Mike Stump11289f42009-09-09 15:08:12 +00008596
Douglas Gregora16548e2009-08-11 05:31:07 +00008597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008598ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008599TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008600 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008601}
8602
8603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008604ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008605TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008606 if (FunctionDecl *FD = E->getDirectCallee())
8607 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008608 return SemaRef.MaybeBindToTemporary(E);
8609}
8610
8611template<typename Derived>
8612ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008613TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8614 ExprResult ControllingExpr =
8615 getDerived().TransformExpr(E->getControllingExpr());
8616 if (ControllingExpr.isInvalid())
8617 return ExprError();
8618
Chris Lattner01cf8db2011-07-20 06:58:45 +00008619 SmallVector<Expr *, 4> AssocExprs;
8620 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008621 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8622 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8623 if (TS) {
8624 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8625 if (!AssocType)
8626 return ExprError();
8627 AssocTypes.push_back(AssocType);
8628 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008629 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008630 }
8631
8632 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8633 if (AssocExpr.isInvalid())
8634 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008635 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008636 }
8637
8638 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8639 E->getDefaultLoc(),
8640 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008641 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008642 AssocTypes,
8643 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008644}
8645
8646template<typename Derived>
8647ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008648TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008649 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008652
Douglas Gregora16548e2009-08-11 05:31:07 +00008653 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008654 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008655
John McCallb268a282010-08-23 23:25:46 +00008656 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008657 E->getRParen());
8658}
8659
Richard Smithdb2630f2012-10-21 03:28:35 +00008660/// \brief The operand of a unary address-of operator has special rules: it's
8661/// allowed to refer to a non-static member of a class even if there's no 'this'
8662/// object available.
8663template<typename Derived>
8664ExprResult
8665TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8666 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008667 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008668 else
8669 return getDerived().TransformExpr(E);
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>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008675 ExprResult SubExpr;
8676 if (E->getOpcode() == UO_AddrOf)
8677 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8678 else
8679 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008680 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008681 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008682
Douglas Gregora16548e2009-08-11 05:31:07 +00008683 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008684 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008685
Douglas Gregora16548e2009-08-11 05:31:07 +00008686 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8687 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008688 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008689}
Mike Stump11289f42009-09-09 15:08:12 +00008690
Douglas Gregora16548e2009-08-11 05:31:07 +00008691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008692ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008693TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8694 // Transform the type.
8695 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8696 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008697 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008698
Douglas Gregor882211c2010-04-28 22:16:22 +00008699 // Transform all of the components into components similar to what the
8700 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008701 // FIXME: It would be slightly more efficient in the non-dependent case to
8702 // just map FieldDecls, rather than requiring the rebuilder to look for
8703 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008704 // template code that we don't care.
8705 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008706 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008707 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008708 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008709 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008710 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008711 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008712 Comp.LocStart = ON.getSourceRange().getBegin();
8713 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008714 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008715 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008716 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008717 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008718 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008719 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008720
Douglas Gregor882211c2010-04-28 22:16:22 +00008721 ExprChanged = ExprChanged || Index.get() != FromIndex;
8722 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008723 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008724 break;
8725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008726
James Y Knight7281c352015-12-29 22:31:18 +00008727 case OffsetOfNode::Field:
8728 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008729 Comp.isBrackets = false;
8730 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008731 if (!Comp.U.IdentInfo)
8732 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008733
Douglas Gregor882211c2010-04-28 22:16:22 +00008734 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008735
James Y Knight7281c352015-12-29 22:31:18 +00008736 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008737 // Will be recomputed during the rebuild.
8738 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008739 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008740
Douglas Gregor882211c2010-04-28 22:16:22 +00008741 Components.push_back(Comp);
8742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008743
Douglas Gregor882211c2010-04-28 22:16:22 +00008744 // If nothing changed, retain the existing expression.
8745 if (!getDerived().AlwaysRebuild() &&
8746 Type == E->getTypeSourceInfo() &&
8747 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008748 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008749
Douglas Gregor882211c2010-04-28 22:16:22 +00008750 // Build a new offsetof expression.
8751 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008752 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008753}
8754
8755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008756ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008757TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008758 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008759 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008760 return E;
John McCall8d69a212010-11-15 23:31:06 +00008761}
8762
8763template<typename Derived>
8764ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008765TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8766 return E;
8767}
8768
8769template<typename Derived>
8770ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008771TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008772 // Rebuild the syntactic form. The original syntactic form has
8773 // opaque-value expressions in it, so strip those away and rebuild
8774 // the result. This is a really awful way of doing this, but the
8775 // better solution (rebuilding the semantic expressions and
8776 // rebinding OVEs as necessary) doesn't work; we'd need
8777 // TreeTransform to not strip away implicit conversions.
8778 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8779 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008780 if (result.isInvalid()) return ExprError();
8781
8782 // If that gives us a pseudo-object result back, the pseudo-object
8783 // expression must have been an lvalue-to-rvalue conversion which we
8784 // should reapply.
8785 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008786 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008787
8788 return result;
8789}
8790
8791template<typename Derived>
8792ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008793TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8794 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008795 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008796 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008797
John McCallbcd03502009-12-07 02:54:59 +00008798 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008799 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008801
John McCall4c98fd82009-11-04 07:28:41 +00008802 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008803 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008804
Peter Collingbournee190dee2011-03-11 19:24:49 +00008805 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8806 E->getKind(),
8807 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008808 }
Mike Stump11289f42009-09-09 15:08:12 +00008809
Eli Friedmane4f22df2012-02-29 04:03:55 +00008810 // C++0x [expr.sizeof]p1:
8811 // The operand is either an expression, which is an unevaluated operand
8812 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00008813 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8814 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008815
Reid Kleckner32506ed2014-06-12 23:03:48 +00008816 // Try to recover if we have something like sizeof(T::X) where X is a type.
8817 // Notably, there must be *exactly* one set of parens if X is a type.
8818 TypeSourceInfo *RecoveryTSI = nullptr;
8819 ExprResult SubExpr;
8820 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8821 if (auto *DRE =
8822 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8823 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8824 PE, DRE, false, &RecoveryTSI);
8825 else
8826 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8827
8828 if (RecoveryTSI) {
8829 return getDerived().RebuildUnaryExprOrTypeTrait(
8830 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8831 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008832 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008833
Eli Friedmane4f22df2012-02-29 04:03:55 +00008834 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008835 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008836
Peter Collingbournee190dee2011-03-11 19:24:49 +00008837 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8838 E->getOperatorLoc(),
8839 E->getKind(),
8840 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008841}
Mike Stump11289f42009-09-09 15:08:12 +00008842
Douglas Gregora16548e2009-08-11 05:31:07 +00008843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008844ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008845TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008846 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008847 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008849
John McCalldadc5752010-08-24 06:29:42 +00008850 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008851 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008852 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008853
8854
Douglas Gregora16548e2009-08-11 05:31:07 +00008855 if (!getDerived().AlwaysRebuild() &&
8856 LHS.get() == E->getLHS() &&
8857 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008858 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008859
John McCallb268a282010-08-23 23:25:46 +00008860 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008861 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008862 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008863 E->getRBracketLoc());
8864}
Mike Stump11289f42009-09-09 15:08:12 +00008865
Alexey Bataev1a3320e2015-08-25 14:24:04 +00008866template <typename Derived>
8867ExprResult
8868TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
8869 ExprResult Base = getDerived().TransformExpr(E->getBase());
8870 if (Base.isInvalid())
8871 return ExprError();
8872
8873 ExprResult LowerBound;
8874 if (E->getLowerBound()) {
8875 LowerBound = getDerived().TransformExpr(E->getLowerBound());
8876 if (LowerBound.isInvalid())
8877 return ExprError();
8878 }
8879
8880 ExprResult Length;
8881 if (E->getLength()) {
8882 Length = getDerived().TransformExpr(E->getLength());
8883 if (Length.isInvalid())
8884 return ExprError();
8885 }
8886
8887 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
8888 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
8889 return E;
8890
8891 return getDerived().RebuildOMPArraySectionExpr(
8892 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
8893 Length.get(), E->getRBracketLoc());
8894}
8895
Mike Stump11289f42009-09-09 15:08:12 +00008896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008898TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008899 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00008900 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008901 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008902 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008903
8904 // Transform arguments.
8905 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008906 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008907 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00008908 &ArgChanged))
8909 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008910
Douglas Gregora16548e2009-08-11 05:31:07 +00008911 if (!getDerived().AlwaysRebuild() &&
8912 Callee.get() == E->getCallee() &&
8913 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00008914 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008915
Douglas Gregora16548e2009-08-11 05:31:07 +00008916 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00008917 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00008918 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00008919 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008920 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00008921 E->getRParenLoc());
8922}
Mike Stump11289f42009-09-09 15:08:12 +00008923
8924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008925ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008926TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008927 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008928 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008930
Douglas Gregorea972d32011-02-28 21:54:11 +00008931 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008932 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008933 QualifierLoc
8934 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008935
Douglas Gregorea972d32011-02-28 21:54:11 +00008936 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008937 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008938 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008939 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008940
Eli Friedman2cfcef62009-12-04 06:40:45 +00008941 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008942 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8943 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008944 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008945 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008946
John McCall16df1e52010-03-30 21:47:33 +00008947 NamedDecl *FoundDecl = E->getFoundDecl();
8948 if (FoundDecl == E->getMemberDecl()) {
8949 FoundDecl = Member;
8950 } else {
8951 FoundDecl = cast_or_null<NamedDecl>(
8952 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8953 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008954 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008955 }
8956
Douglas Gregora16548e2009-08-11 05:31:07 +00008957 if (!getDerived().AlwaysRebuild() &&
8958 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008959 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008960 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008961 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008962 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008963
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008964 // Mark it referenced in the new context regardless.
8965 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008966 SemaRef.MarkMemberReferenced(E);
8967
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008968 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008969 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008970
John McCall6b51f282009-11-23 01:53:49 +00008971 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008972 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008973 TransArgs.setLAngleLoc(E->getLAngleLoc());
8974 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008975 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8976 E->getNumTemplateArgs(),
8977 TransArgs))
8978 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008980
Douglas Gregora16548e2009-08-11 05:31:07 +00008981 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008982 SourceLocation FakeOperatorLoc =
8983 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008984
John McCall38836f02010-01-15 08:34:02 +00008985 // FIXME: to do this check properly, we will need to preserve the
8986 // first-qualifier-in-scope here, just in case we had a dependent
8987 // base (and therefore couldn't do the check) and a
8988 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008989 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00008990 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
8991 if (MemberNameInfo.getName()) {
8992 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
8993 if (!MemberNameInfo.getName())
8994 return ExprError();
8995 }
John McCall38836f02010-01-15 08:34:02 +00008996
John McCallb268a282010-08-23 23:25:46 +00008997 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008998 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008999 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009000 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009001 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009002 Member,
John McCall16df1e52010-03-30 21:47:33 +00009003 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009004 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009005 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009006 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009007}
Mike Stump11289f42009-09-09 15:08:12 +00009008
Douglas Gregora16548e2009-08-11 05:31:07 +00009009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009011TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009012 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009013 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009015
John McCalldadc5752010-08-24 06:29:42 +00009016 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009017 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009019
Douglas Gregora16548e2009-08-11 05:31:07 +00009020 if (!getDerived().AlwaysRebuild() &&
9021 LHS.get() == E->getLHS() &&
9022 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009023 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009024
Lang Hames5de91cc2012-10-02 04:45:10 +00009025 Sema::FPContractStateRAII FPContractState(getSema());
9026 getSema().FPFeatures.fp_contract = E->isFPContractable();
9027
Douglas Gregora16548e2009-08-11 05:31:07 +00009028 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009029 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009030}
9031
Mike Stump11289f42009-09-09 15:08:12 +00009032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009033ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009034TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009035 CompoundAssignOperator *E) {
9036 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009037}
Mike Stump11289f42009-09-09 15:08:12 +00009038
Douglas Gregora16548e2009-08-11 05:31:07 +00009039template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009040ExprResult TreeTransform<Derived>::
9041TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9042 // Just rebuild the common and RHS expressions and see whether we
9043 // get any changes.
9044
9045 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9046 if (commonExpr.isInvalid())
9047 return ExprError();
9048
9049 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9050 if (rhs.isInvalid())
9051 return ExprError();
9052
9053 if (!getDerived().AlwaysRebuild() &&
9054 commonExpr.get() == e->getCommon() &&
9055 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009056 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009057
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009058 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009059 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009060 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009061 e->getColonLoc(),
9062 rhs.get());
9063}
9064
9065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009067TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009068 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009069 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009071
John McCalldadc5752010-08-24 06:29:42 +00009072 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009073 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009075
John McCalldadc5752010-08-24 06:29:42 +00009076 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009077 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009079
Douglas Gregora16548e2009-08-11 05:31:07 +00009080 if (!getDerived().AlwaysRebuild() &&
9081 Cond.get() == E->getCond() &&
9082 LHS.get() == E->getLHS() &&
9083 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009084 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009085
John McCallb268a282010-08-23 23:25:46 +00009086 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009087 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009088 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009089 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009090 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009091}
Mike Stump11289f42009-09-09 15:08:12 +00009092
9093template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009094ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009095TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009096 // Implicit casts are eliminated during transformation, since they
9097 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009098 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009099}
Mike Stump11289f42009-09-09 15:08:12 +00009100
Douglas Gregora16548e2009-08-11 05:31:07 +00009101template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009102ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009103TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009104 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9105 if (!Type)
9106 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009107
John McCalldadc5752010-08-24 06:29:42 +00009108 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009109 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009110 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009111 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009112
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009114 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009115 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009116 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009117
John McCall97513962010-01-15 18:39:57 +00009118 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009119 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009120 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009121 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009122}
Mike Stump11289f42009-09-09 15:08:12 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009126TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009127 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9128 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9129 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009131
John McCalldadc5752010-08-24 06:29:42 +00009132 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009135
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009137 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009138 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009139 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009140
John McCall5d7aa7f2010-01-19 22:33:45 +00009141 // Note: the expression type doesn't necessarily match the
9142 // type-as-written, but that's okay, because it should always be
9143 // derivable from the initializer.
9144
John McCalle15bbff2010-01-18 19:35:47 +00009145 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009146 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009147 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009148}
Mike Stump11289f42009-09-09 15:08:12 +00009149
Douglas Gregora16548e2009-08-11 05:31:07 +00009150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009152TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009153 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009154 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009156
Douglas Gregora16548e2009-08-11 05:31:07 +00009157 if (!getDerived().AlwaysRebuild() &&
9158 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009159 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009160
Douglas Gregora16548e2009-08-11 05:31:07 +00009161 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009162 SourceLocation FakeOperatorLoc =
9163 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009164 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009165 E->getAccessorLoc(),
9166 E->getAccessor());
9167}
Mike Stump11289f42009-09-09 15:08:12 +00009168
Douglas Gregora16548e2009-08-11 05:31:07 +00009169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009172 if (InitListExpr *Syntactic = E->getSyntacticForm())
9173 E = Syntactic;
9174
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009176
Benjamin Kramerf0623432012-08-23 22:51:59 +00009177 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009178 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009179 Inits, &InitChanged))
9180 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009181
Richard Smith520449d2015-02-05 06:15:50 +00009182 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9183 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9184 // in some cases. We can't reuse it in general, because the syntactic and
9185 // semantic forms are linked, and we can't know that semantic form will
9186 // match even if the syntactic form does.
9187 }
Mike Stump11289f42009-09-09 15:08:12 +00009188
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009189 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00009190 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00009191}
Mike Stump11289f42009-09-09 15:08:12 +00009192
Douglas Gregora16548e2009-08-11 05:31:07 +00009193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009195TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009196 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009197
Douglas Gregorebe10102009-08-20 07:17:43 +00009198 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009199 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009200 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009202
Douglas Gregorebe10102009-08-20 07:17:43 +00009203 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009204 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009205 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009206 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9207 if (D.isFieldDesignator()) {
9208 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9209 D.getDotLoc(),
9210 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009211 if (D.getField()) {
9212 FieldDecl *Field = cast_or_null<FieldDecl>(
9213 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9214 if (Field != D.getField())
9215 // Rebuild the expression when the transformed FieldDecl is
9216 // different to the already assigned FieldDecl.
9217 ExprChanged = true;
9218 } else {
9219 // Ensure that the designator expression is rebuilt when there isn't
9220 // a resolved FieldDecl in the designator as we don't want to assign
9221 // a FieldDecl to a pattern designator that will be instantiated again.
9222 ExprChanged = true;
9223 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009224 continue;
9225 }
Mike Stump11289f42009-09-09 15:08:12 +00009226
David Majnemerf7e36092016-06-23 00:15:04 +00009227 if (D.isArrayDesignator()) {
9228 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009229 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009230 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009231
David Majnemerf7e36092016-06-23 00:15:04 +00009232 Desig.AddDesignator(
9233 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009234
David Majnemerf7e36092016-06-23 00:15:04 +00009235 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009236 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009237 continue;
9238 }
Mike Stump11289f42009-09-09 15:08:12 +00009239
David Majnemerf7e36092016-06-23 00:15:04 +00009240 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009241 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009242 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009243 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009245
David Majnemerf7e36092016-06-23 00:15:04 +00009246 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009247 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009248 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009249
9250 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009251 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009252 D.getLBracketLoc(),
9253 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009254
David Majnemerf7e36092016-06-23 00:15:04 +00009255 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9256 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009257
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009258 ArrayExprs.push_back(Start.get());
9259 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009260 }
Mike Stump11289f42009-09-09 15:08:12 +00009261
Douglas Gregora16548e2009-08-11 05:31:07 +00009262 if (!getDerived().AlwaysRebuild() &&
9263 Init.get() == E->getInit() &&
9264 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009265 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009266
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009267 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009268 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009269 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009270}
Mike Stump11289f42009-09-09 15:08:12 +00009271
Yunzhong Gaocb779302015-06-10 00:27:52 +00009272// Seems that if TransformInitListExpr() only works on the syntactic form of an
9273// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9274template<typename Derived>
9275ExprResult
9276TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9277 DesignatedInitUpdateExpr *E) {
9278 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9279 "initializer");
9280 return ExprError();
9281}
9282
9283template<typename Derived>
9284ExprResult
9285TreeTransform<Derived>::TransformNoInitExpr(
9286 NoInitExpr *E) {
9287 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9288 return ExprError();
9289}
9290
Douglas Gregora16548e2009-08-11 05:31:07 +00009291template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009292ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009293TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9294 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9295 return ExprError();
9296}
9297
9298template<typename Derived>
9299ExprResult
9300TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9301 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9302 return ExprError();
9303}
9304
9305template<typename Derived>
9306ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009307TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009308 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009309 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009310
Douglas Gregor3da3c062009-10-28 00:29:27 +00009311 // FIXME: Will we ever have proper type location here? Will we actually
9312 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009313 QualType T = getDerived().TransformType(E->getType());
9314 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009316
Douglas Gregora16548e2009-08-11 05:31:07 +00009317 if (!getDerived().AlwaysRebuild() &&
9318 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009319 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009320
Douglas Gregora16548e2009-08-11 05:31:07 +00009321 return getDerived().RebuildImplicitValueInitExpr(T);
9322}
Mike Stump11289f42009-09-09 15:08:12 +00009323
Douglas Gregora16548e2009-08-11 05:31:07 +00009324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009326TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009327 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9328 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009330
John McCalldadc5752010-08-24 06:29:42 +00009331 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009332 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009334
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009336 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009337 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009338 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009339
John McCallb268a282010-08-23 23:25:46 +00009340 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009341 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009342}
9343
9344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009345ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009346TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009347 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009348 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009349 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9350 &ArgumentChanged))
9351 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009352
Douglas Gregora16548e2009-08-11 05:31:07 +00009353 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009354 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009355 E->getRParenLoc());
9356}
Mike Stump11289f42009-09-09 15:08:12 +00009357
Douglas Gregora16548e2009-08-11 05:31:07 +00009358/// \brief Transform an address-of-label expression.
9359///
9360/// By default, the transformation of an address-of-label expression always
9361/// rebuilds the expression, so that the label identifier can be resolved to
9362/// the corresponding label statement by semantic analysis.
9363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009365TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009366 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9367 E->getLabel());
9368 if (!LD)
9369 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009370
Douglas Gregora16548e2009-08-11 05:31:07 +00009371 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009372 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009373}
Mike Stump11289f42009-09-09 15:08:12 +00009374
9375template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009376ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009377TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009378 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009379 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009380 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009381 if (SubStmt.isInvalid()) {
9382 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009383 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009384 }
Mike Stump11289f42009-09-09 15:08:12 +00009385
Douglas Gregora16548e2009-08-11 05:31:07 +00009386 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009387 SubStmt.get() == E->getSubStmt()) {
9388 // Calling this an 'error' is unintuitive, but it does the right thing.
9389 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009390 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009391 }
Mike Stump11289f42009-09-09 15:08:12 +00009392
9393 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009394 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 E->getRParenLoc());
9396}
Mike Stump11289f42009-09-09 15:08:12 +00009397
Douglas Gregora16548e2009-08-11 05:31:07 +00009398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009400TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009401 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009402 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009404
John McCalldadc5752010-08-24 06:29:42 +00009405 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009406 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009407 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009408
John McCalldadc5752010-08-24 06:29:42 +00009409 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009410 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009412
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (!getDerived().AlwaysRebuild() &&
9414 Cond.get() == E->getCond() &&
9415 LHS.get() == E->getLHS() &&
9416 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009417 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009418
Douglas Gregora16548e2009-08-11 05:31:07 +00009419 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009420 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009421 E->getRParenLoc());
9422}
Mike Stump11289f42009-09-09 15:08:12 +00009423
Douglas Gregora16548e2009-08-11 05:31:07 +00009424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009425ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009426TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009427 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009428}
9429
9430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009431ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009432TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009433 switch (E->getOperator()) {
9434 case OO_New:
9435 case OO_Delete:
9436 case OO_Array_New:
9437 case OO_Array_Delete:
9438 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009439
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009440 case OO_Call: {
9441 // This is a call to an object's operator().
9442 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9443
9444 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009445 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009446 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009447 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009448
9449 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009450 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9451 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009452
9453 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009454 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009455 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009456 Args))
9457 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009458
John McCallb268a282010-08-23 23:25:46 +00009459 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009460 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009461 E->getLocEnd());
9462 }
9463
9464#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9465 case OO_##Name:
9466#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9467#include "clang/Basic/OperatorKinds.def"
9468 case OO_Subscript:
9469 // Handled below.
9470 break;
9471
9472 case OO_Conditional:
9473 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009474
9475 case OO_None:
9476 case NUM_OVERLOADED_OPERATORS:
9477 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009478 }
9479
John McCalldadc5752010-08-24 06:29:42 +00009480 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009481 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009482 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009483
Richard Smithdb2630f2012-10-21 03:28:35 +00009484 ExprResult First;
9485 if (E->getOperator() == OO_Amp)
9486 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9487 else
9488 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009489 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009490 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009491
John McCalldadc5752010-08-24 06:29:42 +00009492 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009493 if (E->getNumArgs() == 2) {
9494 Second = getDerived().TransformExpr(E->getArg(1));
9495 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009496 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009497 }
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499 if (!getDerived().AlwaysRebuild() &&
9500 Callee.get() == E->getCallee() &&
9501 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009502 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009503 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009504
Lang Hames5de91cc2012-10-02 04:45:10 +00009505 Sema::FPContractStateRAII FPContractState(getSema());
9506 getSema().FPFeatures.fp_contract = E->isFPContractable();
9507
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9509 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009510 Callee.get(),
9511 First.get(),
9512 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009513}
Mike Stump11289f42009-09-09 15:08:12 +00009514
Douglas Gregora16548e2009-08-11 05:31:07 +00009515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009516ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009517TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9518 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009519}
Mike Stump11289f42009-09-09 15:08:12 +00009520
Douglas Gregora16548e2009-08-11 05:31:07 +00009521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009522ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009523TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9524 // Transform the callee.
9525 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9526 if (Callee.isInvalid())
9527 return ExprError();
9528
9529 // Transform exec config.
9530 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9531 if (EC.isInvalid())
9532 return ExprError();
9533
9534 // Transform arguments.
9535 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009536 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009537 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009538 &ArgChanged))
9539 return ExprError();
9540
9541 if (!getDerived().AlwaysRebuild() &&
9542 Callee.get() == E->getCallee() &&
9543 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009544 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009545
9546 // FIXME: Wrong source location information for the '('.
9547 SourceLocation FakeLParenLoc
9548 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9549 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009550 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009551 E->getRParenLoc(), EC.get());
9552}
9553
9554template<typename Derived>
9555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009556TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009557 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9558 if (!Type)
9559 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009560
John McCalldadc5752010-08-24 06:29:42 +00009561 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009562 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009563 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009565
Douglas Gregora16548e2009-08-11 05:31:07 +00009566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009567 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009568 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009569 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009570 return getDerived().RebuildCXXNamedCastExpr(
9571 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9572 Type, E->getAngleBrackets().getEnd(),
9573 // FIXME. this should be '(' location
9574 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009575}
Mike Stump11289f42009-09-09 15:08:12 +00009576
Douglas Gregora16548e2009-08-11 05:31:07 +00009577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009579TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9580 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009581}
Mike Stump11289f42009-09-09 15:08:12 +00009582
9583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009585TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9586 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009587}
9588
Douglas Gregora16548e2009-08-11 05:31:07 +00009589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009590ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009591TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009592 CXXReinterpretCastExpr *E) {
9593 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009594}
Mike Stump11289f42009-09-09 15:08:12 +00009595
Douglas Gregora16548e2009-08-11 05:31:07 +00009596template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009597ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009598TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9599 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009600}
Mike Stump11289f42009-09-09 15:08:12 +00009601
Douglas Gregora16548e2009-08-11 05:31:07 +00009602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009603ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009604TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009605 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009606 TypeSourceInfo *Type =
9607 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009608 if (!Type)
9609 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009610
John McCalldadc5752010-08-24 06:29:42 +00009611 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009612 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009613 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009615
Douglas Gregora16548e2009-08-11 05:31:07 +00009616 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009617 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009618 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009619 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009620
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009621 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009622 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009623 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009624 E->getRParenLoc());
9625}
Mike Stump11289f42009-09-09 15:08:12 +00009626
Douglas Gregora16548e2009-08-11 05:31:07 +00009627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009628ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009629TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009630 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009631 TypeSourceInfo *TInfo
9632 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9633 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009634 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009635
Douglas Gregora16548e2009-08-11 05:31:07 +00009636 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009637 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009638 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009639
Douglas Gregor9da64192010-04-26 22:37:10 +00009640 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9641 E->getLocStart(),
9642 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009643 E->getLocEnd());
9644 }
Mike Stump11289f42009-09-09 15:08:12 +00009645
Eli Friedman456f0182012-01-20 01:26:23 +00009646 // We don't know whether the subexpression is potentially evaluated until
9647 // after we perform semantic analysis. We speculatively assume it is
9648 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009649 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00009650 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
9651 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009652
John McCalldadc5752010-08-24 06:29:42 +00009653 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009654 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009656
Douglas Gregora16548e2009-08-11 05:31:07 +00009657 if (!getDerived().AlwaysRebuild() &&
9658 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009659 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009660
Douglas Gregor9da64192010-04-26 22:37:10 +00009661 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9662 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009663 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009664 E->getLocEnd());
9665}
9666
9667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009668ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009669TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9670 if (E->isTypeOperand()) {
9671 TypeSourceInfo *TInfo
9672 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9673 if (!TInfo)
9674 return ExprError();
9675
9676 if (!getDerived().AlwaysRebuild() &&
9677 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009678 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009679
Douglas Gregor69735112011-03-06 17:40:41 +00009680 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009681 E->getLocStart(),
9682 TInfo,
9683 E->getLocEnd());
9684 }
9685
Francois Pichet9f4f2072010-09-08 12:20:18 +00009686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9687
9688 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9689 if (SubExpr.isInvalid())
9690 return ExprError();
9691
9692 if (!getDerived().AlwaysRebuild() &&
9693 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009694 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009695
9696 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9697 E->getLocStart(),
9698 SubExpr.get(),
9699 E->getLocEnd());
9700}
9701
9702template<typename Derived>
9703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009704TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009705 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009706}
Mike Stump11289f42009-09-09 15:08:12 +00009707
Douglas Gregora16548e2009-08-11 05:31:07 +00009708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009709ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009710TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009711 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009712 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009713}
Mike Stump11289f42009-09-09 15:08:12 +00009714
Douglas Gregora16548e2009-08-11 05:31:07 +00009715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009716ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009717TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009718 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009719
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009720 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9721 // Make sure that we capture 'this'.
9722 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009723 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009725
Douglas Gregorb15af892010-01-07 23:12:05 +00009726 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009727}
Mike Stump11289f42009-09-09 15:08:12 +00009728
Douglas Gregora16548e2009-08-11 05:31:07 +00009729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009730ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009731TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009732 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009733 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009734 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009735
Douglas Gregora16548e2009-08-11 05:31:07 +00009736 if (!getDerived().AlwaysRebuild() &&
9737 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009738 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009739
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009740 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9741 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009742}
Mike Stump11289f42009-09-09 15:08:12 +00009743
Douglas Gregora16548e2009-08-11 05:31:07 +00009744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009746TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009747 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009748 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9749 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009750 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009752
Chandler Carruth794da4c2010-02-08 06:42:49 +00009753 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009754 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009755 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009756
Douglas Gregor033f6752009-12-23 23:03:06 +00009757 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009758}
Mike Stump11289f42009-09-09 15:08:12 +00009759
Douglas Gregora16548e2009-08-11 05:31:07 +00009760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009761ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009762TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9763 FieldDecl *Field
9764 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9765 E->getField()));
9766 if (!Field)
9767 return ExprError();
9768
9769 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009770 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009771
9772 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9773}
9774
9775template<typename Derived>
9776ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009777TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9778 CXXScalarValueInitExpr *E) {
9779 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9780 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009781 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009782
Douglas Gregora16548e2009-08-11 05:31:07 +00009783 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009784 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009785 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009786
Chad Rosier1dcde962012-08-08 18:46:20 +00009787 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009788 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009789 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009790}
Mike Stump11289f42009-09-09 15:08:12 +00009791
Douglas Gregora16548e2009-08-11 05:31:07 +00009792template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009793ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009794TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009795 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +00009796 TypeSourceInfo *AllocTypeInfo =
9797 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +00009798 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009799 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009800
Douglas Gregora16548e2009-08-11 05:31:07 +00009801 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009802 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009803 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009805
Douglas Gregora16548e2009-08-11 05:31:07 +00009806 // Transform the placement arguments (if any).
9807 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009808 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009809 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009810 E->getNumPlacementArgs(), true,
9811 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009813
Sebastian Redl6047f072012-02-16 12:22:20 +00009814 // Transform the initializer (if any).
9815 Expr *OldInit = E->getInitializer();
9816 ExprResult NewInit;
9817 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009818 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009819 if (NewInit.isInvalid())
9820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009821
Sebastian Redl6047f072012-02-16 12:22:20 +00009822 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009823 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009824 if (E->getOperatorNew()) {
9825 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009826 getDerived().TransformDecl(E->getLocStart(),
9827 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009828 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009829 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009830 }
9831
Craig Topperc3ec1492014-05-26 06:22:03 +00009832 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009833 if (E->getOperatorDelete()) {
9834 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009835 getDerived().TransformDecl(E->getLocStart(),
9836 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009837 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009838 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009839 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009840
Douglas Gregora16548e2009-08-11 05:31:07 +00009841 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009842 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009843 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009844 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009845 OperatorNew == E->getOperatorNew() &&
9846 OperatorDelete == E->getOperatorDelete() &&
9847 !ArgumentChanged) {
9848 // Mark any declarations we need as referenced.
9849 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009850 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009851 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009852 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009853 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009854
Sebastian Redl6047f072012-02-16 12:22:20 +00009855 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009856 QualType ElementType
9857 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9858 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9859 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9860 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009861 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009862 }
9863 }
9864 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009865
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009866 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009867 }
Mike Stump11289f42009-09-09 15:08:12 +00009868
Douglas Gregor0744ef62010-09-07 21:49:58 +00009869 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009870 if (!ArraySize.get()) {
9871 // If no array size was specified, but the new expression was
9872 // instantiated with an array type (e.g., "new T" where T is
9873 // instantiated with "int[4]"), extract the outer bound from the
9874 // array type as our array size. We do this with constant and
9875 // dependently-sized array types.
9876 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
9877 if (!ArrayT) {
9878 // Do nothing
9879 } else if (const ConstantArrayType *ConsArrayT
9880 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009881 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
9882 SemaRef.Context.getSizeType(),
9883 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009884 AllocType = ConsArrayT->getElementType();
9885 } else if (const DependentSizedArrayType *DepArrayT
9886 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
9887 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009888 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00009889 AllocType = DepArrayT->getElementType();
9890 }
9891 }
9892 }
Sebastian Redl6047f072012-02-16 12:22:20 +00009893
Douglas Gregora16548e2009-08-11 05:31:07 +00009894 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
9895 E->isGlobalNew(),
9896 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009897 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009898 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00009899 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009900 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00009901 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00009902 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00009903 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009904 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009905}
Mike Stump11289f42009-09-09 15:08:12 +00009906
Douglas Gregora16548e2009-08-11 05:31:07 +00009907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009909TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009910 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00009911 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009912 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009913
Douglas Gregord2d9da02010-02-26 00:38:10 +00009914 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00009915 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009916 if (E->getOperatorDelete()) {
9917 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009918 getDerived().TransformDecl(E->getLocStart(),
9919 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009920 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009921 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009923
Douglas Gregora16548e2009-08-11 05:31:07 +00009924 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009925 Operand.get() == E->getArgument() &&
9926 OperatorDelete == E->getOperatorDelete()) {
9927 // Mark any declarations we need as referenced.
9928 // FIXME: instantiation-specific.
9929 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009930 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009931
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009932 if (!E->getArgument()->isTypeDependent()) {
9933 QualType Destroyed = SemaRef.Context.getBaseElementType(
9934 E->getDestroyedType());
9935 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
9936 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00009937 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00009938 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00009939 }
9940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009941
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009942 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009943 }
Mike Stump11289f42009-09-09 15:08:12 +00009944
Douglas Gregora16548e2009-08-11 05:31:07 +00009945 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
9946 E->isGlobalDelete(),
9947 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00009948 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009949}
Mike Stump11289f42009-09-09 15:08:12 +00009950
Douglas Gregora16548e2009-08-11 05:31:07 +00009951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009952ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00009953TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009954 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009955 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00009956 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009958
John McCallba7bf592010-08-24 05:47:05 +00009959 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00009960 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009961 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009962 E->getOperatorLoc(),
9963 E->isArrow()? tok::arrow : tok::period,
9964 ObjectTypePtr,
9965 MayBePseudoDestructor);
9966 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009967 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009968
John McCallba7bf592010-08-24 05:47:05 +00009969 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009970 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9971 if (QualifierLoc) {
9972 QualifierLoc
9973 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9974 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009975 return ExprError();
9976 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009977 CXXScopeSpec SS;
9978 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009979
Douglas Gregor678f90d2010-02-25 01:56:36 +00009980 PseudoDestructorTypeStorage Destroyed;
9981 if (E->getDestroyedTypeInfo()) {
9982 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009983 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009984 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009985 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009986 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009987 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009988 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009989 // We aren't likely to be able to resolve the identifier down to a type
9990 // now anyway, so just retain the identifier.
9991 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9992 E->getDestroyedTypeLoc());
9993 } else {
9994 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009995 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009996 *E->getDestroyedTypeIdentifier(),
9997 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009998 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009999 SS, ObjectTypePtr,
10000 false);
10001 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010002 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010003
Douglas Gregor678f90d2010-02-25 01:56:36 +000010004 Destroyed
10005 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10006 E->getDestroyedTypeLoc());
10007 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010008
Craig Topperc3ec1492014-05-26 06:22:03 +000010009 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010010 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010011 CXXScopeSpec EmptySS;
10012 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010013 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010014 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010015 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010016 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010017
John McCallb268a282010-08-23 23:25:46 +000010018 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010019 E->getOperatorLoc(),
10020 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010021 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010022 ScopeTypeInfo,
10023 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010024 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010025 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010026}
Mike Stump11289f42009-09-09 15:08:12 +000010027
Richard Smith151c4562016-12-20 21:35:28 +000010028template <typename Derived>
10029bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10030 bool RequiresADL,
10031 LookupResult &R) {
10032 // Transform all the decls.
10033 bool AllEmptyPacks = true;
10034 for (auto *OldD : Old->decls()) {
10035 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10036 if (!InstD) {
10037 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10038 // This can happen because of dependent hiding.
10039 if (isa<UsingShadowDecl>(OldD))
10040 continue;
10041 else {
10042 R.clear();
10043 return true;
10044 }
10045 }
10046
10047 // Expand using pack declarations.
10048 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10049 ArrayRef<NamedDecl*> Decls = SingleDecl;
10050 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10051 Decls = UPD->expansions();
10052
10053 // Expand using declarations.
10054 for (auto *D : Decls) {
10055 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10056 for (auto *SD : UD->shadows())
10057 R.addDecl(SD);
10058 } else {
10059 R.addDecl(D);
10060 }
10061 }
10062
10063 AllEmptyPacks &= Decls.empty();
10064 };
10065
10066 // C++ [temp.res]/8.4.2:
10067 // The program is ill-formed, no diagnostic required, if [...] lookup for
10068 // a name in the template definition found a using-declaration, but the
10069 // lookup in the corresponding scope in the instantiation odoes not find
10070 // any declarations because the using-declaration was a pack expansion and
10071 // the corresponding pack is empty
10072 if (AllEmptyPacks && !RequiresADL) {
10073 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10074 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10075 return true;
10076 }
10077
10078 // Resolve a kind, but don't do any further analysis. If it's
10079 // ambiguous, the callee needs to deal with it.
10080 R.resolveKind();
10081 return false;
10082}
10083
Douglas Gregorad8a3362009-09-04 17:36:40 +000010084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010085ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010086TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010087 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010088 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10089 Sema::LookupOrdinaryName);
10090
Richard Smith151c4562016-12-20 21:35:28 +000010091 // Transform the declaration set.
10092 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10093 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010094
10095 // Rebuild the nested-name qualifier, if present.
10096 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010097 if (Old->getQualifierLoc()) {
10098 NestedNameSpecifierLoc QualifierLoc
10099 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10100 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010101 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010102
Douglas Gregor0da1d432011-02-28 20:01:57 +000010103 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010104 }
10105
Douglas Gregor9262f472010-04-27 18:19:34 +000010106 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010107 CXXRecordDecl *NamingClass
10108 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10109 Old->getNameLoc(),
10110 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010111 if (!NamingClass) {
10112 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010114 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010115
Douglas Gregorda7be082010-04-27 16:10:10 +000010116 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010117 }
10118
Abramo Bagnara7945c982012-01-27 09:46:47 +000010119 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10120
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010121 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010122 // it's a normal declaration name or member reference.
10123 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10124 NamedDecl *D = R.getAsSingle<NamedDecl>();
10125 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10126 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10127 // give a good diagnostic.
10128 if (D && D->isCXXInstanceMember()) {
10129 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10130 /*TemplateArgs=*/nullptr,
10131 /*Scope=*/nullptr);
10132 }
10133
John McCalle66edc12009-11-24 19:00:30 +000010134 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010135 }
John McCalle66edc12009-11-24 19:00:30 +000010136
10137 // If we have template arguments, rebuild them, then rebuild the
10138 // templateid expression.
10139 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010140 if (Old->hasExplicitTemplateArgs() &&
10141 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010142 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010143 TransArgs)) {
10144 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010145 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010146 }
John McCalle66edc12009-11-24 19:00:30 +000010147
Abramo Bagnara7945c982012-01-27 09:46:47 +000010148 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010149 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010150}
Mike Stump11289f42009-09-09 15:08:12 +000010151
Douglas Gregora16548e2009-08-11 05:31:07 +000010152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010153ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010154TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10155 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010156 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010157 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10158 TypeSourceInfo *From = E->getArg(I);
10159 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010160 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010161 TypeLocBuilder TLB;
10162 TLB.reserve(FromTL.getFullDataSize());
10163 QualType To = getDerived().TransformType(TLB, FromTL);
10164 if (To.isNull())
10165 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010166
Douglas Gregor29c42f22012-02-24 07:38:34 +000010167 if (To == From->getType())
10168 Args.push_back(From);
10169 else {
10170 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10171 ArgChanged = true;
10172 }
10173 continue;
10174 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010175
Douglas Gregor29c42f22012-02-24 07:38:34 +000010176 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010177
Douglas Gregor29c42f22012-02-24 07:38:34 +000010178 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010179 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010180 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10181 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10182 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010183
Douglas Gregor29c42f22012-02-24 07:38:34 +000010184 // Determine whether the set of unexpanded parameter packs can and should
10185 // be expanded.
10186 bool Expand = true;
10187 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010188 Optional<unsigned> OrigNumExpansions =
10189 ExpansionTL.getTypePtr()->getNumExpansions();
10190 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010191 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10192 PatternTL.getSourceRange(),
10193 Unexpanded,
10194 Expand, RetainExpansion,
10195 NumExpansions))
10196 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010197
Douglas Gregor29c42f22012-02-24 07:38:34 +000010198 if (!Expand) {
10199 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010200 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010201 // expansion.
10202 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010203
Douglas Gregor29c42f22012-02-24 07:38:34 +000010204 TypeLocBuilder TLB;
10205 TLB.reserve(From->getTypeLoc().getFullDataSize());
10206
10207 QualType To = getDerived().TransformType(TLB, PatternTL);
10208 if (To.isNull())
10209 return ExprError();
10210
Chad Rosier1dcde962012-08-08 18:46:20 +000010211 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010212 PatternTL.getSourceRange(),
10213 ExpansionTL.getEllipsisLoc(),
10214 NumExpansions);
10215 if (To.isNull())
10216 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010217
Douglas Gregor29c42f22012-02-24 07:38:34 +000010218 PackExpansionTypeLoc ToExpansionTL
10219 = TLB.push<PackExpansionTypeLoc>(To);
10220 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10221 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10222 continue;
10223 }
10224
10225 // Expand the pack expansion by substituting for each argument in the
10226 // pack(s).
10227 for (unsigned I = 0; I != *NumExpansions; ++I) {
10228 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10229 TypeLocBuilder TLB;
10230 TLB.reserve(PatternTL.getFullDataSize());
10231 QualType To = getDerived().TransformType(TLB, PatternTL);
10232 if (To.isNull())
10233 return ExprError();
10234
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010235 if (To->containsUnexpandedParameterPack()) {
10236 To = getDerived().RebuildPackExpansionType(To,
10237 PatternTL.getSourceRange(),
10238 ExpansionTL.getEllipsisLoc(),
10239 NumExpansions);
10240 if (To.isNull())
10241 return ExprError();
10242
10243 PackExpansionTypeLoc ToExpansionTL
10244 = TLB.push<PackExpansionTypeLoc>(To);
10245 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10246 }
10247
Douglas Gregor29c42f22012-02-24 07:38:34 +000010248 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10249 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010250
Douglas Gregor29c42f22012-02-24 07:38:34 +000010251 if (!RetainExpansion)
10252 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010253
Douglas Gregor29c42f22012-02-24 07:38:34 +000010254 // If we're supposed to retain a pack expansion, do so by temporarily
10255 // forgetting the partially-substituted parameter pack.
10256 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10257
10258 TypeLocBuilder TLB;
10259 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010260
Douglas Gregor29c42f22012-02-24 07:38:34 +000010261 QualType To = getDerived().TransformType(TLB, PatternTL);
10262 if (To.isNull())
10263 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010264
10265 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010266 PatternTL.getSourceRange(),
10267 ExpansionTL.getEllipsisLoc(),
10268 NumExpansions);
10269 if (To.isNull())
10270 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010271
Douglas Gregor29c42f22012-02-24 07:38:34 +000010272 PackExpansionTypeLoc ToExpansionTL
10273 = TLB.push<PackExpansionTypeLoc>(To);
10274 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10275 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10276 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010277
Douglas Gregor29c42f22012-02-24 07:38:34 +000010278 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010279 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010280
10281 return getDerived().RebuildTypeTrait(E->getTrait(),
10282 E->getLocStart(),
10283 Args,
10284 E->getLocEnd());
10285}
10286
10287template<typename Derived>
10288ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010289TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10290 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10291 if (!T)
10292 return ExprError();
10293
10294 if (!getDerived().AlwaysRebuild() &&
10295 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010296 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010297
10298 ExprResult SubExpr;
10299 {
10300 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10301 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10302 if (SubExpr.isInvalid())
10303 return ExprError();
10304
10305 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010306 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010307 }
10308
10309 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10310 E->getLocStart(),
10311 T,
10312 SubExpr.get(),
10313 E->getLocEnd());
10314}
10315
10316template<typename Derived>
10317ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010318TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10319 ExprResult SubExpr;
10320 {
10321 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
10322 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10323 if (SubExpr.isInvalid())
10324 return ExprError();
10325
10326 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010327 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010328 }
10329
10330 return getDerived().RebuildExpressionTrait(
10331 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10332}
10333
Reid Kleckner32506ed2014-06-12 23:03:48 +000010334template <typename Derived>
10335ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10336 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10337 TypeSourceInfo **RecoveryTSI) {
10338 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10339 DRE, AddrTaken, RecoveryTSI);
10340
10341 // Propagate both errors and recovered types, which return ExprEmpty.
10342 if (!NewDRE.isUsable())
10343 return NewDRE;
10344
10345 // We got an expr, wrap it up in parens.
10346 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10347 return PE;
10348 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10349 PE->getRParen());
10350}
10351
10352template <typename Derived>
10353ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10354 DependentScopeDeclRefExpr *E) {
10355 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10356 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010357}
10358
10359template<typename Derived>
10360ExprResult
10361TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10362 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010363 bool IsAddressOfOperand,
10364 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010365 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010366 NestedNameSpecifierLoc QualifierLoc
10367 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10368 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010369 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010370 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010371
John McCall31f82722010-11-12 08:19:04 +000010372 // TODO: If this is a conversion-function-id, verify that the
10373 // destination type name (if present) resolves the same way after
10374 // instantiation as it did in the local scope.
10375
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010376 DeclarationNameInfo NameInfo
10377 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10378 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010380
John McCalle66edc12009-11-24 19:00:30 +000010381 if (!E->hasExplicitTemplateArgs()) {
10382 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010383 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010384 // Note: it is sufficient to compare the Name component of NameInfo:
10385 // if name has not changed, DNLoc has not changed either.
10386 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010387 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010388
Reid Kleckner32506ed2014-06-12 23:03:48 +000010389 return getDerived().RebuildDependentScopeDeclRefExpr(
10390 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10391 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010392 }
John McCall6b51f282009-11-23 01:53:49 +000010393
10394 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010395 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10396 E->getNumTemplateArgs(),
10397 TransArgs))
10398 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010399
Reid Kleckner32506ed2014-06-12 23:03:48 +000010400 return getDerived().RebuildDependentScopeDeclRefExpr(
10401 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10402 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010403}
10404
10405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010406ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010407TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010408 // CXXConstructExprs other than for list-initialization and
10409 // CXXTemporaryObjectExpr are always implicit, so when we have
10410 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010411 if ((E->getNumArgs() == 1 ||
10412 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010413 (!getDerived().DropCallArgument(E->getArg(0))) &&
10414 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010415 return getDerived().TransformExpr(E->getArg(0));
10416
Douglas Gregora16548e2009-08-11 05:31:07 +000010417 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10418
10419 QualType T = getDerived().TransformType(E->getType());
10420 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010421 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010422
10423 CXXConstructorDecl *Constructor
10424 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010425 getDerived().TransformDecl(E->getLocStart(),
10426 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010427 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010428 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010429
Douglas Gregora16548e2009-08-11 05:31:07 +000010430 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010431 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010432 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010433 &ArgumentChanged))
10434 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010435
Douglas Gregora16548e2009-08-11 05:31:07 +000010436 if (!getDerived().AlwaysRebuild() &&
10437 T == E->getType() &&
10438 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010439 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010440 // Mark the constructor as referenced.
10441 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010442 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010443 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010444 }
Mike Stump11289f42009-09-09 15:08:12 +000010445
Douglas Gregordb121ba2009-12-14 16:27:04 +000010446 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010447 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010448 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010449 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010450 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010451 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010452 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010453 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010454 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010455}
Mike Stump11289f42009-09-09 15:08:12 +000010456
Richard Smith5179eb72016-06-28 19:03:57 +000010457template<typename Derived>
10458ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10459 CXXInheritedCtorInitExpr *E) {
10460 QualType T = getDerived().TransformType(E->getType());
10461 if (T.isNull())
10462 return ExprError();
10463
10464 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10465 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10466 if (!Constructor)
10467 return ExprError();
10468
10469 if (!getDerived().AlwaysRebuild() &&
10470 T == E->getType() &&
10471 Constructor == E->getConstructor()) {
10472 // Mark the constructor as referenced.
10473 // FIXME: Instantiation-specific
10474 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10475 return E;
10476 }
10477
10478 return getDerived().RebuildCXXInheritedCtorInitExpr(
10479 T, E->getLocation(), Constructor,
10480 E->constructsVBase(), E->inheritedFromVBase());
10481}
10482
Douglas Gregora16548e2009-08-11 05:31:07 +000010483/// \brief Transform a C++ temporary-binding expression.
10484///
Douglas Gregor363b1512009-12-24 18:51:59 +000010485/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10486/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010489TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010490 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010491}
Mike Stump11289f42009-09-09 15:08:12 +000010492
John McCall5d413782010-12-06 08:20:24 +000010493/// \brief Transform a C++ expression that contains cleanups that should
10494/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010495///
John McCall5d413782010-12-06 08:20:24 +000010496/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010497/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010499ExprResult
John McCall5d413782010-12-06 08:20:24 +000010500TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010501 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010502}
Mike Stump11289f42009-09-09 15:08:12 +000010503
Douglas Gregora16548e2009-08-11 05:31:07 +000010504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010505ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010506TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010507 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010508 TypeSourceInfo *T =
10509 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010510 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010512
Douglas Gregora16548e2009-08-11 05:31:07 +000010513 CXXConstructorDecl *Constructor
10514 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010515 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010516 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010517 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010519
Douglas Gregora16548e2009-08-11 05:31:07 +000010520 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010521 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010522 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010523 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010524 &ArgumentChanged))
10525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010526
Douglas Gregora16548e2009-08-11 05:31:07 +000010527 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010528 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010529 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010530 !ArgumentChanged) {
10531 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010532 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010533 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010534 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010535
Richard Smithd59b8322012-12-19 01:39:02 +000010536 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010537 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10538 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010539 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010540 E->getLocEnd());
10541}
Mike Stump11289f42009-09-09 15:08:12 +000010542
Douglas Gregora16548e2009-08-11 05:31:07 +000010543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010544ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010545TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010546 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010547 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010548 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010549 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10550 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010551 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010552 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010553 CEnd = E->capture_end();
10554 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010555 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010556 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000010557 EnterExpressionEvaluationContext EEEC(getSema(),
10558 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010559 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10560 C->getCapturedVar()->getInit(),
10561 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010562
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010563 if (NewExprInitResult.isInvalid())
10564 return ExprError();
10565 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010566
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010567 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010568 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010569 getSema().buildLambdaInitCaptureInitialization(
10570 C->getLocation(), OldVD->getType()->isReferenceType(),
10571 OldVD->getIdentifier(),
10572 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010573 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010574 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10575 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010576 }
10577
Faisal Vali2cba1332013-10-23 06:44:28 +000010578 // Transform the template parameters, and add them to the current
10579 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010580 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010581 E->getTemplateParameterList());
10582
Richard Smith01014ce2014-11-20 23:53:14 +000010583 // Transform the type of the original lambda's call operator.
10584 // The transformation MUST be done in the CurrentInstantiationScope since
10585 // it introduces a mapping of the original to the newly created
10586 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010587 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010588 {
10589 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10590 FunctionProtoTypeLoc OldCallOpFPTL =
10591 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010592
10593 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010594 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010595 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010596 QualType NewCallOpType = TransformFunctionProtoType(
10597 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010598 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10599 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10600 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010601 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010602 if (NewCallOpType.isNull())
10603 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010604 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10605 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010606 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010607
Richard Smithc38498f2015-04-27 21:27:54 +000010608 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10609 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10610 LSI->GLTemplateParameterList = TPL;
10611
Eli Friedmand564afb2012-09-19 01:18:11 +000010612 // Create the local class that will describe the lambda.
10613 CXXRecordDecl *Class
10614 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010615 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010616 /*KnownDependent=*/false,
10617 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010618 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10619
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010620 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010621 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10622 Class, E->getIntroducerRange(), NewCallOpTSI,
10623 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010624 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10625 E->getCallOperator()->isConstexpr());
10626
Faisal Vali2cba1332013-10-23 06:44:28 +000010627 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010628
Akira Hatanaka402818462016-12-16 21:16:57 +000010629 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10630 I != NumParams; ++I) {
10631 auto *P = NewCallOperator->getParamDecl(I);
10632 if (P->hasUninstantiatedDefaultArg()) {
10633 EnterExpressionEvaluationContext Eval(
10634 getSema(), Sema::PotentiallyEvaluatedIfUsed, P);
10635 ExprResult R = getDerived().TransformExpr(
10636 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10637 P->setDefaultArg(R.get());
10638 }
10639 }
10640
Faisal Vali2cba1332013-10-23 06:44:28 +000010641 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010642 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010643
Douglas Gregorb4328232012-02-14 00:00:48 +000010644 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010645 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010646 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010647
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010648 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010649 getSema().buildLambdaScope(LSI, NewCallOperator,
10650 E->getIntroducerRange(),
10651 E->getCaptureDefault(),
10652 E->getCaptureDefaultLoc(),
10653 E->hasExplicitParameters(),
10654 E->hasExplicitResultType(),
10655 E->isMutable());
10656
10657 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010658
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010659 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010660 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010661 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010662 CEnd = E->capture_end();
10663 C != CEnd; ++C) {
10664 // When we hit the first implicit capture, tell Sema that we've finished
10665 // the list of explicit captures.
10666 if (!FinishedExplicitCaptures && C->isImplicit()) {
10667 getSema().finishLambdaExplicitCaptures(LSI);
10668 FinishedExplicitCaptures = true;
10669 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010670
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010671 // Capturing 'this' is trivial.
10672 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010673 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10674 /*BuildAndDiagnose*/ true, nullptr,
10675 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010676 continue;
10677 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010678 // Captured expression will be recaptured during captured variables
10679 // rebuilding.
10680 if (C->capturesVLAType())
10681 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010682
Richard Smithba71c082013-05-16 06:20:58 +000010683 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010684 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010685 InitCaptureInfoTy InitExprTypePair =
10686 InitCaptureExprsAndTypes[C - E->capture_begin()];
10687 ExprResult Init = InitExprTypePair.first;
10688 QualType InitQualType = InitExprTypePair.second;
10689 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010690 Invalid = true;
10691 continue;
10692 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010693 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010694 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010695 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10696 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010697 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010698 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010699 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010700 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010701 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010702 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010703 continue;
10704 }
10705
10706 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10707
Douglas Gregor3e308b12012-02-14 19:27:52 +000010708 // Determine the capture kind for Sema.
10709 Sema::TryCaptureKind Kind
10710 = C->isImplicit()? Sema::TryCapture_Implicit
10711 : C->getCaptureKind() == LCK_ByCopy
10712 ? Sema::TryCapture_ExplicitByVal
10713 : Sema::TryCapture_ExplicitByRef;
10714 SourceLocation EllipsisLoc;
10715 if (C->isPackExpansion()) {
10716 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10717 bool ShouldExpand = false;
10718 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010719 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010720 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10721 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010722 Unexpanded,
10723 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010724 NumExpansions)) {
10725 Invalid = true;
10726 continue;
10727 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010728
Douglas Gregor3e308b12012-02-14 19:27:52 +000010729 if (ShouldExpand) {
10730 // The transform has determined that we should perform an expansion;
10731 // transform and capture each of the arguments.
10732 // expansion of the pattern. Do so.
10733 VarDecl *Pack = C->getCapturedVar();
10734 for (unsigned I = 0; I != *NumExpansions; ++I) {
10735 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10736 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010737 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010738 Pack));
10739 if (!CapturedVar) {
10740 Invalid = true;
10741 continue;
10742 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010743
Douglas Gregor3e308b12012-02-14 19:27:52 +000010744 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010745 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10746 }
Richard Smith9467be42014-06-06 17:33:35 +000010747
10748 // FIXME: Retain a pack expansion if RetainExpansion is true.
10749
Douglas Gregor3e308b12012-02-14 19:27:52 +000010750 continue;
10751 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010752
Douglas Gregor3e308b12012-02-14 19:27:52 +000010753 EllipsisLoc = C->getEllipsisLoc();
10754 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010755
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010756 // Transform the captured variable.
10757 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010758 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010759 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010760 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010761 Invalid = true;
10762 continue;
10763 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010764
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010765 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010766 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10767 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010768 }
10769 if (!FinishedExplicitCaptures)
10770 getSema().finishLambdaExplicitCaptures(LSI);
10771
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010772 // Enter a new evaluation context to insulate the lambda from any
10773 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +000010774 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010775
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010776 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010777 StmtResult Body =
10778 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10779
10780 // ActOnLambda* will pop the function scope for us.
10781 FuncScopeCleanup.disable();
10782
Douglas Gregorb4328232012-02-14 00:00:48 +000010783 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010784 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010785 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010786 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010787 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010788 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010789
Richard Smithc38498f2015-04-27 21:27:54 +000010790 // Copy the LSI before ActOnFinishFunctionBody removes it.
10791 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10792 // the call operator.
10793 auto LSICopy = *LSI;
10794 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10795 /*IsInstantiation*/ true);
10796 SavedContext.pop();
10797
10798 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10799 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010800}
10801
10802template<typename Derived>
10803ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010804TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010805 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010806 TypeSourceInfo *T =
10807 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010808 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010809 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010810
Douglas Gregora16548e2009-08-11 05:31:07 +000010811 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010812 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010813 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010814 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010815 &ArgumentChanged))
10816 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010817
Douglas Gregora16548e2009-08-11 05:31:07 +000010818 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010819 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010820 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010821 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010822
Douglas Gregora16548e2009-08-11 05:31:07 +000010823 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010824 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010825 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010826 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010827 E->getRParenLoc());
10828}
Mike Stump11289f42009-09-09 15:08:12 +000010829
Douglas Gregora16548e2009-08-11 05:31:07 +000010830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010831ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010832TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010833 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010834 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010835 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010836 Expr *OldBase;
10837 QualType BaseType;
10838 QualType ObjectType;
10839 if (!E->isImplicitAccess()) {
10840 OldBase = E->getBase();
10841 Base = getDerived().TransformExpr(OldBase);
10842 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010844
John McCall2d74de92009-12-01 22:10:20 +000010845 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010846 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010847 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010848 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010849 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010850 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010851 ObjectTy,
10852 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010853 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010854 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010855
John McCallba7bf592010-08-24 05:47:05 +000010856 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010857 BaseType = ((Expr*) Base.get())->getType();
10858 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000010859 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000010860 BaseType = getDerived().TransformType(E->getBaseType());
10861 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
10862 }
Mike Stump11289f42009-09-09 15:08:12 +000010863
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010864 // Transform the first part of the nested-name-specifier that qualifies
10865 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000010866 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000010867 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000010868 E->getFirstQualifierFoundInScope(),
10869 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000010870
Douglas Gregore16af532011-02-28 18:50:33 +000010871 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010872 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000010873 QualifierLoc
10874 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
10875 ObjectType,
10876 FirstQualifierInScope);
10877 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010878 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010879 }
Mike Stump11289f42009-09-09 15:08:12 +000010880
Abramo Bagnara7945c982012-01-27 09:46:47 +000010881 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
10882
John McCall31f82722010-11-12 08:19:04 +000010883 // TODO: If this is a conversion-function-id, verify that the
10884 // destination type name (if present) resolves the same way after
10885 // instantiation as it did in the local scope.
10886
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010887 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000010888 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010889 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010891
John McCall2d74de92009-12-01 22:10:20 +000010892 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000010893 // This is a reference to a member without an explicitly-specified
10894 // template argument list. Optimize for this common case.
10895 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000010896 Base.get() == OldBase &&
10897 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000010898 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010899 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000010900 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010901 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010902
John McCallb268a282010-08-23 23:25:46 +000010903 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010904 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000010905 E->isArrow(),
10906 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010907 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010908 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000010909 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010910 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000010911 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000010912 }
10913
John McCall6b51f282009-11-23 01:53:49 +000010914 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010915 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10916 E->getNumTemplateArgs(),
10917 TransArgs))
10918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010919
John McCallb268a282010-08-23 23:25:46 +000010920 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010921 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000010922 E->isArrow(),
10923 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000010924 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010925 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000010926 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010927 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000010928 &TransArgs);
10929}
10930
10931template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010932ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010933TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000010934 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010935 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010936 QualType BaseType;
10937 if (!Old->isImplicitAccess()) {
10938 Base = getDerived().TransformExpr(Old->getBase());
10939 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010940 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010941 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000010942 Old->isArrow());
10943 if (Base.isInvalid())
10944 return ExprError();
10945 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000010946 } else {
10947 BaseType = getDerived().TransformType(Old->getBaseType());
10948 }
John McCall10eae182009-11-30 22:42:35 +000010949
Douglas Gregor0da1d432011-02-28 20:01:57 +000010950 NestedNameSpecifierLoc QualifierLoc;
10951 if (Old->getQualifierLoc()) {
10952 QualifierLoc
10953 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10954 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010955 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010956 }
10957
Abramo Bagnara7945c982012-01-27 09:46:47 +000010958 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10959
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010960 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000010961 Sema::LookupOrdinaryName);
10962
Richard Smith151c4562016-12-20 21:35:28 +000010963 // Transform the declaration set.
10964 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
10965 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010966
Douglas Gregor9262f472010-04-27 18:19:34 +000010967 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000010968 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010969 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000010970 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000010971 Old->getMemberLoc(),
10972 Old->getNamingClass()));
10973 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000010974 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010975
Douglas Gregorda7be082010-04-27 16:10:10 +000010976 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000010977 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010978
John McCall10eae182009-11-30 22:42:35 +000010979 TemplateArgumentListInfo TransArgs;
10980 if (Old->hasExplicitTemplateArgs()) {
10981 TransArgs.setLAngleLoc(Old->getLAngleLoc());
10982 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010983 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
10984 Old->getNumTemplateArgs(),
10985 TransArgs))
10986 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000010987 }
John McCall38836f02010-01-15 08:34:02 +000010988
10989 // FIXME: to do this check properly, we will need to preserve the
10990 // first-qualifier-in-scope here, just in case we had a dependent
10991 // base (and therefore couldn't do the check) and a
10992 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000010993 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000010994
John McCallb268a282010-08-23 23:25:46 +000010995 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010996 BaseType,
John McCall10eae182009-11-30 22:42:35 +000010997 Old->getOperatorLoc(),
10998 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000010999 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011000 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011001 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011002 R,
11003 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011004 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011005}
11006
11007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011008ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011009TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +000011010 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011011 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11012 if (SubExpr.isInvalid())
11013 return ExprError();
11014
11015 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011016 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011017
11018 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11019}
11020
11021template<typename Derived>
11022ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011023TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011024 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11025 if (Pattern.isInvalid())
11026 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011027
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011028 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011029 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011030
Douglas Gregorb8840002011-01-14 21:20:45 +000011031 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11032 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011033}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011034
11035template<typename Derived>
11036ExprResult
11037TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11038 // If E is not value-dependent, then nothing will change when we transform it.
11039 // Note: This is an instantiation-centric view.
11040 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011041 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011042
Richard Smithd784e682015-09-23 21:41:42 +000011043 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011044
Richard Smithd784e682015-09-23 21:41:42 +000011045 ArrayRef<TemplateArgument> PackArgs;
11046 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011047
Richard Smithd784e682015-09-23 21:41:42 +000011048 // Find the argument list to transform.
11049 if (E->isPartiallySubstituted()) {
11050 PackArgs = E->getPartialArguments();
11051 } else if (E->isValueDependent()) {
11052 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11053 bool ShouldExpand = false;
11054 bool RetainExpansion = false;
11055 Optional<unsigned> NumExpansions;
11056 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11057 Unexpanded,
11058 ShouldExpand, RetainExpansion,
11059 NumExpansions))
11060 return ExprError();
11061
11062 // If we need to expand the pack, build a template argument from it and
11063 // expand that.
11064 if (ShouldExpand) {
11065 auto *Pack = E->getPack();
11066 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11067 ArgStorage = getSema().Context.getPackExpansionType(
11068 getSema().Context.getTypeDeclType(TTPD), None);
11069 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11070 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11071 } else {
11072 auto *VD = cast<ValueDecl>(Pack);
11073 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11074 VK_RValue, E->getPackLoc());
11075 if (DRE.isInvalid())
11076 return ExprError();
11077 ArgStorage = new (getSema().Context) PackExpansionExpr(
11078 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11079 }
11080 PackArgs = ArgStorage;
11081 }
11082 }
11083
11084 // If we're not expanding the pack, just transform the decl.
11085 if (!PackArgs.size()) {
11086 auto *Pack = cast_or_null<NamedDecl>(
11087 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011088 if (!Pack)
11089 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011090 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11091 E->getPackLoc(),
11092 E->getRParenLoc(), None, None);
11093 }
11094
Richard Smithc5452ed2016-10-19 22:18:42 +000011095 // Try to compute the result without performing a partial substitution.
11096 Optional<unsigned> Result = 0;
11097 for (const TemplateArgument &Arg : PackArgs) {
11098 if (!Arg.isPackExpansion()) {
11099 Result = *Result + 1;
11100 continue;
11101 }
11102
11103 TemplateArgumentLoc ArgLoc;
11104 InventTemplateArgumentLoc(Arg, ArgLoc);
11105
11106 // Find the pattern of the pack expansion.
11107 SourceLocation Ellipsis;
11108 Optional<unsigned> OrigNumExpansions;
11109 TemplateArgumentLoc Pattern =
11110 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11111 OrigNumExpansions);
11112
11113 // Substitute under the pack expansion. Do not expand the pack (yet).
11114 TemplateArgumentLoc OutPattern;
11115 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11116 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11117 /*Uneval*/ true))
11118 return true;
11119
11120 // See if we can determine the number of arguments from the result.
11121 Optional<unsigned> NumExpansions =
11122 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11123 if (!NumExpansions) {
11124 // No: we must be in an alias template expansion, and we're going to need
11125 // to actually expand the packs.
11126 Result = None;
11127 break;
11128 }
11129
11130 Result = *Result + *NumExpansions;
11131 }
11132
11133 // Common case: we could determine the number of expansions without
11134 // substituting.
11135 if (Result)
11136 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11137 E->getPackLoc(),
11138 E->getRParenLoc(), *Result, None);
11139
Richard Smithd784e682015-09-23 21:41:42 +000011140 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11141 E->getPackLoc());
11142 {
11143 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11144 typedef TemplateArgumentLocInventIterator<
11145 Derived, const TemplateArgument*> PackLocIterator;
11146 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11147 PackLocIterator(*this, PackArgs.end()),
11148 TransformedPackArgs, /*Uneval*/true))
11149 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011150 }
11151
Richard Smithc5452ed2016-10-19 22:18:42 +000011152 // Check whether we managed to fully-expand the pack.
11153 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011154 SmallVector<TemplateArgument, 8> Args;
11155 bool PartialSubstitution = false;
11156 for (auto &Loc : TransformedPackArgs.arguments()) {
11157 Args.push_back(Loc.getArgument());
11158 if (Loc.getArgument().isPackExpansion())
11159 PartialSubstitution = true;
11160 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011161
Richard Smithd784e682015-09-23 21:41:42 +000011162 if (PartialSubstitution)
11163 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11164 E->getPackLoc(),
11165 E->getRParenLoc(), None, Args);
11166
11167 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011168 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011169 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011170}
11171
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011172template<typename Derived>
11173ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011174TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11175 SubstNonTypeTemplateParmPackExpr *E) {
11176 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011177 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011178}
11179
11180template<typename Derived>
11181ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011182TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11183 SubstNonTypeTemplateParmExpr *E) {
11184 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011185 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011186}
11187
11188template<typename Derived>
11189ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011190TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11191 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011192 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011193}
11194
11195template<typename Derived>
11196ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011197TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11198 MaterializeTemporaryExpr *E) {
11199 return getDerived().TransformExpr(E->GetTemporaryExpr());
11200}
Chad Rosier1dcde962012-08-08 18:46:20 +000011201
Douglas Gregorfe314812011-06-21 17:03:29 +000011202template<typename Derived>
11203ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011204TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11205 Expr *Pattern = E->getPattern();
11206
11207 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11208 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11209 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11210
11211 // Determine whether the set of unexpanded parameter packs can and should
11212 // be expanded.
11213 bool Expand = true;
11214 bool RetainExpansion = false;
11215 Optional<unsigned> NumExpansions;
11216 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11217 Pattern->getSourceRange(),
11218 Unexpanded,
11219 Expand, RetainExpansion,
11220 NumExpansions))
11221 return true;
11222
11223 if (!Expand) {
11224 // Do not expand any packs here, just transform and rebuild a fold
11225 // expression.
11226 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11227
11228 ExprResult LHS =
11229 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11230 if (LHS.isInvalid())
11231 return true;
11232
11233 ExprResult RHS =
11234 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11235 if (RHS.isInvalid())
11236 return true;
11237
11238 if (!getDerived().AlwaysRebuild() &&
11239 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11240 return E;
11241
11242 return getDerived().RebuildCXXFoldExpr(
11243 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11244 RHS.get(), E->getLocEnd());
11245 }
11246
11247 // The transform has determined that we should perform an elementwise
11248 // expansion of the pattern. Do so.
11249 ExprResult Result = getDerived().TransformExpr(E->getInit());
11250 if (Result.isInvalid())
11251 return true;
11252 bool LeftFold = E->isLeftFold();
11253
11254 // If we're retaining an expansion for a right fold, it is the innermost
11255 // component and takes the init (if any).
11256 if (!LeftFold && RetainExpansion) {
11257 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11258
11259 ExprResult Out = getDerived().TransformExpr(Pattern);
11260 if (Out.isInvalid())
11261 return true;
11262
11263 Result = getDerived().RebuildCXXFoldExpr(
11264 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11265 Result.get(), E->getLocEnd());
11266 if (Result.isInvalid())
11267 return true;
11268 }
11269
11270 for (unsigned I = 0; I != *NumExpansions; ++I) {
11271 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11272 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11273 ExprResult Out = getDerived().TransformExpr(Pattern);
11274 if (Out.isInvalid())
11275 return true;
11276
11277 if (Out.get()->containsUnexpandedParameterPack()) {
11278 // We still have a pack; retain a pack expansion for this slice.
11279 Result = getDerived().RebuildCXXFoldExpr(
11280 E->getLocStart(),
11281 LeftFold ? Result.get() : Out.get(),
11282 E->getOperator(), E->getEllipsisLoc(),
11283 LeftFold ? Out.get() : Result.get(),
11284 E->getLocEnd());
11285 } else if (Result.isUsable()) {
11286 // We've got down to a single element; build a binary operator.
11287 Result = getDerived().RebuildBinaryOperator(
11288 E->getEllipsisLoc(), E->getOperator(),
11289 LeftFold ? Result.get() : Out.get(),
11290 LeftFold ? Out.get() : Result.get());
11291 } else
11292 Result = Out;
11293
11294 if (Result.isInvalid())
11295 return true;
11296 }
11297
11298 // If we're retaining an expansion for a left fold, it is the outermost
11299 // component and takes the complete expansion so far as its init (if any).
11300 if (LeftFold && RetainExpansion) {
11301 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11302
11303 ExprResult Out = getDerived().TransformExpr(Pattern);
11304 if (Out.isInvalid())
11305 return true;
11306
11307 Result = getDerived().RebuildCXXFoldExpr(
11308 E->getLocStart(), Result.get(),
11309 E->getOperator(), E->getEllipsisLoc(),
11310 Out.get(), E->getLocEnd());
11311 if (Result.isInvalid())
11312 return true;
11313 }
11314
11315 // If we had no init and an empty pack, and we're not retaining an expansion,
11316 // then produce a fallback value or error.
11317 if (Result.isUnset())
11318 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11319 E->getOperator());
11320
11321 return Result;
11322}
11323
11324template<typename Derived>
11325ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011326TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11327 CXXStdInitializerListExpr *E) {
11328 return getDerived().TransformExpr(E->getSubExpr());
11329}
11330
11331template<typename Derived>
11332ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011333TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011334 return SemaRef.MaybeBindToTemporary(E);
11335}
11336
11337template<typename Derived>
11338ExprResult
11339TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011340 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011341}
11342
11343template<typename Derived>
11344ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011345TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11346 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11347 if (SubExpr.isInvalid())
11348 return ExprError();
11349
11350 if (!getDerived().AlwaysRebuild() &&
11351 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011352 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011353
11354 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011355}
11356
11357template<typename Derived>
11358ExprResult
11359TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11360 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011361 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011362 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011363 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011364 /*IsCall=*/false, Elements, &ArgChanged))
11365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011366
Ted Kremeneke65b0862012-03-06 20:05:56 +000011367 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11368 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011369
Ted Kremeneke65b0862012-03-06 20:05:56 +000011370 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11371 Elements.data(),
11372 Elements.size());
11373}
11374
11375template<typename Derived>
11376ExprResult
11377TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011378 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011379 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011380 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011381 bool ArgChanged = false;
11382 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11383 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011384
Ted Kremeneke65b0862012-03-06 20:05:56 +000011385 if (OrigElement.isPackExpansion()) {
11386 // This key/value element is a pack expansion.
11387 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11388 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11389 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11390 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11391
11392 // Determine whether the set of unexpanded parameter packs can
11393 // and should be expanded.
11394 bool Expand = true;
11395 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011396 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11397 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011398 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11399 OrigElement.Value->getLocEnd());
11400 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11401 PatternRange,
11402 Unexpanded,
11403 Expand, RetainExpansion,
11404 NumExpansions))
11405 return ExprError();
11406
11407 if (!Expand) {
11408 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011409 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011410 // expansion.
11411 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11412 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11413 if (Key.isInvalid())
11414 return ExprError();
11415
11416 if (Key.get() != OrigElement.Key)
11417 ArgChanged = true;
11418
11419 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11420 if (Value.isInvalid())
11421 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011422
Ted Kremeneke65b0862012-03-06 20:05:56 +000011423 if (Value.get() != OrigElement.Value)
11424 ArgChanged = true;
11425
Chad Rosier1dcde962012-08-08 18:46:20 +000011426 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011427 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11428 };
11429 Elements.push_back(Expansion);
11430 continue;
11431 }
11432
11433 // Record right away that the argument was changed. This needs
11434 // to happen even if the array expands to nothing.
11435 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011436
Ted Kremeneke65b0862012-03-06 20:05:56 +000011437 // The transform has determined that we should perform an elementwise
11438 // expansion of the pattern. Do so.
11439 for (unsigned I = 0; I != *NumExpansions; ++I) {
11440 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11441 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11442 if (Key.isInvalid())
11443 return ExprError();
11444
11445 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11446 if (Value.isInvalid())
11447 return ExprError();
11448
Chad Rosier1dcde962012-08-08 18:46:20 +000011449 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011450 Key.get(), Value.get(), SourceLocation(), NumExpansions
11451 };
11452
11453 // If any unexpanded parameter packs remain, we still have a
11454 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011455 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011456 if (Key.get()->containsUnexpandedParameterPack() ||
11457 Value.get()->containsUnexpandedParameterPack())
11458 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011459
Ted Kremeneke65b0862012-03-06 20:05:56 +000011460 Elements.push_back(Element);
11461 }
11462
Richard Smith9467be42014-06-06 17:33:35 +000011463 // FIXME: Retain a pack expansion if RetainExpansion is true.
11464
Ted Kremeneke65b0862012-03-06 20:05:56 +000011465 // We've finished with this pack expansion.
11466 continue;
11467 }
11468
11469 // Transform and check key.
11470 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11471 if (Key.isInvalid())
11472 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011473
Ted Kremeneke65b0862012-03-06 20:05:56 +000011474 if (Key.get() != OrigElement.Key)
11475 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011476
Ted Kremeneke65b0862012-03-06 20:05:56 +000011477 // Transform and check value.
11478 ExprResult Value
11479 = getDerived().TransformExpr(OrigElement.Value);
11480 if (Value.isInvalid())
11481 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011482
Ted Kremeneke65b0862012-03-06 20:05:56 +000011483 if (Value.get() != OrigElement.Value)
11484 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011485
11486 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011487 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011488 };
11489 Elements.push_back(Element);
11490 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011491
Ted Kremeneke65b0862012-03-06 20:05:56 +000011492 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11493 return SemaRef.MaybeBindToTemporary(E);
11494
11495 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011496 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011497}
11498
Mike Stump11289f42009-09-09 15:08:12 +000011499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011501TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011502 TypeSourceInfo *EncodedTypeInfo
11503 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11504 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011505 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011506
Douglas Gregora16548e2009-08-11 05:31:07 +000011507 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011508 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011509 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011510
11511 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011512 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011513 E->getRParenLoc());
11514}
Mike Stump11289f42009-09-09 15:08:12 +000011515
Douglas Gregora16548e2009-08-11 05:31:07 +000011516template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011517ExprResult TreeTransform<Derived>::
11518TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011519 // This is a kind of implicit conversion, and it needs to get dropped
11520 // and recomputed for the same general reasons that ImplicitCastExprs
11521 // do, as well a more specific one: this expression is only valid when
11522 // it appears *immediately* as an argument expression.
11523 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011524}
11525
11526template<typename Derived>
11527ExprResult TreeTransform<Derived>::
11528TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011529 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011530 = getDerived().TransformType(E->getTypeInfoAsWritten());
11531 if (!TSInfo)
11532 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011533
John McCall31168b02011-06-15 23:02:42 +000011534 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011535 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011536 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011537
John McCall31168b02011-06-15 23:02:42 +000011538 if (!getDerived().AlwaysRebuild() &&
11539 TSInfo == E->getTypeInfoAsWritten() &&
11540 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011541 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011542
John McCall31168b02011-06-15 23:02:42 +000011543 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011544 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011545 Result.get());
11546}
11547
Erik Pilkington29099de2016-07-16 00:35:23 +000011548template <typename Derived>
11549ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11550 ObjCAvailabilityCheckExpr *E) {
11551 return E;
11552}
11553
John McCall31168b02011-06-15 23:02:42 +000011554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011556TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011557 // Transform arguments.
11558 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011559 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011560 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011561 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011562 &ArgChanged))
11563 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011564
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011565 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11566 // Class message: transform the receiver type.
11567 TypeSourceInfo *ReceiverTypeInfo
11568 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11569 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011570 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011571
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011572 // If nothing changed, just retain the existing message send.
11573 if (!getDerived().AlwaysRebuild() &&
11574 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011575 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011576
11577 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011578 SmallVector<SourceLocation, 16> SelLocs;
11579 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011580 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11581 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011582 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011583 E->getMethodDecl(),
11584 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011585 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011586 E->getRightLoc());
11587 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011588 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11589 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011590 if (!E->getMethodDecl())
11591 return ExprError();
11592
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011593 // Build a new class message send to 'super'.
11594 SmallVector<SourceLocation, 16> SelLocs;
11595 E->getSelectorLocs(SelLocs);
11596 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11597 E->getSelector(),
11598 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011599 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011600 E->getMethodDecl(),
11601 E->getLeftLoc(),
11602 Args,
11603 E->getRightLoc());
11604 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011605
11606 // Instance message: transform the receiver
11607 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11608 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011609 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011610 = getDerived().TransformExpr(E->getInstanceReceiver());
11611 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011612 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011613
11614 // If nothing changed, just retain the existing message send.
11615 if (!getDerived().AlwaysRebuild() &&
11616 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011617 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011618
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011619 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011620 SmallVector<SourceLocation, 16> SelLocs;
11621 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011622 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011623 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011624 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011625 E->getMethodDecl(),
11626 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011627 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011628 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011629}
11630
Mike Stump11289f42009-09-09 15:08:12 +000011631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011632ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011633TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011634 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011635}
11636
Mike Stump11289f42009-09-09 15:08:12 +000011637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011639TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011640 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011641}
11642
Mike Stump11289f42009-09-09 15:08:12 +000011643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011645TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011646 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011647 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011648 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011649 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011650
11651 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011652
Douglas Gregord51d90d2010-04-26 20:11:03 +000011653 // If nothing changed, just retain the existing expression.
11654 if (!getDerived().AlwaysRebuild() &&
11655 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011656 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011657
John McCallb268a282010-08-23 23:25:46 +000011658 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011659 E->getLocation(),
11660 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011661}
11662
Mike Stump11289f42009-09-09 15:08:12 +000011663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011665TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011666 // 'super' and types never change. Property never changes. Just
11667 // retain the existing expression.
11668 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011669 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011670
Douglas Gregor9faee212010-04-26 20:47:02 +000011671 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011672 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011673 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011674 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011675
Douglas Gregor9faee212010-04-26 20:47:02 +000011676 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011677
Douglas Gregor9faee212010-04-26 20:47:02 +000011678 // If nothing changed, just retain the existing expression.
11679 if (!getDerived().AlwaysRebuild() &&
11680 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011681 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011682
John McCallb7bd14f2010-12-02 01:19:52 +000011683 if (E->isExplicitProperty())
11684 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11685 E->getExplicitProperty(),
11686 E->getLocation());
11687
11688 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011689 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011690 E->getImplicitPropertyGetter(),
11691 E->getImplicitPropertySetter(),
11692 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011693}
11694
Mike Stump11289f42009-09-09 15:08:12 +000011695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011696ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011697TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11698 // Transform the base expression.
11699 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11700 if (Base.isInvalid())
11701 return ExprError();
11702
11703 // Transform the key expression.
11704 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11705 if (Key.isInvalid())
11706 return ExprError();
11707
11708 // If nothing changed, just retain the existing expression.
11709 if (!getDerived().AlwaysRebuild() &&
11710 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011711 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011712
Chad Rosier1dcde962012-08-08 18:46:20 +000011713 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011714 Base.get(), Key.get(),
11715 E->getAtIndexMethodDecl(),
11716 E->setAtIndexMethodDecl());
11717}
11718
11719template<typename Derived>
11720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011721TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011722 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011723 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011724 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011725 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011726
Douglas Gregord51d90d2010-04-26 20:11:03 +000011727 // If nothing changed, just retain the existing expression.
11728 if (!getDerived().AlwaysRebuild() &&
11729 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011730 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011731
John McCallb268a282010-08-23 23:25:46 +000011732 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011733 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011734 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011735}
11736
Mike Stump11289f42009-09-09 15:08:12 +000011737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011739TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011740 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011741 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011742 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011743 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011744 SubExprs, &ArgumentChanged))
11745 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011746
Douglas Gregora16548e2009-08-11 05:31:07 +000011747 if (!getDerived().AlwaysRebuild() &&
11748 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011749 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011750
Douglas Gregora16548e2009-08-11 05:31:07 +000011751 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011752 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011753 E->getRParenLoc());
11754}
11755
Mike Stump11289f42009-09-09 15:08:12 +000011756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011757ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011758TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11759 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11760 if (SrcExpr.isInvalid())
11761 return ExprError();
11762
11763 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11764 if (!Type)
11765 return ExprError();
11766
11767 if (!getDerived().AlwaysRebuild() &&
11768 Type == E->getTypeSourceInfo() &&
11769 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011770 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011771
11772 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11773 SrcExpr.get(), Type,
11774 E->getRParenLoc());
11775}
11776
11777template<typename Derived>
11778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011779TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011780 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011781
Craig Topperc3ec1492014-05-26 06:22:03 +000011782 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011783 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11784
11785 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011786 blockScope->TheDecl->setBlockMissingReturnType(
11787 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011788
Chris Lattner01cf8db2011-07-20 06:58:45 +000011789 SmallVector<ParmVarDecl*, 4> params;
11790 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011791
John McCallc8e321d2016-03-01 02:09:25 +000011792 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11793
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011794 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011795 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011796 if (getDerived().TransformFunctionTypeParams(
11797 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11798 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11799 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011800 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011801 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011802 }
John McCall490112f2011-02-04 18:33:18 +000011803
Eli Friedman34b49062012-01-26 03:00:14 +000011804 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011805 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011806
John McCallc8e321d2016-03-01 02:09:25 +000011807 auto epi = exprFunctionType->getExtProtoInfo();
11808 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11809
Jordan Rose5c382722013-03-08 21:51:21 +000011810 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011811 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011812 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011813
11814 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011815 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011816 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011817
11818 if (!oldBlock->blockMissingReturnType()) {
11819 blockScope->HasImplicitReturnType = false;
11820 blockScope->ReturnType = exprResultType;
11821 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011822
John McCall3882ace2011-01-05 12:14:39 +000011823 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011824 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011825 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011826 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011827 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011828 }
John McCall3882ace2011-01-05 12:14:39 +000011829
John McCall490112f2011-02-04 18:33:18 +000011830#ifndef NDEBUG
11831 // In builds with assertions, make sure that we captured everything we
11832 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011833 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011834 for (const auto &I : oldBlock->captures()) {
11835 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011836
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011837 // Ignore parameter packs.
11838 if (isa<ParmVarDecl>(oldCapture) &&
11839 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11840 continue;
John McCall490112f2011-02-04 18:33:18 +000011841
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011842 VarDecl *newCapture =
11843 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11844 oldCapture));
11845 assert(blockScope->CaptureMap.count(newCapture));
11846 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011847 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011848 }
11849#endif
11850
11851 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011852 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011853}
11854
Mike Stump11289f42009-09-09 15:08:12 +000011855template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011856ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000011857TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000011858 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000011859}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011860
11861template<typename Derived>
11862ExprResult
11863TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011864 QualType RetTy = getDerived().TransformType(E->getType());
11865 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011866 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011867 SubExprs.reserve(E->getNumSubExprs());
11868 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
11869 SubExprs, &ArgumentChanged))
11870 return ExprError();
11871
11872 if (!getDerived().AlwaysRebuild() &&
11873 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011874 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011875
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011876 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000011877 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000011878}
Chad Rosier1dcde962012-08-08 18:46:20 +000011879
Douglas Gregora16548e2009-08-11 05:31:07 +000011880//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000011881// Type reconstruction
11882//===----------------------------------------------------------------------===//
11883
Mike Stump11289f42009-09-09 15:08:12 +000011884template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011885QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
11886 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011887 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011888 getDerived().getBaseEntity());
11889}
11890
Mike Stump11289f42009-09-09 15:08:12 +000011891template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000011892QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
11893 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000011894 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011895 getDerived().getBaseEntity());
11896}
11897
Mike Stump11289f42009-09-09 15:08:12 +000011898template<typename Derived>
11899QualType
John McCall70dd5f62009-10-30 00:06:24 +000011900TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
11901 bool WrittenAsLValue,
11902 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000011903 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000011904 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011905}
11906
11907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011908QualType
John McCall70dd5f62009-10-30 00:06:24 +000011909TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
11910 QualType ClassType,
11911 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000011912 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
11913 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011914}
11915
11916template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000011917QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
11918 const ObjCTypeParamDecl *Decl,
11919 SourceLocation ProtocolLAngleLoc,
11920 ArrayRef<ObjCProtocolDecl *> Protocols,
11921 ArrayRef<SourceLocation> ProtocolLocs,
11922 SourceLocation ProtocolRAngleLoc) {
11923 return SemaRef.BuildObjCTypeParamType(Decl,
11924 ProtocolLAngleLoc, Protocols,
11925 ProtocolLocs, ProtocolRAngleLoc,
11926 /*FailOnError=*/true);
11927}
11928
11929template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000011930QualType TreeTransform<Derived>::RebuildObjCObjectType(
11931 QualType BaseType,
11932 SourceLocation Loc,
11933 SourceLocation TypeArgsLAngleLoc,
11934 ArrayRef<TypeSourceInfo *> TypeArgs,
11935 SourceLocation TypeArgsRAngleLoc,
11936 SourceLocation ProtocolLAngleLoc,
11937 ArrayRef<ObjCProtocolDecl *> Protocols,
11938 ArrayRef<SourceLocation> ProtocolLocs,
11939 SourceLocation ProtocolRAngleLoc) {
11940 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
11941 TypeArgs, TypeArgsRAngleLoc,
11942 ProtocolLAngleLoc, Protocols, ProtocolLocs,
11943 ProtocolRAngleLoc,
11944 /*FailOnError=*/true);
11945}
11946
11947template<typename Derived>
11948QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
11949 QualType PointeeType,
11950 SourceLocation Star) {
11951 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
11952}
11953
11954template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011955QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000011956TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
11957 ArrayType::ArraySizeModifier SizeMod,
11958 const llvm::APInt *Size,
11959 Expr *SizeExpr,
11960 unsigned IndexTypeQuals,
11961 SourceRange BracketsRange) {
11962 if (SizeExpr || !Size)
11963 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
11964 IndexTypeQuals, BracketsRange,
11965 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000011966
11967 QualType Types[] = {
11968 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
11969 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
11970 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000011971 };
Craig Toppere5ce8312013-07-15 03:38:40 +000011972 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011973 QualType SizeType;
11974 for (unsigned I = 0; I != NumTypes; ++I)
11975 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
11976 SizeType = Types[I];
11977 break;
11978 }
Mike Stump11289f42009-09-09 15:08:12 +000011979
Eli Friedman9562f392012-01-25 23:20:27 +000011980 // Note that we can return a VariableArrayType here in the case where
11981 // the element type was a dependent VariableArrayType.
11982 IntegerLiteral *ArraySize
11983 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
11984 /*FIXME*/BracketsRange.getBegin());
11985 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011986 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000011987 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000011988}
Mike Stump11289f42009-09-09 15:08:12 +000011989
Douglas Gregord6ff3322009-08-04 16:50:30 +000011990template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011991QualType
11992TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000011993 ArrayType::ArraySizeModifier SizeMod,
11994 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000011995 unsigned IndexTypeQuals,
11996 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011997 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000011998 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011999}
12000
12001template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012002QualType
Mike Stump11289f42009-09-09 15:08:12 +000012003TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012004 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012005 unsigned IndexTypeQuals,
12006 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012007 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012008 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012009}
Mike Stump11289f42009-09-09 15:08:12 +000012010
Douglas Gregord6ff3322009-08-04 16:50:30 +000012011template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012012QualType
12013TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012014 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012015 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012016 unsigned IndexTypeQuals,
12017 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012018 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012019 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012020 IndexTypeQuals, BracketsRange);
12021}
12022
12023template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012024QualType
12025TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012026 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012027 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012028 unsigned IndexTypeQuals,
12029 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012030 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012031 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012032 IndexTypeQuals, BracketsRange);
12033}
12034
12035template<typename Derived>
12036QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000012037 unsigned NumElements,
12038 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012039 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012040 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012041}
Mike Stump11289f42009-09-09 15:08:12 +000012042
Douglas Gregord6ff3322009-08-04 16:50:30 +000012043template<typename Derived>
12044QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12045 unsigned NumElements,
12046 SourceLocation AttributeLoc) {
12047 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12048 NumElements, true);
12049 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012050 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12051 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012052 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012053}
Mike Stump11289f42009-09-09 15:08:12 +000012054
Douglas Gregord6ff3322009-08-04 16:50:30 +000012055template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012056QualType
12057TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012058 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012059 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012060 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012061}
Mike Stump11289f42009-09-09 15:08:12 +000012062
Douglas Gregord6ff3322009-08-04 16:50:30 +000012063template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012064QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12065 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012066 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012067 const FunctionProtoType::ExtProtoInfo &EPI) {
12068 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012069 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012070 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012071 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012072}
Mike Stump11289f42009-09-09 15:08:12 +000012073
Douglas Gregord6ff3322009-08-04 16:50:30 +000012074template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012075QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12076 return SemaRef.Context.getFunctionNoProtoType(T);
12077}
12078
12079template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012080QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12081 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012082 assert(D && "no decl found");
12083 if (D->isInvalidDecl()) return QualType();
12084
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012085 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012086 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012087 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12088 // A valid resolved using typename pack expansion decl can have multiple
12089 // UsingDecls, but they must each have exactly one type, and it must be
12090 // the same type in every case. But we must have at least one expansion!
12091 if (UPD->expansions().empty()) {
12092 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12093 << UPD->isCXXClassMember() << UPD;
12094 return QualType();
12095 }
12096
12097 // We might still have some unresolved types. Try to pick a resolved type
12098 // if we can. The final instantiation will check that the remaining
12099 // unresolved types instantiate to the type we pick.
12100 QualType FallbackT;
12101 QualType T;
12102 for (auto *E : UPD->expansions()) {
12103 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12104 if (ThisT.isNull())
12105 continue;
12106 else if (ThisT->getAs<UnresolvedUsingType>())
12107 FallbackT = ThisT;
12108 else if (T.isNull())
12109 T = ThisT;
12110 else
12111 assert(getSema().Context.hasSameType(ThisT, T) &&
12112 "mismatched resolved types in using pack expansion");
12113 }
12114 return T.isNull() ? FallbackT : T;
12115 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012116 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012117 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12118
12119 // A valid resolved using typename decl points to exactly one type decl.
12120 assert(++Using->shadow_begin() == Using->shadow_end());
12121 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012122 } else {
12123 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12124 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12125 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12126 }
12127
12128 return SemaRef.Context.getTypeDeclType(Ty);
12129}
12130
12131template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012132QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12133 SourceLocation Loc) {
12134 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012135}
12136
12137template<typename Derived>
12138QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12139 return SemaRef.Context.getTypeOfType(Underlying);
12140}
12141
12142template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012143QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12144 SourceLocation Loc) {
12145 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012146}
12147
12148template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012149QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12150 UnaryTransformType::UTTKind UKind,
12151 SourceLocation Loc) {
12152 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12153}
12154
12155template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012156QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012157 TemplateName Template,
12158 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012159 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012160 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012161}
Mike Stump11289f42009-09-09 15:08:12 +000012162
Douglas Gregor1135c352009-08-06 05:28:30 +000012163template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012164QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12165 SourceLocation KWLoc) {
12166 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12167}
12168
12169template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012170QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012171 SourceLocation KWLoc,
12172 bool isReadPipe) {
12173 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12174 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012175}
12176
12177template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012178TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012179TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012180 bool TemplateKW,
12181 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012182 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012183 Template);
12184}
12185
12186template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012187TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012188TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12189 const IdentifierInfo &Name,
12190 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012191 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012192 NamedDecl *FirstQualifierInScope,
12193 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012194 UnqualifiedId TemplateName;
12195 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012196 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012197 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012198 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012199 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012200 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012201 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012202 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012203 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012204}
Mike Stump11289f42009-09-09 15:08:12 +000012205
Douglas Gregora16548e2009-08-11 05:31:07 +000012206template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012207TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012208TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012209 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012210 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012211 QualType ObjectType,
12212 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012213 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012214 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012215 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012216 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012217 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012218 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012219 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012220 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012221 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012222 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012223 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012224 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012225}
Chad Rosier1dcde962012-08-08 18:46:20 +000012226
Douglas Gregor71395fa2009-11-04 00:56:37 +000012227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012228ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012229TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12230 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012231 Expr *OrigCallee,
12232 Expr *First,
12233 Expr *Second) {
12234 Expr *Callee = OrigCallee->IgnoreParenCasts();
12235 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012236
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012237 if (First->getObjectKind() == OK_ObjCProperty) {
12238 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12239 if (BinaryOperator::isAssignmentOp(Opc))
12240 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12241 First, Second);
12242 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12243 if (Result.isInvalid())
12244 return ExprError();
12245 First = Result.get();
12246 }
12247
12248 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12249 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12250 if (Result.isInvalid())
12251 return ExprError();
12252 Second = Result.get();
12253 }
12254
Douglas Gregora16548e2009-08-11 05:31:07 +000012255 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012256 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012257 if (!First->getType()->isOverloadableType() &&
12258 !Second->getType()->isOverloadableType())
12259 return getSema().CreateBuiltinArraySubscriptExpr(First,
12260 Callee->getLocStart(),
12261 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012262 } else if (Op == OO_Arrow) {
12263 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012264 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12265 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012266 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012267 // The argument is not of overloadable type, so try to create a
12268 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012269 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012270 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012271
John McCallb268a282010-08-23 23:25:46 +000012272 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012273 }
12274 } else {
John McCallb268a282010-08-23 23:25:46 +000012275 if (!First->getType()->isOverloadableType() &&
12276 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012277 // Neither of the arguments is an overloadable type, so try to
12278 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012279 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012280 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012281 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012282 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012284
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012285 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012286 }
12287 }
Mike Stump11289f42009-09-09 15:08:12 +000012288
12289 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012290 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012291 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012292
John McCallb268a282010-08-23 23:25:46 +000012293 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012294 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012295 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012296 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012297 // If we've resolved this to a particular non-member function, just call
12298 // that function. If we resolved it to a member function,
12299 // CreateOverloaded* will find that function for us.
12300 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12301 if (!isa<CXXMethodDecl>(ND))
12302 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012303 }
Mike Stump11289f42009-09-09 15:08:12 +000012304
Douglas Gregora16548e2009-08-11 05:31:07 +000012305 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012306 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012307 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012308
Douglas Gregora16548e2009-08-11 05:31:07 +000012309 // Create the overloaded operator invocation for unary operators.
12310 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012311 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012312 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012313 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012314 }
Mike Stump11289f42009-09-09 15:08:12 +000012315
Douglas Gregore9d62932011-07-15 16:25:15 +000012316 if (Op == OO_Subscript) {
12317 SourceLocation LBrace;
12318 SourceLocation RBrace;
12319
12320 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012321 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012322 LBrace = SourceLocation::getFromRawEncoding(
12323 NameLoc.CXXOperatorName.BeginOpNameLoc);
12324 RBrace = SourceLocation::getFromRawEncoding(
12325 NameLoc.CXXOperatorName.EndOpNameLoc);
12326 } else {
12327 LBrace = Callee->getLocStart();
12328 RBrace = OpLoc;
12329 }
12330
12331 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12332 First, Second);
12333 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012334
Douglas Gregora16548e2009-08-11 05:31:07 +000012335 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012336 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012337 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012338 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12339 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012340 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012341
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012342 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012343}
Mike Stump11289f42009-09-09 15:08:12 +000012344
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012345template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012346ExprResult
John McCallb268a282010-08-23 23:25:46 +000012347TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012348 SourceLocation OperatorLoc,
12349 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012350 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012351 TypeSourceInfo *ScopeType,
12352 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012353 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012354 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012355 QualType BaseType = Base->getType();
12356 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012357 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012358 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012359 !BaseType->getAs<PointerType>()->getPointeeType()
12360 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012361 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012362 return SemaRef.BuildPseudoDestructorExpr(
12363 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12364 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012365 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012366
Douglas Gregor678f90d2010-02-25 01:56:36 +000012367 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012368 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12369 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12370 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12371 NameInfo.setNamedTypeInfo(DestroyedType);
12372
Richard Smith8e4a3862012-05-15 06:15:11 +000012373 // The scope type is now known to be a valid nested name specifier
12374 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012375 if (ScopeType) {
12376 if (!ScopeType->getType()->getAs<TagType>()) {
12377 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12378 diag::err_expected_class_or_namespace)
12379 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12380 return ExprError();
12381 }
12382 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12383 CCLoc);
12384 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012385
Abramo Bagnara7945c982012-01-27 09:46:47 +000012386 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012387 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012388 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012389 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012390 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012391 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012392 /*TemplateArgs*/ nullptr,
12393 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012394}
12395
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012396template<typename Derived>
12397StmtResult
12398TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012399 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012400 CapturedDecl *CD = S->getCapturedDecl();
12401 unsigned NumParams = CD->getNumParams();
12402 unsigned ContextParamPos = CD->getContextParamPosition();
12403 SmallVector<Sema::CapturedParamNameType, 4> Params;
12404 for (unsigned I = 0; I < NumParams; ++I) {
12405 if (I != ContextParamPos) {
12406 Params.push_back(
12407 std::make_pair(
12408 CD->getParam(I)->getName(),
12409 getDerived().TransformType(CD->getParam(I)->getType())));
12410 } else {
12411 Params.push_back(std::make_pair(StringRef(), QualType()));
12412 }
12413 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012414 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012415 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012416 StmtResult Body;
12417 {
12418 Sema::CompoundScopeRAII CompoundScope(getSema());
12419 Body = getDerived().TransformStmt(S->getCapturedStmt());
12420 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012421
12422 if (Body.isInvalid()) {
12423 getSema().ActOnCapturedRegionError();
12424 return StmtError();
12425 }
12426
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012427 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012428}
12429
Douglas Gregord6ff3322009-08-04 16:50:30 +000012430} // end namespace clang
12431
Hans Wennborg59dbe862015-09-29 20:56:43 +000012432#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H