blob: 4b3a6708717c220f953fdd86c2b3da54b8d1a3fb [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattnercab02a62011-02-17 20:34:02 +00006//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
Chris Lattnercab02a62011-02-17 20:34:02 +000011//===----------------------------------------------------------------------===//
12
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000013#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000015
Eric Fiselierbee782b2017-04-03 19:21:00 +000016#include "CoroutineStmtBuilder.h"
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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000043/// A semantic tree transformation that allows one to transform one
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// 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
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +000059/// overriding function should not be virtual.
Douglas Gregord6ff3322009-08-04 16:50:30 +000060///
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 {
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000096 /// Private RAII object that helps us forget and then re-remember
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000116 /// The set of local declarations that have been transformed, for
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// 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:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000122 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000125 /// Retrieves a reference to the derived class.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000128 /// 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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000136 /// Retrieves a reference to the semantic analysis object used for
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000140 /// Whether the transformation should always rebuild AST nodes, even
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// 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
Richard Smith87346a12019-06-02 18:53:44 +0000151 /// Whether the transformation is forming an expression or statement that
152 /// replaces the original. In this case, we'll reuse mangling numbers from
153 /// existing lambdas.
154 bool ReplacingOriginal() { return false; }
155
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000156 /// Returns the location of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000157 /// information was not available elsewhere in the AST.
158 ///
Mike Stump11289f42009-09-09 15:08:12 +0000159 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// provide an alternative implementation that provides better location
161 /// information.
162 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000164 /// Returns the name of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// information was not available elsewhere in the AST.
166 ///
167 /// By default, returns an empty name. Subclasses can provide an alternative
168 /// implementation with a more precise name.
169 DeclarationName getBaseEntity() { return DeclarationName(); }
170
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000171 /// Sets the "base" location and entity when that
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// information is known based on another transformation.
173 ///
174 /// By default, the source location and entity are ignored. Subclasses can
175 /// override this function to provide a customized implementation.
176 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000178 /// RAII object that temporarily sets the base location and entity
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 /// used for reporting diagnostics in types.
180 class TemporaryBase {
181 TreeTransform &Self;
182 SourceLocation OldLocation;
183 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000184
Douglas Gregora16548e2009-08-11 05:31:07 +0000185 public:
186 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000187 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 OldLocation = Self.getDerived().getBaseLocation();
189 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000190
Douglas Gregora518d5b2011-01-25 17:51:48 +0000191 if (Location.isValid())
192 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000193 }
Mike Stump11289f42009-09-09 15:08:12 +0000194
Douglas Gregora16548e2009-08-11 05:31:07 +0000195 ~TemporaryBase() {
196 Self.getDerived().setBase(OldLocation, OldEntity);
197 }
198 };
Mike Stump11289f42009-09-09 15:08:12 +0000199
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000200 /// Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// transformed.
202 ///
203 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000204 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000205 /// not change. For example, template instantiation need not traverse
206 /// non-dependent types.
207 bool AlreadyTransformed(QualType T) {
208 return T.isNull();
209 }
210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000211 /// Determine whether the given call argument should be dropped, e.g.,
Douglas Gregord196a582009-12-14 19:27:10 +0000212 /// because it is a default argument.
213 ///
214 /// Subclasses can provide an alternative implementation of this routine to
215 /// determine which kinds of call arguments get dropped. By default,
216 /// CXXDefaultArgument nodes are dropped (prior to transformation).
217 bool DropCallArgument(Expr *E) {
218 return E->isDefaultArgument();
219 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000220
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000221 /// Determine whether we should expand a pack expansion with the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// given set of parameter packs into separate arguments by repeatedly
223 /// transforming the pattern.
224 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000225 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000226 /// Subclasses can override this routine to provide different behavior.
227 ///
228 /// \param EllipsisLoc The location of the ellipsis that identifies the
229 /// pack expansion.
230 ///
231 /// \param PatternRange The source range that covers the entire pattern of
232 /// the pack expansion.
233 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000234 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000235 /// pattern.
236 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000237 /// \param ShouldExpand Will be set to \c true if the transformer should
238 /// expand the corresponding pack expansions into separate arguments. When
239 /// set, \c NumExpansions must also be set.
240 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000241 /// \param RetainExpansion Whether the caller should add an unexpanded
242 /// pack expansion after all of the expanded arguments. This is used
243 /// when extending explicitly-specified template argument packs per
244 /// C++0x [temp.arg.explicit]p9.
245 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000246 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000247 /// the expanded form of the corresponding pack expansion. This is both an
248 /// input and an output parameter, which can be set by the caller if the
249 /// number of expansions is known a priori (e.g., due to a prior substitution)
250 /// and will be set by the callee when the number of expansions is known.
251 /// The callee must set this value when \c ShouldExpand is \c true; it may
252 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000254 /// \returns true if an error occurred (e.g., because the parameter packs
255 /// are to be instantiated with arguments of different lengths), false
256 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 /// must be set.
258 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
259 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000260 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000261 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000263 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000264 ShouldExpand = false;
265 return false;
266 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000267
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000268 /// "Forget" about the partially-substituted pack template argument,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000269 /// when performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 TemplateArgument ForgetPartiallySubstitutedPack() {
274 return TemplateArgument();
275 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000277 /// "Remember" the partially-substituted pack template argument
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000278 /// after performing an instantiation that must preserve the parameter pack
279 /// use.
280 ///
281 /// This routine is meant to be overridden by the template instantiator.
282 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000284 /// Note to the derived class when a function parameter pack is
Douglas Gregorf3010112011-01-07 16:43:16 +0000285 /// being expanded.
286 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000288 /// Transforms the given type into another type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000291 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000292 /// function. This is expensive, but we don't mind, because
293 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000294 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
296 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000297 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000298
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000299 /// Transforms the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000300 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000301 ///
John McCall550e0c22009-10-21 00:40:46 +0000302 /// By default, this routine transforms a type by delegating to the
303 /// appropriate TransformXXXType to build a new type. Subclasses
304 /// may override this function (to take over all type
305 /// transformations) or some set of the TransformXXXType functions
306 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000307 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000309 /// Transform the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000310 /// type, collecting location information in the given builder
311 /// as necessary.
312 ///
John McCall31f82722010-11-12 08:19:04 +0000313 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000315 /// Transform a type that is permitted to produce a
Richard Smithee579842017-01-30 20:39:26 +0000316 /// DeducedTemplateSpecializationType.
317 ///
318 /// This is used in the (relatively rare) contexts where it is acceptable
319 /// for transformation to produce a class template type with deduced
320 /// template arguments.
321 /// @{
322 QualType TransformTypeWithDeducedTST(QualType T);
323 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
324 /// @}
325
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000326 /// The reason why the value of a statement is not discarded, if any.
327 enum StmtDiscardKind {
328 SDK_Discarded,
329 SDK_NotDiscarded,
330 SDK_StmtExprResult,
331 };
332
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000333 /// Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000334 ///
Mike Stump11289f42009-09-09 15:08:12 +0000335 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000336 /// appropriate TransformXXXStmt function to transform a specific kind of
337 /// statement or the TransformExpr() function to transform an expression.
338 /// Subclasses may override this function to transform statements using some
339 /// other mechanism.
340 ///
341 /// \returns the transformed statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000342 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
Mike Stump11289f42009-09-09 15:08:12 +0000343
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000344 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000345 ///
346 /// By default, this routine transforms a statement by delegating to the
347 /// appropriate TransformOMPXXXClause function to transform a specific kind
348 /// of clause. Subclasses may override this function to transform statements
349 /// using some other mechanism.
350 ///
351 /// \returns the transformed OpenMP clause.
352 OMPClause *TransformOMPClause(OMPClause *S);
353
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000354 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000355 ///
356 /// By default, this routine transforms a statement by delegating to the
357 /// appropriate TransformXXXAttr function to transform a specific kind
358 /// of attribute. Subclasses may override this function to transform
359 /// attributed statements using some other mechanism.
360 ///
361 /// \returns the transformed attribute
362 const Attr *TransformAttr(const Attr *S);
363
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000364/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000365///
366/// Subclasses should override the transformation of attributes with a pragma
367/// spelling to transform expressions stored within the attribute.
368///
369/// \returns the transformed attribute.
370#define ATTR(X)
371#define PRAGMA_SPELLING_ATTR(X) \
372 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
373#include "clang/Basic/AttrList.inc"
374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000375 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000377 /// By default, this routine transforms an expression by delegating to the
378 /// appropriate TransformXXXExpr function to build a new expression.
379 /// Subclasses may override this function to transform expressions using some
380 /// other mechanism.
381 ///
382 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000383 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000385 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000386 ///
387 /// By default, this routine transforms an initializer by stripping off the
388 /// semantic nodes added by initialization, then passing the result to
389 /// TransformExpr or TransformExprs.
390 ///
391 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000392 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000393
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000394 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000395 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// This routine transforms a list of expressions by invoking
397 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000398 /// support for variadic templates by expanding any pack expansions (if the
399 /// derived class permits such expansion) along the way. When pack expansions
400 /// are present, the number of outputs may not equal the number of inputs.
401 ///
402 /// \param Inputs The set of expressions to be transformed.
403 ///
404 /// \param NumInputs The number of expressions in \c Inputs.
405 ///
406 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000407 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000408 /// be.
409 ///
410 /// \param Outputs The transformed input expressions will be added to this
411 /// vector.
412 ///
413 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
414 /// due to transformation.
415 ///
416 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000417 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000418 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000419 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000420
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000421 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 /// or expression.
423 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// By default, acts as the identity function on declarations, unless the
425 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000426 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 llvm::DenseMap<Decl *, Decl *>::iterator Known
429 = TransformedLocalDecls.find(D);
430 if (Known != TransformedLocalDecls.end())
431 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000432
433 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000435
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000436 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000437 ///
438 /// By default, this transforms the variable and expression and rebuilds
439 /// the condition.
440 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
441 Expr *Expr,
442 Sema::ConditionKind Kind);
443
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000444 /// Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000445 /// place them on the new declaration.
446 ///
447 /// By default, this operation does nothing. Subclasses may override this
448 /// behavior to transform attributes.
449 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000451 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000452 /// transformer.
453 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000454 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000455 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
456 /// the transformer itself has to transform the declarations. This routine
457 /// can be overridden by a subclass that keeps track of such mappings.
Richard Smithb2997f52019-05-21 20:10:50 +0000458 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) {
459 assert(New.size() == 1 &&
460 "must override transformedLocalDecl if performing pack expansion");
461 TransformedLocalDecls[Old] = New.front();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000462 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000463
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000464 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000465 ///
Mike Stump11289f42009-09-09 15:08:12 +0000466 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
469 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000470 }
Mike Stump11289f42009-09-09 15:08:12 +0000471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000472 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000473 /// nested-name-specifier in a member access expression.
474 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000475 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000476 /// identifier in a nested-name-specifier of a member access expression, e.g.,
477 /// the \c T in \c x->T::member
478 ///
479 /// By default, invokes TransformDecl() to transform the declaration.
480 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
482 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000483 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000484
Richard Smith151c4562016-12-20 21:35:28 +0000485 /// Transform the set of declarations in an OverloadExpr.
486 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
487 LookupResult &R);
488
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000489 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000490 /// information.
491 ///
492 /// By default, transforms all of the types and declarations within the
493 /// nested-name-specifier. Subclasses may override this function to provide
494 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000495 NestedNameSpecifierLoc
496 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
497 QualType ObjectType = QualType(),
498 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000499
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000500 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000501 ///
502 /// By default, transforms the types of conversion function, constructor,
503 /// and destructor names and then (if needed) rebuilds the declaration name.
504 /// Identifiers and selectors are returned unmodified. Sublcasses may
505 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000506 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000507 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000509 /// Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000510 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000511 /// \param SS The nested-name-specifier that qualifies the template
512 /// name. This nested-name-specifier must already have been transformed.
513 ///
514 /// \param Name The template name to transform.
515 ///
516 /// \param NameLoc The source location of the template name.
517 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000518 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000519 /// access expression, this is the type of the object whose member template
520 /// is being referenced.
521 ///
522 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
523 /// also refers to a name within the current (lexical) scope, this is the
524 /// declaration it refers to.
525 ///
526 /// By default, transforms the template name by transforming the declarations
527 /// and nested-name-specifiers that occur within the template name.
528 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000529 TemplateName
530 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
531 SourceLocation NameLoc,
532 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000533 NamedDecl *FirstQualifierInScope = nullptr,
534 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000535
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000536 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537 ///
Mike Stump11289f42009-09-09 15:08:12 +0000538 /// By default, this operation transforms the type, expression, or
539 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000540 /// new template argument from the transformed result. Subclasses may
541 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000542 ///
543 /// Returns true if there was an error.
544 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000545 TemplateArgumentLoc &Output,
546 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000547
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000548 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000549 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000550 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000551 /// in the input set using \c TransformTemplateArgument(), and appends
552 /// the transformed arguments to the output list.
553 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000554 /// Note that this overload of \c TransformTemplateArguments() is merely
555 /// a convenience function. Subclasses that wish to override this behavior
556 /// should override the iterator-based member template version.
557 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000558 /// \param Inputs The set of template arguments to be transformed.
559 ///
560 /// \param NumInputs The number of template arguments in \p Inputs.
561 ///
562 /// \param Outputs The set of transformed template arguments output by this
563 /// routine.
564 ///
565 /// Returns true if an error occurred.
566 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
567 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000568 TemplateArgumentListInfo &Outputs,
569 bool Uneval = false) {
570 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
571 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000572 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000573
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000574 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000575 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000576 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000577 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000578 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000579 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000580 /// \param First An iterator to the first template argument.
581 ///
582 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000583 ///
584 /// \param Outputs The set of transformed template arguments output by this
585 /// routine.
586 ///
587 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000588 template<typename InputIterator>
589 bool TransformTemplateArguments(InputIterator First,
590 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000591 TemplateArgumentListInfo &Outputs,
592 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000593
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000594 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000595 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
596 TemplateArgumentLoc &ArgLoc);
597
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000598 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000599 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
600 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000601 getDerived().getBaseLocation());
602 }
Mike Stump11289f42009-09-09 15:08:12 +0000603
John McCall550e0c22009-10-21 00:40:46 +0000604#define ABSTRACT_TYPELOC(CLASS, PARENT)
605#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000606 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000607#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000608
Richard Smith2e321552014-11-12 02:00:47 +0000609 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000610 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
611 FunctionProtoTypeLoc TL,
612 CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +0000613 Qualifiers ThisTypeQuals,
Richard Smith2e321552014-11-12 02:00:47 +0000614 Fn TransformExceptionSpec);
615
616 bool TransformExceptionSpec(SourceLocation Loc,
617 FunctionProtoType::ExceptionSpecInfo &ESI,
618 SmallVectorImpl<QualType> &Exceptions,
619 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000620
David Majnemerfad8f482013-10-15 09:33:02 +0000621 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000622
Chad Rosier1dcde962012-08-08 18:46:20 +0000623 QualType
John McCall31f82722010-11-12 08:19:04 +0000624 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
625 TemplateSpecializationTypeLoc TL,
626 TemplateName Template);
627
Chad Rosier1dcde962012-08-08 18:46:20 +0000628 QualType
John McCall31f82722010-11-12 08:19:04 +0000629 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
630 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000631 TemplateName Template,
632 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000633
Nico Weberc153d242014-07-28 00:02:09 +0000634 QualType TransformDependentTemplateSpecializationType(
635 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
636 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000638 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000639 /// given vectors.
640 ///
641 /// The result vectors should be kept in sync; null entries in the
642 /// variables vector are acceptable.
643 ///
644 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000645 bool TransformFunctionTypeParams(
646 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
647 const QualType *ParamTypes,
648 const FunctionProtoType::ExtParameterInfo *ParamInfos,
649 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
650 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000652 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000653 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000654 ///
655 /// \param indexAdjustment - A number to add to the parameter's
656 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000657 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000658 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000659 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000660 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000661
Richard Smith87346a12019-06-02 18:53:44 +0000662 /// Transform the body of a lambda-expression.
Richard Smith7bf8f6f2019-06-04 17:17:20 +0000663 StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
664 /// Alternative implementation of TransformLambdaBody that skips transforming
665 /// the body.
666 StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
Richard Smith87346a12019-06-02 18:53:44 +0000667
John McCall31f82722010-11-12 08:19:04 +0000668 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000669
John McCalldadc5752010-08-24 06:29:42 +0000670 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
671 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000672
Faisal Vali2cba1332013-10-23 06:44:28 +0000673 TemplateParameterList *TransformTemplateParameterList(
674 TemplateParameterList *TPL) {
675 return TPL;
676 }
677
Richard Smithdb2630f2012-10-21 03:28:35 +0000678 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000679
Richard Smithdb2630f2012-10-21 03:28:35 +0000680 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000681 bool IsAddressOfOperand,
682 TypeSourceInfo **RecoveryTSI);
683
684 ExprResult TransformParenDependentScopeDeclRefExpr(
685 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
686 TypeSourceInfo **RecoveryTSI);
687
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000688 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000689
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000690// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
691// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000692#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000693 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000694 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000695#define VALUESTMT(Node, Parent) \
696 LLVM_ATTRIBUTE_NOINLINE \
697 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000698#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000699 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000700 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000701#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000702#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000703
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000704#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000705 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000706 OMPClause *Transform ## Class(Class *S);
707#include "clang/Basic/OpenMPKinds.def"
708
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000709 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000710 ///
711 /// By default, this routine adds type qualifiers only to types that can
712 /// have qualifiers, and silently suppresses those qualifiers that are not
713 /// permitted. Subclasses may override this routine to provide different
714 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000715 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000716
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000717 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ///
719 /// By default, performs semantic analysis when building the pointer type.
720 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000721 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000723 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 ///
Mike Stump11289f42009-09-09 15:08:12 +0000725 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000726 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000727 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000729 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 ///
John McCall70dd5f62009-10-30 00:06:24 +0000731 /// By default, performs semantic analysis when building the
732 /// reference type. Subclasses may override this routine to provide
733 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ///
John McCall70dd5f62009-10-30 00:06:24 +0000735 /// \param LValue whether the type was written with an lvalue sigil
736 /// or an rvalue sigil.
737 QualType RebuildReferenceType(QualType ReferentType,
738 bool LValue,
739 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000741 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// class type it refers into.
743 ///
744 /// By default, performs semantic analysis when building the member pointer
745 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000746 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
747 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000748
Manman Rene6be26c2016-09-13 17:25:08 +0000749 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
750 SourceLocation ProtocolLAngleLoc,
751 ArrayRef<ObjCProtocolDecl *> Protocols,
752 ArrayRef<SourceLocation> ProtocolLocs,
753 SourceLocation ProtocolRAngleLoc);
754
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000755 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000756 ///
757 /// By default, performs semantic analysis when building the object type.
758 /// Subclasses may override this routine to provide different behavior.
759 QualType RebuildObjCObjectType(QualType BaseType,
760 SourceLocation Loc,
761 SourceLocation TypeArgsLAngleLoc,
762 ArrayRef<TypeSourceInfo *> TypeArgs,
763 SourceLocation TypeArgsRAngleLoc,
764 SourceLocation ProtocolLAngleLoc,
765 ArrayRef<ObjCProtocolDecl *> Protocols,
766 ArrayRef<SourceLocation> ProtocolLocs,
767 SourceLocation ProtocolRAngleLoc);
768
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000769 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000770 ///
771 /// By default, directly builds the pointer type, with no additional semantic
772 /// analysis.
773 QualType RebuildObjCObjectPointerType(QualType PointeeType,
774 SourceLocation Star);
775
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000776 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 /// modifier, size of the array (if known), size expression, and index type
778 /// qualifiers.
779 ///
780 /// By default, performs semantic analysis when building the array type.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 QualType RebuildArrayType(QualType ElementType,
784 ArrayType::ArraySizeModifier SizeMod,
785 const llvm::APInt *Size,
786 Expr *SizeExpr,
787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000789
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000790 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// modifier, (known) size of the array, 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 RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 ArrayType::ArraySizeModifier SizeMod,
797 const llvm::APInt &Size,
Richard Smith772e2662019-10-04 01:25:59 +0000798 Expr *SizeExpr,
John McCall70dd5f62009-10-30 00:06:24 +0000799 unsigned IndexTypeQuals,
800 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000802 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// modifier, and index type qualifiers.
804 ///
805 /// By default, performs semantic analysis when building the array type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000809 unsigned IndexTypeQuals,
810 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000812 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 /// size modifier, size expression, and index type qualifiers.
814 ///
815 /// By default, performs semantic analysis when building the array type.
816 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000817 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000818 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000819 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 unsigned IndexTypeQuals,
821 SourceRange BracketsRange);
822
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000823 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000824 /// size modifier, size expression, and index type qualifiers.
825 ///
826 /// By default, performs semantic analysis when building the array type.
827 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000828 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000829 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000830 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 unsigned IndexTypeQuals,
832 SourceRange BracketsRange);
833
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000834 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000835 /// number of elements.
836 ///
837 /// By default, performs semantic analysis when building the vector type.
838 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000839 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000840 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000841
Erich Keanef702b022018-07-13 19:46:04 +0000842 /// Build a new potentially dependently-sized extended vector type
843 /// given the element type and number of elements.
844 ///
845 /// By default, performs semantic analysis when building the vector type.
846 /// Subclasses may override this routine to provide different behavior.
847 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
848 SourceLocation AttributeLoc,
849 VectorType::VectorKind);
850
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000851 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000852 /// number of elements.
853 ///
854 /// By default, performs semantic analysis when building the vector type.
855 /// Subclasses may override this routine to provide different behavior.
856 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
857 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000858
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000859 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000860 /// given the element type and number of elements.
861 ///
862 /// By default, performs semantic analysis when building the vector type.
863 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000864 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000865 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000866 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000868 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000869 /// type variable with the correct address space (retrieved from
870 /// AddrSpaceExpr) applied to it. The former will be returned in cases
871 /// where the address space remains dependent.
872 ///
873 /// By default, performs semantic analysis when building the type with address
874 /// space applied. Subclasses may override this routine to provide different
875 /// behavior.
876 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
877 Expr *AddrSpaceExpr,
878 SourceLocation AttributeLoc);
879
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000880 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000881 ///
882 /// By default, performs semantic analysis when building the function type.
883 /// Subclasses may override this routine to provide different behavior.
884 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000885 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000886 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000887
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000888 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000889 QualType RebuildFunctionNoProtoType(QualType ResultType);
890
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000891 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000892 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000893 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000894
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000895 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000896 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000897 return SemaRef.Context.getTypeDeclType(Typedef);
898 }
899
Leonard Chanc72aaf62019-05-07 03:20:17 +0000900 /// Build a new MacroDefined type.
901 QualType RebuildMacroQualifiedType(QualType T,
902 const IdentifierInfo *MacroII) {
903 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
904 }
905
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000906 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000907 QualType RebuildRecordType(RecordDecl *Record) {
908 return SemaRef.Context.getTypeDeclType(Record);
909 }
910
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000911 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000912 QualType RebuildEnumType(EnumDecl *Enum) {
913 return SemaRef.Context.getTypeDeclType(Enum);
914 }
John McCallfcc33b02009-09-05 00:15:47 +0000915
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000916 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000917 ///
918 /// By default, performs semantic analysis when building the typeof type.
919 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000920 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000921
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000922 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000923 ///
924 /// By default, builds a new TypeOfType with the given underlying type.
925 QualType RebuildTypeOfType(QualType Underlying);
926
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000927 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000928 QualType RebuildUnaryTransformType(QualType BaseType,
929 UnaryTransformType::UTTKind UKind,
930 SourceLocation Loc);
931
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000932 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 ///
934 /// By default, performs semantic analysis when building the decltype type.
935 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000936 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000937
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000938 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000939 ///
940 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000941 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000942 // Note, IsDependent is always false here: we implicitly convert an 'auto'
943 // which has been deduced to a dependent type into an undeduced 'auto', so
944 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000945 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000946 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000947 }
948
Richard Smith600b5262017-01-26 20:40:47 +0000949 /// By default, builds a new DeducedTemplateSpecializationType with the given
950 /// deduced type.
951 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
952 QualType Deduced) {
953 return SemaRef.Context.getDeducedTemplateSpecializationType(
954 Template, Deduced, /*IsDependent*/ false);
955 }
956
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000957 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000958 ///
959 /// By default, performs semantic analysis when building the template
960 /// specialization type. Subclasses may override this routine to provide
961 /// different behavior.
962 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000963 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000964 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000965
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000966 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000967 ///
968 /// By default, builds a new ParenType type from the inner type.
969 /// Subclasses may override this routine to provide different behavior.
970 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000971 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000972 }
973
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000974 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000975 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000976 /// By default, builds a new ElaboratedType type from the keyword,
977 /// the nested-name-specifier and the named type.
978 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000979 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
980 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000981 NestedNameSpecifierLoc QualifierLoc,
982 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000983 return SemaRef.Context.getElaboratedType(Keyword,
984 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000985 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000986 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000987
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000988 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000989 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000990 /// By default, builds a new DependentNameType type from the
991 /// nested-name-specifier and the given type. Subclasses may override
992 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000993 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000994 ElaboratedTypeKeyword Keyword,
995 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000996 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000997 const IdentifierInfo *Name,
998 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000999 TemplateArgumentListInfo &Args,
1000 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00001001 // Rebuild the template name.
1002 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +00001003 CXXScopeSpec SS;
1004 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +00001005 TemplateName InstName = getDerived().RebuildTemplateName(
1006 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1007 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +00001008
Douglas Gregora7a795b2011-03-01 20:11:18 +00001009 if (InstName.isNull())
1010 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001011
Douglas Gregora7a795b2011-03-01 20:11:18 +00001012 // If it's still dependent, make a dependent specialization.
1013 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +00001014 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1015 QualifierLoc.getNestedNameSpecifier(),
1016 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +00001017 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +00001018
Douglas Gregora7a795b2011-03-01 20:11:18 +00001019 // Otherwise, make an elaborated type wrapping a non-dependent
1020 // specialization.
1021 QualType T =
1022 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1023 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001024
Craig Topperc3ec1492014-05-26 06:22:03 +00001025 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001026 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001027
1028 return SemaRef.Context.getElaboratedType(Keyword,
1029 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001030 T);
1031 }
1032
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001033 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001034 ///
1035 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001036 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001037 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001038 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001039 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001040 NestedNameSpecifierLoc QualifierLoc,
1041 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001042 SourceLocation IdLoc,
1043 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001044 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001045 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001046
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001047 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001048 // If the name is still dependent, just build a new dependent name type.
1049 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001050 return SemaRef.Context.getDependentNameType(Keyword,
1051 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001052 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001053 }
1054
Richard Smithee579842017-01-30 20:39:26 +00001055 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1056 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1057 *Id, IdLoc);
1058 // If a dependent name resolves to a deduced template specialization type,
1059 // check that we're in one of the syntactic contexts permitting it.
1060 if (!DeducedTSTContext) {
1061 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1062 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1063 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1064 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1065 Deduced->getTemplateName())
1066 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1067 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1068 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1069 return QualType();
1070 }
1071 }
1072 return T;
1073 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001074
1075 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1076
Abramo Bagnarad7548482010-05-19 21:37:53 +00001077 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001078 // into a non-dependent elaborated-type-specifier. Find the tag we're
1079 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001080 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001081 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1082 if (!DC)
1083 return QualType();
1084
John McCallbf8c5192010-05-27 06:40:31 +00001085 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1086 return QualType();
1087
Craig Topperc3ec1492014-05-26 06:22:03 +00001088 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001089 SemaRef.LookupQualifiedName(Result, DC);
1090 switch (Result.getResultKind()) {
1091 case LookupResult::NotFound:
1092 case LookupResult::NotFoundInCurrentInstantiation:
1093 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001094
Douglas Gregore677daf2010-03-31 22:19:08 +00001095 case LookupResult::Found:
1096 Tag = Result.getAsSingle<TagDecl>();
1097 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001098
Douglas Gregore677daf2010-03-31 22:19:08 +00001099 case LookupResult::FoundOverloaded:
1100 case LookupResult::FoundUnresolvedValue:
1101 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001102
Douglas Gregore677daf2010-03-31 22:19:08 +00001103 case LookupResult::Ambiguous:
1104 // Let the LookupResult structure handle ambiguities.
1105 return QualType();
1106 }
1107
1108 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001109 // Check where the name exists but isn't a tag type and use that to emit
1110 // better diagnostics.
1111 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1112 SemaRef.LookupQualifiedName(Result, DC);
1113 switch (Result.getResultKind()) {
1114 case LookupResult::Found:
1115 case LookupResult::FoundOverloaded:
1116 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001117 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001118 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1119 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1120 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001121 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1122 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001123 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001124 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001125 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001126 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001127 break;
1128 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001129 return QualType();
1130 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001131
Richard Trieucaa33d32011-06-10 03:11:26 +00001132 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001133 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001134 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001135 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1136 return QualType();
1137 }
1138
1139 // Build the elaborated-type-specifier type.
1140 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001141 return SemaRef.Context.getElaboratedType(Keyword,
1142 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001143 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001146 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001147 ///
1148 /// By default, builds a new PackExpansionType type from the given pattern.
1149 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001150 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001151 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001152 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001153 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001154 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1155 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001156 }
1157
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001158 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001159 ///
1160 /// By default, performs semantic analysis when building the atomic type.
1161 /// Subclasses may override this routine to provide different behavior.
1162 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001164 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001165 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1166 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001167
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001168 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001169 /// indicating whether the "template" keyword was provided, and the template
1170 /// that the template name refers to.
1171 ///
1172 /// By default, builds the new template name directly. Subclasses may override
1173 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001174 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001175 bool TemplateKW,
1176 TemplateDecl *Template);
1177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001178 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001179 /// name that is referred to as a template.
1180 ///
1181 /// By default, performs semantic analysis to determine whether the name can
1182 /// be resolved to a specific template, then builds the appropriate kind of
1183 /// template name. Subclasses may override this routine to provide different
1184 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001185 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001186 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001187 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001188 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001189 NamedDecl *FirstQualifierInScope,
1190 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001191
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001192 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001193 /// overloaded operator name that is referred to as a template.
1194 ///
1195 /// By default, performs semantic analysis to determine whether the name can
1196 /// be resolved to a specific template, then builds the appropriate kind of
1197 /// template name. Subclasses may override this routine to provide different
1198 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001199 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001200 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001201 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001202 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001203 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001204
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001205 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001206 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001207 ///
1208 /// By default, performs semantic analysis to determine whether the name can
1209 /// be resolved to a specific template, then builds the appropriate kind of
1210 /// template name. Subclasses may override this routine to provide different
1211 /// behavior.
1212 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1213 const TemplateArgument &ArgPack) {
1214 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1215 }
1216
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001217 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001221 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 MultiStmtArg Statements,
1223 SourceLocation RBraceLoc,
1224 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001225 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 IsStmtExpr);
1227 }
1228
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001229 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001234 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001236 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001237 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001238 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001239 ColonLoc);
1240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001242 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001246 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001247 getSema().ActOnCaseStmtBody(S, Body);
1248 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001251 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 ///
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 RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001257 Stmt *SubStmt) {
1258 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001259 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001260 }
Mike Stump11289f42009-09-09 15:08:12 +00001261
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001262 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001266 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1267 SourceLocation ColonLoc, Stmt *SubStmt) {
1268 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001269 }
Mike Stump11289f42009-09-09 15:08:12 +00001270
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001271 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001275 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1276 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001277 Stmt *SubStmt) {
1278 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1279 }
1280
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001281 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001285 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001286 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001287 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001288 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001289 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001290 }
Mike Stump11289f42009-09-09 15:08:12 +00001291
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001292 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 ///
1294 /// By default, performs semantic analysis to build the new statement.
1295 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001296 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001297 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001298 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001299 }
Mike Stump11289f42009-09-09 15:08:12 +00001300
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001301 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001302 ///
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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001306 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001307 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001308 }
1309
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001310 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001314 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1315 Sema::ConditionResult Cond, Stmt *Body) {
1316 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001319 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001320 ///
1321 /// By default, performs semantic analysis to build the new statement.
1322 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001323 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001324 SourceLocation WhileLoc, SourceLocation LParenLoc,
1325 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001326 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1327 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001328 }
1329
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001330 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001334 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001335 Stmt *Init, Sema::ConditionResult Cond,
1336 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1337 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001338 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001339 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001342 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001346 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1347 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001348 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001349 }
1350
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001351 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001352 ///
1353 /// By default, performs semantic analysis to build the new statement.
1354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001355 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001356 SourceLocation StarLoc,
1357 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001358 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001359 }
Mike Stump11289f42009-09-09 15:08:12 +00001360
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001361 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001362 ///
1363 /// By default, performs semantic analysis to build the new statement.
1364 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001365 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001366 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001367 }
Mike Stump11289f42009-09-09 15:08:12 +00001368
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001369 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001370 ///
1371 /// By default, performs semantic analysis to build the new statement.
1372 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001373 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001374 SourceLocation StartLoc, SourceLocation EndLoc) {
1375 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001376 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001377 }
Mike Stump11289f42009-09-09 15:08:12 +00001378
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001379 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001383 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1384 bool IsVolatile, unsigned NumOutputs,
1385 unsigned NumInputs, IdentifierInfo **Names,
1386 MultiExprArg Constraints, MultiExprArg Exprs,
1387 Expr *AsmString, MultiExprArg Clobbers,
Jennifer Yub8fee672019-06-03 15:57:25 +00001388 unsigned NumLabels,
Chad Rosierde70e0e2012-08-25 00:11:56 +00001389 SourceLocation RParenLoc) {
1390 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1391 NumInputs, Names, Constraints, Exprs,
Jennifer Yub8fee672019-06-03 15:57:25 +00001392 AsmString, Clobbers, NumLabels, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001393 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001394
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001395 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001396 ///
1397 /// By default, performs semantic analysis to build the new statement.
1398 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001399 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001400 ArrayRef<Token> AsmToks,
1401 StringRef AsmString,
1402 unsigned NumOutputs, unsigned NumInputs,
1403 ArrayRef<StringRef> Constraints,
1404 ArrayRef<StringRef> Clobbers,
1405 ArrayRef<Expr*> Exprs,
1406 SourceLocation EndLoc) {
1407 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1408 NumOutputs, NumInputs,
1409 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001410 }
1411
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001412 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001413 ///
1414 /// By default, performs semantic analysis to build the new statement.
1415 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001416 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1417 bool IsImplicit) {
1418 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001419 }
1420
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001421 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001422 ///
1423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001425 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1426 bool IsImplicit) {
1427 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1428 }
1429
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001430 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1435 Expr *Result,
1436 UnresolvedLookupExpr *Lookup) {
1437 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001438 }
1439
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001440 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001441 ///
1442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
1444 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1445 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1446 }
1447
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001448 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1449 return getSema().BuildCoroutineBodyStmt(Args);
1450 }
1451
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001452 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001453 ///
1454 /// By default, performs semantic analysis to build the new statement.
1455 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001456 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001457 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001458 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001459 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001460 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001461 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001462 }
1463
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001464 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001465 ///
1466 /// By default, performs semantic analysis to build the new declaration.
1467 /// Subclasses may override this routine to provide different behavior.
1468 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1469 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001470 return getSema().BuildObjCExceptionDecl(TInfo, T,
1471 ExceptionDecl->getInnerLocStart(),
1472 ExceptionDecl->getLocation(),
1473 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001475
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001476 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001480 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001481 SourceLocation RParenLoc,
1482 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001483 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001484 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001485 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001486 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001487
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001488 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001489 ///
1490 /// By default, performs semantic analysis to build the new statement.
1491 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001492 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001493 Stmt *Body) {
1494 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001495 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001496
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001497 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001498 ///
1499 /// By default, performs semantic analysis to build the new statement.
1500 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001501 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001502 Expr *Operand) {
1503 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001505
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001506 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001507 ///
1508 /// By default, performs semantic analysis to build the new statement.
1509 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001510 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001511 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001512 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001513 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001514 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001515 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001516 return getSema().ActOnOpenMPExecutableDirective(
1517 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001518 }
1519
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001520 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001521 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001522 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001523 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001524 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1525 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001526 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001527 SourceLocation NameModifierLoc,
1528 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001529 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001530 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1531 LParenLoc, NameModifierLoc, ColonLoc,
1532 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001533 }
1534
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001535 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001536 ///
1537 /// By default, performs semantic analysis to build the new OpenMP clause.
1538 /// Subclasses may override this routine to provide different behavior.
1539 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1540 SourceLocation LParenLoc,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1543 EndLoc);
1544 }
1545
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001546 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001547 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001548 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001549 /// Subclasses may override this routine to provide different behavior.
1550 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1551 SourceLocation StartLoc,
1552 SourceLocation LParenLoc,
1553 SourceLocation EndLoc) {
1554 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1555 LParenLoc, EndLoc);
1556 }
1557
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001558 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1563 SourceLocation LParenLoc,
1564 SourceLocation EndLoc) {
1565 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1566 }
1567
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001568 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001569 ///
1570 /// By default, performs semantic analysis to build the new OpenMP clause.
1571 /// Subclasses may override this routine to provide different behavior.
1572 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1573 SourceLocation LParenLoc,
1574 SourceLocation EndLoc) {
1575 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1576 }
1577
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001578 /// Build a new OpenMP 'allocator' clause.
1579 ///
1580 /// By default, performs semantic analysis to build the new OpenMP clause.
1581 /// Subclasses may override this routine to provide different behavior.
1582 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
1583 SourceLocation LParenLoc,
1584 SourceLocation EndLoc) {
1585 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1586 }
1587
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001588 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001589 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001590 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001591 /// Subclasses may override this routine to provide different behavior.
1592 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1593 SourceLocation LParenLoc,
1594 SourceLocation EndLoc) {
1595 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1596 EndLoc);
1597 }
1598
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001599 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001600 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001601 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001602 /// Subclasses may override this routine to provide different behavior.
1603 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1604 SourceLocation KindKwLoc,
1605 SourceLocation StartLoc,
1606 SourceLocation LParenLoc,
1607 SourceLocation EndLoc) {
1608 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1609 StartLoc, LParenLoc, EndLoc);
1610 }
1611
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001612 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001613 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001614 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001615 /// Subclasses may override this routine to provide different behavior.
1616 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1617 SourceLocation KindKwLoc,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1622 StartLoc, LParenLoc, EndLoc);
1623 }
1624
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001625 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001626 ///
1627 /// By default, performs semantic analysis to build the new OpenMP clause.
1628 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001629 OMPClause *RebuildOMPScheduleClause(
1630 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1631 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1632 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1633 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001634 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001635 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1636 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001637 }
1638
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001639 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001640 ///
1641 /// By default, performs semantic analysis to build the new OpenMP clause.
1642 /// Subclasses may override this routine to provide different behavior.
1643 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1644 SourceLocation EndLoc,
1645 SourceLocation LParenLoc, Expr *Num) {
1646 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1647 }
1648
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001649 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001650 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001651 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001652 /// Subclasses may override this routine to provide different behavior.
1653 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1654 SourceLocation StartLoc,
1655 SourceLocation LParenLoc,
1656 SourceLocation EndLoc) {
1657 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1658 EndLoc);
1659 }
1660
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001661 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001662 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001663 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001664 /// Subclasses may override this routine to provide different behavior.
1665 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1666 SourceLocation StartLoc,
1667 SourceLocation LParenLoc,
1668 SourceLocation EndLoc) {
1669 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1670 EndLoc);
1671 }
1672
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001673 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001674 ///
1675 /// By default, performs semantic analysis to build the new OpenMP clause.
1676 /// Subclasses may override this routine to provide different behavior.
1677 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1678 SourceLocation StartLoc,
1679 SourceLocation LParenLoc,
1680 SourceLocation EndLoc) {
1681 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1682 EndLoc);
1683 }
1684
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001685 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001686 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001687 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001688 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001689 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1690 SourceLocation StartLoc,
1691 SourceLocation LParenLoc,
1692 SourceLocation EndLoc) {
1693 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1694 EndLoc);
1695 }
1696
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001697 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001698 ///
1699 /// By default, performs semantic analysis to build the new statement.
1700 /// Subclasses may override this routine to provide different behavior.
1701 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1702 SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
1704 SourceLocation ColonLoc,
1705 SourceLocation EndLoc,
1706 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001707 const DeclarationNameInfo &ReductionId,
1708 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001709 return getSema().ActOnOpenMPReductionClause(
1710 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001711 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001712 }
1713
Alexey Bataev169d96a2017-07-18 20:17:46 +00001714 /// Build a new OpenMP 'task_reduction' clause.
1715 ///
1716 /// By default, performs semantic analysis to build the new statement.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OMPClause *RebuildOMPTaskReductionClause(
1719 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1720 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1721 CXXScopeSpec &ReductionIdScopeSpec,
1722 const DeclarationNameInfo &ReductionId,
1723 ArrayRef<Expr *> UnresolvedReductions) {
1724 return getSema().ActOnOpenMPTaskReductionClause(
1725 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1726 ReductionId, UnresolvedReductions);
1727 }
1728
Alexey Bataevfa312f32017-07-21 18:48:21 +00001729 /// Build a new OpenMP 'in_reduction' clause.
1730 ///
1731 /// By default, performs semantic analysis to build the new statement.
1732 /// Subclasses may override this routine to provide different behavior.
1733 OMPClause *
1734 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1735 SourceLocation LParenLoc, SourceLocation ColonLoc,
1736 SourceLocation EndLoc,
1737 CXXScopeSpec &ReductionIdScopeSpec,
1738 const DeclarationNameInfo &ReductionId,
1739 ArrayRef<Expr *> UnresolvedReductions) {
1740 return getSema().ActOnOpenMPInReductionClause(
1741 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1742 ReductionId, UnresolvedReductions);
1743 }
1744
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001745 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001746 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001747 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001748 /// Subclasses may override this routine to provide different behavior.
1749 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1750 SourceLocation StartLoc,
1751 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001752 OpenMPLinearClauseKind Modifier,
1753 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001754 SourceLocation ColonLoc,
1755 SourceLocation EndLoc) {
1756 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001757 Modifier, ModifierLoc, ColonLoc,
1758 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001759 }
1760
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001761 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001762 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001763 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001764 /// Subclasses may override this routine to provide different behavior.
1765 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1766 SourceLocation StartLoc,
1767 SourceLocation LParenLoc,
1768 SourceLocation ColonLoc,
1769 SourceLocation EndLoc) {
1770 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1771 LParenLoc, ColonLoc, EndLoc);
1772 }
1773
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001774 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001775 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001776 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001777 /// Subclasses may override this routine to provide different behavior.
1778 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1779 SourceLocation StartLoc,
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1783 EndLoc);
1784 }
1785
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001786 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1790 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1791 SourceLocation StartLoc,
1792 SourceLocation LParenLoc,
1793 SourceLocation EndLoc) {
1794 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1795 EndLoc);
1796 }
1797
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001798 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001799 ///
1800 /// By default, performs semantic analysis to build the new OpenMP clause.
1801 /// Subclasses may override this routine to provide different behavior.
1802 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1803 SourceLocation StartLoc,
1804 SourceLocation LParenLoc,
1805 SourceLocation EndLoc) {
1806 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1807 EndLoc);
1808 }
1809
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001810 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001811 ///
1812 /// By default, performs semantic analysis to build the new OpenMP clause.
1813 /// Subclasses may override this routine to provide different behavior.
1814 OMPClause *
1815 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1816 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1817 SourceLocation StartLoc, SourceLocation LParenLoc,
1818 SourceLocation EndLoc) {
1819 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1820 StartLoc, LParenLoc, EndLoc);
1821 }
1822
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001823 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001824 ///
1825 /// By default, performs semantic analysis to build the new statement.
1826 /// Subclasses may override this routine to provide different behavior.
1827 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001830 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001831 EndLoc);
1832 }
1833
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001834 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001835 ///
1836 /// By default, performs semantic analysis to build the new OpenMP clause.
1837 /// Subclasses may override this routine to provide different behavior.
Michael Kruse4304e9d2019-02-19 16:38:20 +00001838 OMPClause *RebuildOMPMapClause(
1839 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1840 ArrayRef<SourceLocation> MapTypeModifiersLoc,
1841 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1842 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1843 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1844 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
Kelvin Lief579432018-12-18 22:18:41 +00001845 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001846 MapperIdScopeSpec, MapperId, MapType,
1847 IsMapTypeImplicit, MapLoc, ColonLoc,
1848 VarList, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001849 }
1850
Alexey Bataeve04483e2019-03-27 14:14:31 +00001851 /// Build a new OpenMP 'allocate' clause.
1852 ///
1853 /// By default, performs semantic analysis to build the new OpenMP clause.
1854 /// Subclasses may override this routine to provide different behavior.
1855 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
1856 SourceLocation StartLoc,
1857 SourceLocation LParenLoc,
1858 SourceLocation ColonLoc,
1859 SourceLocation EndLoc) {
1860 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1861 LParenLoc, ColonLoc, EndLoc);
1862 }
1863
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001864 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001865 ///
1866 /// By default, performs semantic analysis to build the new statement.
1867 /// Subclasses may override this routine to provide different behavior.
1868 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1869 SourceLocation LParenLoc,
1870 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001871 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001872 EndLoc);
1873 }
1874
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001875 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001876 ///
1877 /// By default, performs semantic analysis to build the new statement.
1878 /// Subclasses may override this routine to provide different behavior.
1879 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1880 SourceLocation StartLoc,
1881 SourceLocation LParenLoc,
1882 SourceLocation EndLoc) {
1883 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1884 LParenLoc, EndLoc);
1885 }
1886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001887 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001888 ///
1889 /// By default, performs semantic analysis to build the new statement.
1890 /// Subclasses may override this routine to provide different behavior.
1891 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1892 SourceLocation LParenLoc,
1893 SourceLocation EndLoc) {
1894 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1895 EndLoc);
1896 }
1897
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001898 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001899 ///
1900 /// By default, performs semantic analysis to build the new statement.
1901 /// Subclasses may override this routine to provide different behavior.
1902 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1906 EndLoc);
1907 }
1908
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001909 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001910 ///
1911 /// By default, performs semantic analysis to build the new statement.
1912 /// Subclasses may override this routine to provide different behavior.
1913 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1914 SourceLocation LParenLoc,
1915 SourceLocation EndLoc) {
1916 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1917 EndLoc);
1918 }
1919
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001920 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001921 ///
1922 /// By default, performs semantic analysis to build the new statement.
1923 /// Subclasses may override this routine to provide different behavior.
1924 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1925 SourceLocation LParenLoc,
1926 SourceLocation EndLoc) {
1927 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1928 }
1929
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001930 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001931 ///
1932 /// By default, performs semantic analysis to build the new OpenMP clause.
1933 /// Subclasses may override this routine to provide different behavior.
1934 OMPClause *
1935 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1936 Expr *ChunkSize, SourceLocation StartLoc,
1937 SourceLocation LParenLoc, SourceLocation KindLoc,
1938 SourceLocation CommaLoc, SourceLocation EndLoc) {
1939 return getSema().ActOnOpenMPDistScheduleClause(
1940 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1941 }
1942
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001943 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001944 ///
1945 /// By default, performs semantic analysis to build the new statement.
1946 /// Subclasses may override this routine to provide different behavior.
1947 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
Michael Kruse01f670d2019-02-22 22:29:42 +00001948 CXXScopeSpec &MapperIdScopeSpec,
1949 DeclarationNameInfo &MapperId,
1950 const OMPVarListLocTy &Locs,
1951 ArrayRef<Expr *> UnresolvedMappers) {
1952 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1953 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00001954 }
1955
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001956 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001957 ///
1958 /// By default, performs semantic analysis to build the new statement.
1959 /// Subclasses may override this routine to provide different behavior.
1960 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
Michael Kruse0336c752019-02-25 20:34:15 +00001961 CXXScopeSpec &MapperIdScopeSpec,
1962 DeclarationNameInfo &MapperId,
1963 const OMPVarListLocTy &Locs,
1964 ArrayRef<Expr *> UnresolvedMappers) {
1965 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1966 Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00001967 }
1968
Carlo Bertolli2404b172016-07-13 15:37:16 +00001969 /// Build a new OpenMP 'use_device_ptr' clause.
1970 ///
1971 /// By default, performs semantic analysis to build the new OpenMP clause.
1972 /// Subclasses may override this routine to provide different behavior.
1973 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001974 const OMPVarListLocTy &Locs) {
1975 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001976 }
1977
Carlo Bertolli70594e92016-07-13 17:16:49 +00001978 /// Build a new OpenMP 'is_device_ptr' clause.
1979 ///
1980 /// By default, performs semantic analysis to build the new OpenMP clause.
1981 /// Subclasses may override this routine to provide different behavior.
1982 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001983 const OMPVarListLocTy &Locs) {
1984 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001985 }
1986
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001987 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001988 ///
1989 /// By default, performs semantic analysis to build the new statement.
1990 /// Subclasses may override this routine to provide different behavior.
1991 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1992 Expr *object) {
1993 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1994 }
1995
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001996 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001997 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001998 /// By default, performs semantic analysis to build the new statement.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00002001 Expr *Object, Stmt *Body) {
2002 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00002003 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00002004
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002005 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00002006 ///
2007 /// By default, performs semantic analysis to build the new statement.
2008 /// Subclasses may override this routine to provide different behavior.
2009 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
2010 Stmt *Body) {
2011 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2012 }
John McCall53848232011-07-27 01:07:15 +00002013
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002014 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00002015 ///
2016 /// By default, performs semantic analysis to build the new statement.
2017 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002018 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002019 Stmt *Element,
2020 Expr *Collection,
2021 SourceLocation RParenLoc,
2022 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00002023 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002024 Element,
John McCallb268a282010-08-23 23:25:46 +00002025 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002026 RParenLoc);
2027 if (ForEachStmt.isInvalid())
2028 return StmtError();
2029
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002030 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00002031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002032
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002033 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00002034 ///
2035 /// By default, performs semantic analysis to build the new decaration.
2036 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00002037 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00002038 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00002039 SourceLocation StartLoc,
2040 SourceLocation IdLoc,
2041 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002042 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002043 StartLoc, IdLoc, Id);
2044 if (Var)
2045 getSema().CurContext->addDecl(Var);
2046 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002047 }
2048
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002049 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002050 ///
2051 /// By default, performs semantic analysis to build the new statement.
2052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002053 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002054 VarDecl *ExceptionDecl,
2055 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002056 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2057 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002060 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002061 ///
2062 /// By default, performs semantic analysis to build the new statement.
2063 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002064 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2065 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002066 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002067 }
Mike Stump11289f42009-09-09 15:08:12 +00002068
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002069 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002070 ///
2071 /// By default, performs semantic analysis to build the new statement.
2072 /// Subclasses may override this routine to provide different behavior.
2073 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002074 SourceLocation CoawaitLoc, Stmt *Init,
2075 SourceLocation ColonLoc, Stmt *Range,
2076 Stmt *Begin, Stmt *End, Expr *Cond,
2077 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002078 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002079 // If we've just learned that the range is actually an Objective-C
2080 // collection, treat this as an Objective-C fast enumeration loop.
2081 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2082 if (RangeStmt->isSingleDecl()) {
2083 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002084 if (RangeVar->isInvalidDecl())
2085 return StmtError();
2086
Douglas Gregorf7106af2013-04-08 18:40:13 +00002087 Expr *RangeExpr = RangeVar->getInit();
2088 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002089 RangeExpr->getType()->isObjCObjectPointerType()) {
2090 // FIXME: Support init-statements in Objective-C++20 ranged for
2091 // statement.
2092 if (Init) {
2093 return SemaRef.Diag(Init->getBeginLoc(),
2094 diag::err_objc_for_range_init_stmt)
2095 << Init->getSourceRange();
2096 }
2097 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2098 RangeExpr, RParenLoc);
2099 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002100 }
2101 }
2102 }
2103
Richard Smith8baa5002018-09-28 18:44:09 +00002104 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2105 Range, Begin, End, Cond, Inc, LoopVar,
2106 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002107 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002108
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002109 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002110 ///
2111 /// By default, performs semantic analysis to build the new statement.
2112 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002113 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002114 bool IsIfExists,
2115 NestedNameSpecifierLoc QualifierLoc,
2116 DeclarationNameInfo NameInfo,
2117 Stmt *Nested) {
2118 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2119 QualifierLoc, NameInfo, Nested);
2120 }
2121
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002122 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002123 ///
2124 /// By default, performs semantic analysis to finish the new statement.
2125 /// Subclasses may override this routine to provide different behavior.
2126 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2127 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002129
David Majnemerfad8f482013-10-15 09:33:02 +00002130 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002131 Stmt *TryBlock, Stmt *Handler) {
2132 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002133 }
2134
David Majnemerfad8f482013-10-15 09:33:02 +00002135 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002136 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002137 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002138 }
2139
David Majnemerfad8f482013-10-15 09:33:02 +00002140 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002141 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002142 }
2143
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002144 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
2148 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002149 PredefinedExpr::IdentKind IK) {
2150 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002151 }
2152
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002153 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 ///
2155 /// By default, performs semantic analysis to build the new expression.
2156 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002157 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002158 LookupResult &R,
2159 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002160 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2161 }
2162
2163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002164 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002168 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002169 ValueDecl *VD,
2170 const DeclarationNameInfo &NameInfo,
Richard Smith57aee092019-08-27 01:06:21 +00002171 NamedDecl *Found,
John McCallfaf5fb42010-08-26 23:41:50 +00002172 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002173 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002174 SS.Adopt(QualifierLoc);
Richard Smith57aee092019-08-27 01:06:21 +00002175 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2176 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002179 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002180 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002185 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
2187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002188 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002189 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002193 SourceLocation OperatorLoc,
2194 bool isArrow,
2195 CXXScopeSpec &SS,
2196 TypeSourceInfo *ScopeType,
2197 SourceLocation CCLoc,
2198 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002199 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002201 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002202 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002206 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002207 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002208 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002211 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002216 TypeSourceInfo *Type,
2217 ArrayRef<Sema::OffsetOfComponent> Components,
2218 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002219 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002220 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002222
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002223 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002224 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002225 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002228 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2229 SourceLocation OpLoc,
2230 UnaryExprOrTypeTrait ExprKind,
2231 SourceRange R) {
2232 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002235 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002236 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002240 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2241 UnaryExprOrTypeTrait ExprKind,
2242 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002244 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002247
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 }
Mike Stump11289f42009-09-09 15:08:12 +00002250
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002251 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002252 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002255 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002259 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002260 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 RBracketLoc);
2262 }
2263
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002264 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2269 Expr *LowerBound,
2270 SourceLocation ColonLoc, Expr *Length,
2271 SourceLocation RBracketLoc) {
2272 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2273 ColonLoc, Length, RBracketLoc);
2274 }
2275
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002276 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002277 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// By default, performs semantic analysis to build the new expression.
2279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002280 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002282 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002283 Expr *ExecConfig = nullptr) {
Richard Smith255b85f2019-05-08 01:36:36 +00002284 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args,
2285 RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 }
2287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002288 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 /// By default, performs semantic analysis to build the new expression.
2291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002293 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002294 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002295 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002296 const DeclarationNameInfo &MemberNameInfo,
2297 ValueDecl *Member,
2298 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002299 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002300 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002301 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2302 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002303 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002304 // We have a reference to an unnamed field. This is always the
2305 // base of an anonymous struct/union member access, i.e. the
2306 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002307 assert(Member->getType()->isRecordType() &&
2308 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002309
Richard Smithcab9a7d2011-10-26 19:06:56 +00002310 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002311 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002312 QualifierLoc.getNestedNameSpecifier(),
2313 FoundDecl, Member);
2314 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002315 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002316 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002317
2318 CXXScopeSpec EmptySS;
2319 return getSema().BuildFieldReferenceExpr(
2320 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2321 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002324 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002325 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002326
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002327 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002328 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002329
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002330 if (isArrow && !BaseType->isPointerType())
2331 return ExprError();
2332
John McCall16df1e52010-03-30 21:47:33 +00002333 // FIXME: this involves duplicating earlier analysis in a lot of
2334 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002335 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002336 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002337 R.resolveKind();
2338
John McCallb268a282010-08-23 23:25:46 +00002339 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002340 SS, TemplateKWLoc,
2341 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002342 R, ExplicitTemplateArgs,
2343 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002346 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002347 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002351 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002353 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 }
2355
Richard Smith778dc0f2019-10-19 00:04:38 +00002356 /// Build a new rewritten operator expression.
2357 ///
Richard Smith974c8b72019-10-19 00:04:43 +00002358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
2360 ExprResult RebuildCXXRewrittenBinaryOperator(
2361 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2362 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2363 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2364 RHS, /*RequiresADL*/false);
Richard Smith778dc0f2019-10-19 00:04:38 +00002365 }
2366
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002367 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002368 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 /// By default, performs semantic analysis to build the new expression.
2370 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002371 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002372 SourceLocation QuestionLoc,
2373 Expr *LHS,
2374 SourceLocation ColonLoc,
2375 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002376 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2377 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 }
2379
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002380 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002381 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002384 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002385 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002387 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002388 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002389 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002392 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002393 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002396 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002397 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002399 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002400 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002401 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 }
Mike Stump11289f42009-09-09 15:08:12 +00002403
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002404 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002405 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 /// By default, performs semantic analysis to build the new expression.
2407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002408 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 SourceLocation OpLoc,
2410 SourceLocation AccessorLoc,
2411 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002412
John McCall10eae182009-11-30 22:42:35 +00002413 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002414 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002415 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002416 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002417 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002418 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002419 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002420 /* TemplateArgs */ nullptr,
2421 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 }
Mike Stump11289f42009-09-09 15:08:12 +00002423
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002424 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002425 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 /// By default, performs semantic analysis to build the new expression.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002429 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002430 SourceLocation RBraceLoc) {
Richard Smith50309282019-08-30 22:52:55 +00002431 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 }
Mike Stump11289f42009-09-09 15:08:12 +00002433
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002434 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 /// By default, performs semantic analysis to build the new expression.
2437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002438 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 MultiExprArg ArrayExprs,
2440 SourceLocation EqualOrColonLoc,
2441 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002442 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002443 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002445 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002446 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002447 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002448
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002449 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002450 }
Mike Stump11289f42009-09-09 15:08:12 +00002451
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002452 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002453 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 /// By default, builds the implicit value initialization without performing
2455 /// any semantic analysis. Subclasses may override this routine to provide
2456 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002458 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 }
Mike Stump11289f42009-09-09 15:08:12 +00002460
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002461 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002462 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 /// By default, performs semantic analysis to build the new expression.
2464 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002465 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002466 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002467 SourceLocation RParenLoc) {
2468 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002469 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002470 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 }
2472
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002473 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 /// 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 RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002478 MultiExprArg SubExprs,
2479 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002480 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 }
Mike Stump11289f42009-09-09 15:08:12 +00002482
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002483 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002484 ///
2485 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 /// rather than attempting to map the label statement itself.
2487 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002488 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002489 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002490 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 }
Mike Stump11289f42009-09-09 15:08:12 +00002492
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002493 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002494 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 /// By default, performs semantic analysis to build the new expression.
2496 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002497 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002498 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002499 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002500 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 }
Mike Stump11289f42009-09-09 15:08:12 +00002502
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002503 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002504 ///
2505 /// By default, performs semantic analysis to build the new expression.
2506 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002507 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002508 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002509 SourceLocation RParenLoc) {
2510 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002511 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 RParenLoc);
2513 }
Mike Stump11289f42009-09-09 15:08:12 +00002514
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002515 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// Subclasses may override this routine to provide different behavior.
2519 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2520 SourceLocation DefaultLoc,
2521 SourceLocation RParenLoc,
2522 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002523 ArrayRef<TypeSourceInfo *> Types,
2524 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002525 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002526 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002527 }
2528
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002529 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 ///
2531 /// By default, performs semantic analysis to build the new expression.
2532 /// The semantic analysis provides the behavior of template instantiation,
2533 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002534 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 /// argument-dependent lookup, etc. Subclasses may override this routine to
2536 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002537 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002538 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002539 Expr *Callee,
2540 Expr *First,
2541 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002542
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002543 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 /// reinterpret_cast.
2545 ///
2546 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002547 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002549 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 Stmt::StmtClass Class,
2551 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002552 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 SourceLocation RAngleLoc,
2554 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002555 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 SourceLocation RParenLoc) {
2557 switch (Class) {
2558 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002559 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002560 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002561 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002562
2563 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002564 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002565 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002566 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002569 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002570 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002571 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002573
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002575 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002576 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002577 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002578
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002580 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002581 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002584 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 ///
2586 /// By default, performs semantic analysis to build the new expression.
2587 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002588 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002590 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 SourceLocation RAngleLoc,
2592 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002593 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002594 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002595 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002596 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002597 SourceRange(LAngleLoc, RAngleLoc),
2598 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002599 }
2600
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002601 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 ///
2603 /// By default, performs semantic analysis to build the new expression.
2604 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002605 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002606 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002607 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 SourceLocation RAngleLoc,
2609 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002610 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002611 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002612 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002613 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002614 SourceRange(LAngleLoc, RAngleLoc),
2615 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002616 }
2617
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002618 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002619 ///
2620 /// By default, performs semantic analysis to build the new expression.
2621 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002622 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002624 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 SourceLocation RAngleLoc,
2626 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002627 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002629 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002630 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002631 SourceRange(LAngleLoc, RAngleLoc),
2632 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002633 }
2634
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002635 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002636 ///
2637 /// By default, performs semantic analysis to build the new expression.
2638 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002639 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002641 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 SourceLocation RAngleLoc,
2643 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002644 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002645 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002646 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002647 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002648 SourceRange(LAngleLoc, RAngleLoc),
2649 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 }
Mike Stump11289f42009-09-09 15:08:12 +00002651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002652 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002656 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2657 SourceLocation LParenLoc,
2658 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002659 SourceLocation RParenLoc,
2660 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002661 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002662 MultiExprArg(&Sub, 1), RParenLoc,
2663 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002664 }
Mike Stump11289f42009-09-09 15:08:12 +00002665
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00002666 /// Build a new C++ __builtin_bit_cast expression.
2667 ///
2668 /// By default, performs semantic analysis to build the new expression.
2669 /// Subclasses may override this routine to provide different behavior.
2670 ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc,
2671 TypeSourceInfo *TSI, Expr *Sub,
2672 SourceLocation RParenLoc) {
2673 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
2674 }
2675
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002676 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002677 ///
2678 /// By default, performs semantic analysis to build the new expression.
2679 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002680 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002681 SourceLocation TypeidLoc,
2682 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002683 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002684 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002685 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002686 }
Mike Stump11289f42009-09-09 15:08:12 +00002687
Francois Pichet9f4f2072010-09-08 12:20:18 +00002688
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002689 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002693 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002694 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002695 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002696 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002697 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002698 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002699 }
2700
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002701 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002702 ///
2703 /// By default, performs semantic analysis to build the new expression.
2704 /// Subclasses may override this routine to provide different behavior.
2705 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2706 SourceLocation TypeidLoc,
2707 TypeSourceInfo *Operand,
2708 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002709 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002710 RParenLoc);
2711 }
2712
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002713 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002714 ///
2715 /// By default, performs semantic analysis to build the new expression.
2716 /// Subclasses may override this routine to provide different behavior.
2717 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2718 SourceLocation TypeidLoc,
2719 Expr *Operand,
2720 SourceLocation RParenLoc) {
2721 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2722 RParenLoc);
2723 }
2724
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002725 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 ///
2727 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002728 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002730 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002731 QualType ThisType,
2732 bool isImplicit) {
Richard Smith8458c9e2019-05-24 01:35:07 +00002733 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002734 }
2735
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002736 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002737 ///
2738 /// By default, performs semantic analysis to build the new expression.
2739 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002740 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2741 bool IsThrownVariableInScope) {
2742 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002743 }
2744
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002745 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002746 ///
2747 /// By default, builds a new default-argument expression, which does not
2748 /// require any semantic analysis. Subclasses may override this routine to
2749 /// provide different behavior.
Eric Fiselier708afb52019-05-16 21:04:15 +00002750 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
2751 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2752 getSema().CurContext);
Douglas Gregora16548e2009-08-11 05:31:07 +00002753 }
2754
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002755 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002756 ///
2757 /// By default, builds a new default field initialization expression, which
2758 /// does not require any semantic analysis. Subclasses may override this
2759 /// routine to provide different behavior.
2760 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2761 FieldDecl *Field) {
Eric Fiselier708afb52019-05-16 21:04:15 +00002762 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2763 getSema().CurContext);
Richard Smith852c9db2013-04-20 22:23:05 +00002764 }
2765
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002766 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002767 ///
2768 /// By default, performs semantic analysis to build the new expression.
2769 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002770 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2771 SourceLocation LParenLoc,
2772 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002773 return getSema().BuildCXXTypeConstructExpr(
2774 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002775 }
Mike Stump11289f42009-09-09 15:08:12 +00002776
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002777 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002778 ///
2779 /// By default, performs semantic analysis to build the new expression.
2780 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002781 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002782 bool UseGlobal,
2783 SourceLocation PlacementLParen,
2784 MultiExprArg PlacementArgs,
2785 SourceLocation PlacementRParen,
2786 SourceRange TypeIdParens,
2787 QualType AllocatedType,
2788 TypeSourceInfo *AllocatedTypeInfo,
Richard Smithb9fb1212019-05-06 03:47:15 +00002789 Optional<Expr *> ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002790 SourceRange DirectInitRange,
2791 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002792 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002793 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002794 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002795 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002796 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002797 AllocatedType,
2798 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002799 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002800 DirectInitRange,
2801 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002802 }
Mike Stump11289f42009-09-09 15:08:12 +00002803
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002804 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002805 ///
2806 /// By default, performs semantic analysis to build the new expression.
2807 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002808 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002809 bool IsGlobalDelete,
2810 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002811 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002812 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002813 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002814 }
Mike Stump11289f42009-09-09 15:08:12 +00002815
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002816 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
2820 ExprResult RebuildTypeTrait(TypeTrait Trait,
2821 SourceLocation StartLoc,
2822 ArrayRef<TypeSourceInfo *> Args,
2823 SourceLocation RParenLoc) {
2824 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002826
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002827 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002828 ///
2829 /// By default, performs semantic analysis to build the new expression.
2830 /// Subclasses may override this routine to provide different behavior.
2831 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2832 SourceLocation StartLoc,
2833 TypeSourceInfo *TSInfo,
2834 Expr *DimExpr,
2835 SourceLocation RParenLoc) {
2836 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2837 }
2838
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002839 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002840 ///
2841 /// By default, performs semantic analysis to build the new expression.
2842 /// Subclasses may override this routine to provide different behavior.
2843 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2844 SourceLocation StartLoc,
2845 Expr *Queried,
2846 SourceLocation RParenLoc) {
2847 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2848 }
2849
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002850 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002851 /// expression.
2852 ///
2853 /// By default, performs semantic analysis to build the new expression.
2854 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002855 ExprResult RebuildDependentScopeDeclRefExpr(
2856 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002857 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002858 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002859 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002860 bool IsAddressOfOperand,
2861 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002862 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002863 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002864
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002865 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002866 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2867 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002868
Reid Kleckner32506ed2014-06-12 23:03:48 +00002869 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002870 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002871 }
2872
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002873 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002874 ///
2875 /// By default, performs semantic analysis to build the new expression.
2876 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002877 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002878 SourceLocation TemplateKWLoc,
2879 LookupResult &R,
2880 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002881 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002882 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2883 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002884 }
2885
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002886 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002887 ///
2888 /// By default, performs semantic analysis to build the new expression.
2889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002890 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002891 SourceLocation Loc,
2892 CXXConstructorDecl *Constructor,
2893 bool IsElidable,
2894 MultiExprArg Args,
2895 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002896 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002897 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002898 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002899 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002900 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002901 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002902 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002903 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002904 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002905
Richard Smithc83bf822016-06-10 00:58:19 +00002906 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002907 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002908 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002909 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002910 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002911 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002912 RequiresZeroInit, ConstructKind,
2913 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002914 }
2915
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002916 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002917 /// expression.
2918 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2919 CXXConstructorDecl *Constructor,
2920 bool ConstructsVBase,
2921 bool InheritedFromVBase) {
2922 return new (getSema().Context) CXXInheritedCtorInitExpr(
2923 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2924 }
2925
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002926 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002927 ///
2928 /// By default, performs semantic analysis to build the new expression.
2929 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002930 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002931 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002932 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002933 SourceLocation RParenOrBraceLoc,
2934 bool ListInitialization) {
2935 return getSema().BuildCXXTypeConstructExpr(
2936 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002937 }
2938
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002939 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002940 ///
2941 /// By default, performs semantic analysis to build the new expression.
2942 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002943 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2944 SourceLocation LParenLoc,
2945 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002946 SourceLocation RParenLoc,
2947 bool ListInitialization) {
2948 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2949 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002950 }
Mike Stump11289f42009-09-09 15:08:12 +00002951
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002952 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002953 ///
2954 /// By default, performs semantic analysis to build the new expression.
2955 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002956 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002957 QualType BaseType,
2958 bool IsArrow,
2959 SourceLocation OperatorLoc,
2960 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002961 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002962 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002963 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002964 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002965 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002966 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002967
John McCallb268a282010-08-23 23:25:46 +00002968 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002969 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002970 SS, TemplateKWLoc,
2971 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002972 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002973 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002974 }
2975
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002976 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002977 ///
2978 /// By default, performs semantic analysis to build the new expression.
2979 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002980 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2981 SourceLocation OperatorLoc,
2982 bool IsArrow,
2983 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002984 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002985 NamedDecl *FirstQualifierInScope,
2986 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002987 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002988 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002989 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002990
John McCallb268a282010-08-23 23:25:46 +00002991 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002992 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002993 SS, TemplateKWLoc,
2994 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002995 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002996 }
Mike Stump11289f42009-09-09 15:08:12 +00002997
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002998 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002999 ///
3000 /// By default, performs semantic analysis to build the new expression.
3001 /// Subclasses may override this routine to provide different behavior.
3002 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
3003 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3004 }
3005
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003006 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00003007 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
3008 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00003009 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00003010 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00003011 Optional<unsigned> Length,
3012 ArrayRef<TemplateArgument> PartialArgs) {
3013 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3014 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00003015 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00003016
Eric Fiselier708afb52019-05-16 21:04:15 +00003017 /// Build a new expression representing a call to a source location
3018 /// builtin.
3019 ///
3020 /// By default, performs semantic analysis to build the new expression.
3021 /// Subclasses may override this routine to provide different behavior.
3022 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
3023 SourceLocation BuiltinLoc,
3024 SourceLocation RPLoc,
3025 DeclContext *ParentContext) {
3026 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3027 }
3028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003029 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00003030 ///
3031 /// By default, performs semantic analysis to build the new expression.
3032 /// Subclasses may override this routine to provide different behavior.
Saar Raz5d98ba62019-10-15 15:24:26 +00003033 ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
3034 SourceLocation TemplateKWLoc, SourceLocation ConceptNameLoc,
3035 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3036 TemplateArgumentListInfo *TALI) {
3037 CXXScopeSpec SS;
3038 SS.Adopt(NNS);
3039 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3040 ConceptNameLoc,
3041 FoundDecl,
3042 NamedConcept, TALI);
3043 if (Result.isInvalid())
3044 return ExprError();
3045 return Result;
3046 }
3047
3048 /// \brief Build a new Objective-C boxed expression.
3049 ///
3050 /// By default, performs semantic analysis to build the new expression.
3051 /// Subclasses may override this routine to provide different behavior.
Patrick Beard0caa3942012-04-19 00:25:12 +00003052 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
3053 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003055
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003056 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003057 ///
3058 /// By default, performs semantic analysis to build the new expression.
3059 /// Subclasses may override this routine to provide different behavior.
3060 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
3061 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003062 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003063 MultiExprArg(Elements, NumElements));
3064 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003065
3066 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003067 Expr *Base, Expr *Key,
3068 ObjCMethodDecl *getterMethod,
3069 ObjCMethodDecl *setterMethod) {
3070 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3071 getterMethod, setterMethod);
3072 }
3073
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003074 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003075 ///
3076 /// By default, performs semantic analysis to build the new expression.
3077 /// Subclasses may override this routine to provide different behavior.
3078 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00003079 MutableArrayRef<ObjCDictionaryElement> Elements) {
3080 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00003081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003082
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003083 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003084 ///
3085 /// By default, performs semantic analysis to build the new expression.
3086 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003087 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00003088 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00003089 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003090 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003091 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003092
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003093 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003094 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003095 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003096 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003097 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003098 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003099 MultiExprArg Args,
3100 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003101 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3102 ReceiverTypeInfo->getType(),
3103 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003104 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003105 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003106 }
3107
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003108 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003109 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003110 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003111 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003112 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003113 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003114 MultiExprArg Args,
3115 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003116 return SemaRef.BuildInstanceMessage(Receiver,
3117 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003118 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003119 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003120 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003121 }
3122
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003123 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003124 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3125 Selector Sel,
3126 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003127 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003128 ObjCMethodDecl *Method,
3129 SourceLocation LBracLoc,
3130 MultiExprArg Args,
3131 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003132 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003133 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003134 SuperLoc,
3135 Sel, Method, LBracLoc, SelectorLocs,
3136 RBracLoc, Args)
3137 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003138 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003139 SuperLoc,
3140 Sel, Method, LBracLoc, SelectorLocs,
3141 RBracLoc, Args);
3142
Fangrui Song6907ce22018-07-30 19:24:48 +00003143
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003144 }
3145
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003146 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003147 ///
3148 /// By default, performs semantic analysis to build the new expression.
3149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003150 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003151 SourceLocation IvarLoc,
3152 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003153 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003154 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003155 ExprResult Result = getSema().BuildMemberReferenceExpr(
3156 BaseArg, BaseArg->getType(),
3157 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3158 /*FirstQualifierInScope=*/nullptr, NameInfo,
3159 /*TemplateArgs=*/nullptr,
3160 /*S=*/nullptr);
3161 if (IsFreeIvar && Result.isUsable())
3162 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3163 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003164 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003165
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003166 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003170 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003171 ObjCPropertyDecl *Property,
3172 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003173 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003174 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3175 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3176 /*FIXME:*/PropertyLoc,
3177 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003178 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003179 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003180 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003181 /*TemplateArgs=*/nullptr,
3182 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003183 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003184
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003185 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003186 ///
3187 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003188 /// Subclasses may override this routine to provide different behavior.
3189 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3190 ObjCMethodDecl *Getter,
3191 ObjCMethodDecl *Setter,
3192 SourceLocation PropertyLoc) {
3193 // Since these expressions can only be value-dependent, we do not
3194 // need to perform semantic analysis again.
3195 return Owned(
3196 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3197 VK_LValue, OK_ObjCProperty,
3198 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003199 }
3200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003201 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003202 ///
3203 /// By default, performs semantic analysis to build the new expression.
3204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003205 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003206 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003207 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003208 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3209 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003210 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003211 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003212 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003213 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003214 /*TemplateArgs=*/nullptr,
3215 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003217
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003218 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003219 ///
3220 /// By default, performs semantic analysis to build the new expression.
3221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003222 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003223 MultiExprArg SubExprs,
3224 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003225 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003226 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003227 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3228 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3229 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003230 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregora16548e2009-08-11 05:31:07 +00003232 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003233 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003234 Expr *Callee = new (SemaRef.Context)
3235 DeclRefExpr(SemaRef.Context, Builtin, false,
3236 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003237 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3238 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003239 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003240
3241 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003242 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003243 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003244 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003245
Douglas Gregora16548e2009-08-11 05:31:07 +00003246 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003247 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003248 }
John McCall31f82722010-11-12 08:19:04 +00003249
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003250 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003251 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3252 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3253 SourceLocation RParenLoc) {
3254 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3255 BuiltinLoc, RParenLoc);
3256 }
3257
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003258 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003259 ///
3260 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003261 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003262 /// different behavior.
3263 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003264 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003265 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003266 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003267 case TemplateArgument::Expression: {
3268 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003269 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3270 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003271 if (Result.isInvalid())
3272 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003273
Douglas Gregor98318c22011-01-03 21:37:45 +00003274 return TemplateArgumentLoc(Result.get(), Result.get());
3275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003276
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003277 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003278 return TemplateArgumentLoc(TemplateArgument(
3279 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003280 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003281 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003282 Pattern.getTemplateNameLoc(),
3283 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003284
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003285 case TemplateArgument::Null:
3286 case TemplateArgument::Integral:
3287 case TemplateArgument::Declaration:
3288 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003289 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003290 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003291 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003292
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003293 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003294 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003295 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003296 EllipsisLoc,
3297 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003298 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3299 Expansion);
3300 break;
3301 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003303 return TemplateArgumentLoc();
3304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003306 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003307 ///
3308 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003309 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003310 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003311 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003312 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003313 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003314 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003315
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003316 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003317 ///
3318 /// By default, performs semantic analysis in order to build a new fold
3319 /// expression.
3320 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3321 BinaryOperatorKind Operator,
3322 SourceLocation EllipsisLoc, Expr *RHS,
Richard Smithc7214f62019-05-13 08:31:14 +00003323 SourceLocation RParenLoc,
3324 Optional<unsigned> NumExpansions) {
Richard Smith0f0af192014-11-08 05:07:16 +00003325 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
Richard Smithc7214f62019-05-13 08:31:14 +00003326 RHS, RParenLoc, NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +00003327 }
3328
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003329 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003330 ///
3331 /// By default, produces the fallback value for the fold-expression, or
3332 /// produce an error if there is no fallback value.
3333 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3334 BinaryOperatorKind Operator) {
3335 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3336 }
3337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003338 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003339 ///
3340 /// By default, performs semantic analysis to build the new expression.
3341 /// Subclasses may override this routine to provide different behavior.
Michael Liao566b3162019-09-23 18:48:06 +00003342 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003343 AtomicExpr::AtomicOp Op,
3344 SourceLocation RParenLoc) {
Erich Keane830909b2019-09-20 19:17:31 +00003345 // Use this for all of the locations, since we don't know the difference
3346 // between the call and the expr at this point.
3347 SourceRange Range{BuiltinLoc, RParenLoc};
Michael Liao566b3162019-09-23 18:48:06 +00003348 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
3349 Sema::AtomicArgumentOrder::AST);
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003350 }
3351
John McCall31f82722010-11-12 08:19:04 +00003352private:
Douglas Gregor14454802011-02-25 02:25:35 +00003353 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3354 QualType ObjectType,
3355 NamedDecl *FirstQualifierInScope,
3356 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003357
3358 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3359 QualType ObjectType,
3360 NamedDecl *FirstQualifierInScope,
3361 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003362
3363 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3364 NamedDecl *FirstQualifierInScope,
3365 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003366
3367 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3368 DependentNameTypeLoc TL,
3369 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003370};
Douglas Gregora16548e2009-08-11 05:31:07 +00003371
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003372template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003373StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003374 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003375 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003376
Douglas Gregorebe10102009-08-20 07:17:43 +00003377 switch (S->getStmtClass()) {
3378 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003379
Douglas Gregorebe10102009-08-20 07:17:43 +00003380 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003381 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003382#define STMT(Node, Parent) \
3383 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003384#define VALUESTMT(Node, Parent) \
3385 case Stmt::Node##Class: \
3386 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003387#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003388#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003389#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003390
Douglas Gregorebe10102009-08-20 07:17:43 +00003391 // Transform expressions by calling TransformExpr.
3392#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003393#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003394#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003395#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 {
John McCalldadc5752010-08-24 06:29:42 +00003397 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003398
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003399 if (SDK == SDK_StmtExprResult)
3400 E = getSema().ActOnStmtExprResult(E);
3401 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003402 }
Mike Stump11289f42009-09-09 15:08:12 +00003403 }
3404
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003405 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003406}
Mike Stump11289f42009-09-09 15:08:12 +00003407
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003408template<typename Derived>
3409OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3410 if (!S)
3411 return S;
3412
3413 switch (S->getClauseKind()) {
3414 default: break;
3415 // Transform individual clause nodes
3416#define OPENMP_CLAUSE(Name, Class) \
3417 case OMPC_ ## Name : \
3418 return getDerived().Transform ## Class(cast<Class>(S));
3419#include "clang/Basic/OpenMPKinds.def"
3420 }
3421
3422 return S;
3423}
3424
Mike Stump11289f42009-09-09 15:08:12 +00003425
Douglas Gregore922c772009-08-04 22:27:00 +00003426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003427ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003428 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003429 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003430
3431 switch (E->getStmtClass()) {
3432 case Stmt::NoStmtClass: break;
3433#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003434#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003435#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003436 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003437#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003438 }
3439
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003440 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003441}
3442
3443template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003444ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003445 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003446 // Initializers are instantiated like expressions, except that various outer
3447 // layers are stripped.
3448 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003449 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003450
Bill Wendling7c44da22018-10-31 03:48:47 +00003451 if (auto *FE = dyn_cast<FullExpr>(Init))
3452 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003453
Richard Smith410306b2016-12-12 02:53:20 +00003454 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3455 Init = AIL->getCommonExpr();
3456
Richard Smithe6ca4752013-05-30 22:40:16 +00003457 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3458 Init = MTE->GetTemporaryExpr();
3459
Richard Smithd59b8322012-12-19 01:39:02 +00003460 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3461 Init = Binder->getSubExpr();
3462
3463 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3464 Init = ICE->getSubExprAsWritten();
3465
Richard Smithcc1b96d2013-06-12 22:31:48 +00003466 if (CXXStdInitializerListExpr *ILE =
3467 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003468 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003469
Richard Smithc6abd962014-07-25 01:12:44 +00003470 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003471 // InitListExprs. Other forms of copy-initialization will be a no-op if
3472 // the initializer is already the right type.
3473 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003474 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003475 return getDerived().TransformExpr(Init);
3476
3477 // Revert value-initialization back to empty parens.
3478 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3479 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003480 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003481 Parens.getEnd());
3482 }
3483
3484 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3485 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003486 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003487 SourceLocation());
3488
3489 // Revert initialization by constructor back to a parenthesized or braced list
3490 // of expressions. Any other form of initializer can just be reused directly.
3491 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003492 return getDerived().TransformExpr(Init);
3493
Richard Smithf8adcdc2014-07-17 05:12:35 +00003494 // If the initialization implicitly converted an initializer list to a
3495 // std::initializer_list object, unwrap the std::initializer_list too.
3496 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003497 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003498
Richard Smith12938cf2018-09-26 04:36:55 +00003499 // Enter a list-init context if this was list initialization.
3500 EnterExpressionEvaluationContext Context(
3501 getSema(), EnterExpressionEvaluationContext::InitList,
3502 Construct->isListInitialization());
3503
Richard Smithd59b8322012-12-19 01:39:02 +00003504 SmallVector<Expr*, 8> NewArgs;
3505 bool ArgChanged = false;
3506 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003507 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003508 return ExprError();
3509
Richard Smithd1036122018-01-12 22:21:33 +00003510 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003511 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003512 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003513 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003514
Richard Smithd59b8322012-12-19 01:39:02 +00003515 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003516 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003517 if (Parens.isInvalid()) {
3518 // This was a variable declaration's initialization for which no initializer
3519 // was specified.
3520 assert(NewArgs.empty() &&
3521 "no parens or braces but have direct init with arguments?");
3522 return ExprEmpty();
3523 }
Richard Smithd59b8322012-12-19 01:39:02 +00003524 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3525 Parens.getEnd());
3526}
3527
3528template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003529bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003530 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003531 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003532 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003533 bool *ArgChanged) {
3534 for (unsigned I = 0; I != NumInputs; ++I) {
3535 // If requested, drop call arguments that need to be dropped.
3536 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3537 if (ArgChanged)
3538 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregora3efea12011-01-03 19:04:46 +00003540 break;
3541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregor968f23a2011-01-03 19:31:53 +00003543 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3544 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Chris Lattner01cf8db2011-07-20 06:58:45 +00003546 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003547 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3548 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor968f23a2011-01-03 19:31:53 +00003550 // Determine whether the set of unexpanded parameter packs can and should
3551 // be expanded.
3552 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003553 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003554 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3555 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003556 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3557 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003558 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003559 Expand, RetainExpansion,
3560 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003561 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003562
Douglas Gregor968f23a2011-01-03 19:31:53 +00003563 if (!Expand) {
3564 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003565 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003566 // expansion.
3567 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3568 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3569 if (OutPattern.isInvalid())
3570 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
3572 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003573 Expansion->getEllipsisLoc(),
3574 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003575 if (Out.isInvalid())
3576 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Douglas Gregor968f23a2011-01-03 19:31:53 +00003578 if (ArgChanged)
3579 *ArgChanged = true;
3580 Outputs.push_back(Out.get());
3581 continue;
3582 }
John McCall542e7c62011-07-06 07:30:07 +00003583
3584 // Record right away that the argument was changed. This needs
3585 // to happen even if the array expands to nothing.
3586 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregor968f23a2011-01-03 19:31:53 +00003588 // The transform has determined that we should perform an elementwise
3589 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003590 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003591 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3592 ExprResult Out = getDerived().TransformExpr(Pattern);
3593 if (Out.isInvalid())
3594 return true;
3595
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003596 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003597 Out = getDerived().RebuildPackExpansion(
3598 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003599 if (Out.isInvalid())
3600 return true;
3601 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
Douglas Gregor968f23a2011-01-03 19:31:53 +00003603 Outputs.push_back(Out.get());
3604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Richard Smith9467be42014-06-06 17:33:35 +00003606 // If we're supposed to retain a pack expansion, do so by temporarily
3607 // forgetting the partially-substituted parameter pack.
3608 if (RetainExpansion) {
3609 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3610
3611 ExprResult Out = getDerived().TransformExpr(Pattern);
3612 if (Out.isInvalid())
3613 return true;
3614
3615 Out = getDerived().RebuildPackExpansion(
3616 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3617 if (Out.isInvalid())
3618 return true;
3619
3620 Outputs.push_back(Out.get());
3621 }
3622
Douglas Gregor968f23a2011-01-03 19:31:53 +00003623 continue;
3624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Richard Smithd59b8322012-12-19 01:39:02 +00003626 ExprResult Result =
3627 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3628 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003629 if (Result.isInvalid())
3630 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003631
Douglas Gregora3efea12011-01-03 19:04:46 +00003632 if (Result.get() != Inputs[I] && ArgChanged)
3633 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003634
3635 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregora3efea12011-01-03 19:04:46 +00003638 return false;
3639}
3640
Richard Smith03a4aa32016-06-23 19:02:52 +00003641template <typename Derived>
3642Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3643 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3644 if (Var) {
3645 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3646 getDerived().TransformDefinition(Var->getLocation(), Var));
3647
3648 if (!ConditionVar)
3649 return Sema::ConditionError();
3650
3651 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3652 }
3653
3654 if (Expr) {
3655 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3656
3657 if (CondExpr.isInvalid())
3658 return Sema::ConditionError();
3659
3660 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3661 }
3662
3663 return Sema::ConditionResult();
3664}
3665
Douglas Gregora3efea12011-01-03 19:04:46 +00003666template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003667NestedNameSpecifierLoc
3668TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3669 NestedNameSpecifierLoc NNS,
3670 QualType ObjectType,
3671 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003672 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003673 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003674 Qualifier = Qualifier.getPrefix())
3675 Qualifiers.push_back(Qualifier);
3676
3677 CXXScopeSpec SS;
3678 while (!Qualifiers.empty()) {
3679 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3680 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003681
Douglas Gregor14454802011-02-25 02:25:35 +00003682 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003683 case NestedNameSpecifier::Identifier: {
3684 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3685 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3686 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3687 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003688 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003689 }
Douglas Gregor14454802011-02-25 02:25:35 +00003690 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor14454802011-02-25 02:25:35 +00003692 case NestedNameSpecifier::Namespace: {
3693 NamespaceDecl *NS
3694 = cast_or_null<NamespaceDecl>(
3695 getDerived().TransformDecl(
3696 Q.getLocalBeginLoc(),
3697 QNNS->getAsNamespace()));
3698 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3699 break;
3700 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003701
Douglas Gregor14454802011-02-25 02:25:35 +00003702 case NestedNameSpecifier::NamespaceAlias: {
3703 NamespaceAliasDecl *Alias
3704 = cast_or_null<NamespaceAliasDecl>(
3705 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3706 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003707 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003708 Q.getLocalEndLoc());
3709 break;
3710 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003711
Douglas Gregor14454802011-02-25 02:25:35 +00003712 case NestedNameSpecifier::Global:
3713 // There is no meaningful transformation that one could perform on the
3714 // global scope.
3715 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3716 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Nikola Smiljanic67860242014-09-26 00:28:20 +00003718 case NestedNameSpecifier::Super: {
3719 CXXRecordDecl *RD =
3720 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3721 SourceLocation(), QNNS->getAsRecordDecl()));
3722 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3723 break;
3724 }
3725
Douglas Gregor14454802011-02-25 02:25:35 +00003726 case NestedNameSpecifier::TypeSpecWithTemplate:
3727 case NestedNameSpecifier::TypeSpec: {
3728 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3729 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Douglas Gregor14454802011-02-25 02:25:35 +00003731 if (!TL)
3732 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Douglas Gregor14454802011-02-25 02:25:35 +00003734 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003735 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003736 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003737 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003738 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003739 if (TL.getType()->isEnumeralType())
3740 SemaRef.Diag(TL.getBeginLoc(),
3741 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003742 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3743 Q.getLocalEndLoc());
3744 break;
3745 }
Richard Trieude756fb2011-05-07 01:36:37 +00003746 // If the nested-name-specifier is an invalid type def, don't emit an
3747 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003748 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3749 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003750 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003751 << TL.getType() << SS.getRange();
3752 }
Douglas Gregor14454802011-02-25 02:25:35 +00003753 return NestedNameSpecifierLoc();
3754 }
Douglas Gregore16af532011-02-28 18:50:33 +00003755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003756
Douglas Gregore16af532011-02-28 18:50:33 +00003757 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003758 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003759 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003761
Douglas Gregor14454802011-02-25 02:25:35 +00003762 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003763 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003764 !getDerived().AlwaysRebuild())
3765 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
3767 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003768 // nested-name-specifier, do so.
3769 if (SS.location_size() == NNS.getDataLength() &&
3770 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3771 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3772
3773 // Allocate new nested-name-specifier location information.
3774 return SS.getWithLocInContext(SemaRef.Context);
3775}
3776
3777template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003778DeclarationNameInfo
3779TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003780::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003781 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003782 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003783 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003784
3785 switch (Name.getNameKind()) {
3786 case DeclarationName::Identifier:
3787 case DeclarationName::ObjCZeroArgSelector:
3788 case DeclarationName::ObjCOneArgSelector:
3789 case DeclarationName::ObjCMultiArgSelector:
3790 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003791 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003792 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003793 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003794
Richard Smith35845152017-02-07 01:37:30 +00003795 case DeclarationName::CXXDeductionGuideName: {
3796 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3797 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3798 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3799 if (!NewTemplate)
3800 return DeclarationNameInfo();
3801
3802 DeclarationNameInfo NewNameInfo(NameInfo);
3803 NewNameInfo.setName(
3804 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3805 return NewNameInfo;
3806 }
3807
Douglas Gregorf816bd72009-09-03 22:13:48 +00003808 case DeclarationName::CXXConstructorName:
3809 case DeclarationName::CXXDestructorName:
3810 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003811 TypeSourceInfo *NewTInfo;
3812 CanQualType NewCanTy;
3813 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003814 NewTInfo = getDerived().TransformType(OldTInfo);
3815 if (!NewTInfo)
3816 return DeclarationNameInfo();
3817 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003818 }
3819 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003820 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003821 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003822 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003823 if (NewT.isNull())
3824 return DeclarationNameInfo();
3825 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3826 }
Mike Stump11289f42009-09-09 15:08:12 +00003827
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003828 DeclarationName NewName
3829 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3830 NewCanTy);
3831 DeclarationNameInfo NewNameInfo(NameInfo);
3832 NewNameInfo.setName(NewName);
3833 NewNameInfo.setNamedTypeInfo(NewTInfo);
3834 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003835 }
Mike Stump11289f42009-09-09 15:08:12 +00003836 }
3837
David Blaikie83d382b2011-09-23 05:06:16 +00003838 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003839}
3840
3841template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003842TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003843TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3844 TemplateName Name,
3845 SourceLocation NameLoc,
3846 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003847 NamedDecl *FirstQualifierInScope,
3848 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003849 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3850 TemplateDecl *Template = QTN->getTemplateDecl();
3851 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003852
Douglas Gregor9db53502011-03-02 18:07:45 +00003853 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003854 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003855 Template));
3856 if (!TransTemplate)
3857 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003858
Douglas Gregor9db53502011-03-02 18:07:45 +00003859 if (!getDerived().AlwaysRebuild() &&
3860 SS.getScopeRep() == QTN->getQualifier() &&
3861 TransTemplate == Template)
3862 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003863
Douglas Gregor9db53502011-03-02 18:07:45 +00003864 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3865 TransTemplate);
3866 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
Douglas Gregor9db53502011-03-02 18:07:45 +00003868 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3869 if (SS.getScopeRep()) {
3870 // These apply to the scope specifier, not the template.
3871 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003872 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003873 }
3874
Douglas Gregor9db53502011-03-02 18:07:45 +00003875 if (!getDerived().AlwaysRebuild() &&
3876 SS.getScopeRep() == DTN->getQualifier() &&
3877 ObjectType.isNull())
3878 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003879
Richard Smith79810042018-05-11 02:43:08 +00003880 // FIXME: Preserve the location of the "template" keyword.
3881 SourceLocation TemplateKWLoc = NameLoc;
3882
Douglas Gregor9db53502011-03-02 18:07:45 +00003883 if (DTN->isIdentifier()) {
3884 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003885 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003886 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003887 NameLoc,
3888 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003889 FirstQualifierInScope,
3890 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003891 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003892
Richard Smith79810042018-05-11 02:43:08 +00003893 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3894 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003895 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003896 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003897
Douglas Gregor9db53502011-03-02 18:07:45 +00003898 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3899 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003900 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003901 Template));
3902 if (!TransTemplate)
3903 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003904
Douglas Gregor9db53502011-03-02 18:07:45 +00003905 if (!getDerived().AlwaysRebuild() &&
3906 TransTemplate == Template)
3907 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003908
Douglas Gregor9db53502011-03-02 18:07:45 +00003909 return TemplateName(TransTemplate);
3910 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003911
Douglas Gregor9db53502011-03-02 18:07:45 +00003912 if (SubstTemplateTemplateParmPackStorage *SubstPack
3913 = Name.getAsSubstTemplateTemplateParmPack()) {
3914 TemplateTemplateParmDecl *TransParam
3915 = cast_or_null<TemplateTemplateParmDecl>(
3916 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3917 if (!TransParam)
3918 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003919
Douglas Gregor9db53502011-03-02 18:07:45 +00003920 if (!getDerived().AlwaysRebuild() &&
3921 TransParam == SubstPack->getParameterPack())
3922 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
3924 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003925 SubstPack->getArgumentPack());
3926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
Douglas Gregor9db53502011-03-02 18:07:45 +00003928 // These should be getting filtered out before they reach the AST.
3929 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003930}
3931
3932template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003933void TreeTransform<Derived>::InventTemplateArgumentLoc(
3934 const TemplateArgument &Arg,
3935 TemplateArgumentLoc &Output) {
3936 SourceLocation Loc = getDerived().getBaseLocation();
3937 switch (Arg.getKind()) {
3938 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003939 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003940 break;
3941
3942 case TemplateArgument::Type:
3943 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003944 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003945
John McCall0ad16662009-10-29 08:12:44 +00003946 break;
3947
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003948 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003949 case TemplateArgument::TemplateExpansion: {
3950 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003951 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003952 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3953 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3954 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3955 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003956
Douglas Gregor9d802122011-03-02 17:09:35 +00003957 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003958 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003959 Builder.getWithLocInContext(SemaRef.Context),
3960 Loc);
3961 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003962 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003963 Builder.getWithLocInContext(SemaRef.Context),
3964 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003965
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003966 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003967 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003968
John McCall0ad16662009-10-29 08:12:44 +00003969 case TemplateArgument::Expression:
3970 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3971 break;
3972
3973 case TemplateArgument::Declaration:
3974 case TemplateArgument::Integral:
3975 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003976 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003977 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003978 break;
3979 }
3980}
3981
3982template<typename Derived>
3983bool TreeTransform<Derived>::TransformTemplateArgument(
3984 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003985 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003986 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003987 switch (Arg.getKind()) {
3988 case TemplateArgument::Null:
3989 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003990 case TemplateArgument::Pack:
3991 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003992 case TemplateArgument::NullPtr:
3993 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregore922c772009-08-04 22:27:00 +00003995 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003996 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003997 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003998 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003999
4000 DI = getDerived().TransformType(DI);
4001 if (!DI) return true;
4002
4003 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4004 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004005 }
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregor9167f8b2009-11-11 01:00:40 +00004007 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00004008 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4009 if (QualifierLoc) {
4010 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4011 if (!QualifierLoc)
4012 return true;
4013 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004014
Douglas Gregordf846d12011-03-02 18:46:51 +00004015 CXXScopeSpec SS;
4016 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00004017 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004018 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
4019 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00004020 if (Template.isNull())
4021 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004022
Douglas Gregor9d802122011-03-02 17:09:35 +00004023 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00004024 Input.getTemplateNameLoc());
4025 return false;
4026 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00004027
4028 case TemplateArgument::TemplateExpansion:
4029 llvm_unreachable("Caller should expand pack expansions");
4030
Douglas Gregore922c772009-08-04 22:27:00 +00004031 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00004032 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00004033 EnterExpressionEvaluationContext Unevaluated(
Richard Smithdcd7eb72019-06-25 20:40:27 +00004034 getSema(),
4035 Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
4036 : Sema::ExpressionEvaluationContext::ConstantEvaluated,
4037 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4038 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
Mike Stump11289f42009-09-09 15:08:12 +00004039
John McCall0ad16662009-10-29 08:12:44 +00004040 Expr *InputExpr = Input.getSourceExpression();
4041 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4042
Chris Lattnercdb591a2011-04-25 20:37:58 +00004043 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004044 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00004045 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004046 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00004047 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004048 }
Douglas Gregore922c772009-08-04 22:27:00 +00004049 }
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregore922c772009-08-04 22:27:00 +00004051 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00004052 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00004053}
4054
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004055/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00004056/// for each of the template arguments in its underlying iterator.
4057template<typename Derived, typename InputIterator>
4058class TemplateArgumentLocInventIterator {
4059 TreeTransform<Derived> &Self;
4060 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00004061
Douglas Gregorfe921a72010-12-20 23:36:19 +00004062public:
4063 typedef TemplateArgumentLoc value_type;
4064 typedef TemplateArgumentLoc reference;
4065 typedef typename std::iterator_traits<InputIterator>::difference_type
4066 difference_type;
4067 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004068
Douglas Gregorfe921a72010-12-20 23:36:19 +00004069 class pointer {
4070 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004071
Douglas Gregorfe921a72010-12-20 23:36:19 +00004072 public:
4073 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
Douglas Gregorfe921a72010-12-20 23:36:19 +00004075 const TemplateArgumentLoc *operator->() const { return &Arg; }
4076 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004077
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00004078 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004079
Douglas Gregorfe921a72010-12-20 23:36:19 +00004080 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4081 InputIterator Iter)
4082 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004083
Douglas Gregorfe921a72010-12-20 23:36:19 +00004084 TemplateArgumentLocInventIterator &operator++() {
4085 ++Iter;
4086 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
Douglas Gregorfe921a72010-12-20 23:36:19 +00004089 TemplateArgumentLocInventIterator operator++(int) {
4090 TemplateArgumentLocInventIterator Old(*this);
4091 ++(*this);
4092 return Old;
4093 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004094
Douglas Gregorfe921a72010-12-20 23:36:19 +00004095 reference operator*() const {
4096 TemplateArgumentLoc Result;
4097 Self.InventTemplateArgumentLoc(*Iter, Result);
4098 return Result;
4099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004100
Douglas Gregorfe921a72010-12-20 23:36:19 +00004101 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
Douglas Gregorfe921a72010-12-20 23:36:19 +00004103 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4104 const TemplateArgumentLocInventIterator &Y) {
4105 return X.Iter == Y.Iter;
4106 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004107
Douglas Gregorfe921a72010-12-20 23:36:19 +00004108 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4109 const TemplateArgumentLocInventIterator &Y) {
4110 return X.Iter != Y.Iter;
4111 }
4112};
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Douglas Gregor42cafa82010-12-20 17:42:22 +00004114template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004115template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004116bool TreeTransform<Derived>::TransformTemplateArguments(
4117 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4118 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004119 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004120 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004121 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004123 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4124 // Unpack argument packs, which we translate them into separate
4125 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004126 // FIXME: We could do much better if we could guarantee that the
4127 // TemplateArgumentLocInfo for the pack expansion would be usable for
4128 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004129 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004130 TemplateArgument::pack_iterator>
4131 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004132 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004133 In.getArgument().pack_begin()),
4134 PackLocIterator(*this,
4135 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004136 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004137 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004138
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004139 continue;
4140 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004141
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004142 if (In.getArgument().isPackExpansion()) {
4143 // We have a pack expansion, for which we will be substituting into
4144 // the pattern.
4145 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004146 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004147 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004148 = getSema().getTemplateArgumentPackExpansionPattern(
4149 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004150
Chris Lattner01cf8db2011-07-20 06:58:45 +00004151 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004152 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4153 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004155 // Determine whether the set of unexpanded parameter packs can and should
4156 // be expanded.
4157 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004158 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004159 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004160 if (getDerived().TryExpandParameterPacks(Ellipsis,
4161 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004162 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004163 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004164 RetainExpansion,
4165 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004166 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004167
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004168 if (!Expand) {
4169 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004170 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004171 // expansion.
4172 TemplateArgumentLoc OutPattern;
4173 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004174 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004175 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004177 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4178 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004179 if (Out.getArgument().isNull())
4180 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004181
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004182 Outputs.addArgument(Out);
4183 continue;
4184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004185
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004186 // The transform has determined that we should perform an elementwise
4187 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004188 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004189 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4190
Richard Smithd784e682015-09-23 21:41:42 +00004191 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004192 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004193
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004194 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004195 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4196 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004197 if (Out.getArgument().isNull())
4198 return true;
4199 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004200
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004201 Outputs.addArgument(Out);
4202 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004203
Douglas Gregor48d24112011-01-10 20:53:55 +00004204 // If we're supposed to retain a pack expansion, do so by temporarily
4205 // forgetting the partially-substituted parameter pack.
4206 if (RetainExpansion) {
4207 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004208
Richard Smithd784e682015-09-23 21:41:42 +00004209 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004210 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004212 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4213 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004214 if (Out.getArgument().isNull())
4215 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004216
Douglas Gregor48d24112011-01-10 20:53:55 +00004217 Outputs.addArgument(Out);
4218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004219
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004220 continue;
4221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004222
4223 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004224 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004225 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004226
Douglas Gregor42cafa82010-12-20 17:42:22 +00004227 Outputs.addArgument(Out);
4228 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004229
Douglas Gregor42cafa82010-12-20 17:42:22 +00004230 return false;
4231
4232}
4233
Douglas Gregord6ff3322009-08-04 16:50:30 +00004234//===----------------------------------------------------------------------===//
4235// Type transformation
4236//===----------------------------------------------------------------------===//
4237
4238template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004239QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004240 if (getDerived().AlreadyTransformed(T))
4241 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004242
John McCall550e0c22009-10-21 00:40:46 +00004243 // Temporary workaround. All of these transformations should
4244 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004245 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4246 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004247
John McCall31f82722010-11-12 08:19:04 +00004248 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004249
John McCall550e0c22009-10-21 00:40:46 +00004250 if (!NewDI)
4251 return QualType();
4252
4253 return NewDI->getType();
4254}
4255
4256template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004257TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004258 // Refine the base location to the type's location.
4259 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4260 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004261 if (getDerived().AlreadyTransformed(DI->getType()))
4262 return DI;
4263
4264 TypeLocBuilder TLB;
4265
4266 TypeLoc TL = DI->getTypeLoc();
4267 TLB.reserve(TL.getFullDataSize());
4268
John McCall31f82722010-11-12 08:19:04 +00004269 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004270 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004271 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004272
John McCallbcd03502009-12-07 02:54:59 +00004273 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004274}
4275
4276template<typename Derived>
4277QualType
John McCall31f82722010-11-12 08:19:04 +00004278TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004279 switch (T.getTypeLocClass()) {
4280#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004281#define TYPELOC(CLASS, PARENT) \
4282 case TypeLoc::CLASS: \
4283 return getDerived().Transform##CLASS##Type(TLB, \
4284 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004285#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286 }
Mike Stump11289f42009-09-09 15:08:12 +00004287
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004288 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004289}
4290
Richard Smithee579842017-01-30 20:39:26 +00004291template<typename Derived>
4292QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4293 if (!isa<DependentNameType>(T))
4294 return TransformType(T);
4295
4296 if (getDerived().AlreadyTransformed(T))
4297 return T;
4298 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4299 getDerived().getBaseLocation());
4300 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4301 return NewDI ? NewDI->getType() : QualType();
4302}
4303
4304template<typename Derived>
4305TypeSourceInfo *
4306TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4307 if (!isa<DependentNameType>(DI->getType()))
4308 return TransformType(DI);
4309
4310 // Refine the base location to the type's location.
4311 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4312 getDerived().getBaseEntity());
4313 if (getDerived().AlreadyTransformed(DI->getType()))
4314 return DI;
4315
4316 TypeLocBuilder TLB;
4317
4318 TypeLoc TL = DI->getTypeLoc();
4319 TLB.reserve(TL.getFullDataSize());
4320
Richard Smithee579842017-01-30 20:39:26 +00004321 auto QTL = TL.getAs<QualifiedTypeLoc>();
4322 if (QTL)
4323 TL = QTL.getUnqualifiedLoc();
4324
4325 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4326
4327 QualType Result = getDerived().TransformDependentNameType(
4328 TLB, DNTL, /*DeducedTSTContext*/true);
4329 if (Result.isNull())
4330 return nullptr;
4331
4332 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004333 Result = getDerived().RebuildQualifiedType(Result, QTL);
4334 if (Result.isNull())
4335 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004336 TLB.TypeWasModifiedSafely(Result);
4337 }
4338
4339 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4340}
4341
John McCall550e0c22009-10-21 00:40:46 +00004342template<typename Derived>
4343QualType
4344TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004345 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004346 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004347 if (Result.isNull())
4348 return QualType();
4349
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004350 Result = getDerived().RebuildQualifiedType(Result, T);
4351
4352 if (Result.isNull())
4353 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004354
4355 // RebuildQualifiedType might have updated the type, but not in a way
4356 // that invalidates the TypeLoc. (There's no location information for
4357 // qualifiers.)
4358 TLB.TypeWasModifiedSafely(Result);
4359
4360 return Result;
4361}
4362
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004363template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004364QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004365 QualifiedTypeLoc TL) {
4366
4367 SourceLocation Loc = TL.getBeginLoc();
4368 Qualifiers Quals = TL.getType().getLocalQualifiers();
4369
4370 if (((T.getAddressSpace() != LangAS::Default &&
4371 Quals.getAddressSpace() != LangAS::Default)) &&
4372 T.getAddressSpace() != Quals.getAddressSpace()) {
4373 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4374 << TL.getType() << T;
4375 return QualType();
4376 }
4377
Richard Smithee579842017-01-30 20:39:26 +00004378 // C++ [dcl.fct]p7:
4379 // [When] adding cv-qualifications on top of the function type [...] the
4380 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004381 if (T->isFunctionType()) {
4382 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4383 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004384 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004385 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004386
Richard Smithee579842017-01-30 20:39:26 +00004387 // C++ [dcl.ref]p1:
4388 // when the cv-qualifiers are introduced through the use of a typedef-name
4389 // or decltype-specifier [...] the cv-qualifiers are ignored.
4390 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4391 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004392 if (T->isReferenceType()) {
4393 // The only qualifier that applies to a reference type is restrict.
4394 if (!Quals.hasRestrict())
4395 return T;
4396 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4397 }
Mike Stump11289f42009-09-09 15:08:12 +00004398
John McCall31168b02011-06-15 23:02:42 +00004399 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004400 // resulting type.
4401 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004402 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004403 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004404 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004405 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004406 // A lifetime qualifier applied to a substituted template parameter
4407 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004408 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004409 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004410 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004411 QualType Replacement = SubstTypeParam->getReplacementType();
4412 Qualifiers Qs = Replacement.getQualifiers();
4413 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004414 Replacement = SemaRef.Context.getQualifiedType(
4415 Replacement.getUnqualifiedType(), Qs);
4416 T = SemaRef.Context.getSubstTemplateTypeParmType(
4417 SubstTypeParam->getReplacedParameter(), Replacement);
4418 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004419 // 'auto' types behave the same way as template parameters.
4420 QualType Deduced = AutoTy->getDeducedType();
4421 Qualifiers Qs = Deduced.getQualifiers();
4422 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004423 Deduced =
4424 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4425 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4426 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004427 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004428 // Otherwise, complain about the addition of a qualifier to an
4429 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004430 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4431 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004432 Quals.removeObjCLifetime();
4433 }
4434 }
4435 }
John McCall550e0c22009-10-21 00:40:46 +00004436
Richard Smithee579842017-01-30 20:39:26 +00004437 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004438}
4439
Douglas Gregor14454802011-02-25 02:25:35 +00004440template<typename Derived>
4441TypeLoc
4442TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4443 QualType ObjectType,
4444 NamedDecl *UnqualLookup,
4445 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004446 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004447 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004448
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004449 TypeSourceInfo *TSI =
4450 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4451 if (TSI)
4452 return TSI->getTypeLoc();
4453 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004454}
4455
Douglas Gregor579c15f2011-03-02 18:32:08 +00004456template<typename Derived>
4457TypeSourceInfo *
4458TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4459 QualType ObjectType,
4460 NamedDecl *UnqualLookup,
4461 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004462 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004463 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004464
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004465 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4466 UnqualLookup, SS);
4467}
4468
4469template <typename Derived>
4470TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4471 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4472 CXXScopeSpec &SS) {
4473 QualType T = TL.getType();
4474 assert(!getDerived().AlreadyTransformed(T));
4475
Douglas Gregor579c15f2011-03-02 18:32:08 +00004476 TypeLocBuilder TLB;
4477 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004478
Douglas Gregor579c15f2011-03-02 18:32:08 +00004479 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004480 TemplateSpecializationTypeLoc SpecTL =
4481 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004482
Richard Smithfd3dae02017-01-20 00:20:39 +00004483 TemplateName Template = getDerived().TransformTemplateName(
4484 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4485 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004486 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004487 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
4489 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004490 Template);
4491 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004492 DependentTemplateSpecializationTypeLoc SpecTL =
4493 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004494
Douglas Gregor579c15f2011-03-02 18:32:08 +00004495 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004496 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004497 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004498 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004499 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004500 ObjectType, UnqualLookup,
4501 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004502 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004503 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004504
4505 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004506 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004507 Template,
4508 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004509 } else {
4510 // Nothing special needs to be done for these.
4511 Result = getDerived().TransformType(TLB, TL);
4512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004513
4514 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004515 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004516
Douglas Gregor579c15f2011-03-02 18:32:08 +00004517 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4518}
4519
John McCall550e0c22009-10-21 00:40:46 +00004520template <class TyLoc> static inline
4521QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4522 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4523 NewT.setNameLoc(T.getNameLoc());
4524 return T.getType();
4525}
4526
John McCall550e0c22009-10-21 00:40:46 +00004527template<typename Derived>
4528QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004529 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004530 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4531 NewT.setBuiltinLoc(T.getBuiltinLoc());
4532 if (T.needsExtraLocalData())
4533 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4534 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregord6ff3322009-08-04 16:50:30 +00004537template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004538QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004539 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004540 // FIXME: recurse?
4541 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004542}
Mike Stump11289f42009-09-09 15:08:12 +00004543
Reid Kleckner0503a872013-12-05 01:23:43 +00004544template <typename Derived>
4545QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4546 AdjustedTypeLoc TL) {
4547 // Adjustments applied during transformation are handled elsewhere.
4548 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4549}
4550
Douglas Gregord6ff3322009-08-04 16:50:30 +00004551template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004552QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4553 DecayedTypeLoc TL) {
4554 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4555 if (OriginalType.isNull())
4556 return QualType();
4557
4558 QualType Result = TL.getType();
4559 if (getDerived().AlwaysRebuild() ||
4560 OriginalType != TL.getOriginalLoc().getType())
4561 Result = SemaRef.Context.getDecayedType(OriginalType);
4562 TLB.push<DecayedTypeLoc>(Result);
4563 // Nothing to set for DecayedTypeLoc.
4564 return Result;
4565}
4566
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004567/// Helper to deduce addr space of a pointee type in OpenCL mode.
4568/// If the type is updated it will be overwritten in PointeeType param.
4569static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) {
4570 if (PointeeType.getAddressSpace() == LangAS::Default)
4571 PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
4572 LangAS::opencl_generic);
4573}
4574
Reid Kleckner8a365022013-06-24 17:51:48 +00004575template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004576QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004577 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004578 QualType PointeeType
4579 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004580 if (PointeeType.isNull())
4581 return QualType();
4582
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004583 if (SemaRef.getLangOpts().OpenCL)
4584 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4585
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004586 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004587 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004588 // A dependent pointer type 'T *' has is being transformed such
4589 // that an Objective-C class type is being replaced for 'T'. The
4590 // resulting pointer type is an ObjCObjectPointerType, not a
4591 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004592 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004593
John McCall8b07ec22010-05-15 11:32:37 +00004594 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4595 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004596 return Result;
4597 }
John McCall31f82722010-11-12 08:19:04 +00004598
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004599 if (getDerived().AlwaysRebuild() ||
4600 PointeeType != TL.getPointeeLoc().getType()) {
4601 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4602 if (Result.isNull())
4603 return QualType();
4604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004605
John McCall31168b02011-06-15 23:02:42 +00004606 // Objective-C ARC can add lifetime qualifiers to the type that we're
4607 // pointing to.
4608 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004609
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004610 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4611 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004612 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004613}
Mike Stump11289f42009-09-09 15:08:12 +00004614
4615template<typename Derived>
4616QualType
John McCall550e0c22009-10-21 00:40:46 +00004617TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004618 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004619 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004620 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4621 if (PointeeType.isNull())
4622 return QualType();
4623
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004624 if (SemaRef.getLangOpts().OpenCL)
4625 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4626
Chad Rosier1dcde962012-08-08 18:46:20 +00004627 QualType Result = TL.getType();
4628 if (getDerived().AlwaysRebuild() ||
4629 PointeeType != TL.getPointeeLoc().getType()) {
4630 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004631 TL.getSigilLoc());
4632 if (Result.isNull())
4633 return QualType();
4634 }
4635
Douglas Gregor049211a2010-04-22 16:50:51 +00004636 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004637 NewT.setSigilLoc(TL.getSigilLoc());
4638 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004639}
4640
John McCall70dd5f62009-10-30 00:06:24 +00004641/// Transforms a reference type. Note that somewhat paradoxically we
4642/// don't care whether the type itself is an l-value type or an r-value
4643/// type; we only care if the type was *written* as an l-value type
4644/// or an r-value type.
4645template<typename Derived>
4646QualType
4647TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004648 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004649 const ReferenceType *T = TL.getTypePtr();
4650
4651 // Note that this works with the pointee-as-written.
4652 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4653 if (PointeeType.isNull())
4654 return QualType();
4655
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004656 if (SemaRef.getLangOpts().OpenCL)
4657 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4658
John McCall70dd5f62009-10-30 00:06:24 +00004659 QualType Result = TL.getType();
4660 if (getDerived().AlwaysRebuild() ||
4661 PointeeType != T->getPointeeTypeAsWritten()) {
4662 Result = getDerived().RebuildReferenceType(PointeeType,
4663 T->isSpelledAsLValue(),
4664 TL.getSigilLoc());
4665 if (Result.isNull())
4666 return QualType();
4667 }
4668
John McCall31168b02011-06-15 23:02:42 +00004669 // Objective-C ARC can add lifetime qualifiers to the type that we're
4670 // referring to.
4671 TLB.TypeWasModifiedSafely(
Simon Pilgrim22b68732019-10-05 13:20:59 +00004672 Result->castAs<ReferenceType>()->getPointeeTypeAsWritten());
John McCall31168b02011-06-15 23:02:42 +00004673
John McCall70dd5f62009-10-30 00:06:24 +00004674 // r-value references can be rebuilt as l-value references.
4675 ReferenceTypeLoc NewTL;
4676 if (isa<LValueReferenceType>(Result))
4677 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4678 else
4679 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4680 NewTL.setSigilLoc(TL.getSigilLoc());
4681
4682 return Result;
4683}
4684
Mike Stump11289f42009-09-09 15:08:12 +00004685template<typename Derived>
4686QualType
John McCall550e0c22009-10-21 00:40:46 +00004687TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004688 LValueReferenceTypeLoc TL) {
4689 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004690}
4691
Mike Stump11289f42009-09-09 15:08:12 +00004692template<typename Derived>
4693QualType
John McCall550e0c22009-10-21 00:40:46 +00004694TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004695 RValueReferenceTypeLoc TL) {
4696 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregord6ff3322009-08-04 16:50:30 +00004699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004700QualType
John McCall550e0c22009-10-21 00:40:46 +00004701TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004702 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004703 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704 if (PointeeType.isNull())
4705 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004706
Abramo Bagnara509357842011-03-05 14:42:21 +00004707 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004708 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004709 if (OldClsTInfo) {
4710 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4711 if (!NewClsTInfo)
4712 return QualType();
4713 }
4714
4715 const MemberPointerType *T = TL.getTypePtr();
4716 QualType OldClsType = QualType(T->getClass(), 0);
4717 QualType NewClsType;
4718 if (NewClsTInfo)
4719 NewClsType = NewClsTInfo->getType();
4720 else {
4721 NewClsType = getDerived().TransformType(OldClsType);
4722 if (NewClsType.isNull())
4723 return QualType();
4724 }
Mike Stump11289f42009-09-09 15:08:12 +00004725
John McCall550e0c22009-10-21 00:40:46 +00004726 QualType Result = TL.getType();
4727 if (getDerived().AlwaysRebuild() ||
4728 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004729 NewClsType != OldClsType) {
4730 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004731 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004732 if (Result.isNull())
4733 return QualType();
4734 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735
Reid Kleckner0503a872013-12-05 01:23:43 +00004736 // If we had to adjust the pointee type when building a member pointer, make
4737 // sure to push TypeLoc info for it.
4738 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4739 if (MPT && PointeeType != MPT->getPointeeType()) {
4740 assert(isa<AdjustedType>(MPT->getPointeeType()));
4741 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4742 }
4743
John McCall550e0c22009-10-21 00:40:46 +00004744 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4745 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004746 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004747
4748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004749}
4750
Mike Stump11289f42009-09-09 15:08:12 +00004751template<typename Derived>
4752QualType
John McCall550e0c22009-10-21 00:40:46 +00004753TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004754 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004755 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004756 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004757 if (ElementType.isNull())
4758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004759
Richard Smith772e2662019-10-04 01:25:59 +00004760 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4761 Expr *OldSize = TL.getSizeExpr();
4762 if (!OldSize)
4763 OldSize = const_cast<Expr*>(T->getSizeExpr());
4764 Expr *NewSize = nullptr;
4765 if (OldSize) {
4766 EnterExpressionEvaluationContext Unevaluated(
4767 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4768 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
4769 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
4770 }
4771
John McCall550e0c22009-10-21 00:40:46 +00004772 QualType Result = TL.getType();
4773 if (getDerived().AlwaysRebuild() ||
Richard Smith772e2662019-10-04 01:25:59 +00004774 ElementType != T->getElementType() ||
4775 (T->getSizeExpr() && NewSize != OldSize)) {
John McCall550e0c22009-10-21 00:40:46 +00004776 Result = getDerived().RebuildConstantArrayType(ElementType,
4777 T->getSizeModifier(),
Richard Smith772e2662019-10-04 01:25:59 +00004778 T->getSize(), NewSize,
John McCall70dd5f62009-10-30 00:06:24 +00004779 T->getIndexTypeCVRQualifiers(),
4780 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004781 if (Result.isNull())
4782 return QualType();
4783 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004784
4785 // We might have either a ConstantArrayType or a VariableArrayType now:
4786 // a ConstantArrayType is allowed to have an element type which is a
4787 // VariableArrayType if the type is dependent. Fortunately, all array
4788 // types have the same location layout.
4789 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004790 NewTL.setLBracketLoc(TL.getLBracketLoc());
4791 NewTL.setRBracketLoc(TL.getRBracketLoc());
Richard Smith772e2662019-10-04 01:25:59 +00004792 NewTL.setSizeExpr(NewSize);
John McCall550e0c22009-10-21 00:40:46 +00004793
4794 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004795}
Mike Stump11289f42009-09-09 15:08:12 +00004796
Douglas Gregord6ff3322009-08-04 16:50:30 +00004797template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004798QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004799 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004800 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004801 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004802 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004803 if (ElementType.isNull())
4804 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004805
John McCall550e0c22009-10-21 00:40:46 +00004806 QualType Result = TL.getType();
4807 if (getDerived().AlwaysRebuild() ||
4808 ElementType != T->getElementType()) {
4809 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004810 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004811 T->getIndexTypeCVRQualifiers(),
4812 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004813 if (Result.isNull())
4814 return QualType();
4815 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004816
John McCall550e0c22009-10-21 00:40:46 +00004817 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4818 NewTL.setLBracketLoc(TL.getLBracketLoc());
4819 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004820 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004821
4822 return Result;
4823}
4824
4825template<typename Derived>
4826QualType
4827TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004828 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004829 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004830 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4831 if (ElementType.isNull())
4832 return QualType();
4833
Tim Shenb34d0ef2017-02-14 23:46:37 +00004834 ExprResult SizeResult;
4835 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004836 EnterExpressionEvaluationContext Context(
4837 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004838 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4839 }
4840 if (SizeResult.isInvalid())
4841 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004842 SizeResult =
4843 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004844 if (SizeResult.isInvalid())
4845 return QualType();
4846
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004847 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004848
4849 QualType Result = TL.getType();
4850 if (getDerived().AlwaysRebuild() ||
4851 ElementType != T->getElementType() ||
4852 Size != T->getSizeExpr()) {
4853 Result = getDerived().RebuildVariableArrayType(ElementType,
4854 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004855 Size,
John McCall550e0c22009-10-21 00:40:46 +00004856 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004857 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004858 if (Result.isNull())
4859 return QualType();
4860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004861
Serge Pavlov774c6d02014-02-06 03:49:11 +00004862 // We might have constant size array now, but fortunately it has the same
4863 // location layout.
4864 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004865 NewTL.setLBracketLoc(TL.getLBracketLoc());
4866 NewTL.setRBracketLoc(TL.getRBracketLoc());
4867 NewTL.setSizeExpr(Size);
4868
4869 return Result;
4870}
4871
4872template<typename Derived>
4873QualType
4874TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004875 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004876 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004877 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4878 if (ElementType.isNull())
4879 return QualType();
4880
Richard Smith764d2fe2011-12-20 02:08:33 +00004881 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004882 EnterExpressionEvaluationContext Unevaluated(
4883 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004884
John McCall33ddac02011-01-19 10:06:00 +00004885 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4886 Expr *origSize = TL.getSizeExpr();
4887 if (!origSize) origSize = T->getSizeExpr();
4888
4889 ExprResult sizeResult
4890 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004891 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004892 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004893 return QualType();
4894
John McCall33ddac02011-01-19 10:06:00 +00004895 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004896
4897 QualType Result = TL.getType();
4898 if (getDerived().AlwaysRebuild() ||
4899 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004900 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004901 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4902 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004903 size,
John McCall550e0c22009-10-21 00:40:46 +00004904 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004905 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004906 if (Result.isNull())
4907 return QualType();
4908 }
John McCall550e0c22009-10-21 00:40:46 +00004909
4910 // We might have any sort of array type now, but fortunately they
4911 // all have the same location layout.
4912 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4913 NewTL.setLBracketLoc(TL.getLBracketLoc());
4914 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004915 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004916
4917 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004918}
Mike Stump11289f42009-09-09 15:08:12 +00004919
Erich Keanef702b022018-07-13 19:46:04 +00004920template <typename Derived>
4921QualType TreeTransform<Derived>::TransformDependentVectorType(
4922 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4923 const DependentVectorType *T = TL.getTypePtr();
4924 QualType ElementType = getDerived().TransformType(T->getElementType());
4925 if (ElementType.isNull())
4926 return QualType();
4927
4928 EnterExpressionEvaluationContext Unevaluated(
4929 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4930
4931 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4932 Size = SemaRef.ActOnConstantExpression(Size);
4933 if (Size.isInvalid())
4934 return QualType();
4935
4936 QualType Result = TL.getType();
4937 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4938 Size.get() != T->getSizeExpr()) {
4939 Result = getDerived().RebuildDependentVectorType(
4940 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4941 if (Result.isNull())
4942 return QualType();
4943 }
4944
4945 // Result might be dependent or not.
4946 if (isa<DependentVectorType>(Result)) {
4947 DependentVectorTypeLoc NewTL =
4948 TLB.push<DependentVectorTypeLoc>(Result);
4949 NewTL.setNameLoc(TL.getNameLoc());
4950 } else {
4951 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4952 NewTL.setNameLoc(TL.getNameLoc());
4953 }
4954
4955 return Result;
4956}
4957
Mike Stump11289f42009-09-09 15:08:12 +00004958template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004959QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004960 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004961 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004962 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004963
4964 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004965 QualType ElementType = getDerived().TransformType(T->getElementType());
4966 if (ElementType.isNull())
4967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004968
Richard Smith764d2fe2011-12-20 02:08:33 +00004969 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004970 EnterExpressionEvaluationContext Unevaluated(
4971 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004972
John McCalldadc5752010-08-24 06:29:42 +00004973 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004974 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004975 if (Size.isInvalid())
4976 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004977
John McCall550e0c22009-10-21 00:40:46 +00004978 QualType Result = TL.getType();
4979 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004980 ElementType != T->getElementType() ||
4981 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004982 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004983 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004984 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004985 if (Result.isNull())
4986 return QualType();
4987 }
John McCall550e0c22009-10-21 00:40:46 +00004988
4989 // Result might be dependent or not.
4990 if (isa<DependentSizedExtVectorType>(Result)) {
4991 DependentSizedExtVectorTypeLoc NewTL
4992 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4993 NewTL.setNameLoc(TL.getNameLoc());
4994 } else {
4995 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4996 NewTL.setNameLoc(TL.getNameLoc());
4997 }
4998
4999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005000}
Mike Stump11289f42009-09-09 15:08:12 +00005001
Andrew Gozillon572bbb02017-10-02 06:25:51 +00005002template <typename Derived>
5003QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5004 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5005 const DependentAddressSpaceType *T = TL.getTypePtr();
5006
5007 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5008
5009 if (pointeeType.isNull())
5010 return QualType();
5011
5012 // Address spaces are constant expressions.
5013 EnterExpressionEvaluationContext Unevaluated(
5014 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
5015
5016 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5017 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5018 if (AddrSpace.isInvalid())
5019 return QualType();
5020
5021 QualType Result = TL.getType();
5022 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5023 AddrSpace.get() != T->getAddrSpaceExpr()) {
5024 Result = getDerived().RebuildDependentAddressSpaceType(
5025 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5026 if (Result.isNull())
5027 return QualType();
5028 }
5029
5030 // Result might be dependent or not.
5031 if (isa<DependentAddressSpaceType>(Result)) {
5032 DependentAddressSpaceTypeLoc NewTL =
5033 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5034
5035 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5036 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5037 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5038
5039 } else {
5040 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5041 Result, getDerived().getBaseLocation());
5042 TransformType(TLB, DI->getTypeLoc());
5043 }
5044
5045 return Result;
5046}
5047
5048template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005049QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005050 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005051 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005052 QualType ElementType = getDerived().TransformType(T->getElementType());
5053 if (ElementType.isNull())
5054 return QualType();
5055
John McCall550e0c22009-10-21 00:40:46 +00005056 QualType Result = TL.getType();
5057 if (getDerived().AlwaysRebuild() ||
5058 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00005059 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00005060 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00005061 if (Result.isNull())
5062 return QualType();
5063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005064
John McCall550e0c22009-10-21 00:40:46 +00005065 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5066 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005067
John McCall550e0c22009-10-21 00:40:46 +00005068 return Result;
5069}
5070
5071template<typename Derived>
5072QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005073 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005074 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005075 QualType ElementType = getDerived().TransformType(T->getElementType());
5076 if (ElementType.isNull())
5077 return QualType();
5078
5079 QualType Result = TL.getType();
5080 if (getDerived().AlwaysRebuild() ||
5081 ElementType != T->getElementType()) {
5082 Result = getDerived().RebuildExtVectorType(ElementType,
5083 T->getNumElements(),
5084 /*FIXME*/ SourceLocation());
5085 if (Result.isNull())
5086 return QualType();
5087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005088
John McCall550e0c22009-10-21 00:40:46 +00005089 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5090 NewTL.setNameLoc(TL.getNameLoc());
5091
5092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005093}
Mike Stump11289f42009-09-09 15:08:12 +00005094
David Blaikie05785d12013-02-20 22:23:23 +00005095template <typename Derived>
5096ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
5097 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5098 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00005099 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00005100 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005101
Douglas Gregor715e4612011-01-14 22:40:04 +00005102 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005103 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005104 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00005105 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005106 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00005107
Douglas Gregor715e4612011-01-14 22:40:04 +00005108 TypeLocBuilder TLB;
5109 TypeLoc NewTL = OldDI->getTypeLoc();
5110 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005111
5112 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005113 OldExpansionTL.getPatternLoc());
5114 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005115 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
5117 Result = RebuildPackExpansionType(Result,
5118 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005119 OldExpansionTL.getEllipsisLoc(),
5120 NumExpansions);
5121 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005122 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005123
Douglas Gregor715e4612011-01-14 22:40:04 +00005124 PackExpansionTypeLoc NewExpansionTL
5125 = TLB.push<PackExpansionTypeLoc>(Result);
5126 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5127 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5128 } else
5129 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005130 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005131 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005132
John McCall8fb0d9d2011-05-01 22:35:37 +00005133 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005134 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005135
5136 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5137 OldParm->getDeclContext(),
5138 OldParm->getInnerLocStart(),
5139 OldParm->getLocation(),
5140 OldParm->getIdentifier(),
5141 NewDI->getType(),
5142 NewDI,
5143 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005144 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005145 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5146 OldParm->getFunctionScopeIndex() + indexAdjustment);
5147 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005148}
5149
David Majnemer59f77922016-06-24 04:05:48 +00005150template <typename Derived>
5151bool TreeTransform<Derived>::TransformFunctionTypeParams(
5152 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5153 const QualType *ParamTypes,
5154 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5155 SmallVectorImpl<QualType> &OutParamTypes,
5156 SmallVectorImpl<ParmVarDecl *> *PVars,
5157 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005158 int indexAdjustment = 0;
5159
David Majnemer59f77922016-06-24 04:05:48 +00005160 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005161 for (unsigned i = 0; i != NumParams; ++i) {
5162 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005163 assert(OldParm->getFunctionScopeIndex() == i);
5164
David Blaikie05785d12013-02-20 22:23:23 +00005165 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005166 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005167 if (OldParm->isParameterPack()) {
5168 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005169 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005170
Douglas Gregor5499af42011-01-05 23:12:31 +00005171 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005172 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005173 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005174 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5175 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005176 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5177
Douglas Gregor5499af42011-01-05 23:12:31 +00005178 // Determine whether we should expand the parameter packs.
5179 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005180 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005181 Optional<unsigned> OrigNumExpansions =
5182 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005183 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005184 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5185 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005186 Unexpanded,
5187 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005188 RetainExpansion,
5189 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005190 return true;
5191 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005192
Douglas Gregor5499af42011-01-05 23:12:31 +00005193 if (ShouldExpand) {
5194 // Expand the function parameter pack into multiple, separate
5195 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005196 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005197 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005198 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005199 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005200 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005201 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005202 OrigNumExpansions,
5203 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005204 if (!NewParm)
5205 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005206
John McCallc8e321d2016-03-01 02:09:25 +00005207 if (ParamInfos)
5208 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005209 OutParamTypes.push_back(NewParm->getType());
5210 if (PVars)
5211 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005212 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005213
5214 // If we're supposed to retain a pack expansion, do so by temporarily
5215 // forgetting the partially-substituted parameter pack.
5216 if (RetainExpansion) {
5217 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005218 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005219 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005220 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005221 OrigNumExpansions,
5222 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005223 if (!NewParm)
5224 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
John McCallc8e321d2016-03-01 02:09:25 +00005226 if (ParamInfos)
5227 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005228 OutParamTypes.push_back(NewParm->getType());
5229 if (PVars)
5230 PVars->push_back(NewParm);
5231 }
5232
John McCall8fb0d9d2011-05-01 22:35:37 +00005233 // The next parameter should have the same adjustment as the
5234 // last thing we pushed, but we post-incremented indexAdjustment
5235 // on every push. Also, if we push nothing, the adjustment should
5236 // go down by one.
5237 indexAdjustment--;
5238
Douglas Gregor5499af42011-01-05 23:12:31 +00005239 // We're done with the pack expansion.
5240 continue;
5241 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005242
5243 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005244 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005245 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5246 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005247 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005248 NumExpansions,
5249 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005250 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005251 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005252 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005253 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005254
John McCall58f10c32010-03-11 09:03:00 +00005255 if (!NewParm)
5256 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005257
John McCallc8e321d2016-03-01 02:09:25 +00005258 if (ParamInfos)
5259 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005260 OutParamTypes.push_back(NewParm->getType());
5261 if (PVars)
5262 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005263 continue;
5264 }
John McCall58f10c32010-03-11 09:03:00 +00005265
5266 // Deal with the possibility that we don't have a parameter
5267 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005268 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005269 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005270 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005271 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005272 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005273 = dyn_cast<PackExpansionType>(OldType)) {
5274 // We have a function parameter pack that may need to be expanded.
5275 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005276 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005277 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005278
Douglas Gregor5499af42011-01-05 23:12:31 +00005279 // Determine whether we should expand the parameter packs.
5280 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005281 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005282 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005283 Unexpanded,
5284 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005285 RetainExpansion,
5286 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005287 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005288 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005289
Douglas Gregor5499af42011-01-05 23:12:31 +00005290 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005291 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005292 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005293 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005294 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5295 QualType NewType = getDerived().TransformType(Pattern);
5296 if (NewType.isNull())
5297 return true;
John McCall58f10c32010-03-11 09:03:00 +00005298
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005299 if (NewType->containsUnexpandedParameterPack()) {
5300 NewType =
5301 getSema().getASTContext().getPackExpansionType(NewType, None);
5302
5303 if (NewType.isNull())
5304 return true;
5305 }
5306
John McCallc8e321d2016-03-01 02:09:25 +00005307 if (ParamInfos)
5308 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005309 OutParamTypes.push_back(NewType);
5310 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005311 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005313
Douglas Gregor5499af42011-01-05 23:12:31 +00005314 // We're done with the pack expansion.
5315 continue;
5316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005317
Douglas Gregor48d24112011-01-10 20:53:55 +00005318 // If we're supposed to retain a pack expansion, do so by temporarily
5319 // forgetting the partially-substituted parameter pack.
5320 if (RetainExpansion) {
5321 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5322 QualType NewType = getDerived().TransformType(Pattern);
5323 if (NewType.isNull())
5324 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005325
John McCallc8e321d2016-03-01 02:09:25 +00005326 if (ParamInfos)
5327 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005328 OutParamTypes.push_back(NewType);
5329 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005330 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005331 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005332
Chad Rosier1dcde962012-08-08 18:46:20 +00005333 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005334 // expansion.
5335 OldType = Expansion->getPattern();
5336 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005337 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5338 NewType = getDerived().TransformType(OldType);
5339 } else {
5340 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005341 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005342
Douglas Gregor5499af42011-01-05 23:12:31 +00005343 if (NewType.isNull())
5344 return true;
5345
5346 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005347 NewType = getSema().Context.getPackExpansionType(NewType,
5348 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005349
John McCallc8e321d2016-03-01 02:09:25 +00005350 if (ParamInfos)
5351 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005352 OutParamTypes.push_back(NewType);
5353 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005354 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005355 }
5356
John McCall8fb0d9d2011-05-01 22:35:37 +00005357#ifndef NDEBUG
5358 if (PVars) {
5359 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5360 if (ParmVarDecl *parm = (*PVars)[i])
5361 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005362 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005363#endif
5364
5365 return false;
5366}
John McCall58f10c32010-03-11 09:03:00 +00005367
5368template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005369QualType
John McCall550e0c22009-10-21 00:40:46 +00005370TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005371 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005372 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005373 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005374 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005375 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005376 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5377 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5378 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005379 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005380}
5381
Richard Smith2e321552014-11-12 02:00:47 +00005382template<typename Derived> template<typename Fn>
5383QualType TreeTransform<Derived>::TransformFunctionProtoType(
5384 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005385 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005386
Douglas Gregor4afc2362010-08-31 00:26:14 +00005387 // Transform the parameters and return type.
5388 //
Richard Smithf623c962012-04-17 00:58:00 +00005389 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005390 // When the function has a trailing return type, we instantiate the
5391 // parameters before the return type, since the return type can then refer
5392 // to the parameters themselves (via decltype, sizeof, etc.).
5393 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005394 SmallVector<QualType, 4> ParamTypes;
5395 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005396 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005397 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005398
Douglas Gregor7fb25412010-10-01 18:44:50 +00005399 QualType ResultType;
5400
Richard Smith1226c602012-08-14 22:51:13 +00005401 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005402 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005403 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005404 TL.getTypePtr()->param_type_begin(),
5405 T->getExtParameterInfosOrNull(),
5406 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005407 return QualType();
5408
Douglas Gregor3024f072012-04-16 07:05:22 +00005409 {
5410 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005411 // If a declaration declares a member function or member function
5412 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005413 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005414 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005415 // declarator.
5416 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005417
Alp Toker42a16a62014-01-25 23:51:36 +00005418 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005419 if (ResultType.isNull())
5420 return QualType();
5421 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005422 }
5423 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005424 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005425 if (ResultType.isNull())
5426 return QualType();
5427
Alp Toker9cacbab2014-01-20 20:26:09 +00005428 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005429 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005430 TL.getTypePtr()->param_type_begin(),
5431 T->getExtParameterInfosOrNull(),
5432 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005433 return QualType();
5434 }
5435
Richard Smith2e321552014-11-12 02:00:47 +00005436 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5437
5438 bool EPIChanged = false;
5439 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5440 return QualType();
5441
John McCallc8e321d2016-03-01 02:09:25 +00005442 // Handle extended parameter information.
5443 if (auto NewExtParamInfos =
5444 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5445 if (!EPI.ExtParameterInfos ||
5446 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5447 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5448 EPIChanged = true;
5449 }
5450 EPI.ExtParameterInfos = NewExtParamInfos;
5451 } else if (EPI.ExtParameterInfos) {
5452 EPIChanged = true;
5453 EPI.ExtParameterInfos = nullptr;
5454 }
Richard Smithf623c962012-04-17 00:58:00 +00005455
John McCall550e0c22009-10-21 00:40:46 +00005456 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005457 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005458 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005459 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005460 if (Result.isNull())
5461 return QualType();
5462 }
Mike Stump11289f42009-09-09 15:08:12 +00005463
John McCall550e0c22009-10-21 00:40:46 +00005464 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005465 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005466 NewTL.setLParenLoc(TL.getLParenLoc());
5467 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005468 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005469 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005470 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5471 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005472
5473 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005474}
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregord6ff3322009-08-04 16:50:30 +00005476template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005477bool TreeTransform<Derived>::TransformExceptionSpec(
5478 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5479 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5480 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5481
5482 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005483 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005484 EnterExpressionEvaluationContext Unevaluated(
5485 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005486 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5487 if (NoexceptExpr.isInvalid())
5488 return true;
5489
Richard Smitheaf11ad2018-05-03 03:58:32 +00005490 ExceptionSpecificationType EST = ESI.Type;
5491 NoexceptExpr =
5492 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005493 if (NoexceptExpr.isInvalid())
5494 return true;
5495
Richard Smitheaf11ad2018-05-03 03:58:32 +00005496 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005497 Changed = true;
5498 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005499 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005500 }
5501
5502 if (ESI.Type != EST_Dynamic)
5503 return false;
5504
5505 // Instantiate a dynamic exception specification's type.
5506 for (QualType T : ESI.Exceptions) {
5507 if (const PackExpansionType *PackExpansion =
5508 T->getAs<PackExpansionType>()) {
5509 Changed = true;
5510
5511 // We have a pack expansion. Instantiate it.
5512 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5513 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5514 Unexpanded);
5515 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5516
5517 // Determine whether the set of unexpanded parameter packs can and
5518 // should
5519 // be expanded.
5520 bool Expand = false;
5521 bool RetainExpansion = false;
5522 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5523 // FIXME: Track the location of the ellipsis (and track source location
5524 // information for the types in the exception specification in general).
5525 if (getDerived().TryExpandParameterPacks(
5526 Loc, SourceRange(), Unexpanded, Expand,
5527 RetainExpansion, NumExpansions))
5528 return true;
5529
5530 if (!Expand) {
5531 // We can't expand this pack expansion into separate arguments yet;
5532 // just substitute into the pattern and create a new pack expansion
5533 // type.
5534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5535 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5536 if (U.isNull())
5537 return true;
5538
5539 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5540 Exceptions.push_back(U);
5541 continue;
5542 }
5543
5544 // Substitute into the pack expansion pattern for each slice of the
5545 // pack.
5546 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5547 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5548
5549 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5550 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5551 return true;
5552
5553 Exceptions.push_back(U);
5554 }
5555 } else {
5556 QualType U = getDerived().TransformType(T);
5557 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5558 return true;
5559 if (T != U)
5560 Changed = true;
5561
5562 Exceptions.push_back(U);
5563 }
5564 }
5565
5566 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005567 if (ESI.Exceptions.empty())
5568 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005569 return false;
5570}
5571
5572template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005574 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005575 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005576 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005577 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005578 if (ResultType.isNull())
5579 return QualType();
5580
5581 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005582 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005583 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5584
5585 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005586 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005587 NewTL.setLParenLoc(TL.getLParenLoc());
5588 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005589 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005590
5591 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
John McCallb96ec562009-12-04 22:46:56 +00005594template<typename Derived> QualType
5595TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005596 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005597 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005598 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005599 if (!D)
5600 return QualType();
5601
5602 QualType Result = TL.getType();
5603 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005604 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005605 if (Result.isNull())
5606 return QualType();
5607 }
5608
5609 // We might get an arbitrary type spec type back. We should at
5610 // least always get a type spec type, though.
5611 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5612 NewTL.setNameLoc(TL.getNameLoc());
5613
5614 return Result;
5615}
5616
Douglas Gregord6ff3322009-08-04 16:50:30 +00005617template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005618QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005619 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005620 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005621 TypedefNameDecl *Typedef
5622 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5623 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005624 if (!Typedef)
5625 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005626
John McCall550e0c22009-10-21 00:40:46 +00005627 QualType Result = TL.getType();
5628 if (getDerived().AlwaysRebuild() ||
5629 Typedef != T->getDecl()) {
5630 Result = getDerived().RebuildTypedefType(Typedef);
5631 if (Result.isNull())
5632 return QualType();
5633 }
Mike Stump11289f42009-09-09 15:08:12 +00005634
John McCall550e0c22009-10-21 00:40:46 +00005635 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5636 NewTL.setNameLoc(TL.getNameLoc());
5637
5638 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005639}
Mike Stump11289f42009-09-09 15:08:12 +00005640
Douglas Gregord6ff3322009-08-04 16:50:30 +00005641template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005642QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005643 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005644 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005645 EnterExpressionEvaluationContext Unevaluated(
5646 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5647 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005648
John McCalldadc5752010-08-24 06:29:42 +00005649 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005650 if (E.isInvalid())
5651 return QualType();
5652
Eli Friedmane4f22df2012-02-29 04:03:55 +00005653 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5654 if (E.isInvalid())
5655 return QualType();
5656
John McCall550e0c22009-10-21 00:40:46 +00005657 QualType Result = TL.getType();
5658 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005659 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005660 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005661 if (Result.isNull())
5662 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005664 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005665
John McCall550e0c22009-10-21 00:40:46 +00005666 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005667 NewTL.setTypeofLoc(TL.getTypeofLoc());
5668 NewTL.setLParenLoc(TL.getLParenLoc());
5669 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005670
5671 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005672}
Mike Stump11289f42009-09-09 15:08:12 +00005673
5674template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005675QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005676 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005677 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5678 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5679 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005681
John McCall550e0c22009-10-21 00:40:46 +00005682 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005683 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5684 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005685 if (Result.isNull())
5686 return QualType();
5687 }
Mike Stump11289f42009-09-09 15:08:12 +00005688
John McCall550e0c22009-10-21 00:40:46 +00005689 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005690 NewTL.setTypeofLoc(TL.getTypeofLoc());
5691 NewTL.setLParenLoc(TL.getLParenLoc());
5692 NewTL.setRParenLoc(TL.getRParenLoc());
5693 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005694
5695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005696}
Mike Stump11289f42009-09-09 15:08:12 +00005697
5698template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005699QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005700 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005701 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005702
Douglas Gregore922c772009-08-04 22:27:00 +00005703 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005704 EnterExpressionEvaluationContext Unevaluated(
5705 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005706 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005707
John McCalldadc5752010-08-24 06:29:42 +00005708 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005709 if (E.isInvalid())
5710 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005711
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005712 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005713 if (E.isInvalid())
5714 return QualType();
5715
John McCall550e0c22009-10-21 00:40:46 +00005716 QualType Result = TL.getType();
5717 if (getDerived().AlwaysRebuild() ||
5718 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005719 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005720 if (Result.isNull())
5721 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005722 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005723 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005724
John McCall550e0c22009-10-21 00:40:46 +00005725 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5726 NewTL.setNameLoc(TL.getNameLoc());
5727
5728 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005729}
5730
5731template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005732QualType TreeTransform<Derived>::TransformUnaryTransformType(
5733 TypeLocBuilder &TLB,
5734 UnaryTransformTypeLoc TL) {
5735 QualType Result = TL.getType();
5736 if (Result->isDependentType()) {
5737 const UnaryTransformType *T = TL.getTypePtr();
5738 QualType NewBase =
5739 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5740 Result = getDerived().RebuildUnaryTransformType(NewBase,
5741 T->getUTTKind(),
5742 TL.getKWLoc());
5743 if (Result.isNull())
5744 return QualType();
5745 }
5746
5747 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5748 NewTL.setKWLoc(TL.getKWLoc());
5749 NewTL.setParensRange(TL.getParensRange());
5750 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5751 return Result;
5752}
5753
5754template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005755QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5756 AutoTypeLoc TL) {
5757 const AutoType *T = TL.getTypePtr();
5758 QualType OldDeduced = T->getDeducedType();
5759 QualType NewDeduced;
5760 if (!OldDeduced.isNull()) {
5761 NewDeduced = getDerived().TransformType(OldDeduced);
5762 if (NewDeduced.isNull())
5763 return QualType();
5764 }
5765
5766 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005767 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5768 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005769 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005770 if (Result.isNull())
5771 return QualType();
5772 }
5773
5774 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5775 NewTL.setNameLoc(TL.getNameLoc());
5776
5777 return Result;
5778}
5779
5780template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005781QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5782 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5783 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5784
5785 CXXScopeSpec SS;
5786 TemplateName TemplateName = getDerived().TransformTemplateName(
5787 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5788 if (TemplateName.isNull())
5789 return QualType();
5790
5791 QualType OldDeduced = T->getDeducedType();
5792 QualType NewDeduced;
5793 if (!OldDeduced.isNull()) {
5794 NewDeduced = getDerived().TransformType(OldDeduced);
5795 if (NewDeduced.isNull())
5796 return QualType();
5797 }
5798
5799 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5800 TemplateName, NewDeduced);
5801 if (Result.isNull())
5802 return QualType();
5803
5804 DeducedTemplateSpecializationTypeLoc NewTL =
5805 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5806 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5807
5808 return Result;
5809}
5810
5811template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005812QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005813 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005814 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005815 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005816 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5817 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005818 if (!Record)
5819 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005820
John McCall550e0c22009-10-21 00:40:46 +00005821 QualType Result = TL.getType();
5822 if (getDerived().AlwaysRebuild() ||
5823 Record != T->getDecl()) {
5824 Result = getDerived().RebuildRecordType(Record);
5825 if (Result.isNull())
5826 return QualType();
5827 }
Mike Stump11289f42009-09-09 15:08:12 +00005828
John McCall550e0c22009-10-21 00:40:46 +00005829 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5830 NewTL.setNameLoc(TL.getNameLoc());
5831
5832 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005833}
Mike Stump11289f42009-09-09 15:08:12 +00005834
5835template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005836QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005837 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005838 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005839 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005840 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5841 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005842 if (!Enum)
5843 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005844
John McCall550e0c22009-10-21 00:40:46 +00005845 QualType Result = TL.getType();
5846 if (getDerived().AlwaysRebuild() ||
5847 Enum != T->getDecl()) {
5848 Result = getDerived().RebuildEnumType(Enum);
5849 if (Result.isNull())
5850 return QualType();
5851 }
Mike Stump11289f42009-09-09 15:08:12 +00005852
John McCall550e0c22009-10-21 00:40:46 +00005853 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5854 NewTL.setNameLoc(TL.getNameLoc());
5855
5856 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005857}
John McCallfcc33b02009-09-05 00:15:47 +00005858
John McCalle78aac42010-03-10 03:28:59 +00005859template<typename Derived>
5860QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5861 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005862 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005863 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5864 TL.getTypePtr()->getDecl());
5865 if (!D) return QualType();
5866
5867 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5868 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5869 return T;
5870}
5871
Douglas Gregord6ff3322009-08-04 16:50:30 +00005872template<typename Derived>
5873QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005874 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005875 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005876 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005877}
5878
Mike Stump11289f42009-09-09 15:08:12 +00005879template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005880QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005881 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005882 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005883 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005884
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005885 // Substitute into the replacement type, which itself might involve something
5886 // that needs to be transformed. This only tends to occur with default
5887 // template arguments of template template parameters.
5888 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5889 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5890 if (Replacement.isNull())
5891 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005892
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005893 // Always canonicalize the replacement type.
5894 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5895 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005896 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005897 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005898
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005899 // Propagate type-source information.
5900 SubstTemplateTypeParmTypeLoc NewTL
5901 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5902 NewTL.setNameLoc(TL.getNameLoc());
5903 return Result;
5904
John McCallcebee162009-10-18 09:09:24 +00005905}
5906
5907template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005908QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5909 TypeLocBuilder &TLB,
5910 SubstTemplateTypeParmPackTypeLoc TL) {
5911 return TransformTypeSpecType(TLB, TL);
5912}
5913
5914template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005915QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005916 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005917 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005918 const TemplateSpecializationType *T = TL.getTypePtr();
5919
Douglas Gregordf846d12011-03-02 18:46:51 +00005920 // The nested-name-specifier never matters in a TemplateSpecializationType,
5921 // because we can't have a dependent nested-name-specifier anyway.
5922 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005923 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005924 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5925 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005926 if (Template.isNull())
5927 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005928
John McCall31f82722010-11-12 08:19:04 +00005929 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5930}
5931
Eli Friedman0dfb8892011-10-06 23:00:33 +00005932template<typename Derived>
5933QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5934 AtomicTypeLoc TL) {
5935 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5936 if (ValueType.isNull())
5937 return QualType();
5938
5939 QualType Result = TL.getType();
5940 if (getDerived().AlwaysRebuild() ||
5941 ValueType != TL.getValueLoc().getType()) {
5942 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5943 if (Result.isNull())
5944 return QualType();
5945 }
5946
5947 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5948 NewTL.setKWLoc(TL.getKWLoc());
5949 NewTL.setLParenLoc(TL.getLParenLoc());
5950 NewTL.setRParenLoc(TL.getRParenLoc());
5951
5952 return Result;
5953}
5954
Xiuli Pan9c14e282016-01-09 12:53:17 +00005955template <typename Derived>
5956QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5957 PipeTypeLoc TL) {
5958 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5959 if (ValueType.isNull())
5960 return QualType();
5961
5962 QualType Result = TL.getType();
5963 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Simon Pilgrim22b68732019-10-05 13:20:59 +00005964 const PipeType *PT = Result->castAs<PipeType>();
Joey Gouly5788b782016-11-18 14:10:54 +00005965 bool isReadPipe = PT->isReadOnly();
5966 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005967 if (Result.isNull())
5968 return QualType();
5969 }
5970
5971 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5972 NewTL.setKWLoc(TL.getKWLoc());
5973
5974 return Result;
5975}
5976
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005977 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005978 /// container that provides a \c getArgLoc() member function.
5979 ///
5980 /// This iterator is intended to be used with the iterator form of
5981 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5982 template<typename ArgLocContainer>
5983 class TemplateArgumentLocContainerIterator {
5984 ArgLocContainer *Container;
5985 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005986
Douglas Gregorfe921a72010-12-20 23:36:19 +00005987 public:
5988 typedef TemplateArgumentLoc value_type;
5989 typedef TemplateArgumentLoc reference;
5990 typedef int difference_type;
5991 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005992
Douglas Gregorfe921a72010-12-20 23:36:19 +00005993 class pointer {
5994 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Douglas Gregorfe921a72010-12-20 23:36:19 +00005996 public:
5997 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005998
Douglas Gregorfe921a72010-12-20 23:36:19 +00005999 const TemplateArgumentLoc *operator->() const {
6000 return &Arg;
6001 }
6002 };
Chad Rosier1dcde962012-08-08 18:46:20 +00006003
6004
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00006005 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00006006
Douglas Gregorfe921a72010-12-20 23:36:19 +00006007 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
6008 unsigned Index)
6009 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00006010
Douglas Gregorfe921a72010-12-20 23:36:19 +00006011 TemplateArgumentLocContainerIterator &operator++() {
6012 ++Index;
6013 return *this;
6014 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006015
Douglas Gregorfe921a72010-12-20 23:36:19 +00006016 TemplateArgumentLocContainerIterator operator++(int) {
6017 TemplateArgumentLocContainerIterator Old(*this);
6018 ++(*this);
6019 return Old;
6020 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006021
Douglas Gregorfe921a72010-12-20 23:36:19 +00006022 TemplateArgumentLoc operator*() const {
6023 return Container->getArgLoc(Index);
6024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006025
Douglas Gregorfe921a72010-12-20 23:36:19 +00006026 pointer operator->() const {
6027 return pointer(Container->getArgLoc(Index));
6028 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006029
Douglas Gregorfe921a72010-12-20 23:36:19 +00006030 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00006031 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00006032 return X.Container == Y.Container && X.Index == Y.Index;
6033 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006034
Douglas Gregorfe921a72010-12-20 23:36:19 +00006035 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00006036 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00006037 return !(X == Y);
6038 }
6039 };
Chad Rosier1dcde962012-08-08 18:46:20 +00006040
6041
John McCall31f82722010-11-12 08:19:04 +00006042template <typename Derived>
6043QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
6044 TypeLocBuilder &TLB,
6045 TemplateSpecializationTypeLoc TL,
6046 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00006047 TemplateArgumentListInfo NewTemplateArgs;
6048 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6049 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00006050 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
6051 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006052 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00006053 ArgIterator(TL, TL.getNumArgs()),
6054 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00006055 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006056
John McCall0ad16662009-10-29 08:12:44 +00006057 // FIXME: maybe don't rebuild if all the template arguments are the same.
6058
6059 QualType Result =
6060 getDerived().RebuildTemplateSpecializationType(Template,
6061 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00006062 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00006063
6064 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00006065 // Specializations of template template parameters are represented as
6066 // TemplateSpecializationTypes, and substitution of type alias templates
6067 // within a dependent context can transform them into
6068 // DependentTemplateSpecializationTypes.
6069 if (isa<DependentTemplateSpecializationType>(Result)) {
6070 DependentTemplateSpecializationTypeLoc NewTL
6071 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006072 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006073 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006074 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006075 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006076 NewTL.setLAngleLoc(TL.getLAngleLoc());
6077 NewTL.setRAngleLoc(TL.getRAngleLoc());
6078 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6079 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6080 return Result;
6081 }
6082
John McCall0ad16662009-10-29 08:12:44 +00006083 TemplateSpecializationTypeLoc NewTL
6084 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006085 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00006086 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6087 NewTL.setLAngleLoc(TL.getLAngleLoc());
6088 NewTL.setRAngleLoc(TL.getRAngleLoc());
6089 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6090 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006091 }
Mike Stump11289f42009-09-09 15:08:12 +00006092
John McCall0ad16662009-10-29 08:12:44 +00006093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006094}
Mike Stump11289f42009-09-09 15:08:12 +00006095
Douglas Gregor5a064722011-02-28 17:23:35 +00006096template <typename Derived>
6097QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6098 TypeLocBuilder &TLB,
6099 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00006100 TemplateName Template,
6101 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006102 TemplateArgumentListInfo NewTemplateArgs;
6103 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6104 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6105 typedef TemplateArgumentLocContainerIterator<
6106 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006107 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006108 ArgIterator(TL, TL.getNumArgs()),
6109 NewTemplateArgs))
6110 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006111
Douglas Gregor5a064722011-02-28 17:23:35 +00006112 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006113
Douglas Gregor5a064722011-02-28 17:23:35 +00006114 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6115 QualType Result
6116 = getSema().Context.getDependentTemplateSpecializationType(
6117 TL.getTypePtr()->getKeyword(),
6118 DTN->getQualifier(),
6119 DTN->getIdentifier(),
6120 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006121
Douglas Gregor5a064722011-02-28 17:23:35 +00006122 DependentTemplateSpecializationTypeLoc NewTL
6123 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006124 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006125 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006126 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006127 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006128 NewTL.setLAngleLoc(TL.getLAngleLoc());
6129 NewTL.setRAngleLoc(TL.getRAngleLoc());
6130 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6131 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6132 return Result;
6133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006134
6135 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006136 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006137 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006138 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006139
Douglas Gregor5a064722011-02-28 17:23:35 +00006140 if (!Result.isNull()) {
6141 /// FIXME: Wrap this in an elaborated-type-specifier?
6142 TemplateSpecializationTypeLoc NewTL
6143 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006144 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006145 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006146 NewTL.setLAngleLoc(TL.getLAngleLoc());
6147 NewTL.setRAngleLoc(TL.getRAngleLoc());
6148 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6149 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6150 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006151
Douglas Gregor5a064722011-02-28 17:23:35 +00006152 return Result;
6153}
6154
Mike Stump11289f42009-09-09 15:08:12 +00006155template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006156QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006157TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006158 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006159 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006160
Douglas Gregor844cb502011-03-01 18:12:44 +00006161 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006162 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006163 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006164 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006165 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6166 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006167 return QualType();
6168 }
Mike Stump11289f42009-09-09 15:08:12 +00006169
John McCall31f82722010-11-12 08:19:04 +00006170 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6171 if (NamedT.isNull())
6172 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006173
Richard Smith3f1b5d02011-05-05 21:57:07 +00006174 // C++0x [dcl.type.elab]p2:
6175 // If the identifier resolves to a typedef-name or the simple-template-id
6176 // resolves to an alias template specialization, the
6177 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006178 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6179 if (const TemplateSpecializationType *TST =
6180 NamedT->getAs<TemplateSpecializationType>()) {
6181 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006182 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6183 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006184 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006185 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006186 << TAT << Sema::NTK_TypeAliasTemplate
6187 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006188 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6189 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006190 }
6191 }
6192
John McCall550e0c22009-10-21 00:40:46 +00006193 QualType Result = TL.getType();
6194 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006195 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006196 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006197 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006198 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006199 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006200 if (Result.isNull())
6201 return QualType();
6202 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006203
Abramo Bagnara6150c882010-05-11 21:36:43 +00006204 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006205 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006206 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006207 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006208}
Mike Stump11289f42009-09-09 15:08:12 +00006209
6210template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006211QualType TreeTransform<Derived>::TransformAttributedType(
6212 TypeLocBuilder &TLB,
6213 AttributedTypeLoc TL) {
6214 const AttributedType *oldType = TL.getTypePtr();
6215 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6216 if (modifiedType.isNull())
6217 return QualType();
6218
Richard Smithe43e2b32018-08-20 21:47:29 +00006219 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6220 const Attr *oldAttr = TL.getAttr();
6221 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6222 if (oldAttr && !newAttr)
6223 return QualType();
6224
John McCall81904512011-01-06 01:58:22 +00006225 QualType result = TL.getType();
6226
6227 // FIXME: dependent operand expressions?
6228 if (getDerived().AlwaysRebuild() ||
6229 modifiedType != oldType->getModifiedType()) {
6230 // TODO: this is really lame; we should really be rebuilding the
6231 // equivalent type from first principles.
6232 QualType equivalentType
6233 = getDerived().TransformType(oldType->getEquivalentType());
6234 if (equivalentType.isNull())
6235 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006236
6237 // Check whether we can add nullability; it is only represented as
6238 // type sugar, and therefore cannot be diagnosed in any other way.
6239 if (auto nullability = oldType->getImmediateNullability()) {
6240 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006241 SemaRef.Diag(TL.getAttr()->getLocation(),
6242 diag::err_nullability_nonpointer)
6243 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006244 return QualType();
6245 }
6246 }
6247
Richard Smithe43e2b32018-08-20 21:47:29 +00006248 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006249 modifiedType,
6250 equivalentType);
6251 }
6252
6253 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006254 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006255 return result;
6256}
6257
6258template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006259QualType
6260TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6261 ParenTypeLoc TL) {
6262 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6263 if (Inner.isNull())
6264 return QualType();
6265
6266 QualType Result = TL.getType();
6267 if (getDerived().AlwaysRebuild() ||
6268 Inner != TL.getInnerLoc().getType()) {
6269 Result = getDerived().RebuildParenType(Inner);
6270 if (Result.isNull())
6271 return QualType();
6272 }
6273
6274 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6275 NewTL.setLParenLoc(TL.getLParenLoc());
6276 NewTL.setRParenLoc(TL.getRParenLoc());
6277 return Result;
6278}
6279
Leonard Chanc72aaf62019-05-07 03:20:17 +00006280template <typename Derived>
6281QualType
6282TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6283 MacroQualifiedTypeLoc TL) {
6284 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6285 if (Inner.isNull())
6286 return QualType();
6287
6288 QualType Result = TL.getType();
6289 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6290 Result =
6291 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6292 if (Result.isNull())
6293 return QualType();
6294 }
6295
6296 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6297 NewTL.setExpansionLoc(TL.getExpansionLoc());
6298 return Result;
6299}
6300
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006301template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006302QualType TreeTransform<Derived>::TransformDependentNameType(
6303 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6304 return TransformDependentNameType(TLB, TL, false);
6305}
6306
6307template<typename Derived>
6308QualType TreeTransform<Derived>::TransformDependentNameType(
6309 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006310 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006311
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006312 NestedNameSpecifierLoc QualifierLoc
6313 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6314 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006316
John McCallc392f372010-06-11 00:33:02 +00006317 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006318 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006319 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006320 QualifierLoc,
6321 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006322 TL.getNameLoc(),
6323 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006324 if (Result.isNull())
6325 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006326
Abramo Bagnarad7548482010-05-19 21:37:53 +00006327 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6328 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006329 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6330
Abramo Bagnarad7548482010-05-19 21:37:53 +00006331 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006332 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006333 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006334 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006335 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006336 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006337 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006338 NewTL.setNameLoc(TL.getNameLoc());
6339 }
John McCall550e0c22009-10-21 00:40:46 +00006340 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006341}
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregord6ff3322009-08-04 16:50:30 +00006343template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006344QualType TreeTransform<Derived>::
6345 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006346 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006347 NestedNameSpecifierLoc QualifierLoc;
6348 if (TL.getQualifierLoc()) {
6349 QualifierLoc
6350 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6351 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006352 return QualType();
6353 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006354
John McCall31f82722010-11-12 08:19:04 +00006355 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006356 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006357}
6358
6359template<typename Derived>
6360QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006361TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6362 DependentTemplateSpecializationTypeLoc TL,
6363 NestedNameSpecifierLoc QualifierLoc) {
6364 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006365
Douglas Gregora7a795b2011-03-01 20:11:18 +00006366 TemplateArgumentListInfo NewTemplateArgs;
6367 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6368 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006369
Douglas Gregora7a795b2011-03-01 20:11:18 +00006370 typedef TemplateArgumentLocContainerIterator<
6371 DependentTemplateSpecializationTypeLoc> ArgIterator;
6372 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6373 ArgIterator(TL, TL.getNumArgs()),
6374 NewTemplateArgs))
6375 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006376
Richard Smithfd3dae02017-01-20 00:20:39 +00006377 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006378 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6379 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006380 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006381 if (Result.isNull())
6382 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006383
Douglas Gregora7a795b2011-03-01 20:11:18 +00006384 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6385 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006386
Douglas Gregora7a795b2011-03-01 20:11:18 +00006387 // Copy information relevant to the template specialization.
6388 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006389 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006390 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006391 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006392 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6393 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006394 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006395 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006396
Douglas Gregora7a795b2011-03-01 20:11:18 +00006397 // Copy information relevant to the elaborated type.
6398 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006399 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006400 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006401 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6402 DependentTemplateSpecializationTypeLoc SpecTL
6403 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006404 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006405 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006406 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006407 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006408 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6409 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006410 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006411 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006412 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006413 TemplateSpecializationTypeLoc SpecTL
6414 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006415 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006416 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006417 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6418 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006419 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006420 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006421 }
6422 return Result;
6423}
6424
6425template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006426QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6427 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006428 QualType Pattern
6429 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006430 if (Pattern.isNull())
6431 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006432
6433 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006434 if (getDerived().AlwaysRebuild() ||
6435 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006436 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006437 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006438 TL.getEllipsisLoc(),
6439 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006440 if (Result.isNull())
6441 return QualType();
6442 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006443
Douglas Gregor822d0302011-01-12 17:07:58 +00006444 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6445 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6446 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006447}
6448
6449template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006450QualType
6451TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006452 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006453 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006454 TLB.pushFullCopy(TL);
6455 return TL.getType();
6456}
6457
6458template<typename Derived>
6459QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006460TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6461 ObjCTypeParamTypeLoc TL) {
6462 const ObjCTypeParamType *T = TL.getTypePtr();
6463 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6464 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6465 if (!OTP)
6466 return QualType();
6467
6468 QualType Result = TL.getType();
6469 if (getDerived().AlwaysRebuild() ||
6470 OTP != T->getDecl()) {
6471 Result = getDerived().RebuildObjCTypeParamType(OTP,
6472 TL.getProtocolLAngleLoc(),
6473 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6474 TL.getNumProtocols()),
6475 TL.getProtocolLocs(),
6476 TL.getProtocolRAngleLoc());
6477 if (Result.isNull())
6478 return QualType();
6479 }
6480
6481 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6482 if (TL.getNumProtocols()) {
6483 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6484 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6485 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6486 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6487 }
6488 return Result;
6489}
6490
6491template<typename Derived>
6492QualType
John McCall8b07ec22010-05-15 11:32:37 +00006493TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006494 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006495 // Transform base type.
6496 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6497 if (BaseType.isNull())
6498 return QualType();
6499
6500 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6501
6502 // Transform type arguments.
6503 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6504 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6505 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6506 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6507 QualType TypeArg = TypeArgInfo->getType();
6508 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6509 AnyChanged = true;
6510
6511 // We have a pack expansion. Instantiate it.
6512 const auto *PackExpansion = PackExpansionLoc.getType()
6513 ->castAs<PackExpansionType>();
6514 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6515 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6516 Unexpanded);
6517 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6518
6519 // Determine whether the set of unexpanded parameter packs can
6520 // and should be expanded.
6521 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6522 bool Expand = false;
6523 bool RetainExpansion = false;
6524 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6525 if (getDerived().TryExpandParameterPacks(
6526 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6527 Unexpanded, Expand, RetainExpansion, NumExpansions))
6528 return QualType();
6529
6530 if (!Expand) {
6531 // We can't expand this pack expansion into separate arguments yet;
6532 // just substitute into the pattern and create a new pack expansion
6533 // type.
6534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6535
6536 TypeLocBuilder TypeArgBuilder;
6537 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006538 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006539 PatternLoc);
6540 if (NewPatternType.isNull())
6541 return QualType();
6542
6543 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6544 NewPatternType, NumExpansions);
6545 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6546 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6547 NewTypeArgInfos.push_back(
6548 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6549 continue;
6550 }
6551
6552 // Substitute into the pack expansion pattern for each slice of the
6553 // pack.
6554 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6555 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6556
6557 TypeLocBuilder TypeArgBuilder;
6558 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6559
6560 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6561 PatternLoc);
6562 if (NewTypeArg.isNull())
6563 return QualType();
6564
6565 NewTypeArgInfos.push_back(
6566 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6567 }
6568
6569 continue;
6570 }
6571
6572 TypeLocBuilder TypeArgBuilder;
6573 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6574 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6575 if (NewTypeArg.isNull())
6576 return QualType();
6577
6578 // If nothing changed, just keep the old TypeSourceInfo.
6579 if (NewTypeArg == TypeArg) {
6580 NewTypeArgInfos.push_back(TypeArgInfo);
6581 continue;
6582 }
6583
6584 NewTypeArgInfos.push_back(
6585 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6586 AnyChanged = true;
6587 }
6588
6589 QualType Result = TL.getType();
6590 if (getDerived().AlwaysRebuild() || AnyChanged) {
6591 // Rebuild the type.
6592 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006593 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6594 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6595 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6596 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006597
6598 if (Result.isNull())
6599 return QualType();
6600 }
6601
6602 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006603 NewT.setHasBaseTypeAsWritten(true);
6604 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6605 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6606 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6607 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6608 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6609 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6610 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6611 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6612 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006613}
Mike Stump11289f42009-09-09 15:08:12 +00006614
6615template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006616QualType
6617TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006618 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006619 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6620 if (PointeeType.isNull())
6621 return QualType();
6622
6623 QualType Result = TL.getType();
6624 if (getDerived().AlwaysRebuild() ||
6625 PointeeType != TL.getPointeeLoc().getType()) {
6626 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6627 TL.getStarLoc());
6628 if (Result.isNull())
6629 return QualType();
6630 }
6631
6632 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6633 NewT.setStarLoc(TL.getStarLoc());
6634 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006635}
6636
Douglas Gregord6ff3322009-08-04 16:50:30 +00006637//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006638// Statement transformation
6639//===----------------------------------------------------------------------===//
6640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006641StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006642TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006643 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006644}
6645
6646template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006647StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006648TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6649 return getDerived().TransformCompoundStmt(S, false);
6650}
6651
6652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006653StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006654TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006655 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006656 Sema::CompoundScopeRAII CompoundScope(getSema());
6657
Aaron Ballmanb1e511b2019-07-09 15:02:07 +00006658 const Stmt *ExprResult = S->getStmtExprResult();
John McCall1ababa62010-08-27 19:56:05 +00006659 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006660 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006661 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006662 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006663 StmtResult Result = getDerived().TransformStmt(
Aaron Ballmanb1e511b2019-07-09 15:02:07 +00006664 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006665
John McCall1ababa62010-08-27 19:56:05 +00006666 if (Result.isInvalid()) {
6667 // Immediately fail if this was a DeclStmt, since it's very
6668 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006669 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006670 return StmtError();
6671
6672 // Otherwise, just keep processing substatements and fail later.
6673 SubStmtInvalid = true;
6674 continue;
6675 }
Mike Stump11289f42009-09-09 15:08:12 +00006676
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006677 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006678 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006679 }
Mike Stump11289f42009-09-09 15:08:12 +00006680
John McCall1ababa62010-08-27 19:56:05 +00006681 if (SubStmtInvalid)
6682 return StmtError();
6683
Douglas Gregorebe10102009-08-20 07:17:43 +00006684 if (!getDerived().AlwaysRebuild() &&
6685 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006686 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006687
6688 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006689 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 S->getRBracLoc(),
6691 IsStmtExpr);
6692}
Mike Stump11289f42009-09-09 15:08:12 +00006693
Douglas Gregorebe10102009-08-20 07:17:43 +00006694template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006695StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006696TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006697 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006698 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006699 EnterExpressionEvaluationContext Unevaluated(
6700 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006701
Eli Friedman06577382009-11-19 03:14:00 +00006702 // Transform the left-hand case value.
6703 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006704 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006705 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006707
Eli Friedman06577382009-11-19 03:14:00 +00006708 // Transform the right-hand case value (for the GNU case-range extension).
6709 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006710 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006711 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006712 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006713 }
Mike Stump11289f42009-09-09 15:08:12 +00006714
Douglas Gregorebe10102009-08-20 07:17:43 +00006715 // Build the case statement.
6716 // Case statements are always rebuilt so that they will attached to their
6717 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006718 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006719 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006720 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006721 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006722 S->getColonLoc());
6723 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006725
Douglas Gregorebe10102009-08-20 07:17:43 +00006726 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006727 StmtResult SubStmt =
6728 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006729 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006730 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006731
Douglas Gregorebe10102009-08-20 07:17:43 +00006732 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006733 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006734}
6735
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006736template <typename Derived>
6737StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006738 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006739 StmtResult SubStmt =
6740 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006741 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregorebe10102009-08-20 07:17:43 +00006744 // Default statements are always rebuilt
6745 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006746 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006747}
Mike Stump11289f42009-09-09 15:08:12 +00006748
Douglas Gregorebe10102009-08-20 07:17:43 +00006749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006750StmtResult
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006751TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6752 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006753 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006754 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006755
Chris Lattnercab02a62011-02-17 20:34:02 +00006756 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6757 S->getDecl());
6758 if (!LD)
6759 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006760
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006761 // If we're transforming "in-place" (we're not creating new local
6762 // declarations), assume we're replacing the old label statement
6763 // and clear out the reference to it.
6764 if (LD == S->getDecl())
6765 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006766
Douglas Gregorebe10102009-08-20 07:17:43 +00006767 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006768 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006769 cast<LabelDecl>(LD), SourceLocation(),
6770 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006771}
Mike Stump11289f42009-09-09 15:08:12 +00006772
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006773template <typename Derived>
6774const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6775 if (!R)
6776 return R;
6777
6778 switch (R->getKind()) {
6779// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6780#define ATTR(X)
6781#define PRAGMA_SPELLING_ATTR(X) \
6782 case attr::X: \
6783 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6784#include "clang/Basic/AttrList.inc"
6785 default:
6786 return R;
6787 }
6788}
6789
6790template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006791StmtResult
6792TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6793 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006794 bool AttrsChanged = false;
6795 SmallVector<const Attr *, 1> Attrs;
6796
6797 // Visit attributes and keep track if any are transformed.
6798 for (const auto *I : S->getAttrs()) {
6799 const Attr *R = getDerived().TransformAttr(I);
6800 AttrsChanged |= (I != R);
6801 Attrs.push_back(R);
6802 }
6803
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006804 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006805 if (SubStmt.isInvalid())
6806 return StmtError();
6807
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006808 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006809 return S;
6810
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006811 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006812 SubStmt.get());
6813}
6814
6815template<typename Derived>
6816StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006817TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006818 // Transform the initialization statement
6819 StmtResult Init = getDerived().TransformStmt(S->getInit());
6820 if (Init.isInvalid())
6821 return StmtError();
6822
Douglas Gregorebe10102009-08-20 07:17:43 +00006823 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006824 Sema::ConditionResult Cond = getDerived().TransformCondition(
6825 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006826 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6827 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006828 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006830
Richard Smithb130fe72016-06-23 19:16:49 +00006831 // If this is a constexpr if, determine which arm we should instantiate.
6832 llvm::Optional<bool> ConstexprConditionValue;
6833 if (S->isConstexpr())
6834 ConstexprConditionValue = Cond.getKnownValue();
6835
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006837 StmtResult Then;
6838 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6839 Then = getDerived().TransformStmt(S->getThen());
6840 if (Then.isInvalid())
6841 return StmtError();
6842 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006843 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006844 }
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregorebe10102009-08-20 07:17:43 +00006846 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006847 StmtResult Else;
6848 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6849 Else = getDerived().TransformStmt(S->getElse());
6850 if (Else.isInvalid())
6851 return StmtError();
6852 }
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006855 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006856 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006857 Then.get() == S->getThen() &&
6858 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006859 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006860
Richard Smithb130fe72016-06-23 19:16:49 +00006861 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006862 Init.get(), Then.get(), S->getElseLoc(),
6863 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006864}
6865
6866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006867StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006868TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006869 // Transform the initialization statement
6870 StmtResult Init = getDerived().TransformStmt(S->getInit());
6871 if (Init.isInvalid())
6872 return StmtError();
6873
Douglas Gregorebe10102009-08-20 07:17:43 +00006874 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006875 Sema::ConditionResult Cond = getDerived().TransformCondition(
6876 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6877 Sema::ConditionKind::Switch);
6878 if (Cond.isInvalid())
6879 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregorebe10102009-08-20 07:17:43 +00006881 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006882 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006883 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006884 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006885 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregorebe10102009-08-20 07:17:43 +00006887 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006888 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006889 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006890 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006891
Douglas Gregorebe10102009-08-20 07:17:43 +00006892 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006893 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6894 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006895}
Mike Stump11289f42009-09-09 15:08:12 +00006896
Douglas Gregorebe10102009-08-20 07:17:43 +00006897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006898StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006899TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006900 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006901 Sema::ConditionResult Cond = getDerived().TransformCondition(
6902 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6903 Sema::ConditionKind::Boolean);
6904 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006905 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006906
Douglas Gregorebe10102009-08-20 07:17:43 +00006907 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006908 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006909 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006910 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006911
Douglas Gregorebe10102009-08-20 07:17:43 +00006912 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006913 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006914 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006915 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006916
Richard Smith03a4aa32016-06-23 19:02:52 +00006917 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.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
Douglas Gregorebe10102009-08-20 07:17:43 +00006922TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006923 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006924 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006925 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006926 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006927
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006928 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006929 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006930 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006932
Douglas Gregorebe10102009-08-20 07:17:43 +00006933 if (!getDerived().AlwaysRebuild() &&
6934 Cond.get() == S->getCond() &&
6935 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006936 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006937
John McCallb268a282010-08-23 23:25:46 +00006938 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6939 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006940 S->getRParenLoc());
6941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregorebe10102009-08-20 07:17:43 +00006943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006944StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006945TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006946 if (getSema().getLangOpts().OpenMP)
6947 getSema().startOpenMPLoop();
6948
Douglas Gregorebe10102009-08-20 07:17:43 +00006949 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006950 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006951 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006952 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006953
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006954 // In OpenMP loop region loop control variable must be captured and be
6955 // private. Perform analysis of first part (if any).
6956 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6957 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6958
Douglas Gregorebe10102009-08-20 07:17:43 +00006959 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006960 Sema::ConditionResult Cond = getDerived().TransformCondition(
6961 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6962 Sema::ConditionKind::Boolean);
6963 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006964 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006965
Douglas Gregorebe10102009-08-20 07:17:43 +00006966 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006967 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006968 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006970
Richard Smith945f8d32013-01-14 22:39:08 +00006971 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006972 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006973 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006974
Douglas Gregorebe10102009-08-20 07:17:43 +00006975 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006976 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006977 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006978 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregorebe10102009-08-20 07:17:43 +00006980 if (!getDerived().AlwaysRebuild() &&
6981 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006982 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006983 Inc.get() == S->getInc() &&
6984 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006985 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006986
Douglas Gregorebe10102009-08-20 07:17:43 +00006987 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006988 Init.get(), Cond, FullInc,
6989 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006990}
6991
6992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006994TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006995 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6996 S->getLabel());
6997 if (!LD)
6998 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006999
Douglas Gregorebe10102009-08-20 07:17:43 +00007000 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00007001 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00007002 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00007003}
7004
7005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007006StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007007TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007008 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00007009 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007011 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00007012
Douglas Gregorebe10102009-08-20 07:17:43 +00007013 if (!getDerived().AlwaysRebuild() &&
7014 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007015 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007016
7017 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00007018 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007019}
7020
7021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007022StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007023TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007024 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007025}
Mike Stump11289f42009-09-09 15:08:12 +00007026
Douglas Gregorebe10102009-08-20 07:17:43 +00007027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007028StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007029TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007030 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007031}
Mike Stump11289f42009-09-09 15:08:12 +00007032
Douglas Gregorebe10102009-08-20 07:17:43 +00007033template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007034StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007035TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00007036 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
7037 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00007038 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007039 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007040
Mike Stump11289f42009-09-09 15:08:12 +00007041 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00007042 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00007043 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007044}
Mike Stump11289f42009-09-09 15:08:12 +00007045
Douglas Gregorebe10102009-08-20 07:17:43 +00007046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007047StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007048TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007049 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007050 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007051 for (auto *D : S->decls()) {
7052 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00007053 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00007054 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007055
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007056 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00007057 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00007058
Douglas Gregorebe10102009-08-20 07:17:43 +00007059 Decls.push_back(Transformed);
7060 }
Mike Stump11289f42009-09-09 15:08:12 +00007061
Douglas Gregorebe10102009-08-20 07:17:43 +00007062 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007063 return S;
Mike Stump11289f42009-09-09 15:08:12 +00007064
Stephen Kellya6e43582018-08-09 21:05:56 +00007065 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007066}
Mike Stump11289f42009-09-09 15:08:12 +00007067
Douglas Gregorebe10102009-08-20 07:17:43 +00007068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007069StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00007070TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007071
Benjamin Kramerf0623432012-08-23 22:51:59 +00007072 SmallVector<Expr*, 8> Constraints;
7073 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007074 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00007075
John McCalldadc5752010-08-24 06:29:42 +00007076 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007077 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007078
7079 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007080
Anders Carlssonaaeef072010-01-24 05:50:09 +00007081 // Go through the outputs.
7082 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007083 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
Anders Carlssonaaeef072010-01-24 05:50:09 +00007085 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007086 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007087
Anders Carlssonaaeef072010-01-24 05:50:09 +00007088 // Transform the output expr.
7089 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007090 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007091 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007092 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007093
Anders Carlssonaaeef072010-01-24 05:50:09 +00007094 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007095
John McCallb268a282010-08-23 23:25:46 +00007096 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007098
Anders Carlssonaaeef072010-01-24 05:50:09 +00007099 // Go through the inputs.
7100 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007101 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007102
Anders Carlssonaaeef072010-01-24 05:50:09 +00007103 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007104 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007105
Anders Carlssonaaeef072010-01-24 05:50:09 +00007106 // Transform the input expr.
7107 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007108 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007109 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007110 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007111
Anders Carlssonaaeef072010-01-24 05:50:09 +00007112 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007113
John McCallb268a282010-08-23 23:25:46 +00007114 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007116
Jennifer Yub8fee672019-06-03 15:57:25 +00007117 // Go through the Labels.
7118 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
7119 Names.push_back(S->getLabelIdentifier(I));
7120
7121 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
7122 if (Result.isInvalid())
7123 return StmtError();
7124 ExprsChanged |= Result.get() != S->getLabelExpr(I);
7125 Exprs.push_back(Result.get());
7126 }
Anders Carlssonaaeef072010-01-24 05:50:09 +00007127 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007128 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007129
7130 // Go through the clobbers.
7131 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00007132 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007133
7134 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007135 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007136 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7137 S->isVolatile(), S->getNumOutputs(),
7138 S->getNumInputs(), Names.data(),
7139 Constraints, Exprs, AsmString.get(),
Jennifer Yub8fee672019-06-03 15:57:25 +00007140 Clobbers, S->getNumLabels(),
7141 S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007142}
7143
Chad Rosier32503022012-06-11 20:47:18 +00007144template<typename Derived>
7145StmtResult
7146TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007147 ArrayRef<Token> AsmToks =
7148 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007149
John McCallf413f5e2013-05-03 00:10:13 +00007150 bool HadError = false, HadChange = false;
7151
7152 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7153 SmallVector<Expr*, 8> TransformedExprs;
7154 TransformedExprs.reserve(SrcExprs.size());
7155 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7156 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7157 if (!Result.isUsable()) {
7158 HadError = true;
7159 } else {
7160 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007161 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007162 }
7163 }
7164
7165 if (HadError) return StmtError();
7166 if (!HadChange && !getDerived().AlwaysRebuild())
7167 return Owned(S);
7168
Chad Rosierb6f46c12012-08-15 16:53:30 +00007169 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007170 AsmToks, S->getAsmString(),
7171 S->getNumOutputs(), S->getNumInputs(),
7172 S->getAllConstraints(), S->getClobbers(),
7173 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007174}
Douglas Gregorebe10102009-08-20 07:17:43 +00007175
Richard Smith9f690bd2015-10-27 06:02:45 +00007176// C++ Coroutines TS
7177
7178template<typename Derived>
7179StmtResult
7180TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007181 auto *ScopeInfo = SemaRef.getCurFunction();
7182 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007183 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007184 ScopeInfo->NeedsCoroutineSuspends &&
7185 ScopeInfo->CoroutineSuspends.first == nullptr &&
7186 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007187 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007188
7189 // Set that we have (possibly-invalid) suspend points before we do anything
7190 // that may fail.
7191 ScopeInfo->setNeedsCoroutineSuspends(false);
7192
7193 // The new CoroutinePromise object needs to be built and put into the current
7194 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007195 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7196 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007197 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7198 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007199 return StmtError();
Richard Smithb2997f52019-05-21 20:10:50 +00007200 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
Eric Fiselierbee782b2017-04-03 19:21:00 +00007201 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007202
7203 // Transform the implicit coroutine statements we built during the initial
7204 // parse.
7205 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7206 if (InitSuspend.isInvalid())
7207 return StmtError();
7208 StmtResult FinalSuspend =
7209 getDerived().TransformStmt(S->getFinalSuspendStmt());
7210 if (FinalSuspend.isInvalid())
7211 return StmtError();
7212 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7213 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007214
7215 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7216 if (BodyRes.isInvalid())
7217 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007218
Eric Fiselierbee782b2017-04-03 19:21:00 +00007219 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7220 if (Builder.isInvalid())
7221 return StmtError();
7222
7223 Expr *ReturnObject = S->getReturnValueInit();
7224 assert(ReturnObject && "the return object is expected to be valid");
7225 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7226 /*NoCopyInit*/ false);
7227 if (Res.isInvalid())
7228 return StmtError();
7229 Builder.ReturnValue = Res.get();
7230
7231 if (S->hasDependentPromiseType()) {
Brian Gesiak38f11822019-06-03 00:47:32 +00007232 // PR41909: We may find a generic coroutine lambda definition within a
7233 // template function that is being instantiated. In this case, the lambda
7234 // will have a dependent promise type, until it is used in an expression
7235 // that creates an instantiation with a non-dependent promise type. We
7236 // should not assert or build coroutine dependent statements for such a
7237 // generic lambda.
7238 auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD);
7239 if (!MD || !MD->getParent()->isGenericLambda()) {
7240 assert(!Promise->getType()->isDependentType() &&
7241 "the promise type must no longer be dependent");
7242 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7243 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7244 "these nodes should not have been built yet");
7245 if (!Builder.buildDependentStatements())
7246 return StmtError();
7247 }
Eric Fiselierbee782b2017-04-03 19:21:00 +00007248 } else {
7249 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7250 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7251 if (Res.isInvalid())
7252 return StmtError();
7253 Builder.OnFallthrough = Res.get();
7254 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007255
Eric Fiselierbee782b2017-04-03 19:21:00 +00007256 if (auto *OnException = S->getExceptionHandler()) {
7257 StmtResult Res = getDerived().TransformStmt(OnException);
7258 if (Res.isInvalid())
7259 return StmtError();
7260 Builder.OnException = Res.get();
7261 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007262
Eric Fiselierbee782b2017-04-03 19:21:00 +00007263 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7264 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7265 if (Res.isInvalid())
7266 return StmtError();
7267 Builder.ReturnStmtOnAllocFailure = Res.get();
7268 }
7269
7270 // Transform any additional statements we may have already built
7271 assert(S->getAllocate() && S->getDeallocate() &&
7272 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007273 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7274 if (AllocRes.isInvalid())
7275 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007276 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007277
7278 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7279 if (DeallocRes.isInvalid())
7280 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007281 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007282
7283 assert(S->getResultDecl() && "ResultDecl must already be built");
7284 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7285 if (ResultDecl.isInvalid())
7286 return StmtError();
7287 Builder.ResultDecl = ResultDecl.get();
7288
7289 if (auto *ReturnStmt = S->getReturnStmt()) {
7290 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7291 if (Res.isInvalid())
7292 return StmtError();
7293 Builder.ReturnStmt = Res.get();
7294 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007295 }
7296
Eric Fiselierbee782b2017-04-03 19:21:00 +00007297 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007298}
7299
7300template<typename Derived>
7301StmtResult
7302TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7303 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7304 /*NotCopyInit*/false);
7305 if (Result.isInvalid())
7306 return StmtError();
7307
7308 // Always rebuild; we don't know if this needs to be injected into a new
7309 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007310 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7311 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007312}
7313
7314template<typename Derived>
7315ExprResult
7316TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7317 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7318 /*NotCopyInit*/false);
7319 if (Result.isInvalid())
7320 return ExprError();
7321
7322 // Always rebuild; we don't know if this needs to be injected into a new
7323 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007324 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7325 E->isImplicit());
7326}
7327
7328template <typename Derived>
7329ExprResult
7330TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7331 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7332 /*NotCopyInit*/ false);
7333 if (OperandResult.isInvalid())
7334 return ExprError();
7335
7336 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7337 E->getOperatorCoawaitLookup());
7338
7339 if (LookupResult.isInvalid())
7340 return ExprError();
7341
7342 // Always rebuild; we don't know if this needs to be injected into a new
7343 // context or if the promise type has changed.
7344 return getDerived().RebuildDependentCoawaitExpr(
7345 E->getKeywordLoc(), OperandResult.get(),
7346 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007347}
7348
7349template<typename Derived>
7350ExprResult
7351TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7352 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7353 /*NotCopyInit*/false);
7354 if (Result.isInvalid())
7355 return ExprError();
7356
7357 // Always rebuild; we don't know if this needs to be injected into a new
7358 // context or if the promise type has changed.
7359 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7360}
7361
7362// Objective-C Statements.
7363
Douglas Gregorebe10102009-08-20 07:17:43 +00007364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007365StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007366TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007367 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007368 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007369 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007370 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007371
Douglas Gregor96c79492010-04-23 22:50:49 +00007372 // Transform the @catch statements (if present).
7373 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007374 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007375 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007376 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007377 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007378 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007379 if (Catch.get() != S->getCatchStmt(I))
7380 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007381 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007383
Douglas Gregor306de2f2010-04-22 23:59:56 +00007384 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007385 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007386 if (S->getFinallyStmt()) {
7387 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7388 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007389 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007390 }
7391
7392 // If nothing changed, just retain this statement.
7393 if (!getDerived().AlwaysRebuild() &&
7394 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007395 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007396 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007397 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007398
Douglas Gregor306de2f2010-04-22 23:59:56 +00007399 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007400 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007401 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregorebe10102009-08-20 07:17:43 +00007404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007406TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007407 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007408 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007409 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007410 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007411 if (FromVar->getTypeSourceInfo()) {
7412 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7413 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007414 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007416
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007417 QualType T;
7418 if (TSInfo)
7419 T = TSInfo->getType();
7420 else {
7421 T = getDerived().TransformType(FromVar->getType());
7422 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007423 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007425
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007426 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7427 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007428 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007429 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007430
John McCalldadc5752010-08-24 06:29:42 +00007431 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007432 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007433 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007434
7435 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007436 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007437 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007438}
Mike Stump11289f42009-09-09 15:08:12 +00007439
Douglas Gregorebe10102009-08-20 07:17:43 +00007440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007442TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007443 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007444 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007445 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007446 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007447
Douglas Gregor306de2f2010-04-22 23:59:56 +00007448 // If nothing changed, just retain this statement.
7449 if (!getDerived().AlwaysRebuild() &&
7450 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007451 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007452
7453 // Build a new statement.
7454 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007455 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007456}
Mike Stump11289f42009-09-09 15:08:12 +00007457
Douglas Gregorebe10102009-08-20 07:17:43 +00007458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007459StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007460TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007461 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007462 if (S->getThrowExpr()) {
7463 Operand = getDerived().TransformExpr(S->getThrowExpr());
7464 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007465 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007467
Douglas Gregor2900c162010-04-22 21:44:01 +00007468 if (!getDerived().AlwaysRebuild() &&
7469 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007470 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007471
John McCallb268a282010-08-23 23:25:46 +00007472 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007473}
Mike Stump11289f42009-09-09 15:08:12 +00007474
Douglas Gregorebe10102009-08-20 07:17:43 +00007475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007476StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007477TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007478 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007479 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007480 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007481 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007482 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007483 Object =
7484 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7485 Object.get());
7486 if (Object.isInvalid())
7487 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007488
Douglas Gregor6148de72010-04-22 22:01:21 +00007489 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007490 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007491 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007492 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007493
Douglas Gregor6148de72010-04-22 22:01:21 +00007494 // If nothing change, just retain the current statement.
7495 if (!getDerived().AlwaysRebuild() &&
7496 Object.get() == S->getSynchExpr() &&
7497 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007498 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007499
7500 // Build a new statement.
7501 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007502 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007503}
7504
7505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007506StmtResult
John McCall31168b02011-06-15 23:02:42 +00007507TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7508 ObjCAutoreleasePoolStmt *S) {
7509 // Transform the body.
7510 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7511 if (Body.isInvalid())
7512 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007513
John McCall31168b02011-06-15 23:02:42 +00007514 // If nothing changed, just retain this statement.
7515 if (!getDerived().AlwaysRebuild() &&
7516 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007517 return S;
John McCall31168b02011-06-15 23:02:42 +00007518
7519 // Build a new statement.
7520 return getDerived().RebuildObjCAutoreleasePoolStmt(
7521 S->getAtLoc(), Body.get());
7522}
7523
7524template<typename Derived>
7525StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007526TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007527 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007528 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007529 StmtResult Element =
7530 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007531 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007532 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007533
Douglas Gregorf68a5082010-04-22 23:10:45 +00007534 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007535 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007536 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007537 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007538
Douglas Gregorf68a5082010-04-22 23:10:45 +00007539 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007540 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007541 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007543
Douglas Gregorf68a5082010-04-22 23:10:45 +00007544 // If nothing changed, just retain this statement.
7545 if (!getDerived().AlwaysRebuild() &&
7546 Element.get() == S->getElement() &&
7547 Collection.get() == S->getCollection() &&
7548 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007549 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007550
Douglas Gregorf68a5082010-04-22 23:10:45 +00007551 // Build a new statement.
7552 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007553 Element.get(),
7554 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007555 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007556 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007557}
7558
David Majnemer5f7efef2013-10-15 09:50:08 +00007559template <typename Derived>
7560StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007561 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007562 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007563 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7564 TypeSourceInfo *T =
7565 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007566 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007567 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007568
David Majnemer5f7efef2013-10-15 09:50:08 +00007569 Var = getDerived().RebuildExceptionDecl(
7570 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7571 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007572 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007573 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007574 }
Mike Stump11289f42009-09-09 15:08:12 +00007575
Douglas Gregorebe10102009-08-20 07:17:43 +00007576 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007577 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007578 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007579 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007580
David Majnemer5f7efef2013-10-15 09:50:08 +00007581 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007582 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007583 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007584
David Majnemer5f7efef2013-10-15 09:50:08 +00007585 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007586}
Mike Stump11289f42009-09-09 15:08:12 +00007587
David Majnemer5f7efef2013-10-15 09:50:08 +00007588template <typename Derived>
7589StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007590 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007591 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007592 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007593 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007594
Douglas Gregorebe10102009-08-20 07:17:43 +00007595 // Transform the handlers.
7596 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007597 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007598 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007599 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007600 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007602
Douglas Gregorebe10102009-08-20 07:17:43 +00007603 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007604 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007605 }
Mike Stump11289f42009-09-09 15:08:12 +00007606
David Majnemer5f7efef2013-10-15 09:50:08 +00007607 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007608 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007609 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007610
John McCallb268a282010-08-23 23:25:46 +00007611 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007612 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007613}
Mike Stump11289f42009-09-09 15:08:12 +00007614
Richard Smith02e85f32011-04-14 22:09:26 +00007615template<typename Derived>
7616StmtResult
7617TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007618 StmtResult Init =
7619 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7620 if (Init.isInvalid())
7621 return StmtError();
7622
Richard Smith02e85f32011-04-14 22:09:26 +00007623 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7624 if (Range.isInvalid())
7625 return StmtError();
7626
Richard Smith01694c32016-03-20 10:33:40 +00007627 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7628 if (Begin.isInvalid())
7629 return StmtError();
7630 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7631 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007632 return StmtError();
7633
7634 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7635 if (Cond.isInvalid())
7636 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007637 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007638 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007639 if (Cond.isInvalid())
7640 return StmtError();
7641 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007642 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007643
7644 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7645 if (Inc.isInvalid())
7646 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007647 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007648 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007649
7650 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7651 if (LoopVar.isInvalid())
7652 return StmtError();
7653
7654 StmtResult NewStmt = S;
7655 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007656 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007657 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007658 Begin.get() != S->getBeginStmt() ||
7659 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007660 Cond.get() != S->getCond() ||
7661 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007662 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007663 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007664 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007665 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007666 Begin.get(), End.get(),
7667 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007668 Inc.get(), LoopVar.get(),
7669 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007670 if (NewStmt.isInvalid())
7671 return StmtError();
7672 }
Richard Smith02e85f32011-04-14 22:09:26 +00007673
7674 StmtResult Body = getDerived().TransformStmt(S->getBody());
7675 if (Body.isInvalid())
7676 return StmtError();
7677
7678 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7679 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007680 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007681 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007682 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007683 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007684 Begin.get(), End.get(),
7685 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007686 Inc.get(), LoopVar.get(),
7687 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007688 if (NewStmt.isInvalid())
7689 return StmtError();
7690 }
Richard Smith02e85f32011-04-14 22:09:26 +00007691
7692 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007693 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007694
7695 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7696}
7697
John Wiegley1c0675e2011-04-28 01:08:34 +00007698template<typename Derived>
7699StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007700TreeTransform<Derived>::TransformMSDependentExistsStmt(
7701 MSDependentExistsStmt *S) {
7702 // Transform the nested-name-specifier, if any.
7703 NestedNameSpecifierLoc QualifierLoc;
7704 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007705 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007706 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7707 if (!QualifierLoc)
7708 return StmtError();
7709 }
7710
7711 // Transform the declaration name.
7712 DeclarationNameInfo NameInfo = S->getNameInfo();
7713 if (NameInfo.getName()) {
7714 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7715 if (!NameInfo.getName())
7716 return StmtError();
7717 }
7718
7719 // Check whether anything changed.
7720 if (!getDerived().AlwaysRebuild() &&
7721 QualifierLoc == S->getQualifierLoc() &&
7722 NameInfo.getName() == S->getNameInfo().getName())
7723 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007724
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007725 // Determine whether this name exists, if we can.
7726 CXXScopeSpec SS;
7727 SS.Adopt(QualifierLoc);
7728 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007729 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007730 case Sema::IER_Exists:
7731 if (S->isIfExists())
7732 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007733
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007734 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7735
7736 case Sema::IER_DoesNotExist:
7737 if (S->isIfNotExists())
7738 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007739
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007740 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007741
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007742 case Sema::IER_Dependent:
7743 Dependent = true;
7744 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007745
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007746 case Sema::IER_Error:
7747 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007748 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007749
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007750 // We need to continue with the instantiation, so do so now.
7751 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7752 if (SubStmt.isInvalid())
7753 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007754
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007755 // If we have resolved the name, just transform to the substatement.
7756 if (!Dependent)
7757 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007758
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007759 // The name is still dependent, so build a dependent expression again.
7760 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7761 S->isIfExists(),
7762 QualifierLoc,
7763 NameInfo,
7764 SubStmt.get());
7765}
7766
7767template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007768ExprResult
7769TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7770 NestedNameSpecifierLoc QualifierLoc;
7771 if (E->getQualifierLoc()) {
7772 QualifierLoc
7773 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7774 if (!QualifierLoc)
7775 return ExprError();
7776 }
7777
7778 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7779 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7780 if (!PD)
7781 return ExprError();
7782
7783 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7784 if (Base.isInvalid())
7785 return ExprError();
7786
7787 return new (SemaRef.getASTContext())
7788 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7789 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7790 QualifierLoc, E->getMemberLoc());
7791}
7792
David Majnemerfad8f482013-10-15 09:33:02 +00007793template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007794ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7795 MSPropertySubscriptExpr *E) {
7796 auto BaseRes = getDerived().TransformExpr(E->getBase());
7797 if (BaseRes.isInvalid())
7798 return ExprError();
7799 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7800 if (IdxRes.isInvalid())
7801 return ExprError();
7802
7803 if (!getDerived().AlwaysRebuild() &&
7804 BaseRes.get() == E->getBase() &&
7805 IdxRes.get() == E->getIdx())
7806 return E;
7807
7808 return getDerived().RebuildArraySubscriptExpr(
7809 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7810}
7811
7812template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007813StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007814 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007815 if (TryBlock.isInvalid())
7816 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007817
7818 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007819 if (Handler.isInvalid())
7820 return StmtError();
7821
David Majnemerfad8f482013-10-15 09:33:02 +00007822 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7823 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007824 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007825
Warren Huntf6be4cb2014-07-25 20:52:51 +00007826 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7827 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007828}
7829
David Majnemerfad8f482013-10-15 09:33:02 +00007830template <typename Derived>
7831StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007832 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007833 if (Block.isInvalid())
7834 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007835
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007836 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007837}
7838
David Majnemerfad8f482013-10-15 09:33:02 +00007839template <typename Derived>
7840StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007841 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007842 if (FilterExpr.isInvalid())
7843 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007844
David Majnemer7e755502013-10-15 09:30:14 +00007845 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007846 if (Block.isInvalid())
7847 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007848
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007849 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7850 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007851}
7852
David Majnemerfad8f482013-10-15 09:33:02 +00007853template <typename Derived>
7854StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7855 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007856 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7857 else
7858 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7859}
7860
Nico Weber9b982072014-07-07 00:12:30 +00007861template<typename Derived>
7862StmtResult
7863TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7864 return S;
7865}
7866
Alexander Musman64d33f12014-06-04 07:53:32 +00007867//===----------------------------------------------------------------------===//
7868// OpenMP directive transformation
7869//===----------------------------------------------------------------------===//
7870template <typename Derived>
7871StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7872 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007873
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007874 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007875 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007876 ArrayRef<OMPClause *> Clauses = D->clauses();
7877 TClauses.reserve(Clauses.size());
7878 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7879 I != E; ++I) {
7880 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007881 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007882 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007883 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007884 if (Clause)
7885 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007886 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007887 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007888 }
7889 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007890 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007891 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007892 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7893 /*CurScope=*/nullptr);
7894 StmtResult Body;
7895 {
7896 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007897 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007898 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007899 }
7900 AssociatedStmt =
7901 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007902 if (AssociatedStmt.isInvalid()) {
7903 return StmtError();
7904 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007905 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007906 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007907 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007908 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007909
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007910 // Transform directive name for 'omp critical' directive.
7911 DeclarationNameInfo DirName;
7912 if (D->getDirectiveKind() == OMPD_critical) {
7913 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7914 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7915 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007916 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7917 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7918 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007919 } else if (D->getDirectiveKind() == OMPD_cancel) {
7920 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007921 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007922
Alexander Musman64d33f12014-06-04 07:53:32 +00007923 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007924 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007925 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007926}
7927
Alexander Musman64d33f12014-06-04 07:53:32 +00007928template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007929StmtResult
7930TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7931 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007932 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007933 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7936 return Res;
7937}
7938
Alexander Musman64d33f12014-06-04 07:53:32 +00007939template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007940StmtResult
7941TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7942 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007943 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007944 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007947 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007948}
7949
Alexey Bataevf29276e2014-06-18 04:14:57 +00007950template <typename Derived>
7951StmtResult
7952TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7953 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007954 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007955 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7957 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7958 return Res;
7959}
7960
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007961template <typename Derived>
7962StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007963TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7964 DeclarationNameInfo DirName;
7965 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007966 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7969 return Res;
7970}
7971
7972template <typename Derived>
7973StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007974TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7975 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007976 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007977 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7980 return Res;
7981}
7982
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007983template <typename Derived>
7984StmtResult
7985TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7986 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007987 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007988 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7991 return Res;
7992}
7993
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007994template <typename Derived>
7995StmtResult
7996TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7997 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007998 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007999 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00008000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8001 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8002 return Res;
8003}
8004
Alexey Bataev4acb8592014-07-07 13:01:15 +00008005template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00008006StmtResult
8007TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
8008 DeclarationNameInfo DirName;
8009 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008010 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00008011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8013 return Res;
8014}
8015
8016template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00008017StmtResult
8018TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
8019 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008020 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00008021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8023 return Res;
8024}
8025
8026template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00008027StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
8028 OMPParallelForDirective *D) {
8029 DeclarationNameInfo DirName;
8030 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008031 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00008032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8034 return Res;
8035}
8036
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008037template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00008038StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
8039 OMPParallelForSimdDirective *D) {
8040 DeclarationNameInfo DirName;
8041 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008042 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00008043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8045 return Res;
8046}
8047
8048template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008049StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
8050 OMPParallelSectionsDirective *D) {
8051 DeclarationNameInfo DirName;
8052 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008053 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8056 return Res;
8057}
8058
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008059template <typename Derived>
8060StmtResult
8061TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
8062 DeclarationNameInfo DirName;
8063 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008064 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8067 return Res;
8068}
8069
Alexey Bataev68446b72014-07-18 07:47:19 +00008070template <typename Derived>
8071StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8072 OMPTaskyieldDirective *D) {
8073 DeclarationNameInfo DirName;
8074 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008075 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00008076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8078 return Res;
8079}
8080
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008081template <typename Derived>
8082StmtResult
8083TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8084 DeclarationNameInfo DirName;
8085 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008086 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8089 return Res;
8090}
8091
Alexey Bataev2df347a2014-07-18 10:17:07 +00008092template <typename Derived>
8093StmtResult
8094TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8095 DeclarationNameInfo DirName;
8096 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008097 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00008098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8100 return Res;
8101}
8102
Alexey Bataev6125da92014-07-21 11:26:11 +00008103template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008104StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8105 OMPTaskgroupDirective *D) {
8106 DeclarationNameInfo DirName;
8107 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008108 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8111 return Res;
8112}
8113
8114template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00008115StmtResult
8116TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8117 DeclarationNameInfo DirName;
8118 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008119 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8122 return Res;
8123}
8124
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008125template <typename Derived>
8126StmtResult
8127TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8128 DeclarationNameInfo DirName;
8129 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008130 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8133 return Res;
8134}
8135
Alexey Bataev0162e452014-07-22 10:10:35 +00008136template <typename Derived>
8137StmtResult
8138TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8139 DeclarationNameInfo DirName;
8140 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008141 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00008142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8144 return Res;
8145}
8146
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008147template <typename Derived>
8148StmtResult
8149TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8150 DeclarationNameInfo DirName;
8151 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008152 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8155 return Res;
8156}
8157
Alexey Bataev13314bf2014-10-09 04:18:56 +00008158template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008159StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8160 OMPTargetDataDirective *D) {
8161 DeclarationNameInfo DirName;
8162 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008163 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8166 return Res;
8167}
8168
8169template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008170StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8171 OMPTargetEnterDataDirective *D) {
8172 DeclarationNameInfo DirName;
8173 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008174 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8177 return Res;
8178}
8179
8180template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008181StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8182 OMPTargetExitDataDirective *D) {
8183 DeclarationNameInfo DirName;
8184 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008185 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8188 return Res;
8189}
8190
8191template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008192StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8193 OMPTargetParallelDirective *D) {
8194 DeclarationNameInfo DirName;
8195 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008196 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8199 return Res;
8200}
8201
8202template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008203StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8204 OMPTargetParallelForDirective *D) {
8205 DeclarationNameInfo DirName;
8206 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008207 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8210 return Res;
8211}
8212
8213template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008214StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8215 OMPTargetUpdateDirective *D) {
8216 DeclarationNameInfo DirName;
8217 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008218 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8221 return Res;
8222}
8223
8224template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008225StmtResult
8226TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8227 DeclarationNameInfo DirName;
8228 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008229 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8232 return Res;
8233}
8234
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008235template <typename Derived>
8236StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8237 OMPCancellationPointDirective *D) {
8238 DeclarationNameInfo DirName;
8239 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008240 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008241 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8243 return Res;
8244}
8245
Alexey Bataev80909872015-07-02 11:25:17 +00008246template <typename Derived>
8247StmtResult
8248TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8249 DeclarationNameInfo DirName;
8250 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008251 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008252 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8253 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8254 return Res;
8255}
8256
Alexey Bataev49f6e782015-12-01 04:18:41 +00008257template <typename Derived>
8258StmtResult
8259TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8260 DeclarationNameInfo DirName;
8261 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008262 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008263 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8264 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8265 return Res;
8266}
8267
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008268template <typename Derived>
8269StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8270 OMPTaskLoopSimdDirective *D) {
8271 DeclarationNameInfo DirName;
8272 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008273 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008274 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8275 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8276 return Res;
8277}
8278
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008279template <typename Derived>
Alexey Bataev60e51c42019-10-10 20:13:02 +00008280StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
8281 OMPMasterTaskLoopDirective *D) {
8282 DeclarationNameInfo DirName;
8283 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName,
8284 nullptr, D->getBeginLoc());
8285 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8286 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8287 return Res;
8288}
8289
8290template <typename Derived>
Alexey Bataevb8552ab2019-10-18 16:47:35 +00008291StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
8292 OMPMasterTaskLoopSimdDirective *D) {
8293 DeclarationNameInfo DirName;
8294 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName,
8295 nullptr, D->getBeginLoc());
8296 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8297 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8298 return Res;
8299}
8300
8301template <typename Derived>
Alexey Bataev5bbcead2019-10-14 17:17:41 +00008302StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
8303 OMPParallelMasterTaskLoopDirective *D) {
8304 DeclarationNameInfo DirName;
8305 getDerived().getSema().StartOpenMPDSABlock(
8306 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
8307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8309 return Res;
8310}
8311
8312template <typename Derived>
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008313StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8314 OMPDistributeDirective *D) {
8315 DeclarationNameInfo DirName;
8316 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008317 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008318 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8319 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8320 return Res;
8321}
8322
Carlo Bertolli9925f152016-06-27 14:55:37 +00008323template <typename Derived>
8324StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8325 OMPDistributeParallelForDirective *D) {
8326 DeclarationNameInfo DirName;
8327 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008328 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008329 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8330 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8331 return Res;
8332}
8333
Kelvin Li4a39add2016-07-05 05:00:15 +00008334template <typename Derived>
8335StmtResult
8336TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8337 OMPDistributeParallelForSimdDirective *D) {
8338 DeclarationNameInfo DirName;
8339 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008340 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008341 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8342 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8343 return Res;
8344}
8345
Kelvin Li787f3fc2016-07-06 04:45:38 +00008346template <typename Derived>
8347StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8348 OMPDistributeSimdDirective *D) {
8349 DeclarationNameInfo DirName;
8350 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008351 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008352 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8353 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8354 return Res;
8355}
8356
Kelvin Lia579b912016-07-14 02:54:56 +00008357template <typename Derived>
8358StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8359 OMPTargetParallelForSimdDirective *D) {
8360 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008361 getDerived().getSema().StartOpenMPDSABlock(
8362 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008363 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8364 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8365 return Res;
8366}
8367
Kelvin Li986330c2016-07-20 22:57:10 +00008368template <typename Derived>
8369StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8370 OMPTargetSimdDirective *D) {
8371 DeclarationNameInfo DirName;
8372 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008373 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008374 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8375 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8376 return Res;
8377}
8378
Kelvin Li02532872016-08-05 14:37:37 +00008379template <typename Derived>
8380StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8381 OMPTeamsDistributeDirective *D) {
8382 DeclarationNameInfo DirName;
8383 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008384 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008385 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8386 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8387 return Res;
8388}
8389
Kelvin Li4e325f72016-10-25 12:50:55 +00008390template <typename Derived>
8391StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8392 OMPTeamsDistributeSimdDirective *D) {
8393 DeclarationNameInfo DirName;
8394 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008395 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008396 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8397 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8398 return Res;
8399}
8400
Kelvin Li579e41c2016-11-30 23:51:03 +00008401template <typename Derived>
8402StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8403 OMPTeamsDistributeParallelForSimdDirective *D) {
8404 DeclarationNameInfo DirName;
8405 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008406 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8407 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008408 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8409 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8410 return Res;
8411}
8412
Kelvin Li7ade93f2016-12-09 03:24:30 +00008413template <typename Derived>
8414StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8415 OMPTeamsDistributeParallelForDirective *D) {
8416 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008417 getDerived().getSema().StartOpenMPDSABlock(
8418 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008419 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8420 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8421 return Res;
8422}
8423
Kelvin Libf594a52016-12-17 05:48:59 +00008424template <typename Derived>
8425StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8426 OMPTargetTeamsDirective *D) {
8427 DeclarationNameInfo DirName;
8428 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008429 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008430 auto Res = getDerived().TransformOMPExecutableDirective(D);
8431 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8432 return Res;
8433}
Kelvin Li579e41c2016-11-30 23:51:03 +00008434
Kelvin Li83c451e2016-12-25 04:52:54 +00008435template <typename Derived>
8436StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8437 OMPTargetTeamsDistributeDirective *D) {
8438 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008439 getDerived().getSema().StartOpenMPDSABlock(
8440 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008441 auto Res = getDerived().TransformOMPExecutableDirective(D);
8442 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8443 return Res;
8444}
8445
Kelvin Li80e8f562016-12-29 22:16:30 +00008446template <typename Derived>
8447StmtResult
8448TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8449 OMPTargetTeamsDistributeParallelForDirective *D) {
8450 DeclarationNameInfo DirName;
8451 getDerived().getSema().StartOpenMPDSABlock(
8452 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008453 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008454 auto Res = getDerived().TransformOMPExecutableDirective(D);
8455 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8456 return Res;
8457}
8458
Kelvin Li1851df52017-01-03 05:23:48 +00008459template <typename Derived>
8460StmtResult TreeTransform<Derived>::
8461 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8462 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8463 DeclarationNameInfo DirName;
8464 getDerived().getSema().StartOpenMPDSABlock(
8465 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008466 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008467 auto Res = getDerived().TransformOMPExecutableDirective(D);
8468 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8469 return Res;
8470}
8471
Kelvin Lida681182017-01-10 18:08:18 +00008472template <typename Derived>
8473StmtResult
8474TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8475 OMPTargetTeamsDistributeSimdDirective *D) {
8476 DeclarationNameInfo DirName;
8477 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008478 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008479 auto Res = getDerived().TransformOMPExecutableDirective(D);
8480 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8481 return Res;
8482}
8483
Kelvin Li1851df52017-01-03 05:23:48 +00008484
Alexander Musman64d33f12014-06-04 07:53:32 +00008485//===----------------------------------------------------------------------===//
8486// OpenMP clause transformation
8487//===----------------------------------------------------------------------===//
8488template <typename Derived>
8489OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008490 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8491 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008492 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008493 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008494 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008495 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008496}
8497
Alexander Musman64d33f12014-06-04 07:53:32 +00008498template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008499OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8500 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8501 if (Cond.isInvalid())
8502 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008503 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008504 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008505}
8506
8507template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008508OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008509TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8510 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8511 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008512 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008513 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008514 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008515}
8516
Alexey Bataev62c87d22014-03-21 04:51:18 +00008517template <typename Derived>
8518OMPClause *
8519TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8520 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8521 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008522 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008523 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008524 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008525}
8526
Alexander Musman8bd31e62014-05-27 15:12:19 +00008527template <typename Derived>
8528OMPClause *
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00008529TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
8530 ExprResult E = getDerived().TransformExpr(C->getAllocator());
8531 if (E.isInvalid())
8532 return nullptr;
8533 return getDerived().RebuildOMPAllocatorClause(
8534 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
8535}
8536
8537template <typename Derived>
8538OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008539TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8540 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8541 if (E.isInvalid())
8542 return nullptr;
8543 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008544 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008545}
8546
8547template <typename Derived>
8548OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008549TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8550 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8551 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008552 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008553 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008554 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008555}
8556
Alexander Musman64d33f12014-06-04 07:53:32 +00008557template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008558OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008559TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008560 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008561 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008562 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008563}
8564
Alexander Musman64d33f12014-06-04 07:53:32 +00008565template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008566OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008567TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008568 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008569 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008570 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008571}
8572
Alexander Musman64d33f12014-06-04 07:53:32 +00008573template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008574OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008575TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8576 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8577 if (E.isInvalid())
8578 return nullptr;
8579 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008580 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008581 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008582 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008583 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008584}
8585
8586template <typename Derived>
8587OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008588TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008589 ExprResult E;
8590 if (auto *Num = C->getNumForLoops()) {
8591 E = getDerived().TransformExpr(Num);
8592 if (E.isInvalid())
8593 return nullptr;
8594 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008595 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008596 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008597}
8598
8599template <typename Derived>
8600OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008601TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8602 // No need to rebuild this clause, no template-dependent parameters.
8603 return C;
8604}
8605
8606template <typename Derived>
8607OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008608TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8609 // No need to rebuild this clause, no template-dependent parameters.
8610 return C;
8611}
8612
8613template <typename Derived>
8614OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008615TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8616 // No need to rebuild this clause, no template-dependent parameters.
8617 return C;
8618}
8619
8620template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008621OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8622 // No need to rebuild this clause, no template-dependent parameters.
8623 return C;
8624}
8625
8626template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008627OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8628 // No need to rebuild this clause, no template-dependent parameters.
8629 return C;
8630}
8631
8632template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008633OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008634TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8635 // No need to rebuild this clause, no template-dependent parameters.
8636 return C;
8637}
8638
8639template <typename Derived>
8640OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008641TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8642 // No need to rebuild this clause, no template-dependent parameters.
8643 return C;
8644}
8645
8646template <typename Derived>
8647OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008648TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8649 // No need to rebuild this clause, no template-dependent parameters.
8650 return C;
8651}
8652
8653template <typename Derived>
8654OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008655TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8656 // No need to rebuild this clause, no template-dependent parameters.
8657 return C;
8658}
8659
8660template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008661OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8662 // No need to rebuild this clause, no template-dependent parameters.
8663 return C;
8664}
8665
8666template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008667OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008668TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8669 // No need to rebuild this clause, no template-dependent parameters.
8670 return C;
8671}
8672
8673template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008674OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8675 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008676 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008677}
8678
8679template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008680OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8681 OMPUnifiedSharedMemoryClause *C) {
8682 llvm_unreachable(
8683 "unified_shared_memory clause cannot appear in dependent context");
8684}
8685
8686template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008687OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8688 OMPReverseOffloadClause *C) {
8689 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8690}
8691
8692template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008693OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8694 OMPDynamicAllocatorsClause *C) {
8695 llvm_unreachable(
8696 "dynamic_allocators clause cannot appear in dependent context");
8697}
8698
8699template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008700OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8701 OMPAtomicDefaultMemOrderClause *C) {
8702 llvm_unreachable(
8703 "atomic_default_mem_order clause cannot appear in dependent context");
8704}
8705
8706template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008707OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008708TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008709 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008710 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008711 for (auto *VE : C->varlists()) {
8712 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008713 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008714 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008715 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008716 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008717 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008718 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008719}
8720
Alexander Musman64d33f12014-06-04 07:53:32 +00008721template <typename Derived>
8722OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8723 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008724 llvm::SmallVector<Expr *, 16> Vars;
8725 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008726 for (auto *VE : C->varlists()) {
8727 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008728 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008729 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008730 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008731 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008732 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008733 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008734}
8735
Alexander Musman64d33f12014-06-04 07:53:32 +00008736template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008737OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008738TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8739 llvm::SmallVector<Expr *, 16> Vars;
8740 Vars.reserve(C->varlist_size());
8741 for (auto *VE : C->varlists()) {
8742 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8743 if (EVar.isInvalid())
8744 return nullptr;
8745 Vars.push_back(EVar.get());
8746 }
8747 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008748 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008749}
8750
8751template <typename Derived>
8752OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008753TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8754 llvm::SmallVector<Expr *, 16> Vars;
8755 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008756 for (auto *VE : C->varlists()) {
8757 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008758 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008759 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008760 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008761 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008762 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008763 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008764}
8765
Alexander Musman64d33f12014-06-04 07:53:32 +00008766template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008767OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008768TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8769 llvm::SmallVector<Expr *, 16> Vars;
8770 Vars.reserve(C->varlist_size());
8771 for (auto *VE : C->varlists()) {
8772 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8773 if (EVar.isInvalid())
8774 return nullptr;
8775 Vars.push_back(EVar.get());
8776 }
8777 CXXScopeSpec ReductionIdScopeSpec;
8778 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8779
8780 DeclarationNameInfo NameInfo = C->getNameInfo();
8781 if (NameInfo.getName()) {
8782 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8783 if (!NameInfo.getName())
8784 return nullptr;
8785 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008786 // Build a list of all UDR decls with the same names ranged by the Scopes.
8787 // The Scope boundary is a duplication of the previous decl.
8788 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8789 for (auto *E : C->reduction_ops()) {
8790 // Transform all the decls.
8791 if (E) {
8792 auto *ULE = cast<UnresolvedLookupExpr>(E);
8793 UnresolvedSet<8> Decls;
8794 for (auto *D : ULE->decls()) {
8795 NamedDecl *InstD =
8796 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8797 Decls.addDecl(InstD, InstD->getAccess());
8798 }
8799 UnresolvedReductions.push_back(
8800 UnresolvedLookupExpr::Create(
8801 SemaRef.Context, /*NamingClass=*/nullptr,
8802 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8803 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8804 Decls.begin(), Decls.end()));
8805 } else
8806 UnresolvedReductions.push_back(nullptr);
8807 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008808 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008809 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008810 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008811}
8812
8813template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008814OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8815 OMPTaskReductionClause *C) {
8816 llvm::SmallVector<Expr *, 16> Vars;
8817 Vars.reserve(C->varlist_size());
8818 for (auto *VE : C->varlists()) {
8819 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8820 if (EVar.isInvalid())
8821 return nullptr;
8822 Vars.push_back(EVar.get());
8823 }
8824 CXXScopeSpec ReductionIdScopeSpec;
8825 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8826
8827 DeclarationNameInfo NameInfo = C->getNameInfo();
8828 if (NameInfo.getName()) {
8829 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8830 if (!NameInfo.getName())
8831 return nullptr;
8832 }
8833 // Build a list of all UDR decls with the same names ranged by the Scopes.
8834 // The Scope boundary is a duplication of the previous decl.
8835 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8836 for (auto *E : C->reduction_ops()) {
8837 // Transform all the decls.
8838 if (E) {
8839 auto *ULE = cast<UnresolvedLookupExpr>(E);
8840 UnresolvedSet<8> Decls;
8841 for (auto *D : ULE->decls()) {
8842 NamedDecl *InstD =
8843 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8844 Decls.addDecl(InstD, InstD->getAccess());
8845 }
8846 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8847 SemaRef.Context, /*NamingClass=*/nullptr,
8848 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8849 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8850 } else
8851 UnresolvedReductions.push_back(nullptr);
8852 }
8853 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008854 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008855 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008856}
8857
8858template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008859OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008860TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8861 llvm::SmallVector<Expr *, 16> Vars;
8862 Vars.reserve(C->varlist_size());
8863 for (auto *VE : C->varlists()) {
8864 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8865 if (EVar.isInvalid())
8866 return nullptr;
8867 Vars.push_back(EVar.get());
8868 }
8869 CXXScopeSpec ReductionIdScopeSpec;
8870 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8871
8872 DeclarationNameInfo NameInfo = C->getNameInfo();
8873 if (NameInfo.getName()) {
8874 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8875 if (!NameInfo.getName())
8876 return nullptr;
8877 }
8878 // Build a list of all UDR decls with the same names ranged by the Scopes.
8879 // The Scope boundary is a duplication of the previous decl.
8880 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8881 for (auto *E : C->reduction_ops()) {
8882 // Transform all the decls.
8883 if (E) {
8884 auto *ULE = cast<UnresolvedLookupExpr>(E);
8885 UnresolvedSet<8> Decls;
8886 for (auto *D : ULE->decls()) {
8887 NamedDecl *InstD =
8888 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8889 Decls.addDecl(InstD, InstD->getAccess());
8890 }
8891 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8892 SemaRef.Context, /*NamingClass=*/nullptr,
8893 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8894 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8895 } else
8896 UnresolvedReductions.push_back(nullptr);
8897 }
8898 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008899 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008900 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008901}
8902
8903template <typename Derived>
8904OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008905TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8906 llvm::SmallVector<Expr *, 16> Vars;
8907 Vars.reserve(C->varlist_size());
8908 for (auto *VE : C->varlists()) {
8909 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8910 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008911 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008912 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008913 }
8914 ExprResult Step = getDerived().TransformExpr(C->getStep());
8915 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008916 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008917 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008918 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008919 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008920}
8921
Alexander Musman64d33f12014-06-04 07:53:32 +00008922template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008923OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008924TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8925 llvm::SmallVector<Expr *, 16> Vars;
8926 Vars.reserve(C->varlist_size());
8927 for (auto *VE : C->varlists()) {
8928 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8929 if (EVar.isInvalid())
8930 return nullptr;
8931 Vars.push_back(EVar.get());
8932 }
8933 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8934 if (Alignment.isInvalid())
8935 return nullptr;
8936 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008937 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008938 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008939}
8940
Alexander Musman64d33f12014-06-04 07:53:32 +00008941template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008942OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008943TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8944 llvm::SmallVector<Expr *, 16> Vars;
8945 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008946 for (auto *VE : C->varlists()) {
8947 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008948 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008949 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008950 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008951 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008952 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008953 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008954}
8955
Alexey Bataevbae9a792014-06-27 10:37:06 +00008956template <typename Derived>
8957OMPClause *
8958TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8959 llvm::SmallVector<Expr *, 16> Vars;
8960 Vars.reserve(C->varlist_size());
8961 for (auto *VE : C->varlists()) {
8962 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8963 if (EVar.isInvalid())
8964 return nullptr;
8965 Vars.push_back(EVar.get());
8966 }
8967 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008968 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008969}
8970
Alexey Bataev6125da92014-07-21 11:26:11 +00008971template <typename Derived>
8972OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8973 llvm::SmallVector<Expr *, 16> Vars;
8974 Vars.reserve(C->varlist_size());
8975 for (auto *VE : C->varlists()) {
8976 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8977 if (EVar.isInvalid())
8978 return nullptr;
8979 Vars.push_back(EVar.get());
8980 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008981 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008982 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008983}
8984
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008985template <typename Derived>
8986OMPClause *
8987TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8988 llvm::SmallVector<Expr *, 16> Vars;
8989 Vars.reserve(C->varlist_size());
8990 for (auto *VE : C->varlists()) {
8991 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8992 if (EVar.isInvalid())
8993 return nullptr;
8994 Vars.push_back(EVar.get());
8995 }
8996 return getDerived().RebuildOMPDependClause(
8997 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008998 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008999}
9000
Michael Wonge710d542015-08-07 16:16:36 +00009001template <typename Derived>
9002OMPClause *
9003TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
9004 ExprResult E = getDerived().TransformExpr(C->getDevice());
9005 if (E.isInvalid())
9006 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009007 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009008 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00009009}
9010
Michael Kruse01f670d2019-02-22 22:29:42 +00009011template <typename Derived, class T>
9012bool transformOMPMappableExprListClause(
9013 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
9014 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
9015 DeclarationNameInfo &MapperIdInfo,
9016 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
9017 // Transform expressions in the list.
Kelvin Li0bff7af2015-11-23 05:32:03 +00009018 Vars.reserve(C->varlist_size());
9019 for (auto *VE : C->varlists()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00009020 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
Kelvin Li0bff7af2015-11-23 05:32:03 +00009021 if (EVar.isInvalid())
Michael Kruse01f670d2019-02-22 22:29:42 +00009022 return true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00009023 Vars.push_back(EVar.get());
9024 }
Michael Kruse01f670d2019-02-22 22:29:42 +00009025 // Transform mapper scope specifier and identifier.
Michael Kruse4304e9d2019-02-19 16:38:20 +00009026 NestedNameSpecifierLoc QualifierLoc;
9027 if (C->getMapperQualifierLoc()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00009028 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
Michael Kruse4304e9d2019-02-19 16:38:20 +00009029 C->getMapperQualifierLoc());
9030 if (!QualifierLoc)
Michael Kruse01f670d2019-02-22 22:29:42 +00009031 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00009032 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009033 MapperIdScopeSpec.Adopt(QualifierLoc);
Michael Kruse01f670d2019-02-22 22:29:42 +00009034 MapperIdInfo = C->getMapperIdInfo();
Michael Kruse4304e9d2019-02-19 16:38:20 +00009035 if (MapperIdInfo.getName()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00009036 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
Michael Kruse4304e9d2019-02-19 16:38:20 +00009037 if (!MapperIdInfo.getName())
Michael Kruse01f670d2019-02-22 22:29:42 +00009038 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00009039 }
9040 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
9041 // the previous user-defined mapper lookup in dependent environment.
Michael Kruse4304e9d2019-02-19 16:38:20 +00009042 for (auto *E : C->mapperlists()) {
9043 // Transform all the decls.
9044 if (E) {
9045 auto *ULE = cast<UnresolvedLookupExpr>(E);
9046 UnresolvedSet<8> Decls;
9047 for (auto *D : ULE->decls()) {
9048 NamedDecl *InstD =
Michael Kruse01f670d2019-02-22 22:29:42 +00009049 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
Michael Kruse4304e9d2019-02-19 16:38:20 +00009050 Decls.addDecl(InstD, InstD->getAccess());
9051 }
9052 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
Michael Kruse01f670d2019-02-22 22:29:42 +00009053 TT.getSema().Context, /*NamingClass=*/nullptr,
9054 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
9055 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
9056 Decls.end()));
Michael Kruse4304e9d2019-02-19 16:38:20 +00009057 } else {
9058 UnresolvedMappers.push_back(nullptr);
9059 }
9060 }
Michael Kruse01f670d2019-02-22 22:29:42 +00009061 return false;
9062}
9063
9064template <typename Derived>
9065OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009066 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009067 llvm::SmallVector<Expr *, 16> Vars;
9068 CXXScopeSpec MapperIdScopeSpec;
9069 DeclarationNameInfo MapperIdInfo;
9070 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9071 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
9072 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9073 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00009074 return getDerived().RebuildOMPMapClause(
Michael Kruse4304e9d2019-02-19 16:38:20 +00009075 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
9076 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
9077 C->getColonLoc(), Vars, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00009078}
9079
Kelvin Li099bb8c2015-11-24 20:50:12 +00009080template <typename Derived>
9081OMPClause *
Alexey Bataeve04483e2019-03-27 14:14:31 +00009082TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
9083 Expr *Allocator = C->getAllocator();
9084 if (Allocator) {
9085 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
9086 if (AllocatorRes.isInvalid())
9087 return nullptr;
9088 Allocator = AllocatorRes.get();
9089 }
9090 llvm::SmallVector<Expr *, 16> Vars;
9091 Vars.reserve(C->varlist_size());
9092 for (auto *VE : C->varlists()) {
9093 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9094 if (EVar.isInvalid())
9095 return nullptr;
9096 Vars.push_back(EVar.get());
9097 }
9098 return getDerived().RebuildOMPAllocateClause(
9099 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
9100 C->getEndLoc());
9101}
9102
9103template <typename Derived>
9104OMPClause *
Kelvin Li099bb8c2015-11-24 20:50:12 +00009105TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
9106 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
9107 if (E.isInvalid())
9108 return nullptr;
9109 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009110 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00009111}
9112
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009113template <typename Derived>
9114OMPClause *
9115TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
9116 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
9117 if (E.isInvalid())
9118 return nullptr;
9119 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009120 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009121}
9122
Alexey Bataeva0569352015-12-01 10:17:31 +00009123template <typename Derived>
9124OMPClause *
9125TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
9126 ExprResult E = getDerived().TransformExpr(C->getPriority());
9127 if (E.isInvalid())
9128 return nullptr;
9129 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009130 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00009131}
9132
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009133template <typename Derived>
9134OMPClause *
9135TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
9136 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
9137 if (E.isInvalid())
9138 return nullptr;
9139 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009140 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009141}
9142
Alexey Bataev382967a2015-12-08 12:06:20 +00009143template <typename Derived>
9144OMPClause *
9145TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
9146 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
9147 if (E.isInvalid())
9148 return nullptr;
9149 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009150 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00009151}
9152
Alexey Bataev28c75412015-12-15 08:19:24 +00009153template <typename Derived>
9154OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
9155 ExprResult E = getDerived().TransformExpr(C->getHint());
9156 if (E.isInvalid())
9157 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009158 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009159 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00009160}
9161
Carlo Bertollib4adf552016-01-15 18:50:31 +00009162template <typename Derived>
9163OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
9164 OMPDistScheduleClause *C) {
9165 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9166 if (E.isInvalid())
9167 return nullptr;
9168 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009169 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009170 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00009171}
9172
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00009173template <typename Derived>
9174OMPClause *
9175TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
9176 return C;
9177}
9178
Samuel Antao661c0902016-05-26 17:39:58 +00009179template <typename Derived>
9180OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009181 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009182 llvm::SmallVector<Expr *, 16> Vars;
9183 CXXScopeSpec MapperIdScopeSpec;
9184 DeclarationNameInfo MapperIdInfo;
9185 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9186 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
9187 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9188 return nullptr;
9189 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo,
9190 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00009191}
9192
Samuel Antaoec172c62016-05-26 17:49:04 +00009193template <typename Derived>
9194OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009195 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse0336c752019-02-25 20:34:15 +00009196 llvm::SmallVector<Expr *, 16> Vars;
9197 CXXScopeSpec MapperIdScopeSpec;
9198 DeclarationNameInfo MapperIdInfo;
9199 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9200 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
9201 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9202 return nullptr;
9203 return getDerived().RebuildOMPFromClause(
9204 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00009205}
9206
Carlo Bertolli2404b172016-07-13 15:37:16 +00009207template <typename Derived>
9208OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
9209 OMPUseDevicePtrClause *C) {
9210 llvm::SmallVector<Expr *, 16> Vars;
9211 Vars.reserve(C->varlist_size());
9212 for (auto *VE : C->varlists()) {
9213 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9214 if (EVar.isInvalid())
9215 return nullptr;
9216 Vars.push_back(EVar.get());
9217 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009218 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9219 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00009220}
9221
Carlo Bertolli70594e92016-07-13 17:16:49 +00009222template <typename Derived>
9223OMPClause *
9224TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
9225 llvm::SmallVector<Expr *, 16> Vars;
9226 Vars.reserve(C->varlist_size());
9227 for (auto *VE : C->varlists()) {
9228 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9229 if (EVar.isInvalid())
9230 return nullptr;
9231 Vars.push_back(EVar.get());
9232 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009233 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9234 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00009235}
9236
Douglas Gregorebe10102009-08-20 07:17:43 +00009237//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00009238// Expression transformation
9239//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00009240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009241ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00009242TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
9243 return TransformExpr(E->getSubExpr());
9244}
9245
9246template<typename Derived>
9247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009248TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00009249 if (!E->isTypeDependent())
9250 return E;
9251
9252 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00009253 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00009254}
Mike Stump11289f42009-09-09 15:08:12 +00009255
9256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009258TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009259 NestedNameSpecifierLoc QualifierLoc;
9260 if (E->getQualifierLoc()) {
9261 QualifierLoc
9262 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9263 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009264 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009265 }
John McCallce546572009-12-08 09:08:17 +00009266
9267 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009268 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9269 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009270 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009272
Richard Smith57aee092019-08-27 01:06:21 +00009273 NamedDecl *Found = ND;
9274 if (E->getFoundDecl() != E->getDecl()) {
9275 Found = cast_or_null<NamedDecl>(
9276 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
9277 if (!Found)
9278 return ExprError();
9279 }
9280
John McCall815039a2010-08-17 21:27:17 +00009281 DeclarationNameInfo NameInfo = E->getNameInfo();
9282 if (NameInfo.getName()) {
9283 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9284 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009285 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009286 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009287
9288 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009289 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009290 ND == E->getDecl() &&
Richard Smithbf322b72019-09-26 22:28:32 +00009291 Found == E->getFoundDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009292 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009293 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009294
9295 // Mark it referenced in the new context regardless.
9296 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009297 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009298
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009299 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009300 }
John McCallce546572009-12-08 09:08:17 +00009301
Craig Topperc3ec1492014-05-26 06:22:03 +00009302 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009303 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009304 TemplateArgs = &TransArgs;
9305 TransArgs.setLAngleLoc(E->getLAngleLoc());
9306 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009307 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9308 E->getNumTemplateArgs(),
9309 TransArgs))
9310 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009311 }
9312
Chad Rosier1dcde962012-08-08 18:46:20 +00009313 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Richard Smith57aee092019-08-27 01:06:21 +00009314 Found, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009315}
Mike Stump11289f42009-09-09 15:08:12 +00009316
Douglas Gregora16548e2009-08-11 05:31:07 +00009317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009319TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009320 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009321}
Mike Stump11289f42009-09-09 15:08:12 +00009322
Leonard Chandb01c3a2018-06-20 17:19:40 +00009323template <typename Derived>
9324ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9325 FixedPointLiteral *E) {
9326 return E;
9327}
9328
Douglas Gregora16548e2009-08-11 05:31:07 +00009329template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009330ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009331TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009332 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009333}
Mike Stump11289f42009-09-09 15:08:12 +00009334
Douglas Gregora16548e2009-08-11 05:31:07 +00009335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009337TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009338 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009339}
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009342ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009343TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009344 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009345}
Mike Stump11289f42009-09-09 15:08:12 +00009346
Douglas Gregora16548e2009-08-11 05:31:07 +00009347template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009348ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009349TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009350 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009351}
9352
9353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009354ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009355TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009356 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009357 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009358 return SemaRef.MaybeBindToTemporary(E);
9359}
9360
9361template<typename Derived>
9362ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009363TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9364 ExprResult ControllingExpr =
9365 getDerived().TransformExpr(E->getControllingExpr());
9366 if (ControllingExpr.isInvalid())
9367 return ExprError();
9368
Chris Lattner01cf8db2011-07-20 06:58:45 +00009369 SmallVector<Expr *, 4> AssocExprs;
9370 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009371 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9372 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9373 if (TSI) {
9374 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009375 if (!AssocType)
9376 return ExprError();
9377 AssocTypes.push_back(AssocType);
9378 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009379 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009380 }
9381
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009382 ExprResult AssocExpr =
9383 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009384 if (AssocExpr.isInvalid())
9385 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009386 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009387 }
9388
9389 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9390 E->getDefaultLoc(),
9391 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009392 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009393 AssocTypes,
9394 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009395}
9396
9397template<typename Derived>
9398ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009399TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009400 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009401 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009403
Douglas Gregora16548e2009-08-11 05:31:07 +00009404 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009405 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009406
John McCallb268a282010-08-23 23:25:46 +00009407 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009408 E->getRParen());
9409}
9410
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009411/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009412/// allowed to refer to a non-static member of a class even if there's no 'this'
9413/// object available.
9414template<typename Derived>
9415ExprResult
9416TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9417 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009418 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009419 else
9420 return getDerived().TransformExpr(E);
9421}
9422
Mike Stump11289f42009-09-09 15:08:12 +00009423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009424ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009425TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009426 ExprResult SubExpr;
9427 if (E->getOpcode() == UO_AddrOf)
9428 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9429 else
9430 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009431 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009433
Douglas Gregora16548e2009-08-11 05:31:07 +00009434 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009435 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009436
Douglas Gregora16548e2009-08-11 05:31:07 +00009437 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9438 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009439 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009440}
Mike Stump11289f42009-09-09 15:08:12 +00009441
Douglas Gregora16548e2009-08-11 05:31:07 +00009442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009443ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009444TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9445 // Transform the type.
9446 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9447 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009448 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009449
Douglas Gregor882211c2010-04-28 22:16:22 +00009450 // Transform all of the components into components similar to what the
9451 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009452 // FIXME: It would be slightly more efficient in the non-dependent case to
9453 // just map FieldDecls, rather than requiring the rebuilder to look for
9454 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009455 // template code that we don't care.
9456 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009457 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009458 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009459 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009460 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009461 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009462 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009463 Comp.LocStart = ON.getSourceRange().getBegin();
9464 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009465 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009466 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009467 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009468 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009469 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009470 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009471
Douglas Gregor882211c2010-04-28 22:16:22 +00009472 ExprChanged = ExprChanged || Index.get() != FromIndex;
9473 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009474 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009475 break;
9476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009477
James Y Knight7281c352015-12-29 22:31:18 +00009478 case OffsetOfNode::Field:
9479 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009480 Comp.isBrackets = false;
9481 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009482 if (!Comp.U.IdentInfo)
9483 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009484
Douglas Gregor882211c2010-04-28 22:16:22 +00009485 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009486
James Y Knight7281c352015-12-29 22:31:18 +00009487 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009488 // Will be recomputed during the rebuild.
9489 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009491
Douglas Gregor882211c2010-04-28 22:16:22 +00009492 Components.push_back(Comp);
9493 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009494
Douglas Gregor882211c2010-04-28 22:16:22 +00009495 // If nothing changed, retain the existing expression.
9496 if (!getDerived().AlwaysRebuild() &&
9497 Type == E->getTypeSourceInfo() &&
9498 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009499 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009500
Douglas Gregor882211c2010-04-28 22:16:22 +00009501 // Build a new offsetof expression.
9502 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009503 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009504}
9505
9506template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009507ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009508TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009509 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009510 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009511 return E;
John McCall8d69a212010-11-15 23:31:06 +00009512}
9513
9514template<typename Derived>
9515ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009516TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9517 return E;
9518}
9519
9520template<typename Derived>
9521ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009522TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009523 // Rebuild the syntactic form. The original syntactic form has
9524 // opaque-value expressions in it, so strip those away and rebuild
9525 // the result. This is a really awful way of doing this, but the
9526 // better solution (rebuilding the semantic expressions and
9527 // rebinding OVEs as necessary) doesn't work; we'd need
9528 // TreeTransform to not strip away implicit conversions.
9529 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9530 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009531 if (result.isInvalid()) return ExprError();
9532
9533 // If that gives us a pseudo-object result back, the pseudo-object
9534 // expression must have been an lvalue-to-rvalue conversion which we
9535 // should reapply.
9536 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009537 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009538
9539 return result;
9540}
9541
9542template<typename Derived>
9543ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009544TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9545 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009546 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009547 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009548
John McCallbcd03502009-12-07 02:54:59 +00009549 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009550 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009552
John McCall4c98fd82009-11-04 07:28:41 +00009553 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009554 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009555
Peter Collingbournee190dee2011-03-11 19:24:49 +00009556 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9557 E->getKind(),
9558 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009559 }
Mike Stump11289f42009-09-09 15:08:12 +00009560
Eli Friedmane4f22df2012-02-29 04:03:55 +00009561 // C++0x [expr.sizeof]p1:
9562 // The operand is either an expression, which is an unevaluated operand
9563 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009564 EnterExpressionEvaluationContext Unevaluated(
9565 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9566 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009567
Reid Kleckner32506ed2014-06-12 23:03:48 +00009568 // Try to recover if we have something like sizeof(T::X) where X is a type.
9569 // Notably, there must be *exactly* one set of parens if X is a type.
9570 TypeSourceInfo *RecoveryTSI = nullptr;
9571 ExprResult SubExpr;
9572 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9573 if (auto *DRE =
9574 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9575 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9576 PE, DRE, false, &RecoveryTSI);
9577 else
9578 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9579
9580 if (RecoveryTSI) {
9581 return getDerived().RebuildUnaryExprOrTypeTrait(
9582 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9583 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009585
Eli Friedmane4f22df2012-02-29 04:03:55 +00009586 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009587 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009588
Peter Collingbournee190dee2011-03-11 19:24:49 +00009589 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9590 E->getOperatorLoc(),
9591 E->getKind(),
9592 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009593}
Mike Stump11289f42009-09-09 15:08:12 +00009594
Douglas Gregora16548e2009-08-11 05:31:07 +00009595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009597TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009598 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009599 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009601
John McCalldadc5752010-08-24 06:29:42 +00009602 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009603 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009604 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009605
9606
Douglas Gregora16548e2009-08-11 05:31:07 +00009607 if (!getDerived().AlwaysRebuild() &&
9608 LHS.get() == E->getLHS() &&
9609 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009610 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009611
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009612 return getDerived().RebuildArraySubscriptExpr(
9613 LHS.get(),
9614 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009615}
Mike Stump11289f42009-09-09 15:08:12 +00009616
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009617template <typename Derived>
9618ExprResult
9619TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9620 ExprResult Base = getDerived().TransformExpr(E->getBase());
9621 if (Base.isInvalid())
9622 return ExprError();
9623
9624 ExprResult LowerBound;
9625 if (E->getLowerBound()) {
9626 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9627 if (LowerBound.isInvalid())
9628 return ExprError();
9629 }
9630
9631 ExprResult Length;
9632 if (E->getLength()) {
9633 Length = getDerived().TransformExpr(E->getLength());
9634 if (Length.isInvalid())
9635 return ExprError();
9636 }
9637
9638 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9639 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9640 return E;
9641
9642 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009643 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009644 Length.get(), E->getRBracketLoc());
9645}
9646
Mike Stump11289f42009-09-09 15:08:12 +00009647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009648ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009649TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009650 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009651 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009652 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009653 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009654
9655 // Transform arguments.
9656 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009657 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009658 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009659 &ArgChanged))
9660 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009661
Douglas Gregora16548e2009-08-11 05:31:07 +00009662 if (!getDerived().AlwaysRebuild() &&
9663 Callee.get() == E->getCallee() &&
9664 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009665 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009666
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009668 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009669 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009670 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009671 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009672 E->getRParenLoc());
9673}
Mike Stump11289f42009-09-09 15:08:12 +00009674
9675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009676ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009677TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009678 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009679 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009681
Douglas Gregorea972d32011-02-28 21:54:11 +00009682 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009683 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009684 QualifierLoc
9685 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
Douglas Gregorea972d32011-02-28 21:54:11 +00009687 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009688 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009689 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009690 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009691
Eli Friedman2cfcef62009-12-04 06:40:45 +00009692 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009693 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9694 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009695 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009697
John McCall16df1e52010-03-30 21:47:33 +00009698 NamedDecl *FoundDecl = E->getFoundDecl();
9699 if (FoundDecl == E->getMemberDecl()) {
9700 FoundDecl = Member;
9701 } else {
9702 FoundDecl = cast_or_null<NamedDecl>(
9703 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9704 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009705 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009706 }
9707
Douglas Gregora16548e2009-08-11 05:31:07 +00009708 if (!getDerived().AlwaysRebuild() &&
9709 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009710 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009711 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009712 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009713 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009714
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009715 // Mark it referenced in the new context regardless.
9716 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009717 SemaRef.MarkMemberReferenced(E);
9718
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009719 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009720 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009721
John McCall6b51f282009-11-23 01:53:49 +00009722 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009723 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009724 TransArgs.setLAngleLoc(E->getLAngleLoc());
9725 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009726 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9727 E->getNumTemplateArgs(),
9728 TransArgs))
9729 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009730 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009731
Douglas Gregora16548e2009-08-11 05:31:07 +00009732 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009733 SourceLocation FakeOperatorLoc =
9734 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009735
John McCall38836f02010-01-15 08:34:02 +00009736 // FIXME: to do this check properly, we will need to preserve the
9737 // first-qualifier-in-scope here, just in case we had a dependent
9738 // base (and therefore couldn't do the check) and a
9739 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009740 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009741 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9742 if (MemberNameInfo.getName()) {
9743 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9744 if (!MemberNameInfo.getName())
9745 return ExprError();
9746 }
John McCall38836f02010-01-15 08:34:02 +00009747
John McCallb268a282010-08-23 23:25:46 +00009748 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009749 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009750 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009751 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009752 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009753 Member,
John McCall16df1e52010-03-30 21:47:33 +00009754 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009755 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009756 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009757 FirstQualifierInScope);
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
John McCall47f29ea2009-12-08 09:21:05 +00009762TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009763 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009764 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009766
John McCalldadc5752010-08-24 06:29:42 +00009767 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009768 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009770
Douglas Gregora16548e2009-08-11 05:31:07 +00009771 if (!getDerived().AlwaysRebuild() &&
9772 LHS.get() == E->getLHS() &&
9773 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009774 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009775
Lang Hames5de91cc2012-10-02 04:45:10 +00009776 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009777 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009780 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009781}
9782
Richard Smith778dc0f2019-10-19 00:04:38 +00009783template <typename Derived>
9784ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
9785 CXXRewrittenBinaryOperator *E) {
Richard Smith974c8b72019-10-19 00:04:43 +00009786 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
Richard Smith778dc0f2019-10-19 00:04:38 +00009787
Richard Smith974c8b72019-10-19 00:04:43 +00009788 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
9789 if (LHS.isInvalid())
9790 return ExprError();
9791
9792 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
9793 if (RHS.isInvalid())
Richard Smith778dc0f2019-10-19 00:04:38 +00009794 return ExprError();
9795
9796 if (!getDerived().AlwaysRebuild() &&
Richard Smith974c8b72019-10-19 00:04:43 +00009797 LHS.get() == Decomp.LHS &&
9798 RHS.get() == Decomp.RHS)
Richard Smith778dc0f2019-10-19 00:04:38 +00009799 return E;
9800
Richard Smith974c8b72019-10-19 00:04:43 +00009801 // Extract the already-resolved callee declarations so that we can restrict
9802 // ourselves to using them as the unqualified lookup results when rebuilding.
9803 UnresolvedSet<2> UnqualLookups;
9804 Expr *PossibleBinOps[] = {E->getSemanticForm(),
9805 const_cast<Expr *>(Decomp.InnerBinOp)};
9806 for (Expr *PossibleBinOp : PossibleBinOps) {
9807 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
9808 if (!Op)
9809 continue;
9810 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
9811 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
9812 continue;
9813
9814 // Transform the callee in case we built a call to a local extern
9815 // declaration.
9816 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
9817 E->getOperatorLoc(), Callee->getFoundDecl()));
9818 if (!Found)
9819 return ExprError();
9820 UnqualLookups.addDecl(Found);
9821 }
9822
9823 return getDerived().RebuildCXXRewrittenBinaryOperator(
9824 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
Richard Smith778dc0f2019-10-19 00:04:38 +00009825}
9826
Mike Stump11289f42009-09-09 15:08:12 +00009827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009828ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009829TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009830 CompoundAssignOperator *E) {
9831 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009832}
Mike Stump11289f42009-09-09 15:08:12 +00009833
Douglas Gregora16548e2009-08-11 05:31:07 +00009834template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009835ExprResult TreeTransform<Derived>::
9836TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9837 // Just rebuild the common and RHS expressions and see whether we
9838 // get any changes.
9839
9840 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9841 if (commonExpr.isInvalid())
9842 return ExprError();
9843
9844 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9845 if (rhs.isInvalid())
9846 return ExprError();
9847
9848 if (!getDerived().AlwaysRebuild() &&
9849 commonExpr.get() == e->getCommon() &&
9850 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009851 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009852
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009853 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009854 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009855 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009856 e->getColonLoc(),
9857 rhs.get());
9858}
9859
9860template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009861ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009862TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009863 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009864 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009866
John McCalldadc5752010-08-24 06:29:42 +00009867 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009868 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009870
John McCalldadc5752010-08-24 06:29:42 +00009871 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009872 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009874
Douglas Gregora16548e2009-08-11 05:31:07 +00009875 if (!getDerived().AlwaysRebuild() &&
9876 Cond.get() == E->getCond() &&
9877 LHS.get() == E->getLHS() &&
9878 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009879 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009880
John McCallb268a282010-08-23 23:25:46 +00009881 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009882 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009883 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009884 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009885 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009886}
Mike Stump11289f42009-09-09 15:08:12 +00009887
9888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009889ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009890TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009891 // Implicit casts are eliminated during transformation, since they
9892 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009893 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009894}
Mike Stump11289f42009-09-09 15:08:12 +00009895
Douglas Gregora16548e2009-08-11 05:31:07 +00009896template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009897ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009898TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009899 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9900 if (!Type)
9901 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009902
John McCalldadc5752010-08-24 06:29:42 +00009903 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009904 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009905 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009907
Douglas Gregora16548e2009-08-11 05:31:07 +00009908 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009909 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009910 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009911 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009912
John McCall97513962010-01-15 18:39:57 +00009913 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009914 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009915 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009916 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009917}
Mike Stump11289f42009-09-09 15:08:12 +00009918
Douglas Gregora16548e2009-08-11 05:31:07 +00009919template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009920ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009921TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009922 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9923 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9924 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009925 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009926
John McCalldadc5752010-08-24 06:29:42 +00009927 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009928 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009929 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009930
Douglas Gregora16548e2009-08-11 05:31:07 +00009931 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009932 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009933 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009934 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009935
John McCall5d7aa7f2010-01-19 22:33:45 +00009936 // Note: the expression type doesn't necessarily match the
9937 // type-as-written, but that's okay, because it should always be
9938 // derivable from the initializer.
9939
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009940 return getDerived().RebuildCompoundLiteralExpr(
9941 E->getLParenLoc(), NewT,
9942 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009943}
Mike Stump11289f42009-09-09 15:08:12 +00009944
Douglas Gregora16548e2009-08-11 05:31:07 +00009945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009946ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009947TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009948 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009949 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009951
Douglas Gregora16548e2009-08-11 05:31:07 +00009952 if (!getDerived().AlwaysRebuild() &&
9953 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009954 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009955
Douglas Gregora16548e2009-08-11 05:31:07 +00009956 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009957 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009958 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009959 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009960 E->getAccessorLoc(),
9961 E->getAccessor());
9962}
Mike Stump11289f42009-09-09 15:08:12 +00009963
Douglas Gregora16548e2009-08-11 05:31:07 +00009964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009966TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009967 if (InitListExpr *Syntactic = E->getSyntacticForm())
9968 E = Syntactic;
9969
Douglas Gregora16548e2009-08-11 05:31:07 +00009970 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009971
Richard Smith12938cf2018-09-26 04:36:55 +00009972 EnterExpressionEvaluationContext Context(
9973 getSema(), EnterExpressionEvaluationContext::InitList);
9974
Benjamin Kramerf0623432012-08-23 22:51:59 +00009975 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009976 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009977 Inits, &InitChanged))
9978 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009979
Richard Smith520449d2015-02-05 06:15:50 +00009980 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9981 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9982 // in some cases. We can't reuse it in general, because the syntactic and
9983 // semantic forms are linked, and we can't know that semantic form will
9984 // match even if the syntactic form does.
9985 }
Mike Stump11289f42009-09-09 15:08:12 +00009986
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009987 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009988 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009989}
Mike Stump11289f42009-09-09 15:08:12 +00009990
Douglas Gregora16548e2009-08-11 05:31:07 +00009991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009993TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009994 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009995
Douglas Gregorebe10102009-08-20 07:17:43 +00009996 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009997 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009998 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010000
Douglas Gregorebe10102009-08-20 07:17:43 +000010001 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010002 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +000010003 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +000010004 for (const DesignatedInitExpr::Designator &D : E->designators()) {
10005 if (D.isFieldDesignator()) {
10006 Desig.AddDesignator(Designator::getField(D.getFieldName(),
10007 D.getDotLoc(),
10008 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +000010009 if (D.getField()) {
10010 FieldDecl *Field = cast_or_null<FieldDecl>(
10011 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
10012 if (Field != D.getField())
10013 // Rebuild the expression when the transformed FieldDecl is
10014 // different to the already assigned FieldDecl.
10015 ExprChanged = true;
10016 } else {
10017 // Ensure that the designator expression is rebuilt when there isn't
10018 // a resolved FieldDecl in the designator as we don't want to assign
10019 // a FieldDecl to a pattern designator that will be instantiated again.
10020 ExprChanged = true;
10021 }
Douglas Gregora16548e2009-08-11 05:31:07 +000010022 continue;
10023 }
Mike Stump11289f42009-09-09 15:08:12 +000010024
David Majnemerf7e36092016-06-23 00:15:04 +000010025 if (D.isArrayDesignator()) {
10026 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +000010027 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010029
David Majnemerf7e36092016-06-23 00:15:04 +000010030 Desig.AddDesignator(
10031 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +000010032
David Majnemerf7e36092016-06-23 00:15:04 +000010033 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010034 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010035 continue;
10036 }
Mike Stump11289f42009-09-09 15:08:12 +000010037
David Majnemerf7e36092016-06-23 00:15:04 +000010038 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +000010039 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +000010040 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +000010041 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010042 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010043
David Majnemerf7e36092016-06-23 00:15:04 +000010044 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +000010045 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010047
10048 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010049 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +000010050 D.getLBracketLoc(),
10051 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +000010052
David Majnemerf7e36092016-06-23 00:15:04 +000010053 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
10054 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +000010055
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010056 ArrayExprs.push_back(Start.get());
10057 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010058 }
Mike Stump11289f42009-09-09 15:08:12 +000010059
Douglas Gregora16548e2009-08-11 05:31:07 +000010060 if (!getDerived().AlwaysRebuild() &&
10061 Init.get() == E->getInit() &&
10062 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010063 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010064
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010065 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010066 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +000010067 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010068}
Mike Stump11289f42009-09-09 15:08:12 +000010069
Yunzhong Gaocb779302015-06-10 00:27:52 +000010070// Seems that if TransformInitListExpr() only works on the syntactic form of an
10071// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
10072template<typename Derived>
10073ExprResult
10074TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
10075 DesignatedInitUpdateExpr *E) {
10076 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
10077 "initializer");
10078 return ExprError();
10079}
10080
10081template<typename Derived>
10082ExprResult
10083TreeTransform<Derived>::TransformNoInitExpr(
10084 NoInitExpr *E) {
10085 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
10086 return ExprError();
10087}
10088
Douglas Gregora16548e2009-08-11 05:31:07 +000010089template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010090ExprResult
Richard Smith410306b2016-12-12 02:53:20 +000010091TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
10092 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
10093 return ExprError();
10094}
10095
10096template<typename Derived>
10097ExprResult
10098TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
10099 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
10100 return ExprError();
10101}
10102
10103template<typename Derived>
10104ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010105TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010106 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010107 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +000010108
Douglas Gregor3da3c062009-10-28 00:29:27 +000010109 // FIXME: Will we ever have proper type location here? Will we actually
10110 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +000010111 QualType T = getDerived().TransformType(E->getType());
10112 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010114
Douglas Gregora16548e2009-08-11 05:31:07 +000010115 if (!getDerived().AlwaysRebuild() &&
10116 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010117 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010118
Douglas Gregora16548e2009-08-11 05:31:07 +000010119 return getDerived().RebuildImplicitValueInitExpr(T);
10120}
Mike Stump11289f42009-09-09 15:08:12 +000010121
Douglas Gregora16548e2009-08-11 05:31:07 +000010122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010124TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +000010125 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
10126 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010128
John McCalldadc5752010-08-24 06:29:42 +000010129 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010130 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010132
Douglas Gregora16548e2009-08-11 05:31:07 +000010133 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +000010134 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010135 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010136 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010137
John McCallb268a282010-08-23 23:25:46 +000010138 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +000010139 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010140}
10141
10142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010143ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010144TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010145 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010146 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +000010147 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
10148 &ArgumentChanged))
10149 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010150
Douglas Gregora16548e2009-08-11 05:31:07 +000010151 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010152 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +000010153 E->getRParenLoc());
10154}
Mike Stump11289f42009-09-09 15:08:12 +000010155
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010156/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010157///
10158/// By default, the transformation of an address-of-label expression always
10159/// rebuilds the expression, so that the label identifier can be resolved to
10160/// the corresponding label statement by semantic analysis.
10161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010163TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +000010164 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
10165 E->getLabel());
10166 if (!LD)
10167 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010168
Douglas Gregora16548e2009-08-11 05:31:07 +000010169 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +000010170 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +000010171}
Mike Stump11289f42009-09-09 15:08:12 +000010172
10173template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010174ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010175TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +000010176 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +000010177 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +000010178 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +000010179 if (SubStmt.isInvalid()) {
10180 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +000010181 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +000010182 }
Mike Stump11289f42009-09-09 15:08:12 +000010183
Douglas Gregora16548e2009-08-11 05:31:07 +000010184 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +000010185 SubStmt.get() == E->getSubStmt()) {
10186 // Calling this an 'error' is unintuitive, but it does the right thing.
10187 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010188 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +000010189 }
Mike Stump11289f42009-09-09 15:08:12 +000010190
10191 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010192 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010193 E->getRParenLoc());
10194}
Mike Stump11289f42009-09-09 15:08:12 +000010195
Douglas Gregora16548e2009-08-11 05:31:07 +000010196template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010197ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010198TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010199 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +000010200 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010201 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010202
John McCalldadc5752010-08-24 06:29:42 +000010203 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010204 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010206
John McCalldadc5752010-08-24 06:29:42 +000010207 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010208 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010210
Douglas Gregora16548e2009-08-11 05:31:07 +000010211 if (!getDerived().AlwaysRebuild() &&
10212 Cond.get() == E->getCond() &&
10213 LHS.get() == E->getLHS() &&
10214 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010215 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010216
Douglas Gregora16548e2009-08-11 05:31:07 +000010217 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +000010218 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010219 E->getRParenLoc());
10220}
Mike Stump11289f42009-09-09 15:08:12 +000010221
Douglas Gregora16548e2009-08-11 05:31:07 +000010222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010224TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010225 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010226}
10227
10228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010230TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010231 switch (E->getOperator()) {
10232 case OO_New:
10233 case OO_Delete:
10234 case OO_Array_New:
10235 case OO_Array_Delete:
10236 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +000010237
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010238 case OO_Call: {
10239 // This is a call to an object's operator().
10240 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
10241
10242 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +000010243 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010244 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010245 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010246
10247 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +000010248 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010249 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010250
10251 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010252 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010253 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +000010254 Args))
10255 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010256
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010257 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
10258 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010259 }
10260
10261#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
10262 case OO_##Name:
10263#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
10264#include "clang/Basic/OperatorKinds.def"
10265 case OO_Subscript:
10266 // Handled below.
10267 break;
10268
10269 case OO_Conditional:
10270 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010271
10272 case OO_None:
10273 case NUM_OVERLOADED_OPERATORS:
10274 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010275 }
10276
John McCalldadc5752010-08-24 06:29:42 +000010277 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +000010278 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010280
Richard Smithdb2630f2012-10-21 03:28:35 +000010281 ExprResult First;
10282 if (E->getOperator() == OO_Amp)
10283 First = getDerived().TransformAddressOfOperand(E->getArg(0));
10284 else
10285 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +000010286 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010287 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010288
John McCalldadc5752010-08-24 06:29:42 +000010289 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +000010290 if (E->getNumArgs() == 2) {
10291 Second = getDerived().TransformExpr(E->getArg(1));
10292 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010293 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010294 }
Mike Stump11289f42009-09-09 15:08:12 +000010295
Douglas Gregora16548e2009-08-11 05:31:07 +000010296 if (!getDerived().AlwaysRebuild() &&
10297 Callee.get() == E->getCallee() &&
10298 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +000010299 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010300 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +000010301
Lang Hames5de91cc2012-10-02 04:45:10 +000010302 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +000010303 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +000010304
Douglas Gregora16548e2009-08-11 05:31:07 +000010305 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
10306 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +000010307 Callee.get(),
10308 First.get(),
10309 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010310}
Mike Stump11289f42009-09-09 15:08:12 +000010311
Douglas Gregora16548e2009-08-11 05:31:07 +000010312template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010313ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010314TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10315 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010316}
Mike Stump11289f42009-09-09 15:08:12 +000010317
Eric Fiselier708afb52019-05-16 21:04:15 +000010318template <typename Derived>
10319ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
10320 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
10321 getSema().CurContext != E->getParentContext();
10322
10323 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
10324 return E;
10325
10326 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
10327 E->getEndLoc(),
10328 getSema().CurContext);
10329}
10330
Douglas Gregora16548e2009-08-11 05:31:07 +000010331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010332ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +000010333TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10334 // Transform the callee.
10335 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10336 if (Callee.isInvalid())
10337 return ExprError();
10338
10339 // Transform exec config.
10340 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10341 if (EC.isInvalid())
10342 return ExprError();
10343
10344 // Transform arguments.
10345 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010346 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010347 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010348 &ArgChanged))
10349 return ExprError();
10350
10351 if (!getDerived().AlwaysRebuild() &&
10352 Callee.get() == E->getCallee() &&
10353 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010354 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010355
10356 // FIXME: Wrong source location information for the '('.
10357 SourceLocation FakeLParenLoc
10358 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10359 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010360 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010361 E->getRParenLoc(), EC.get());
10362}
10363
10364template<typename Derived>
10365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010366TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010367 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10368 if (!Type)
10369 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010370
John McCalldadc5752010-08-24 06:29:42 +000010371 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010372 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010373 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010374 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010375
Douglas Gregora16548e2009-08-11 05:31:07 +000010376 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010377 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010378 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010379 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010380 return getDerived().RebuildCXXNamedCastExpr(
10381 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10382 Type, E->getAngleBrackets().getEnd(),
10383 // FIXME. this should be '(' location
10384 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010385}
Mike Stump11289f42009-09-09 15:08:12 +000010386
Douglas Gregora16548e2009-08-11 05:31:07 +000010387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010388ExprResult
Erik Pilkingtoneee944e2019-07-02 18:28:13 +000010389TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) {
10390 TypeSourceInfo *TSI =
10391 getDerived().TransformType(BCE->getTypeInfoAsWritten());
10392 if (!TSI)
10393 return ExprError();
10394
10395 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
10396 if (Sub.isInvalid())
10397 return ExprError();
10398
10399 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
10400 Sub.get(), BCE->getEndLoc());
10401}
10402
10403template<typename Derived>
10404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010405TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10406 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010407}
Mike Stump11289f42009-09-09 15:08:12 +000010408
10409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010411TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10412 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010413}
10414
Douglas Gregora16548e2009-08-11 05:31:07 +000010415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010416ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010417TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010418 CXXReinterpretCastExpr *E) {
10419 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010420}
Mike Stump11289f42009-09-09 15:08:12 +000010421
Douglas Gregora16548e2009-08-11 05:31:07 +000010422template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010423ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010424TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10425 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010426}
Mike Stump11289f42009-09-09 15:08:12 +000010427
Douglas Gregora16548e2009-08-11 05:31:07 +000010428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010429ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010430TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010431 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010432 TypeSourceInfo *Type =
10433 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010434 if (!Type)
10435 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010436
John McCalldadc5752010-08-24 06:29:42 +000010437 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010438 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010439 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010441
Douglas Gregora16548e2009-08-11 05:31:07 +000010442 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010443 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010444 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010445 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010446
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010447 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010448 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010449 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010450 E->getRParenLoc(),
10451 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010452}
Mike Stump11289f42009-09-09 15:08:12 +000010453
Douglas Gregora16548e2009-08-11 05:31:07 +000010454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010455ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010456TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010457 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010458 TypeSourceInfo *TInfo
10459 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10460 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010462
Douglas Gregora16548e2009-08-11 05:31:07 +000010463 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010464 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010465 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010466
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010467 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010468 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010469 }
Mike Stump11289f42009-09-09 15:08:12 +000010470
Eli Friedman456f0182012-01-20 01:26:23 +000010471 // We don't know whether the subexpression is potentially evaluated until
10472 // after we perform semantic analysis. We speculatively assume it is
10473 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010474 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010475 EnterExpressionEvaluationContext Unevaluated(
10476 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10477 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010478
John McCalldadc5752010-08-24 06:29:42 +000010479 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010480 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010482
Douglas Gregora16548e2009-08-11 05:31:07 +000010483 if (!getDerived().AlwaysRebuild() &&
10484 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010485 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010486
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010487 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010488 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010489}
10490
10491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010492ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010493TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10494 if (E->isTypeOperand()) {
10495 TypeSourceInfo *TInfo
10496 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10497 if (!TInfo)
10498 return ExprError();
10499
10500 if (!getDerived().AlwaysRebuild() &&
10501 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010502 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010503
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010504 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010505 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010506 }
10507
Faisal Valid143a0c2017-04-01 21:30:49 +000010508 EnterExpressionEvaluationContext Unevaluated(
10509 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010510
10511 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10512 if (SubExpr.isInvalid())
10513 return ExprError();
10514
10515 if (!getDerived().AlwaysRebuild() &&
10516 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010517 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010518
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010519 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010520 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010521}
10522
10523template<typename Derived>
10524ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010525TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010526 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010527}
Mike Stump11289f42009-09-09 15:08:12 +000010528
Douglas Gregora16548e2009-08-11 05:31:07 +000010529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010530ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010531TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010532 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010533 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010534}
Mike Stump11289f42009-09-09 15:08:12 +000010535
Douglas Gregora16548e2009-08-11 05:31:07 +000010536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010537ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010538TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010539 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010540
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010541 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
Richard Smith8458c9e2019-05-24 01:35:07 +000010542 // Mark it referenced in the new context regardless.
10543 // FIXME: this is a bit instantiation-specific.
10544 getSema().MarkThisReferenced(E);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010545 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010546 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010547
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010548 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010549}
Mike Stump11289f42009-09-09 15:08:12 +000010550
Douglas Gregora16548e2009-08-11 05:31:07 +000010551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010553TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010554 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010555 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010556 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010557
Douglas Gregora16548e2009-08-11 05:31:07 +000010558 if (!getDerived().AlwaysRebuild() &&
10559 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010560 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010561
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010562 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10563 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010564}
Mike Stump11289f42009-09-09 15:08:12 +000010565
Douglas Gregora16548e2009-08-11 05:31:07 +000010566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010568TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010569 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10570 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010571 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010572 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010573
Eric Fiselier708afb52019-05-16 21:04:15 +000010574 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
10575 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010576 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010577
Douglas Gregor033f6752009-12-23 23:03:06 +000010578 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010579}
Mike Stump11289f42009-09-09 15:08:12 +000010580
Douglas Gregora16548e2009-08-11 05:31:07 +000010581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010582ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010583TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010584 FieldDecl *Field = cast_or_null<FieldDecl>(
10585 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010586 if (!Field)
10587 return ExprError();
10588
Eric Fiselier708afb52019-05-16 21:04:15 +000010589 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
10590 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010591 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010592
10593 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10594}
10595
10596template<typename Derived>
10597ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010598TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10599 CXXScalarValueInitExpr *E) {
10600 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10601 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010602 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010603
Douglas Gregora16548e2009-08-11 05:31:07 +000010604 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010605 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010606 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010607
Chad Rosier1dcde962012-08-08 18:46:20 +000010608 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010609 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010610 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010611}
Mike Stump11289f42009-09-09 15:08:12 +000010612
Douglas Gregora16548e2009-08-11 05:31:07 +000010613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010614ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010615TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010616 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010617 TypeSourceInfo *AllocTypeInfo =
10618 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010619 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010621
Douglas Gregora16548e2009-08-11 05:31:07 +000010622 // Transform the size of the array we're allocating (if any).
Richard Smithb9fb1212019-05-06 03:47:15 +000010623 Optional<Expr *> ArraySize;
10624 if (Optional<Expr *> OldArraySize = E->getArraySize()) {
10625 ExprResult NewArraySize;
10626 if (*OldArraySize) {
10627 NewArraySize = getDerived().TransformExpr(*OldArraySize);
10628 if (NewArraySize.isInvalid())
10629 return ExprError();
10630 }
10631 ArraySize = NewArraySize.get();
10632 }
Mike Stump11289f42009-09-09 15:08:12 +000010633
Douglas Gregora16548e2009-08-11 05:31:07 +000010634 // Transform the placement arguments (if any).
10635 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010636 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010637 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010638 E->getNumPlacementArgs(), true,
10639 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010640 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010641
Sebastian Redl6047f072012-02-16 12:22:20 +000010642 // Transform the initializer (if any).
10643 Expr *OldInit = E->getInitializer();
10644 ExprResult NewInit;
10645 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010646 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010647 if (NewInit.isInvalid())
10648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010649
Sebastian Redl6047f072012-02-16 12:22:20 +000010650 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010651 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010652 if (E->getOperatorNew()) {
10653 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010654 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010655 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010656 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010657 }
10658
Craig Topperc3ec1492014-05-26 06:22:03 +000010659 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010660 if (E->getOperatorDelete()) {
10661 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010662 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010663 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010664 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010665 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010666
Douglas Gregora16548e2009-08-11 05:31:07 +000010667 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010668 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Richard Smithb9fb1212019-05-06 03:47:15 +000010669 ArraySize == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010670 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010671 OperatorNew == E->getOperatorNew() &&
10672 OperatorDelete == E->getOperatorDelete() &&
10673 !ArgumentChanged) {
10674 // Mark any declarations we need as referenced.
10675 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010676 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010677 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010678 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010679 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010680
Sebastian Redl6047f072012-02-16 12:22:20 +000010681 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010682 QualType ElementType
10683 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10684 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10685 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10686 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010687 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010688 }
10689 }
10690 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010691
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010692 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010693 }
Mike Stump11289f42009-09-09 15:08:12 +000010694
Douglas Gregor0744ef62010-09-07 21:49:58 +000010695 QualType AllocType = AllocTypeInfo->getType();
Richard Smithb9fb1212019-05-06 03:47:15 +000010696 if (!ArraySize) {
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010697 // If no array size was specified, but the new expression was
10698 // instantiated with an array type (e.g., "new T" where T is
10699 // instantiated with "int[4]"), extract the outer bound from the
10700 // array type as our array size. We do this with constant and
10701 // dependently-sized array types.
10702 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10703 if (!ArrayT) {
10704 // Do nothing
10705 } else if (const ConstantArrayType *ConsArrayT
10706 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010707 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10708 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010709 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010710 AllocType = ConsArrayT->getElementType();
10711 } else if (const DependentSizedArrayType *DepArrayT
10712 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10713 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010714 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010715 AllocType = DepArrayT->getElementType();
10716 }
10717 }
10718 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010719
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010720 return getDerived().RebuildCXXNewExpr(
10721 E->getBeginLoc(), E->isGlobalNew(),
10722 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10723 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
Richard Smithb9fb1212019-05-06 03:47:15 +000010724 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010725}
Mike Stump11289f42009-09-09 15:08:12 +000010726
Douglas Gregora16548e2009-08-11 05:31:07 +000010727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010729TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010730 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010731 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010733
Douglas Gregord2d9da02010-02-26 00:38:10 +000010734 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010735 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010736 if (E->getOperatorDelete()) {
10737 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010738 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010739 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010740 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010741 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010742
Douglas Gregora16548e2009-08-11 05:31:07 +000010743 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010744 Operand.get() == E->getArgument() &&
10745 OperatorDelete == E->getOperatorDelete()) {
10746 // Mark any declarations we need as referenced.
10747 // FIXME: instantiation-specific.
10748 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010749 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010750
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010751 if (!E->getArgument()->isTypeDependent()) {
10752 QualType Destroyed = SemaRef.Context.getBaseElementType(
10753 E->getDestroyedType());
10754 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10755 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010756 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010757 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010758 }
10759 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010760
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010761 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010762 }
Mike Stump11289f42009-09-09 15:08:12 +000010763
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010764 return getDerived().RebuildCXXDeleteExpr(
10765 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010766}
Mike Stump11289f42009-09-09 15:08:12 +000010767
Douglas Gregora16548e2009-08-11 05:31:07 +000010768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010769ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010770TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010771 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010772 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010773 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010775
John McCallba7bf592010-08-24 05:47:05 +000010776 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010777 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010778 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010779 E->getOperatorLoc(),
10780 E->isArrow()? tok::arrow : tok::period,
10781 ObjectTypePtr,
10782 MayBePseudoDestructor);
10783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010784 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010785
John McCallba7bf592010-08-24 05:47:05 +000010786 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010787 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10788 if (QualifierLoc) {
10789 QualifierLoc
10790 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10791 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010792 return ExprError();
10793 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010794 CXXScopeSpec SS;
10795 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010796
Douglas Gregor678f90d2010-02-25 01:56:36 +000010797 PseudoDestructorTypeStorage Destroyed;
10798 if (E->getDestroyedTypeInfo()) {
10799 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010800 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010801 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010802 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010803 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010804 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010805 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010806 // We aren't likely to be able to resolve the identifier down to a type
10807 // now anyway, so just retain the identifier.
10808 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10809 E->getDestroyedTypeLoc());
10810 } else {
10811 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010812 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010813 *E->getDestroyedTypeIdentifier(),
10814 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010815 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010816 SS, ObjectTypePtr,
10817 false);
10818 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010819 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010820
Douglas Gregor678f90d2010-02-25 01:56:36 +000010821 Destroyed
10822 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10823 E->getDestroyedTypeLoc());
10824 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010825
Craig Topperc3ec1492014-05-26 06:22:03 +000010826 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010827 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010828 CXXScopeSpec EmptySS;
10829 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010830 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010831 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010832 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010833 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010834
John McCallb268a282010-08-23 23:25:46 +000010835 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010836 E->getOperatorLoc(),
10837 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010838 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010839 ScopeTypeInfo,
10840 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010841 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010842 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010843}
Mike Stump11289f42009-09-09 15:08:12 +000010844
Richard Smith151c4562016-12-20 21:35:28 +000010845template <typename Derived>
10846bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10847 bool RequiresADL,
10848 LookupResult &R) {
10849 // Transform all the decls.
10850 bool AllEmptyPacks = true;
10851 for (auto *OldD : Old->decls()) {
10852 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10853 if (!InstD) {
10854 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10855 // This can happen because of dependent hiding.
10856 if (isa<UsingShadowDecl>(OldD))
10857 continue;
10858 else {
10859 R.clear();
10860 return true;
10861 }
10862 }
10863
10864 // Expand using pack declarations.
10865 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10866 ArrayRef<NamedDecl*> Decls = SingleDecl;
10867 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10868 Decls = UPD->expansions();
10869
10870 // Expand using declarations.
10871 for (auto *D : Decls) {
10872 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10873 for (auto *SD : UD->shadows())
10874 R.addDecl(SD);
10875 } else {
10876 R.addDecl(D);
10877 }
10878 }
10879
10880 AllEmptyPacks &= Decls.empty();
10881 };
10882
10883 // C++ [temp.res]/8.4.2:
10884 // The program is ill-formed, no diagnostic required, if [...] lookup for
10885 // a name in the template definition found a using-declaration, but the
10886 // lookup in the corresponding scope in the instantiation odoes not find
10887 // any declarations because the using-declaration was a pack expansion and
10888 // the corresponding pack is empty
10889 if (AllEmptyPacks && !RequiresADL) {
10890 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010891 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010892 return true;
10893 }
10894
10895 // Resolve a kind, but don't do any further analysis. If it's
10896 // ambiguous, the callee needs to deal with it.
10897 R.resolveKind();
10898 return false;
10899}
10900
Douglas Gregorad8a3362009-09-04 17:36:40 +000010901template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010902ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010903TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010904 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010905 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10906 Sema::LookupOrdinaryName);
10907
Richard Smith151c4562016-12-20 21:35:28 +000010908 // Transform the declaration set.
10909 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10910 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010911
10912 // Rebuild the nested-name qualifier, if present.
10913 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010914 if (Old->getQualifierLoc()) {
10915 NestedNameSpecifierLoc QualifierLoc
10916 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10917 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010918 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010919
Douglas Gregor0da1d432011-02-28 20:01:57 +000010920 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010921 }
10922
Douglas Gregor9262f472010-04-27 18:19:34 +000010923 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010924 CXXRecordDecl *NamingClass
10925 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10926 Old->getNameLoc(),
10927 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010928 if (!NamingClass) {
10929 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010930 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010931 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010932
Douglas Gregorda7be082010-04-27 16:10:10 +000010933 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010934 }
10935
Abramo Bagnara7945c982012-01-27 09:46:47 +000010936 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10937
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010938 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010939 // it's a normal declaration name or member reference.
10940 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10941 NamedDecl *D = R.getAsSingle<NamedDecl>();
10942 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10943 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10944 // give a good diagnostic.
10945 if (D && D->isCXXInstanceMember()) {
10946 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10947 /*TemplateArgs=*/nullptr,
10948 /*Scope=*/nullptr);
10949 }
10950
John McCalle66edc12009-11-24 19:00:30 +000010951 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010952 }
John McCalle66edc12009-11-24 19:00:30 +000010953
10954 // If we have template arguments, rebuild them, then rebuild the
10955 // templateid expression.
10956 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010957 if (Old->hasExplicitTemplateArgs() &&
10958 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010959 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010960 TransArgs)) {
10961 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010962 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010963 }
John McCalle66edc12009-11-24 19:00:30 +000010964
Abramo Bagnara7945c982012-01-27 09:46:47 +000010965 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010966 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010967}
Mike Stump11289f42009-09-09 15:08:12 +000010968
Douglas Gregora16548e2009-08-11 05:31:07 +000010969template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010970ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010971TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10972 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010973 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010974 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10975 TypeSourceInfo *From = E->getArg(I);
10976 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010977 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010978 TypeLocBuilder TLB;
10979 TLB.reserve(FromTL.getFullDataSize());
10980 QualType To = getDerived().TransformType(TLB, FromTL);
10981 if (To.isNull())
10982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010983
Douglas Gregor29c42f22012-02-24 07:38:34 +000010984 if (To == From->getType())
10985 Args.push_back(From);
10986 else {
10987 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10988 ArgChanged = true;
10989 }
10990 continue;
10991 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010992
Douglas Gregor29c42f22012-02-24 07:38:34 +000010993 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010994
Douglas Gregor29c42f22012-02-24 07:38:34 +000010995 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010996 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010997 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10998 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10999 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000011000
Douglas Gregor29c42f22012-02-24 07:38:34 +000011001 // Determine whether the set of unexpanded parameter packs can and should
11002 // be expanded.
11003 bool Expand = true;
11004 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011005 Optional<unsigned> OrigNumExpansions =
11006 ExpansionTL.getTypePtr()->getNumExpansions();
11007 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000011008 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
11009 PatternTL.getSourceRange(),
11010 Unexpanded,
11011 Expand, RetainExpansion,
11012 NumExpansions))
11013 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011014
Douglas Gregor29c42f22012-02-24 07:38:34 +000011015 if (!Expand) {
11016 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011017 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000011018 // expansion.
11019 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000011020
Douglas Gregor29c42f22012-02-24 07:38:34 +000011021 TypeLocBuilder TLB;
11022 TLB.reserve(From->getTypeLoc().getFullDataSize());
11023
11024 QualType To = getDerived().TransformType(TLB, PatternTL);
11025 if (To.isNull())
11026 return ExprError();
11027
Chad Rosier1dcde962012-08-08 18:46:20 +000011028 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000011029 PatternTL.getSourceRange(),
11030 ExpansionTL.getEllipsisLoc(),
11031 NumExpansions);
11032 if (To.isNull())
11033 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011034
Douglas Gregor29c42f22012-02-24 07:38:34 +000011035 PackExpansionTypeLoc ToExpansionTL
11036 = TLB.push<PackExpansionTypeLoc>(To);
11037 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
11038 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
11039 continue;
11040 }
11041
11042 // Expand the pack expansion by substituting for each argument in the
11043 // pack(s).
11044 for (unsigned I = 0; I != *NumExpansions; ++I) {
11045 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
11046 TypeLocBuilder TLB;
11047 TLB.reserve(PatternTL.getFullDataSize());
11048 QualType To = getDerived().TransformType(TLB, PatternTL);
11049 if (To.isNull())
11050 return ExprError();
11051
Eli Friedman5e05c4a2013-07-19 21:49:32 +000011052 if (To->containsUnexpandedParameterPack()) {
11053 To = getDerived().RebuildPackExpansionType(To,
11054 PatternTL.getSourceRange(),
11055 ExpansionTL.getEllipsisLoc(),
11056 NumExpansions);
11057 if (To.isNull())
11058 return ExprError();
11059
11060 PackExpansionTypeLoc ToExpansionTL
11061 = TLB.push<PackExpansionTypeLoc>(To);
11062 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
11063 }
11064
Douglas Gregor29c42f22012-02-24 07:38:34 +000011065 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
11066 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011067
Douglas Gregor29c42f22012-02-24 07:38:34 +000011068 if (!RetainExpansion)
11069 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011070
Douglas Gregor29c42f22012-02-24 07:38:34 +000011071 // If we're supposed to retain a pack expansion, do so by temporarily
11072 // forgetting the partially-substituted parameter pack.
11073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11074
11075 TypeLocBuilder TLB;
11076 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000011077
Douglas Gregor29c42f22012-02-24 07:38:34 +000011078 QualType To = getDerived().TransformType(TLB, PatternTL);
11079 if (To.isNull())
11080 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011081
11082 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000011083 PatternTL.getSourceRange(),
11084 ExpansionTL.getEllipsisLoc(),
11085 NumExpansions);
11086 if (To.isNull())
11087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011088
Douglas Gregor29c42f22012-02-24 07:38:34 +000011089 PackExpansionTypeLoc ToExpansionTL
11090 = TLB.push<PackExpansionTypeLoc>(To);
11091 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
11092 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
11093 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011094
Douglas Gregor29c42f22012-02-24 07:38:34 +000011095 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011096 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000011097
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011098 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011099 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000011100}
11101
11102template<typename Derived>
11103ExprResult
Saar Raz5d98ba62019-10-15 15:24:26 +000011104TreeTransform<Derived>::TransformConceptSpecializationExpr(
11105 ConceptSpecializationExpr *E) {
11106 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
11107 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
11108 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11109 Old->NumTemplateArgs, TransArgs))
11110 return ExprError();
11111
11112 return getDerived().RebuildConceptSpecializationExpr(
11113 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
11114 E->getConceptNameLoc(), E->getFoundDecl(), E->getNamedConcept(),
11115 &TransArgs);
11116}
11117
11118
11119template<typename Derived>
11120ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000011121TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
11122 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
11123 if (!T)
11124 return ExprError();
11125
11126 if (!getDerived().AlwaysRebuild() &&
11127 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011128 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000011129
11130 ExprResult SubExpr;
11131 {
Faisal Valid143a0c2017-04-01 21:30:49 +000011132 EnterExpressionEvaluationContext Unevaluated(
11133 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000011134 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
11135 if (SubExpr.isInvalid())
11136 return ExprError();
11137
11138 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011139 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000011140 }
11141
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011142 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011143 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000011144}
11145
11146template<typename Derived>
11147ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000011148TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
11149 ExprResult SubExpr;
11150 {
Faisal Valid143a0c2017-04-01 21:30:49 +000011151 EnterExpressionEvaluationContext Unevaluated(
11152 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000011153 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
11154 if (SubExpr.isInvalid())
11155 return ExprError();
11156
11157 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011158 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000011159 }
11160
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011161 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011162 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000011163}
11164
Reid Kleckner32506ed2014-06-12 23:03:48 +000011165template <typename Derived>
11166ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
11167 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
11168 TypeSourceInfo **RecoveryTSI) {
11169 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
11170 DRE, AddrTaken, RecoveryTSI);
11171
11172 // Propagate both errors and recovered types, which return ExprEmpty.
11173 if (!NewDRE.isUsable())
11174 return NewDRE;
11175
11176 // We got an expr, wrap it up in parens.
11177 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
11178 return PE;
11179 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
11180 PE->getRParen());
11181}
11182
11183template <typename Derived>
11184ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11185 DependentScopeDeclRefExpr *E) {
11186 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
11187 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000011188}
11189
11190template<typename Derived>
11191ExprResult
11192TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11193 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000011194 bool IsAddressOfOperand,
11195 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000011196 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011197 NestedNameSpecifierLoc QualifierLoc
11198 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11199 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011200 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000011201 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000011202
John McCall31f82722010-11-12 08:19:04 +000011203 // TODO: If this is a conversion-function-id, verify that the
11204 // destination type name (if present) resolves the same way after
11205 // instantiation as it did in the local scope.
11206
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011207 DeclarationNameInfo NameInfo
11208 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
11209 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011211
John McCalle66edc12009-11-24 19:00:30 +000011212 if (!E->hasExplicitTemplateArgs()) {
11213 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011214 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011215 // Note: it is sufficient to compare the Name component of NameInfo:
11216 // if name has not changed, DNLoc has not changed either.
11217 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011218 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011219
Reid Kleckner32506ed2014-06-12 23:03:48 +000011220 return getDerived().RebuildDependentScopeDeclRefExpr(
11221 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
11222 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000011223 }
John McCall6b51f282009-11-23 01:53:49 +000011224
11225 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011226 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11227 E->getNumTemplateArgs(),
11228 TransArgs))
11229 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011230
Reid Kleckner32506ed2014-06-12 23:03:48 +000011231 return getDerived().RebuildDependentScopeDeclRefExpr(
11232 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
11233 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000011234}
11235
11236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011238TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000011239 // CXXConstructExprs other than for list-initialization and
11240 // CXXTemporaryObjectExpr are always implicit, so when we have
11241 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000011242 if ((E->getNumArgs() == 1 ||
11243 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000011244 (!getDerived().DropCallArgument(E->getArg(0))) &&
11245 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000011246 return getDerived().TransformExpr(E->getArg(0));
11247
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011248 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000011249
11250 QualType T = getDerived().TransformType(E->getType());
11251 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000011252 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011253
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011254 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11255 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011256 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011257 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011258
Douglas Gregora16548e2009-08-11 05:31:07 +000011259 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011260 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000011261 {
11262 EnterExpressionEvaluationContext Context(
11263 getSema(), EnterExpressionEvaluationContext::InitList,
11264 E->isListInitialization());
11265 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11266 &ArgumentChanged))
11267 return ExprError();
11268 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011269
Douglas Gregora16548e2009-08-11 05:31:07 +000011270 if (!getDerived().AlwaysRebuild() &&
11271 T == E->getType() &&
11272 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000011273 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000011274 // Mark the constructor as referenced.
11275 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011276 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011277 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000011278 }
Mike Stump11289f42009-09-09 15:08:12 +000011279
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011280 return getDerived().RebuildCXXConstructExpr(
11281 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
11282 E->hadMultipleCandidates(), E->isListInitialization(),
11283 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
11284 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000011285}
Mike Stump11289f42009-09-09 15:08:12 +000011286
Richard Smith5179eb72016-06-28 19:03:57 +000011287template<typename Derived>
11288ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
11289 CXXInheritedCtorInitExpr *E) {
11290 QualType T = getDerived().TransformType(E->getType());
11291 if (T.isNull())
11292 return ExprError();
11293
11294 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011295 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000011296 if (!Constructor)
11297 return ExprError();
11298
11299 if (!getDerived().AlwaysRebuild() &&
11300 T == E->getType() &&
11301 Constructor == E->getConstructor()) {
11302 // Mark the constructor as referenced.
11303 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011304 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000011305 return E;
11306 }
11307
11308 return getDerived().RebuildCXXInheritedCtorInitExpr(
11309 T, E->getLocation(), Constructor,
11310 E->constructsVBase(), E->inheritedFromVBase());
11311}
11312
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011313/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000011314///
Douglas Gregor363b1512009-12-24 18:51:59 +000011315/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
11316/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011318ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011319TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011320 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011321}
Mike Stump11289f42009-09-09 15:08:12 +000011322
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011323/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000011324/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000011325///
John McCall5d413782010-12-06 08:20:24 +000011326/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000011327/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011329ExprResult
John McCall5d413782010-12-06 08:20:24 +000011330TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011331 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011332}
Mike Stump11289f42009-09-09 15:08:12 +000011333
Douglas Gregora16548e2009-08-11 05:31:07 +000011334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011335ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011336TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000011337 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011338 TypeSourceInfo *T =
11339 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011340 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011341 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011342
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011343 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11344 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011345 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011346 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011347
Douglas Gregora16548e2009-08-11 05:31:07 +000011348 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011349 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000011350 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000011351 {
11352 EnterExpressionEvaluationContext Context(
11353 getSema(), EnterExpressionEvaluationContext::InitList,
11354 E->isListInitialization());
11355 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11356 &ArgumentChanged))
11357 return ExprError();
11358 }
Mike Stump11289f42009-09-09 15:08:12 +000011359
Douglas Gregora16548e2009-08-11 05:31:07 +000011360 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011361 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011362 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011363 !ArgumentChanged) {
11364 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011365 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000011366 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011367 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011368
Vedant Kumara14a1f92018-01-17 18:53:51 +000011369 // FIXME: We should just pass E->isListInitialization(), but we're not
11370 // prepared to handle list-initialization without a child InitListExpr.
11371 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11372 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011373 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011374 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011375}
Mike Stump11289f42009-09-09 15:08:12 +000011376
Douglas Gregora16548e2009-08-11 05:31:07 +000011377template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011378ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011379TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011380 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011381 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011382 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smithb2997f52019-05-21 20:10:50 +000011383 struct TransformedInitCapture {
11384 // The location of the ... if the result is retaining a pack expansion.
11385 SourceLocation EllipsisLoc;
11386 // Zero or more expansions of the init-capture.
11387 SmallVector<InitCaptureInfoTy, 4> Expansions;
11388 };
11389 SmallVector<TransformedInitCapture, 4> InitCaptures;
11390 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011391 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011392 CEnd = E->capture_end();
11393 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011394 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011395 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000011396
Richard Smithb2997f52019-05-21 20:10:50 +000011397 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011398 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011399
11400 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
11401 Optional<unsigned> NumExpansions) {
Richard Smithb2997f52019-05-21 20:10:50 +000011402 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11403 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
11404
11405 if (NewExprInitResult.isInvalid()) {
11406 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
11407 return;
11408 }
11409 Expr *NewExprInit = NewExprInitResult.get();
11410
11411 QualType NewInitCaptureType =
11412 getSema().buildLambdaInitCaptureInitialization(
11413 C->getLocation(), OldVD->getType()->isReferenceType(),
11414 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
11415 C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
11416 NewExprInit);
11417 Result.Expansions.push_back(
11418 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
11419 };
11420
11421 // If this is an init-capture pack, consider expanding the pack now.
11422 if (OldVD->isParameterPack()) {
11423 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
11424 ->getTypeLoc()
11425 .castAs<PackExpansionTypeLoc>();
11426 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11427 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
11428
11429 // Determine whether the set of unexpanded parameter packs can and should
11430 // be expanded.
11431 bool Expand = true;
11432 bool RetainExpansion = false;
11433 Optional<unsigned> OrigNumExpansions =
11434 ExpansionTL.getTypePtr()->getNumExpansions();
11435 Optional<unsigned> NumExpansions = OrigNumExpansions;
11436 if (getDerived().TryExpandParameterPacks(
11437 ExpansionTL.getEllipsisLoc(),
11438 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
11439 RetainExpansion, NumExpansions))
11440 return ExprError();
11441 if (Expand) {
11442 for (unsigned I = 0; I != *NumExpansions; ++I) {
11443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11444 SubstInitCapture(SourceLocation(), None);
11445 }
11446 }
11447 if (!Expand || RetainExpansion) {
11448 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11449 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
11450 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
11451 }
11452 } else {
11453 SubstInitCapture(SourceLocation(), None);
11454 }
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011455 }
11456
Nicholas Allegracbd13bc2019-09-17 01:43:33 +000011457 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11458 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11459
Faisal Vali2cba1332013-10-23 06:44:28 +000011460 // Transform the template parameters, and add them to the current
11461 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011462 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011463 E->getTemplateParameterList());
Nicholas Allegracbd13bc2019-09-17 01:43:33 +000011464 LSI->GLTemplateParameterList = TPL;
Faisal Vali2cba1332013-10-23 06:44:28 +000011465
Richard Smith01014ce2014-11-20 23:53:14 +000011466 // Transform the type of the original lambda's call operator.
11467 // The transformation MUST be done in the CurrentInstantiationScope since
11468 // it introduces a mapping of the original to the newly created
11469 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011470 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011471 {
11472 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011473 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011474 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011475
11476 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011477 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011478 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011479 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011480 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011481 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11482 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11483 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011484 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011485 if (NewCallOpType.isNull())
11486 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011487 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11488 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011489 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011490
Eli Friedmand564afb2012-09-19 01:18:11 +000011491 // Create the local class that will describe the lambda.
Richard Smith87346a12019-06-02 18:53:44 +000011492 CXXRecordDecl *OldClass = E->getLambdaClass();
Eli Friedmand564afb2012-09-19 01:18:11 +000011493 CXXRecordDecl *Class
11494 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011495 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011496 /*KnownDependent=*/false,
11497 E->getCaptureDefault());
Richard Smith87346a12019-06-02 18:53:44 +000011498 getDerived().transformedLocalDecl(OldClass, {Class});
11499
Michael Liao243ebfb2019-10-19 00:15:19 +000011500 Optional<std::tuple<unsigned, bool, Decl *>> Mangling;
Richard Smith87346a12019-06-02 18:53:44 +000011501 if (getDerived().ReplacingOriginal())
Michael Liao243ebfb2019-10-19 00:15:19 +000011502 Mangling = std::make_tuple(OldClass->getLambdaManglingNumber(),
11503 OldClass->hasKnownLambdaInternalLinkage(),
11504 OldClass->getLambdaContextDecl());
Eli Friedmand564afb2012-09-19 01:18:11 +000011505
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011506 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011507 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11508 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011509 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011510 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
Michael Liao243ebfb2019-10-19 00:15:19 +000011511 E->getCallOperator()->getConstexprKind());
Faisal Valia734ab92016-03-26 16:11:37 +000011512
Faisal Vali2cba1332013-10-23 06:44:28 +000011513 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011514
Akira Hatanaka402818462016-12-16 21:16:57 +000011515 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11516 I != NumParams; ++I) {
11517 auto *P = NewCallOperator->getParamDecl(I);
11518 if (P->hasUninstantiatedDefaultArg()) {
11519 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011520 getSema(),
11521 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011522 ExprResult R = getDerived().TransformExpr(
11523 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11524 P->setDefaultArg(R.get());
11525 }
11526 }
11527
Faisal Vali2cba1332013-10-23 06:44:28 +000011528 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithb2997f52019-05-21 20:10:50 +000011529 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
Richard Smithba71c082013-05-16 06:20:58 +000011530
Michael Liao243ebfb2019-10-19 00:15:19 +000011531 // Number the lambda for linkage purposes if necessary.
11532 getSema().handleLambdaNumbering(Class, NewCallOperator, Mangling);
11533
Douglas Gregorb4328232012-02-14 00:00:48 +000011534 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011535 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011536 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011537
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011538 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011539 getSema().buildLambdaScope(LSI, NewCallOperator,
11540 E->getIntroducerRange(),
11541 E->getCaptureDefault(),
11542 E->getCaptureDefaultLoc(),
11543 E->hasExplicitParameters(),
11544 E->hasExplicitResultType(),
11545 E->isMutable());
11546
11547 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011548
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011549 // Transform captures.
Chad Rosier1dcde962012-08-08 18:46:20 +000011550 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011551 CEnd = E->capture_end();
11552 C != CEnd; ++C) {
11553 // When we hit the first implicit capture, tell Sema that we've finished
11554 // the list of explicit captures.
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011555 if (C->isImplicit())
11556 break;
Chad Rosier1dcde962012-08-08 18:46:20 +000011557
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011558 // Capturing 'this' is trivial.
11559 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011560 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11561 /*BuildAndDiagnose*/ true, nullptr,
11562 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011563 continue;
11564 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011565 // Captured expression will be recaptured during captured variables
11566 // rebuilding.
11567 if (C->capturesVLAType())
11568 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011569
Richard Smithba71c082013-05-16 06:20:58 +000011570 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011571 if (E->isInitCapture(C)) {
Richard Smithb2997f52019-05-21 20:10:50 +000011572 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
11573
Richard Smithbb13c9a2013-09-28 04:02:39 +000011574 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011575 llvm::SmallVector<Decl*, 4> NewVDs;
11576
11577 for (InitCaptureInfoTy &Info : NewC.Expansions) {
11578 ExprResult Init = Info.first;
11579 QualType InitQualType = Info.second;
11580 if (Init.isInvalid() || InitQualType.isNull()) {
11581 Invalid = true;
11582 break;
11583 }
11584 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11585 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
11586 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
11587 if (!NewVD) {
11588 Invalid = true;
11589 break;
11590 }
11591 NewVDs.push_back(NewVD);
Richard Smith30116532019-05-28 23:09:46 +000011592 getSema().addInitCapture(LSI, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011593 }
Richard Smithb2997f52019-05-21 20:10:50 +000011594
11595 if (Invalid)
11596 break;
11597
11598 getDerived().transformedLocalDecl(OldVD, NewVDs);
Richard Smithba71c082013-05-16 06:20:58 +000011599 continue;
11600 }
11601
11602 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11603
Douglas Gregor3e308b12012-02-14 19:27:52 +000011604 // Determine the capture kind for Sema.
11605 Sema::TryCaptureKind Kind
11606 = C->isImplicit()? Sema::TryCapture_Implicit
11607 : C->getCaptureKind() == LCK_ByCopy
11608 ? Sema::TryCapture_ExplicitByVal
11609 : Sema::TryCapture_ExplicitByRef;
11610 SourceLocation EllipsisLoc;
11611 if (C->isPackExpansion()) {
11612 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11613 bool ShouldExpand = false;
11614 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011615 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011616 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11617 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011618 Unexpanded,
11619 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011620 NumExpansions)) {
11621 Invalid = true;
11622 continue;
11623 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011624
Douglas Gregor3e308b12012-02-14 19:27:52 +000011625 if (ShouldExpand) {
11626 // The transform has determined that we should perform an expansion;
11627 // transform and capture each of the arguments.
11628 // expansion of the pattern. Do so.
11629 VarDecl *Pack = C->getCapturedVar();
11630 for (unsigned I = 0; I != *NumExpansions; ++I) {
11631 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11632 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011633 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011634 Pack));
11635 if (!CapturedVar) {
11636 Invalid = true;
11637 continue;
11638 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011639
Douglas Gregor3e308b12012-02-14 19:27:52 +000011640 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011641 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11642 }
Richard Smith9467be42014-06-06 17:33:35 +000011643
11644 // FIXME: Retain a pack expansion if RetainExpansion is true.
11645
Douglas Gregor3e308b12012-02-14 19:27:52 +000011646 continue;
11647 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011648
Douglas Gregor3e308b12012-02-14 19:27:52 +000011649 EllipsisLoc = C->getEllipsisLoc();
11650 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011651
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011652 // Transform the captured variable.
11653 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011654 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011655 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011656 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011657 Invalid = true;
11658 continue;
11659 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011660
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011661 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011662 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11663 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011664 }
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011665 getSema().finishLambdaExplicitCaptures(LSI);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011666
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011667 // FIXME: Sema's lambda-building mechanism expects us to push an expression
11668 // evaluation context even if we're not transforming the function body.
Faisal Valid143a0c2017-04-01 21:30:49 +000011669 getSema().PushExpressionEvaluationContext(
11670 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011671
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011672 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011673 StmtResult Body =
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011674 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
Richard Smithc38498f2015-04-27 21:27:54 +000011675
11676 // ActOnLambda* will pop the function scope for us.
11677 FuncScopeCleanup.disable();
11678
Douglas Gregorb4328232012-02-14 00:00:48 +000011679 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011680 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011681 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011682 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011683 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011684 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011685
Richard Smithc38498f2015-04-27 21:27:54 +000011686 // Copy the LSI before ActOnFinishFunctionBody removes it.
11687 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11688 // the call operator.
11689 auto LSICopy = *LSI;
11690 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11691 /*IsInstantiation*/ true);
11692 SavedContext.pop();
11693
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011694 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011695 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011696}
11697
11698template<typename Derived>
Richard Smith87346a12019-06-02 18:53:44 +000011699StmtResult
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011700TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
Richard Smith87346a12019-06-02 18:53:44 +000011701 return TransformStmt(S);
11702}
11703
11704template<typename Derived>
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011705StmtResult
11706TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) {
11707 // Transform captures.
11708 for (LambdaExpr::capture_iterator C = E->capture_begin(),
11709 CEnd = E->capture_end();
11710 C != CEnd; ++C) {
11711 // When we hit the first implicit capture, tell Sema that we've finished
11712 // the list of explicit captures.
11713 if (!C->isImplicit())
11714 continue;
11715
11716 // Capturing 'this' is trivial.
11717 if (C->capturesThis()) {
11718 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11719 /*BuildAndDiagnose*/ true, nullptr,
11720 C->getCaptureKind() == LCK_StarThis);
11721 continue;
11722 }
11723 // Captured expression will be recaptured during captured variables
11724 // rebuilding.
11725 if (C->capturesVLAType())
11726 continue;
11727
11728 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11729 assert(!E->isInitCapture(C) && "implicit init-capture?");
11730
11731 // Transform the captured variable.
11732 VarDecl *CapturedVar = cast_or_null<VarDecl>(
11733 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
11734 if (!CapturedVar || CapturedVar->isInvalidDecl())
11735 return StmtError();
11736
11737 // Capture the transformed variable.
11738 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
11739 }
11740
11741 return S;
11742}
11743
11744template<typename Derived>
Douglas Gregore31e6062012-02-07 10:09:13 +000011745ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011746TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011747 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011748 TypeSourceInfo *T =
11749 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011750 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011751 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011752
Douglas Gregora16548e2009-08-11 05:31:07 +000011753 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011754 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011755 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011756 {
11757 EnterExpressionEvaluationContext Context(
11758 getSema(), EnterExpressionEvaluationContext::InitList,
11759 E->isListInitialization());
11760 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11761 &ArgumentChanged))
11762 return ExprError();
11763 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011764
Douglas Gregora16548e2009-08-11 05:31:07 +000011765 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011766 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011767 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011768 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011769
Douglas Gregora16548e2009-08-11 05:31:07 +000011770 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011771 return getDerived().RebuildCXXUnresolvedConstructExpr(
11772 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011773}
Mike Stump11289f42009-09-09 15:08:12 +000011774
Douglas Gregora16548e2009-08-11 05:31:07 +000011775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011776ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011777TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011778 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011779 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011780 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011781 Expr *OldBase;
11782 QualType BaseType;
11783 QualType ObjectType;
11784 if (!E->isImplicitAccess()) {
11785 OldBase = E->getBase();
11786 Base = getDerived().TransformExpr(OldBase);
11787 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011789
John McCall2d74de92009-12-01 22:10:20 +000011790 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011791 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011792 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011793 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011794 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011795 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011796 ObjectTy,
11797 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011798 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011799 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011800
John McCallba7bf592010-08-24 05:47:05 +000011801 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011802 BaseType = ((Expr*) Base.get())->getType();
11803 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011804 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011805 BaseType = getDerived().TransformType(E->getBaseType());
Simon Pilgrim22b68732019-10-05 13:20:59 +000011806 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
John McCall2d74de92009-12-01 22:10:20 +000011807 }
Mike Stump11289f42009-09-09 15:08:12 +000011808
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011809 // Transform the first part of the nested-name-specifier that qualifies
11810 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011811 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011812 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011813 E->getFirstQualifierFoundInScope(),
11814 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011815
Douglas Gregore16af532011-02-28 18:50:33 +000011816 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011817 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011818 QualifierLoc
11819 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11820 ObjectType,
11821 FirstQualifierInScope);
11822 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011823 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011824 }
Mike Stump11289f42009-09-09 15:08:12 +000011825
Abramo Bagnara7945c982012-01-27 09:46:47 +000011826 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11827
John McCall31f82722010-11-12 08:19:04 +000011828 // TODO: If this is a conversion-function-id, verify that the
11829 // destination type name (if present) resolves the same way after
11830 // instantiation as it did in the local scope.
11831
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011832 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011833 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011834 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011836
John McCall2d74de92009-12-01 22:10:20 +000011837 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011838 // This is a reference to a member without an explicitly-specified
11839 // template argument list. Optimize for this common case.
11840 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011841 Base.get() == OldBase &&
11842 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011843 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011844 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011845 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011846 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011847
John McCallb268a282010-08-23 23:25:46 +000011848 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011849 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011850 E->isArrow(),
11851 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011852 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011853 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011854 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011855 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011856 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011857 }
11858
John McCall6b51f282009-11-23 01:53:49 +000011859 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011860 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11861 E->getNumTemplateArgs(),
11862 TransArgs))
11863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011864
John McCallb268a282010-08-23 23:25:46 +000011865 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011866 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011867 E->isArrow(),
11868 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011869 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011870 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011871 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011872 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011873 &TransArgs);
11874}
11875
11876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011878TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011879 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011880 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011881 QualType BaseType;
11882 if (!Old->isImplicitAccess()) {
11883 Base = getDerived().TransformExpr(Old->getBase());
11884 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011885 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011886 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011887 Old->isArrow());
11888 if (Base.isInvalid())
11889 return ExprError();
11890 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011891 } else {
11892 BaseType = getDerived().TransformType(Old->getBaseType());
11893 }
John McCall10eae182009-11-30 22:42:35 +000011894
Douglas Gregor0da1d432011-02-28 20:01:57 +000011895 NestedNameSpecifierLoc QualifierLoc;
11896 if (Old->getQualifierLoc()) {
11897 QualifierLoc
11898 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11899 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011900 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011901 }
11902
Abramo Bagnara7945c982012-01-27 09:46:47 +000011903 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11904
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011905 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011906 Sema::LookupOrdinaryName);
11907
Richard Smith151c4562016-12-20 21:35:28 +000011908 // Transform the declaration set.
11909 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11910 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011911
Douglas Gregor9262f472010-04-27 18:19:34 +000011912 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011913 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011914 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011915 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011916 Old->getMemberLoc(),
11917 Old->getNamingClass()));
11918 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011919 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011920
Douglas Gregorda7be082010-04-27 16:10:10 +000011921 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011922 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011923
John McCall10eae182009-11-30 22:42:35 +000011924 TemplateArgumentListInfo TransArgs;
11925 if (Old->hasExplicitTemplateArgs()) {
11926 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11927 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011928 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11929 Old->getNumTemplateArgs(),
11930 TransArgs))
11931 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011932 }
John McCall38836f02010-01-15 08:34:02 +000011933
11934 // FIXME: to do this check properly, we will need to preserve the
11935 // first-qualifier-in-scope here, just in case we had a dependent
11936 // base (and therefore couldn't do the check) and a
11937 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011938 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011939
John McCallb268a282010-08-23 23:25:46 +000011940 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011941 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011942 Old->getOperatorLoc(),
11943 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011944 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011945 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011946 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011947 R,
11948 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011949 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011950}
11951
11952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011953ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011954TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011955 EnterExpressionEvaluationContext Unevaluated(
11956 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011957 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11958 if (SubExpr.isInvalid())
11959 return ExprError();
11960
11961 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011962 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011963
11964 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11965}
11966
11967template<typename Derived>
11968ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011969TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011970 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11971 if (Pattern.isInvalid())
11972 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011973
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011974 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011975 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011976
Douglas Gregorb8840002011-01-14 21:20:45 +000011977 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11978 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011979}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011980
11981template<typename Derived>
11982ExprResult
11983TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11984 // If E is not value-dependent, then nothing will change when we transform it.
11985 // Note: This is an instantiation-centric view.
11986 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011987 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011988
Faisal Valid143a0c2017-04-01 21:30:49 +000011989 EnterExpressionEvaluationContext Unevaluated(
11990 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011991
Richard Smithd784e682015-09-23 21:41:42 +000011992 ArrayRef<TemplateArgument> PackArgs;
11993 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011994
Richard Smithd784e682015-09-23 21:41:42 +000011995 // Find the argument list to transform.
11996 if (E->isPartiallySubstituted()) {
11997 PackArgs = E->getPartialArguments();
11998 } else if (E->isValueDependent()) {
11999 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
12000 bool ShouldExpand = false;
12001 bool RetainExpansion = false;
12002 Optional<unsigned> NumExpansions;
12003 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
12004 Unexpanded,
12005 ShouldExpand, RetainExpansion,
12006 NumExpansions))
12007 return ExprError();
12008
12009 // If we need to expand the pack, build a template argument from it and
12010 // expand that.
12011 if (ShouldExpand) {
12012 auto *Pack = E->getPack();
12013 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
12014 ArgStorage = getSema().Context.getPackExpansionType(
12015 getSema().Context.getTypeDeclType(TTPD), None);
12016 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
12017 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
12018 } else {
12019 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000012020 ExprResult DRE = getSema().BuildDeclRefExpr(
12021 VD, VD->getType().getNonLValueExprType(getSema().Context),
12022 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
12023 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000012024 if (DRE.isInvalid())
12025 return ExprError();
12026 ArgStorage = new (getSema().Context) PackExpansionExpr(
12027 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
12028 }
12029 PackArgs = ArgStorage;
12030 }
12031 }
12032
12033 // If we're not expanding the pack, just transform the decl.
12034 if (!PackArgs.size()) {
12035 auto *Pack = cast_or_null<NamedDecl>(
12036 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000012037 if (!Pack)
12038 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000012039 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
12040 E->getPackLoc(),
12041 E->getRParenLoc(), None, None);
12042 }
12043
Richard Smithc5452ed2016-10-19 22:18:42 +000012044 // Try to compute the result without performing a partial substitution.
12045 Optional<unsigned> Result = 0;
12046 for (const TemplateArgument &Arg : PackArgs) {
12047 if (!Arg.isPackExpansion()) {
12048 Result = *Result + 1;
12049 continue;
12050 }
12051
12052 TemplateArgumentLoc ArgLoc;
12053 InventTemplateArgumentLoc(Arg, ArgLoc);
12054
12055 // Find the pattern of the pack expansion.
12056 SourceLocation Ellipsis;
12057 Optional<unsigned> OrigNumExpansions;
12058 TemplateArgumentLoc Pattern =
12059 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
12060 OrigNumExpansions);
12061
12062 // Substitute under the pack expansion. Do not expand the pack (yet).
12063 TemplateArgumentLoc OutPattern;
12064 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12065 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
12066 /*Uneval*/ true))
12067 return true;
12068
12069 // See if we can determine the number of arguments from the result.
12070 Optional<unsigned> NumExpansions =
12071 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
12072 if (!NumExpansions) {
12073 // No: we must be in an alias template expansion, and we're going to need
12074 // to actually expand the packs.
12075 Result = None;
12076 break;
12077 }
12078
12079 Result = *Result + *NumExpansions;
12080 }
12081
12082 // Common case: we could determine the number of expansions without
12083 // substituting.
12084 if (Result)
12085 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
12086 E->getPackLoc(),
12087 E->getRParenLoc(), *Result, None);
12088
Richard Smithd784e682015-09-23 21:41:42 +000012089 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
12090 E->getPackLoc());
12091 {
12092 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
12093 typedef TemplateArgumentLocInventIterator<
12094 Derived, const TemplateArgument*> PackLocIterator;
12095 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
12096 PackLocIterator(*this, PackArgs.end()),
12097 TransformedPackArgs, /*Uneval*/true))
12098 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000012099 }
12100
Richard Smithc5452ed2016-10-19 22:18:42 +000012101 // Check whether we managed to fully-expand the pack.
12102 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000012103 SmallVector<TemplateArgument, 8> Args;
12104 bool PartialSubstitution = false;
12105 for (auto &Loc : TransformedPackArgs.arguments()) {
12106 Args.push_back(Loc.getArgument());
12107 if (Loc.getArgument().isPackExpansion())
12108 PartialSubstitution = true;
12109 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012110
Richard Smithd784e682015-09-23 21:41:42 +000012111 if (PartialSubstitution)
12112 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
12113 E->getPackLoc(),
12114 E->getRParenLoc(), None, Args);
12115
12116 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012117 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000012118 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000012119}
12120
Douglas Gregore8e9dd62011-01-03 17:17:50 +000012121template<typename Derived>
12122ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000012123TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
12124 SubstNonTypeTemplateParmPackExpr *E) {
12125 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012126 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000012127}
12128
12129template<typename Derived>
12130ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000012131TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
12132 SubstNonTypeTemplateParmExpr *E) {
12133 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012134 return E;
John McCall7c454bb2011-07-15 05:09:51 +000012135}
12136
12137template<typename Derived>
12138ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000012139TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
12140 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012141 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000012142}
12143
12144template<typename Derived>
12145ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000012146TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
12147 MaterializeTemporaryExpr *E) {
12148 return getDerived().TransformExpr(E->GetTemporaryExpr());
12149}
Chad Rosier1dcde962012-08-08 18:46:20 +000012150
Douglas Gregorfe314812011-06-21 17:03:29 +000012151template<typename Derived>
12152ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000012153TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
12154 Expr *Pattern = E->getPattern();
12155
12156 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12157 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
12158 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12159
12160 // Determine whether the set of unexpanded parameter packs can and should
12161 // be expanded.
12162 bool Expand = true;
12163 bool RetainExpansion = false;
Richard Smithc7214f62019-05-13 08:31:14 +000012164 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
12165 NumExpansions = OrigNumExpansions;
Richard Smith0f0af192014-11-08 05:07:16 +000012166 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
12167 Pattern->getSourceRange(),
12168 Unexpanded,
12169 Expand, RetainExpansion,
12170 NumExpansions))
12171 return true;
12172
12173 if (!Expand) {
12174 // Do not expand any packs here, just transform and rebuild a fold
12175 // expression.
12176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12177
12178 ExprResult LHS =
12179 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
12180 if (LHS.isInvalid())
12181 return true;
12182
12183 ExprResult RHS =
12184 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
12185 if (RHS.isInvalid())
12186 return true;
12187
12188 if (!getDerived().AlwaysRebuild() &&
12189 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
12190 return E;
12191
12192 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012193 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012194 RHS.get(), E->getEndLoc(), NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012195 }
12196
12197 // The transform has determined that we should perform an elementwise
12198 // expansion of the pattern. Do so.
12199 ExprResult Result = getDerived().TransformExpr(E->getInit());
12200 if (Result.isInvalid())
12201 return true;
12202 bool LeftFold = E->isLeftFold();
12203
12204 // If we're retaining an expansion for a right fold, it is the innermost
12205 // component and takes the init (if any).
12206 if (!LeftFold && RetainExpansion) {
12207 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12208
12209 ExprResult Out = getDerived().TransformExpr(Pattern);
12210 if (Out.isInvalid())
12211 return true;
12212
12213 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012214 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012215 Result.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012216 if (Result.isInvalid())
12217 return true;
12218 }
12219
12220 for (unsigned I = 0; I != *NumExpansions; ++I) {
12221 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
12222 getSema(), LeftFold ? I : *NumExpansions - I - 1);
12223 ExprResult Out = getDerived().TransformExpr(Pattern);
12224 if (Out.isInvalid())
12225 return true;
12226
12227 if (Out.get()->containsUnexpandedParameterPack()) {
12228 // We still have a pack; retain a pack expansion for this slice.
12229 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012230 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000012231 E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012232 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
12233 OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012234 } else if (Result.isUsable()) {
12235 // We've got down to a single element; build a binary operator.
12236 Result = getDerived().RebuildBinaryOperator(
12237 E->getEllipsisLoc(), E->getOperator(),
12238 LeftFold ? Result.get() : Out.get(),
12239 LeftFold ? Out.get() : Result.get());
12240 } else
12241 Result = Out;
12242
12243 if (Result.isInvalid())
12244 return true;
12245 }
12246
12247 // If we're retaining an expansion for a left fold, it is the outermost
12248 // component and takes the complete expansion so far as its init (if any).
12249 if (LeftFold && RetainExpansion) {
12250 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12251
12252 ExprResult Out = getDerived().TransformExpr(Pattern);
12253 if (Out.isInvalid())
12254 return true;
12255
12256 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012257 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012258 Out.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012259 if (Result.isInvalid())
12260 return true;
12261 }
12262
12263 // If we had no init and an empty pack, and we're not retaining an expansion,
12264 // then produce a fallback value or error.
12265 if (Result.isUnset())
12266 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
12267 E->getOperator());
12268
12269 return Result;
12270}
12271
12272template<typename Derived>
12273ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000012274TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
12275 CXXStdInitializerListExpr *E) {
12276 return getDerived().TransformExpr(E->getSubExpr());
12277}
12278
12279template<typename Derived>
12280ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012281TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012282 return SemaRef.MaybeBindToTemporary(E);
12283}
12284
12285template<typename Derived>
12286ExprResult
12287TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012288 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012289}
12290
12291template<typename Derived>
12292ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000012293TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
12294 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12295 if (SubExpr.isInvalid())
12296 return ExprError();
12297
12298 if (!getDerived().AlwaysRebuild() &&
12299 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012300 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000012301
12302 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000012303}
12304
12305template<typename Derived>
12306ExprResult
12307TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
12308 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012309 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012310 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000012311 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012312 /*IsCall=*/false, Elements, &ArgChanged))
12313 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012314
Ted Kremeneke65b0862012-03-06 20:05:56 +000012315 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12316 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012317
Ted Kremeneke65b0862012-03-06 20:05:56 +000012318 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
12319 Elements.data(),
12320 Elements.size());
12321}
12322
12323template<typename Derived>
12324ExprResult
12325TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000012326 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012327 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012328 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012329 bool ArgChanged = false;
12330 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
12331 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000012332
Ted Kremeneke65b0862012-03-06 20:05:56 +000012333 if (OrigElement.isPackExpansion()) {
12334 // This key/value element is a pack expansion.
12335 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12336 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
12337 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
12338 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12339
12340 // Determine whether the set of unexpanded parameter packs can
12341 // and should be expanded.
12342 bool Expand = true;
12343 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000012344 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
12345 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012346 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000012347 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012348 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
12349 PatternRange, Unexpanded, Expand,
12350 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000012351 return ExprError();
12352
12353 if (!Expand) {
12354 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000012355 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000012356 // expansion.
12357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12358 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12359 if (Key.isInvalid())
12360 return ExprError();
12361
12362 if (Key.get() != OrigElement.Key)
12363 ArgChanged = true;
12364
12365 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12366 if (Value.isInvalid())
12367 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012368
Ted Kremeneke65b0862012-03-06 20:05:56 +000012369 if (Value.get() != OrigElement.Value)
12370 ArgChanged = true;
12371
Chad Rosier1dcde962012-08-08 18:46:20 +000012372 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012373 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
12374 };
12375 Elements.push_back(Expansion);
12376 continue;
12377 }
12378
12379 // Record right away that the argument was changed. This needs
12380 // to happen even if the array expands to nothing.
12381 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012382
Ted Kremeneke65b0862012-03-06 20:05:56 +000012383 // The transform has determined that we should perform an elementwise
12384 // expansion of the pattern. Do so.
12385 for (unsigned I = 0; I != *NumExpansions; ++I) {
12386 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
12387 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12388 if (Key.isInvalid())
12389 return ExprError();
12390
12391 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12392 if (Value.isInvalid())
12393 return ExprError();
12394
Chad Rosier1dcde962012-08-08 18:46:20 +000012395 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012396 Key.get(), Value.get(), SourceLocation(), NumExpansions
12397 };
12398
12399 // If any unexpanded parameter packs remain, we still have a
12400 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000012401 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000012402 if (Key.get()->containsUnexpandedParameterPack() ||
12403 Value.get()->containsUnexpandedParameterPack())
12404 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000012405
Ted Kremeneke65b0862012-03-06 20:05:56 +000012406 Elements.push_back(Element);
12407 }
12408
Richard Smith9467be42014-06-06 17:33:35 +000012409 // FIXME: Retain a pack expansion if RetainExpansion is true.
12410
Ted Kremeneke65b0862012-03-06 20:05:56 +000012411 // We've finished with this pack expansion.
12412 continue;
12413 }
12414
12415 // Transform and check key.
12416 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12417 if (Key.isInvalid())
12418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012419
Ted Kremeneke65b0862012-03-06 20:05:56 +000012420 if (Key.get() != OrigElement.Key)
12421 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012422
Ted Kremeneke65b0862012-03-06 20:05:56 +000012423 // Transform and check value.
12424 ExprResult Value
12425 = getDerived().TransformExpr(OrigElement.Value);
12426 if (Value.isInvalid())
12427 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012428
Ted Kremeneke65b0862012-03-06 20:05:56 +000012429 if (Value.get() != OrigElement.Value)
12430 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012431
12432 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000012433 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000012434 };
12435 Elements.push_back(Element);
12436 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012437
Ted Kremeneke65b0862012-03-06 20:05:56 +000012438 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12439 return SemaRef.MaybeBindToTemporary(E);
12440
12441 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000012442 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000012443}
12444
Mike Stump11289f42009-09-09 15:08:12 +000012445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012447TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000012448 TypeSourceInfo *EncodedTypeInfo
12449 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
12450 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012452
Douglas Gregora16548e2009-08-11 05:31:07 +000012453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000012454 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012455 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012456
12457 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000012458 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000012459 E->getRParenLoc());
12460}
Mike Stump11289f42009-09-09 15:08:12 +000012461
Douglas Gregora16548e2009-08-11 05:31:07 +000012462template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000012463ExprResult TreeTransform<Derived>::
12464TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000012465 // This is a kind of implicit conversion, and it needs to get dropped
12466 // and recomputed for the same general reasons that ImplicitCastExprs
12467 // do, as well a more specific one: this expression is only valid when
12468 // it appears *immediately* as an argument expression.
12469 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000012470}
12471
12472template<typename Derived>
12473ExprResult TreeTransform<Derived>::
12474TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000012475 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000012476 = getDerived().TransformType(E->getTypeInfoAsWritten());
12477 if (!TSInfo)
12478 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012479
John McCall31168b02011-06-15 23:02:42 +000012480 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012481 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012482 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012483
John McCall31168b02011-06-15 23:02:42 +000012484 if (!getDerived().AlwaysRebuild() &&
12485 TSInfo == E->getTypeInfoAsWritten() &&
12486 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012487 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012488
John McCall31168b02011-06-15 23:02:42 +000012489 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012490 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012491 Result.get());
12492}
12493
Erik Pilkington29099de2016-07-16 00:35:23 +000012494template <typename Derived>
12495ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12496 ObjCAvailabilityCheckExpr *E) {
12497 return E;
12498}
12499
John McCall31168b02011-06-15 23:02:42 +000012500template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012501ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012502TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012503 // Transform arguments.
12504 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012505 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012506 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012507 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012508 &ArgChanged))
12509 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012510
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012511 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12512 // Class message: transform the receiver type.
12513 TypeSourceInfo *ReceiverTypeInfo
12514 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12515 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012516 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012517
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012518 // If nothing changed, just retain the existing message send.
12519 if (!getDerived().AlwaysRebuild() &&
12520 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012521 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012522
12523 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012524 SmallVector<SourceLocation, 16> SelLocs;
12525 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012526 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12527 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012528 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012529 E->getMethodDecl(),
12530 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012531 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012532 E->getRightLoc());
12533 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012534 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12535 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012536 if (!E->getMethodDecl())
12537 return ExprError();
12538
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012539 // Build a new class message send to 'super'.
12540 SmallVector<SourceLocation, 16> SelLocs;
12541 E->getSelectorLocs(SelLocs);
12542 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12543 E->getSelector(),
12544 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012545 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012546 E->getMethodDecl(),
12547 E->getLeftLoc(),
12548 Args,
12549 E->getRightLoc());
12550 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012551
12552 // Instance message: transform the receiver
12553 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12554 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012555 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012556 = getDerived().TransformExpr(E->getInstanceReceiver());
12557 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012558 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012559
12560 // If nothing changed, just retain the existing message send.
12561 if (!getDerived().AlwaysRebuild() &&
12562 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012563 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012564
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012565 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012566 SmallVector<SourceLocation, 16> SelLocs;
12567 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012568 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012569 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012570 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012571 E->getMethodDecl(),
12572 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012573 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012574 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012575}
12576
Mike Stump11289f42009-09-09 15:08:12 +000012577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012579TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012580 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012581}
12582
Mike Stump11289f42009-09-09 15:08:12 +000012583template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012585TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012586 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012587}
12588
Mike Stump11289f42009-09-09 15:08:12 +000012589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012591TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012592 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012593 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012594 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012595 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012596
12597 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012598
Douglas Gregord51d90d2010-04-26 20:11:03 +000012599 // If nothing changed, just retain the existing expression.
12600 if (!getDerived().AlwaysRebuild() &&
12601 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012602 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012603
John McCallb268a282010-08-23 23:25:46 +000012604 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012605 E->getLocation(),
12606 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012607}
12608
Mike Stump11289f42009-09-09 15:08:12 +000012609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012610ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012611TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012612 // 'super' and types never change. Property never changes. Just
12613 // retain the existing expression.
12614 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012615 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012616
Douglas Gregor9faee212010-04-26 20:47:02 +000012617 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012618 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012619 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012620 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012621
Douglas Gregor9faee212010-04-26 20:47:02 +000012622 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012623
Douglas Gregor9faee212010-04-26 20:47:02 +000012624 // If nothing changed, just retain the existing expression.
12625 if (!getDerived().AlwaysRebuild() &&
12626 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012627 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012628
John McCallb7bd14f2010-12-02 01:19:52 +000012629 if (E->isExplicitProperty())
12630 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12631 E->getExplicitProperty(),
12632 E->getLocation());
12633
12634 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012635 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012636 E->getImplicitPropertyGetter(),
12637 E->getImplicitPropertySetter(),
12638 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012639}
12640
Mike Stump11289f42009-09-09 15:08:12 +000012641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012642ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012643TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12644 // Transform the base expression.
12645 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12646 if (Base.isInvalid())
12647 return ExprError();
12648
12649 // Transform the key expression.
12650 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12651 if (Key.isInvalid())
12652 return ExprError();
12653
12654 // If nothing changed, just retain the existing expression.
12655 if (!getDerived().AlwaysRebuild() &&
12656 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012657 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012658
Chad Rosier1dcde962012-08-08 18:46:20 +000012659 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012660 Base.get(), Key.get(),
12661 E->getAtIndexMethodDecl(),
12662 E->setAtIndexMethodDecl());
12663}
12664
12665template<typename Derived>
12666ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012667TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012668 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012669 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012670 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012671 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012672
Douglas Gregord51d90d2010-04-26 20:11:03 +000012673 // If nothing changed, just retain the existing expression.
12674 if (!getDerived().AlwaysRebuild() &&
12675 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012676 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012677
John McCallb268a282010-08-23 23:25:46 +000012678 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012679 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012680 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012681}
12682
Mike Stump11289f42009-09-09 15:08:12 +000012683template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012684ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012685TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012686 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012687 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012688 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012689 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012690 SubExprs, &ArgumentChanged))
12691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012692
Douglas Gregora16548e2009-08-11 05:31:07 +000012693 if (!getDerived().AlwaysRebuild() &&
12694 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012695 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012696
Douglas Gregora16548e2009-08-11 05:31:07 +000012697 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012698 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012699 E->getRParenLoc());
12700}
12701
Mike Stump11289f42009-09-09 15:08:12 +000012702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012703ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012704TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12705 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12706 if (SrcExpr.isInvalid())
12707 return ExprError();
12708
12709 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12710 if (!Type)
12711 return ExprError();
12712
12713 if (!getDerived().AlwaysRebuild() &&
12714 Type == E->getTypeSourceInfo() &&
12715 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012716 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012717
12718 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12719 SrcExpr.get(), Type,
12720 E->getRParenLoc());
12721}
12722
12723template<typename Derived>
12724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012725TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012726 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012727
Craig Topperc3ec1492014-05-26 06:22:03 +000012728 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012729 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12730
12731 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012732 blockScope->TheDecl->setBlockMissingReturnType(
12733 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012734
Chris Lattner01cf8db2011-07-20 06:58:45 +000012735 SmallVector<ParmVarDecl*, 4> params;
12736 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012737
John McCallc8e321d2016-03-01 02:09:25 +000012738 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12739
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012740 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012741 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012742 if (getDerived().TransformFunctionTypeParams(
12743 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12744 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12745 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012746 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012747 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012748 }
John McCall490112f2011-02-04 18:33:18 +000012749
Eli Friedman34b49062012-01-26 03:00:14 +000012750 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012751 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012752
John McCallc8e321d2016-03-01 02:09:25 +000012753 auto epi = exprFunctionType->getExtProtoInfo();
12754 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12755
Jordan Rose5c382722013-03-08 21:51:21 +000012756 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012757 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012758 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012759
12760 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012761 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012762 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012763
12764 if (!oldBlock->blockMissingReturnType()) {
12765 blockScope->HasImplicitReturnType = false;
12766 blockScope->ReturnType = exprResultType;
12767 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012768
John McCall3882ace2011-01-05 12:14:39 +000012769 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012770 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012771 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012772 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012773 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012774 }
John McCall3882ace2011-01-05 12:14:39 +000012775
John McCall490112f2011-02-04 18:33:18 +000012776#ifndef NDEBUG
12777 // In builds with assertions, make sure that we captured everything we
12778 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012779 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012780 for (const auto &I : oldBlock->captures()) {
12781 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012782
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012783 // Ignore parameter packs.
Richard Smithb2997f52019-05-21 20:10:50 +000012784 if (oldCapture->isParameterPack())
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012785 continue;
John McCall490112f2011-02-04 18:33:18 +000012786
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012787 VarDecl *newCapture =
12788 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12789 oldCapture));
12790 assert(blockScope->CaptureMap.count(newCapture));
12791 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012792 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012793 }
12794#endif
12795
12796 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012797 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012798}
12799
Mike Stump11289f42009-09-09 15:08:12 +000012800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012801ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012802TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012803 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012804}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012805
12806template<typename Derived>
12807ExprResult
12808TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012809 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012810 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012811 SubExprs.reserve(E->getNumSubExprs());
12812 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12813 SubExprs, &ArgumentChanged))
12814 return ExprError();
12815
12816 if (!getDerived().AlwaysRebuild() &&
12817 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012818 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012819
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012820 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Erich Keane830909b2019-09-20 19:17:31 +000012821 E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012822}
Chad Rosier1dcde962012-08-08 18:46:20 +000012823
Douglas Gregora16548e2009-08-11 05:31:07 +000012824//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012825// Type reconstruction
12826//===----------------------------------------------------------------------===//
12827
Mike Stump11289f42009-09-09 15:08:12 +000012828template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012829QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12830 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012831 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012832 getDerived().getBaseEntity());
12833}
12834
Mike Stump11289f42009-09-09 15:08:12 +000012835template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012836QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12837 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012838 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012839 getDerived().getBaseEntity());
12840}
12841
Mike Stump11289f42009-09-09 15:08:12 +000012842template<typename Derived>
12843QualType
John McCall70dd5f62009-10-30 00:06:24 +000012844TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12845 bool WrittenAsLValue,
12846 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012847 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012848 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012849}
12850
12851template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012852QualType
John McCall70dd5f62009-10-30 00:06:24 +000012853TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12854 QualType ClassType,
12855 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012856 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12857 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012858}
12859
12860template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012861QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12862 const ObjCTypeParamDecl *Decl,
12863 SourceLocation ProtocolLAngleLoc,
12864 ArrayRef<ObjCProtocolDecl *> Protocols,
12865 ArrayRef<SourceLocation> ProtocolLocs,
12866 SourceLocation ProtocolRAngleLoc) {
12867 return SemaRef.BuildObjCTypeParamType(Decl,
12868 ProtocolLAngleLoc, Protocols,
12869 ProtocolLocs, ProtocolRAngleLoc,
12870 /*FailOnError=*/true);
12871}
12872
12873template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012874QualType TreeTransform<Derived>::RebuildObjCObjectType(
12875 QualType BaseType,
12876 SourceLocation Loc,
12877 SourceLocation TypeArgsLAngleLoc,
12878 ArrayRef<TypeSourceInfo *> TypeArgs,
12879 SourceLocation TypeArgsRAngleLoc,
12880 SourceLocation ProtocolLAngleLoc,
12881 ArrayRef<ObjCProtocolDecl *> Protocols,
12882 ArrayRef<SourceLocation> ProtocolLocs,
12883 SourceLocation ProtocolRAngleLoc) {
12884 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12885 TypeArgs, TypeArgsRAngleLoc,
12886 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12887 ProtocolRAngleLoc,
12888 /*FailOnError=*/true);
12889}
12890
12891template<typename Derived>
12892QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12893 QualType PointeeType,
12894 SourceLocation Star) {
12895 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12896}
12897
12898template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012899QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012900TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12901 ArrayType::ArraySizeModifier SizeMod,
12902 const llvm::APInt *Size,
12903 Expr *SizeExpr,
12904 unsigned IndexTypeQuals,
12905 SourceRange BracketsRange) {
12906 if (SizeExpr || !Size)
12907 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12908 IndexTypeQuals, BracketsRange,
12909 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012910
12911 QualType Types[] = {
12912 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12913 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12914 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012915 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012916 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012917 QualType SizeType;
12918 for (unsigned I = 0; I != NumTypes; ++I)
12919 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12920 SizeType = Types[I];
12921 break;
12922 }
Mike Stump11289f42009-09-09 15:08:12 +000012923
Eli Friedman9562f392012-01-25 23:20:27 +000012924 // Note that we can return a VariableArrayType here in the case where
12925 // the element type was a dependent VariableArrayType.
12926 IntegerLiteral *ArraySize
12927 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12928 /*FIXME*/BracketsRange.getBegin());
12929 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012930 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012931 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012932}
Mike Stump11289f42009-09-09 15:08:12 +000012933
Douglas Gregord6ff3322009-08-04 16:50:30 +000012934template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012935QualType
12936TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012937 ArrayType::ArraySizeModifier SizeMod,
12938 const llvm::APInt &Size,
Richard Smith772e2662019-10-04 01:25:59 +000012939 Expr *SizeExpr,
John McCall70dd5f62009-10-30 00:06:24 +000012940 unsigned IndexTypeQuals,
12941 SourceRange BracketsRange) {
Richard Smith772e2662019-10-04 01:25:59 +000012942 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
John McCall70dd5f62009-10-30 00:06:24 +000012943 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012944}
12945
12946template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012947QualType
Mike Stump11289f42009-09-09 15:08:12 +000012948TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012949 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012950 unsigned IndexTypeQuals,
12951 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012952 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012953 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012954}
Mike Stump11289f42009-09-09 15:08:12 +000012955
Douglas Gregord6ff3322009-08-04 16:50:30 +000012956template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012957QualType
12958TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012959 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012960 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012961 unsigned IndexTypeQuals,
12962 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012963 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012964 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012965 IndexTypeQuals, BracketsRange);
12966}
12967
12968template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012969QualType
12970TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012971 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012972 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012973 unsigned IndexTypeQuals,
12974 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012975 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012976 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012977 IndexTypeQuals, BracketsRange);
12978}
12979
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012980template <typename Derived>
12981QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12982 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12983 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12984 AttributeLoc);
12985}
12986
12987template <typename Derived>
12988QualType
12989TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12990 unsigned NumElements,
12991 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012992 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012993 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012994}
Mike Stump11289f42009-09-09 15:08:12 +000012995
Erich Keanef702b022018-07-13 19:46:04 +000012996template <typename Derived>
12997QualType TreeTransform<Derived>::RebuildDependentVectorType(
12998 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12999 VectorType::VectorKind VecKind) {
13000 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
13001}
13002
Douglas Gregord6ff3322009-08-04 16:50:30 +000013003template<typename Derived>
13004QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
13005 unsigned NumElements,
13006 SourceLocation AttributeLoc) {
13007 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
13008 NumElements, true);
13009 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000013010 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
13011 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000013012 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013013}
Mike Stump11289f42009-09-09 15:08:12 +000013014
Douglas Gregord6ff3322009-08-04 16:50:30 +000013015template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000013016QualType
13017TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000013018 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000013019 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000013020 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013021}
Mike Stump11289f42009-09-09 15:08:12 +000013022
Douglas Gregord6ff3322009-08-04 16:50:30 +000013023template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000013024QualType TreeTransform<Derived>::RebuildFunctionProtoType(
13025 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000013026 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000013027 const FunctionProtoType::ExtProtoInfo &EPI) {
13028 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000013029 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000013030 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000013031 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013032}
Mike Stump11289f42009-09-09 15:08:12 +000013033
Douglas Gregord6ff3322009-08-04 16:50:30 +000013034template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000013035QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
13036 return SemaRef.Context.getFunctionNoProtoType(T);
13037}
13038
13039template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000013040QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
13041 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000013042 assert(D && "no decl found");
13043 if (D->isInvalidDecl()) return QualType();
13044
Douglas Gregorc298ffc2010-04-22 16:44:27 +000013045 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000013046 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000013047 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
13048 // A valid resolved using typename pack expansion decl can have multiple
13049 // UsingDecls, but they must each have exactly one type, and it must be
13050 // the same type in every case. But we must have at least one expansion!
13051 if (UPD->expansions().empty()) {
13052 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
13053 << UPD->isCXXClassMember() << UPD;
13054 return QualType();
13055 }
13056
13057 // We might still have some unresolved types. Try to pick a resolved type
13058 // if we can. The final instantiation will check that the remaining
13059 // unresolved types instantiate to the type we pick.
13060 QualType FallbackT;
13061 QualType T;
13062 for (auto *E : UPD->expansions()) {
13063 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
13064 if (ThisT.isNull())
13065 continue;
13066 else if (ThisT->getAs<UnresolvedUsingType>())
13067 FallbackT = ThisT;
13068 else if (T.isNull())
13069 T = ThisT;
13070 else
13071 assert(getSema().Context.hasSameType(ThisT, T) &&
13072 "mismatched resolved types in using pack expansion");
13073 }
13074 return T.isNull() ? FallbackT : T;
13075 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000013076 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000013077 "UnresolvedUsingTypenameDecl transformed to non-typename using");
13078
13079 // A valid resolved using typename decl points to exactly one type decl.
13080 assert(++Using->shadow_begin() == Using->shadow_end());
13081 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000013082 } else {
13083 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
13084 "UnresolvedUsingTypenameDecl transformed to non-using decl");
13085 Ty = cast<UnresolvedUsingTypenameDecl>(D);
13086 }
13087
13088 return SemaRef.Context.getTypeDeclType(Ty);
13089}
13090
13091template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000013092QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
13093 SourceLocation Loc) {
13094 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013095}
13096
13097template<typename Derived>
13098QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
13099 return SemaRef.Context.getTypeOfType(Underlying);
13100}
13101
13102template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000013103QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
13104 SourceLocation Loc) {
13105 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013106}
13107
13108template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000013109QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
13110 UnaryTransformType::UTTKind UKind,
13111 SourceLocation Loc) {
13112 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
13113}
13114
13115template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000013116QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000013117 TemplateName Template,
13118 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000013119 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000013120 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000013121}
Mike Stump11289f42009-09-09 15:08:12 +000013122
Douglas Gregor1135c352009-08-06 05:28:30 +000013123template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000013124QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
13125 SourceLocation KWLoc) {
13126 return SemaRef.BuildAtomicType(ValueType, KWLoc);
13127}
13128
13129template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000013130QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000013131 SourceLocation KWLoc,
13132 bool isReadPipe) {
13133 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
13134 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000013135}
13136
13137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000013138TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000013139TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000013140 bool TemplateKW,
13141 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000013142 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000013143 Template);
13144}
13145
13146template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000013147TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000013148TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000013149 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000013150 const IdentifierInfo &Name,
13151 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000013152 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000013153 NamedDecl *FirstQualifierInScope,
13154 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000013155 UnqualifiedId TemplateName;
13156 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000013157 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000013158 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013159 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000013160 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000013161 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000013162 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000013163 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000013164}
Mike Stump11289f42009-09-09 15:08:12 +000013165
Douglas Gregora16548e2009-08-11 05:31:07 +000013166template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000013167TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000013168TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000013169 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000013170 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000013171 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000013172 QualType ObjectType,
13173 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000013174 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000013175 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000013176 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000013177 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000013178 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000013179 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013180 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000013181 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000013182 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000013183 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000013184 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000013185}
Chad Rosier1dcde962012-08-08 18:46:20 +000013186
Douglas Gregor71395fa2009-11-04 00:56:37 +000013187template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000013188ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000013189TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
13190 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000013191 Expr *OrigCallee,
13192 Expr *First,
13193 Expr *Second) {
13194 Expr *Callee = OrigCallee->IgnoreParenCasts();
13195 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000013196
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000013197 if (First->getObjectKind() == OK_ObjCProperty) {
13198 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
13199 if (BinaryOperator::isAssignmentOp(Opc))
13200 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
13201 First, Second);
13202 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
13203 if (Result.isInvalid())
13204 return ExprError();
13205 First = Result.get();
13206 }
13207
13208 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
13209 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
13210 if (Result.isInvalid())
13211 return ExprError();
13212 Second = Result.get();
13213 }
13214
Douglas Gregora16548e2009-08-11 05:31:07 +000013215 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000013216 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000013217 if (!First->getType()->isOverloadableType() &&
13218 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013219 return getSema().CreateBuiltinArraySubscriptExpr(
13220 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000013221 } else if (Op == OO_Arrow) {
13222 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000013223 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
13224 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000013225 if (!First->getType()->isOverloadableType() ||
13226 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
13227 // The argument is not of overloadable type, or this is an expression
13228 // of the form &Class::member, so try to create a built-in unary
13229 // operation.
John McCalle3027922010-08-25 11:45:40 +000013230 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013231 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000013232
John McCallb268a282010-08-23 23:25:46 +000013233 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000013234 }
13235 } else {
John McCallb268a282010-08-23 23:25:46 +000013236 if (!First->getType()->isOverloadableType() &&
13237 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000013238 // Neither of the arguments is an overloadable type, so try to
13239 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000013240 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000013241 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000013242 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000013243 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013244 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013245
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013246 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013247 }
13248 }
Mike Stump11289f42009-09-09 15:08:12 +000013249
13250 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000013251 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000013252 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000013253 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000013254
John McCallb268a282010-08-23 23:25:46 +000013255 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000013256 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000013257 // If the overload could not be resolved in the template definition
13258 // (because we had a dependent argument), ADL is performed as part of
13259 // template instantiation.
13260 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000013261 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000013262 // If we've resolved this to a particular non-member function, just call
13263 // that function. If we resolved it to a member function,
13264 // CreateOverloaded* will find that function for us.
13265 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
13266 if (!isa<CXXMethodDecl>(ND))
13267 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000013268 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000013269 }
Mike Stump11289f42009-09-09 15:08:12 +000013270
Douglas Gregora16548e2009-08-11 05:31:07 +000013271 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000013272 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000013273 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000013274
Douglas Gregora16548e2009-08-11 05:31:07 +000013275 // Create the overloaded operator invocation for unary operators.
13276 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000013277 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013278 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000013279 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
13280 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013281 }
Mike Stump11289f42009-09-09 15:08:12 +000013282
Douglas Gregore9d62932011-07-15 16:25:15 +000013283 if (Op == OO_Subscript) {
13284 SourceLocation LBrace;
13285 SourceLocation RBrace;
13286
13287 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000013288 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000013289 LBrace = SourceLocation::getFromRawEncoding(
13290 NameLoc.CXXOperatorName.BeginOpNameLoc);
13291 RBrace = SourceLocation::getFromRawEncoding(
13292 NameLoc.CXXOperatorName.EndOpNameLoc);
13293 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013294 LBrace = Callee->getBeginLoc();
13295 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000013296 }
13297
13298 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
13299 First, Second);
13300 }
Sebastian Redladba46e2009-10-29 20:17:01 +000013301
Douglas Gregora16548e2009-08-11 05:31:07 +000013302 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000013303 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000013304 ExprResult Result = SemaRef.CreateOverloadedBinOp(
13305 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013306 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013307 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013308
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013309 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013310}
Mike Stump11289f42009-09-09 15:08:12 +000013311
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013312template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000013313ExprResult
John McCallb268a282010-08-23 23:25:46 +000013314TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013315 SourceLocation OperatorLoc,
13316 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000013317 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013318 TypeSourceInfo *ScopeType,
13319 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000013320 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000013321 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000013322 QualType BaseType = Base->getType();
13323 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013324 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000013325 (isArrow && BaseType->getAs<PointerType>() &&
Simon Pilgrim22b68732019-10-05 13:20:59 +000013326 !BaseType->castAs<PointerType>()->getPointeeType()
Gabor Greif5c079262010-02-25 13:04:33 +000013327 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013328 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000013329 return SemaRef.BuildPseudoDestructorExpr(
13330 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
13331 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013332 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013333
Douglas Gregor678f90d2010-02-25 01:56:36 +000013334 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013335 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
13336 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
13337 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
13338 NameInfo.setNamedTypeInfo(DestroyedType);
13339
Richard Smith8e4a3862012-05-15 06:15:11 +000013340 // The scope type is now known to be a valid nested name specifier
13341 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000013342 if (ScopeType) {
13343 if (!ScopeType->getType()->getAs<TagType>()) {
13344 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
13345 diag::err_expected_class_or_namespace)
13346 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
13347 return ExprError();
13348 }
13349 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
13350 CCLoc);
13351 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013352
Abramo Bagnara7945c982012-01-27 09:46:47 +000013353 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000013354 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013355 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013356 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000013357 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013358 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000013359 /*TemplateArgs*/ nullptr,
13360 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013361}
13362
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013363template<typename Derived>
13364StmtResult
13365TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013366 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000013367 CapturedDecl *CD = S->getCapturedDecl();
13368 unsigned NumParams = CD->getNumParams();
13369 unsigned ContextParamPos = CD->getContextParamPosition();
13370 SmallVector<Sema::CapturedParamNameType, 4> Params;
13371 for (unsigned I = 0; I < NumParams; ++I) {
13372 if (I != ContextParamPos) {
13373 Params.push_back(
13374 std::make_pair(
13375 CD->getParam(I)->getName(),
13376 getDerived().TransformType(CD->getParam(I)->getType())));
13377 } else {
13378 Params.push_back(std::make_pair(StringRef(), QualType()));
13379 }
13380 }
Craig Topperc3ec1492014-05-26 06:22:03 +000013381 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000013382 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000013383 StmtResult Body;
13384 {
13385 Sema::CompoundScopeRAII CompoundScope(getSema());
13386 Body = getDerived().TransformStmt(S->getCapturedStmt());
13387 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000013388
13389 if (Body.isInvalid()) {
13390 getSema().ActOnCapturedRegionError();
13391 return StmtError();
13392 }
13393
Nikola Smiljanic01a75982014-05-29 10:55:11 +000013394 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013395}
13396
Douglas Gregord6ff3322009-08-04 16:50:30 +000013397} // end namespace clang
13398
Hans Wennborg59dbe862015-09-29 20:56:43 +000013399#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H