blob: 592787a5870ce3726bd1d597d06933395664e737 [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.
663 StmtResult TransformLambdaBody(Stmt *Body);
664
John McCall31f82722010-11-12 08:19:04 +0000665 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000666
John McCalldadc5752010-08-24 06:29:42 +0000667 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
668 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000669
Faisal Vali2cba1332013-10-23 06:44:28 +0000670 TemplateParameterList *TransformTemplateParameterList(
671 TemplateParameterList *TPL) {
672 return TPL;
673 }
674
Richard Smithdb2630f2012-10-21 03:28:35 +0000675 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000676
Richard Smithdb2630f2012-10-21 03:28:35 +0000677 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000678 bool IsAddressOfOperand,
679 TypeSourceInfo **RecoveryTSI);
680
681 ExprResult TransformParenDependentScopeDeclRefExpr(
682 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
683 TypeSourceInfo **RecoveryTSI);
684
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000685 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000686
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000687// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
688// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000689#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000690 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000691 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000692#define VALUESTMT(Node, Parent) \
693 LLVM_ATTRIBUTE_NOINLINE \
694 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000695#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000696 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000697 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000698#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000699#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000700
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000701#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000702 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000703 OMPClause *Transform ## Class(Class *S);
704#include "clang/Basic/OpenMPKinds.def"
705
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000706 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000707 ///
708 /// By default, this routine adds type qualifiers only to types that can
709 /// have qualifiers, and silently suppresses those qualifiers that are not
710 /// permitted. Subclasses may override this routine to provide different
711 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000712 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000713
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000714 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000715 ///
716 /// By default, performs semantic analysis when building the pointer type.
717 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000718 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000720 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 ///
Mike Stump11289f42009-09-09 15:08:12 +0000722 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000724 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000726 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 ///
John McCall70dd5f62009-10-30 00:06:24 +0000728 /// By default, performs semantic analysis when building the
729 /// reference type. Subclasses may override this routine to provide
730 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 ///
John McCall70dd5f62009-10-30 00:06:24 +0000732 /// \param LValue whether the type was written with an lvalue sigil
733 /// or an rvalue sigil.
734 QualType RebuildReferenceType(QualType ReferentType,
735 bool LValue,
736 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000737
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000738 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// class type it refers into.
740 ///
741 /// By default, performs semantic analysis when building the member pointer
742 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000743 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
744 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000745
Manman Rene6be26c2016-09-13 17:25:08 +0000746 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
747 SourceLocation ProtocolLAngleLoc,
748 ArrayRef<ObjCProtocolDecl *> Protocols,
749 ArrayRef<SourceLocation> ProtocolLocs,
750 SourceLocation ProtocolRAngleLoc);
751
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000752 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000753 ///
754 /// By default, performs semantic analysis when building the object type.
755 /// Subclasses may override this routine to provide different behavior.
756 QualType RebuildObjCObjectType(QualType BaseType,
757 SourceLocation Loc,
758 SourceLocation TypeArgsLAngleLoc,
759 ArrayRef<TypeSourceInfo *> TypeArgs,
760 SourceLocation TypeArgsRAngleLoc,
761 SourceLocation ProtocolLAngleLoc,
762 ArrayRef<ObjCProtocolDecl *> Protocols,
763 ArrayRef<SourceLocation> ProtocolLocs,
764 SourceLocation ProtocolRAngleLoc);
765
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000766 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000767 ///
768 /// By default, directly builds the pointer type, with no additional semantic
769 /// analysis.
770 QualType RebuildObjCObjectPointerType(QualType PointeeType,
771 SourceLocation Star);
772
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000773 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 /// modifier, size of the array (if known), size expression, and index type
775 /// qualifiers.
776 ///
777 /// By default, performs semantic analysis when building the array type.
778 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000779 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780 QualType RebuildArrayType(QualType ElementType,
781 ArrayType::ArraySizeModifier SizeMod,
782 const llvm::APInt *Size,
783 Expr *SizeExpr,
784 unsigned IndexTypeQuals,
785 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000786
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000787 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// modifier, (known) size of the array, and index type qualifiers.
789 ///
790 /// By default, performs semantic analysis when building the array type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000793 ArrayType::ArraySizeModifier SizeMod,
794 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000795 unsigned IndexTypeQuals,
796 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000798 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 /// modifier, and index type qualifiers.
800 ///
801 /// By default, performs semantic analysis when building the array type.
802 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000803 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000805 unsigned IndexTypeQuals,
806 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000808 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 /// size modifier, size expression, and index type qualifiers.
810 ///
811 /// By default, performs semantic analysis when building the array type.
812 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000813 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000814 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000815 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000816 unsigned IndexTypeQuals,
817 SourceRange BracketsRange);
818
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000819 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// size modifier, size expression, and index type qualifiers.
821 ///
822 /// By default, performs semantic analysis when building the array type.
823 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000824 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000825 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000826 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 unsigned IndexTypeQuals,
828 SourceRange BracketsRange);
829
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000830 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 /// number of elements.
832 ///
833 /// By default, performs semantic analysis when building the vector type.
834 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000835 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000836 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Erich Keanef702b022018-07-13 19:46:04 +0000838 /// Build a new potentially dependently-sized extended vector type
839 /// given the element type and number of elements.
840 ///
841 /// By default, performs semantic analysis when building the vector type.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
844 SourceLocation AttributeLoc,
845 VectorType::VectorKind);
846
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000847 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 /// number of elements.
849 ///
850 /// By default, performs semantic analysis when building the vector type.
851 /// Subclasses may override this routine to provide different behavior.
852 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
853 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000854
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000855 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000856 /// given the element type and number of elements.
857 ///
858 /// By default, performs semantic analysis when building the vector type.
859 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000860 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000861 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000862 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000863
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000864 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000865 /// type variable with the correct address space (retrieved from
866 /// AddrSpaceExpr) applied to it. The former will be returned in cases
867 /// where the address space remains dependent.
868 ///
869 /// By default, performs semantic analysis when building the type with address
870 /// space applied. Subclasses may override this routine to provide different
871 /// behavior.
872 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
873 Expr *AddrSpaceExpr,
874 SourceLocation AttributeLoc);
875
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000876 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000877 ///
878 /// By default, performs semantic analysis when building the function type.
879 /// Subclasses may override this routine to provide different behavior.
880 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000881 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000882 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000883
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000884 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000885 QualType RebuildFunctionNoProtoType(QualType ResultType);
886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000888 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000889 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000890
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000891 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000892 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000893 return SemaRef.Context.getTypeDeclType(Typedef);
894 }
895
Leonard Chanc72aaf62019-05-07 03:20:17 +0000896 /// Build a new MacroDefined type.
897 QualType RebuildMacroQualifiedType(QualType T,
898 const IdentifierInfo *MacroII) {
899 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
900 }
901
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000902 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000903 QualType RebuildRecordType(RecordDecl *Record) {
904 return SemaRef.Context.getTypeDeclType(Record);
905 }
906
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000907 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000908 QualType RebuildEnumType(EnumDecl *Enum) {
909 return SemaRef.Context.getTypeDeclType(Enum);
910 }
John McCallfcc33b02009-09-05 00:15:47 +0000911
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000912 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000913 ///
914 /// By default, performs semantic analysis when building the typeof type.
915 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000916 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000917
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000918 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000919 ///
920 /// By default, builds a new TypeOfType with the given underlying type.
921 QualType RebuildTypeOfType(QualType Underlying);
922
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000923 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000924 QualType RebuildUnaryTransformType(QualType BaseType,
925 UnaryTransformType::UTTKind UKind,
926 SourceLocation Loc);
927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000928 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000929 ///
930 /// By default, performs semantic analysis when building the decltype type.
931 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000932 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000933
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000934 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000935 ///
936 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000937 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000938 // Note, IsDependent is always false here: we implicitly convert an 'auto'
939 // which has been deduced to a dependent type into an undeduced 'auto', so
940 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000941 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000942 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000943 }
944
Richard Smith600b5262017-01-26 20:40:47 +0000945 /// By default, builds a new DeducedTemplateSpecializationType with the given
946 /// deduced type.
947 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
948 QualType Deduced) {
949 return SemaRef.Context.getDeducedTemplateSpecializationType(
950 Template, Deduced, /*IsDependent*/ false);
951 }
952
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000953 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000954 ///
955 /// By default, performs semantic analysis when building the template
956 /// specialization type. Subclasses may override this routine to provide
957 /// different behavior.
958 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000959 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000960 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000961
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000962 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000963 ///
964 /// By default, builds a new ParenType type from the inner type.
965 /// Subclasses may override this routine to provide different behavior.
966 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000967 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000968 }
969
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000970 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000971 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000972 /// By default, builds a new ElaboratedType type from the keyword,
973 /// the nested-name-specifier and the named type.
974 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000975 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
976 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000977 NestedNameSpecifierLoc QualifierLoc,
978 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000979 return SemaRef.Context.getElaboratedType(Keyword,
980 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000981 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000982 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000983
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000984 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000985 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000986 /// By default, builds a new DependentNameType type from the
987 /// nested-name-specifier and the given type. Subclasses may override
988 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000989 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000990 ElaboratedTypeKeyword Keyword,
991 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000992 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 const IdentifierInfo *Name,
994 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000995 TemplateArgumentListInfo &Args,
996 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000997 // Rebuild the template name.
998 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000999 CXXScopeSpec SS;
1000 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +00001001 TemplateName InstName = getDerived().RebuildTemplateName(
1002 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1003 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +00001004
Douglas Gregora7a795b2011-03-01 20:11:18 +00001005 if (InstName.isNull())
1006 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001007
Douglas Gregora7a795b2011-03-01 20:11:18 +00001008 // If it's still dependent, make a dependent specialization.
1009 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +00001010 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1011 QualifierLoc.getNestedNameSpecifier(),
1012 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +00001013 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +00001014
Douglas Gregora7a795b2011-03-01 20:11:18 +00001015 // Otherwise, make an elaborated type wrapping a non-dependent
1016 // specialization.
1017 QualType T =
1018 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1019 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001020
Craig Topperc3ec1492014-05-26 06:22:03 +00001021 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001022 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001023
1024 return SemaRef.Context.getElaboratedType(Keyword,
1025 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001026 T);
1027 }
1028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001029 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001030 ///
1031 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001032 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001033 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001034 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001035 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001036 NestedNameSpecifierLoc QualifierLoc,
1037 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001038 SourceLocation IdLoc,
1039 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001040 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001041 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001042
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001043 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001044 // If the name is still dependent, just build a new dependent name type.
1045 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001046 return SemaRef.Context.getDependentNameType(Keyword,
1047 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001048 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001049 }
1050
Richard Smithee579842017-01-30 20:39:26 +00001051 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1052 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1053 *Id, IdLoc);
1054 // If a dependent name resolves to a deduced template specialization type,
1055 // check that we're in one of the syntactic contexts permitting it.
1056 if (!DeducedTSTContext) {
1057 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1058 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1059 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1060 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1061 Deduced->getTemplateName())
1062 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1063 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1064 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1065 return QualType();
1066 }
1067 }
1068 return T;
1069 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001070
1071 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1072
Abramo Bagnarad7548482010-05-19 21:37:53 +00001073 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001074 // into a non-dependent elaborated-type-specifier. Find the tag we're
1075 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001076 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001077 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1078 if (!DC)
1079 return QualType();
1080
John McCallbf8c5192010-05-27 06:40:31 +00001081 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1082 return QualType();
1083
Craig Topperc3ec1492014-05-26 06:22:03 +00001084 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001085 SemaRef.LookupQualifiedName(Result, DC);
1086 switch (Result.getResultKind()) {
1087 case LookupResult::NotFound:
1088 case LookupResult::NotFoundInCurrentInstantiation:
1089 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001090
Douglas Gregore677daf2010-03-31 22:19:08 +00001091 case LookupResult::Found:
1092 Tag = Result.getAsSingle<TagDecl>();
1093 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001094
Douglas Gregore677daf2010-03-31 22:19:08 +00001095 case LookupResult::FoundOverloaded:
1096 case LookupResult::FoundUnresolvedValue:
1097 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001098
Douglas Gregore677daf2010-03-31 22:19:08 +00001099 case LookupResult::Ambiguous:
1100 // Let the LookupResult structure handle ambiguities.
1101 return QualType();
1102 }
1103
1104 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001105 // Check where the name exists but isn't a tag type and use that to emit
1106 // better diagnostics.
1107 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1108 SemaRef.LookupQualifiedName(Result, DC);
1109 switch (Result.getResultKind()) {
1110 case LookupResult::Found:
1111 case LookupResult::FoundOverloaded:
1112 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001113 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001114 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1115 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1116 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001117 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1118 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001119 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001120 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001121 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001122 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001123 break;
1124 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001125 return QualType();
1126 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001127
Richard Trieucaa33d32011-06-10 03:11:26 +00001128 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001129 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001130 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001131 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1132 return QualType();
1133 }
1134
1135 // Build the elaborated-type-specifier type.
1136 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001137 return SemaRef.Context.getElaboratedType(Keyword,
1138 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001139 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001142 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001143 ///
1144 /// By default, builds a new PackExpansionType type from the given pattern.
1145 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001146 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001147 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001148 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001149 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001150 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1151 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001152 }
1153
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001154 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001155 ///
1156 /// By default, performs semantic analysis when building the atomic type.
1157 /// Subclasses may override this routine to provide different behavior.
1158 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1159
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001160 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001161 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1162 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001164 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001165 /// indicating whether the "template" keyword was provided, and the template
1166 /// that the template name refers to.
1167 ///
1168 /// By default, builds the new template name directly. Subclasses may override
1169 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001170 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001171 bool TemplateKW,
1172 TemplateDecl *Template);
1173
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001174 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001175 /// name that is referred to as a template.
1176 ///
1177 /// By default, performs semantic analysis to determine whether the name can
1178 /// be resolved to a specific template, then builds the appropriate kind of
1179 /// template name. Subclasses may override this routine to provide different
1180 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001181 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001182 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001183 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001184 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001185 NamedDecl *FirstQualifierInScope,
1186 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001188 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001189 /// overloaded operator name that is referred to as a template.
1190 ///
1191 /// By default, performs semantic analysis to determine whether the name can
1192 /// be resolved to a specific template, then builds the appropriate kind of
1193 /// template name. Subclasses may override this routine to provide different
1194 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001195 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001196 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001197 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001198 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001199 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001201 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001202 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001203 ///
1204 /// By default, performs semantic analysis to determine whether the name can
1205 /// be resolved to a specific template, then builds the appropriate kind of
1206 /// template name. Subclasses may override this routine to provide different
1207 /// behavior.
1208 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1209 const TemplateArgument &ArgPack) {
1210 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1211 }
1212
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001213 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001217 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 MultiStmtArg Statements,
1219 SourceLocation RBraceLoc,
1220 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001221 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 IsStmtExpr);
1223 }
1224
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001225 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001234 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 ColonLoc);
1236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001238 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001242 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001243 getSema().ActOnCaseStmtBody(S, Body);
1244 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001245 }
Mike Stump11289f42009-09-09 15:08:12 +00001246
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001247 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001251 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001253 Stmt *SubStmt) {
1254 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001255 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001258 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001262 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1263 SourceLocation ColonLoc, Stmt *SubStmt) {
1264 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001265 }
Mike Stump11289f42009-09-09 15:08:12 +00001266
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001267 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001268 ///
1269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001271 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1272 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001273 Stmt *SubStmt) {
1274 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1275 }
1276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001277 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001281 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001282 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001283 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001284 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001285 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001288 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001292 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001293 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001294 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001295 }
Mike Stump11289f42009-09-09 15:08:12 +00001296
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001297 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001298 ///
1299 /// By default, performs semantic analysis to build the new statement.
1300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001301 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001302 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001303 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001304 }
1305
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001306 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001310 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1311 Sema::ConditionResult Cond, Stmt *Body) {
1312 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001315 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001319 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001320 SourceLocation WhileLoc, SourceLocation LParenLoc,
1321 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001322 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1323 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001324 }
1325
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001326 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001330 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001331 Stmt *Init, Sema::ConditionResult Cond,
1332 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1333 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001334 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001335 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001336 }
Mike Stump11289f42009-09-09 15:08:12 +00001337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001338 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001342 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1343 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001344 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001345 }
1346
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001347 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001351 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001352 SourceLocation StarLoc,
1353 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001354 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001355 }
Mike Stump11289f42009-09-09 15:08:12 +00001356
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001357 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001361 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001362 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001365 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001366 ///
1367 /// By default, performs semantic analysis to build the new statement.
1368 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001369 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001370 SourceLocation StartLoc, SourceLocation EndLoc) {
1371 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001372 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001373 }
Mike Stump11289f42009-09-09 15:08:12 +00001374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001375 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001379 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1380 bool IsVolatile, unsigned NumOutputs,
1381 unsigned NumInputs, IdentifierInfo **Names,
1382 MultiExprArg Constraints, MultiExprArg Exprs,
1383 Expr *AsmString, MultiExprArg Clobbers,
1384 SourceLocation RParenLoc) {
1385 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1386 NumInputs, Names, Constraints, Exprs,
Erich Keaned0f34fd2019-05-30 15:38:02 +00001387 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001388 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001389
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001390 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001391 ///
1392 /// By default, performs semantic analysis to build the new statement.
1393 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001394 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001395 ArrayRef<Token> AsmToks,
1396 StringRef AsmString,
1397 unsigned NumOutputs, unsigned NumInputs,
1398 ArrayRef<StringRef> Constraints,
1399 ArrayRef<StringRef> Clobbers,
1400 ArrayRef<Expr*> Exprs,
1401 SourceLocation EndLoc) {
1402 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1403 NumOutputs, NumInputs,
1404 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001405 }
1406
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001407 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001408 ///
1409 /// By default, performs semantic analysis to build the new statement.
1410 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001411 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1412 bool IsImplicit) {
1413 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001414 }
1415
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001416 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001417 ///
1418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001420 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1421 bool IsImplicit) {
1422 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1423 }
1424
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001425 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1430 Expr *Result,
1431 UnresolvedLookupExpr *Lookup) {
1432 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001433 }
1434
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001435 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1440 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1441 }
1442
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001443 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1444 return getSema().BuildCoroutineBodyStmt(Args);
1445 }
1446
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001447 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001453 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001454 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001455 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001456 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001457 }
1458
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001459 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001460 ///
1461 /// By default, performs semantic analysis to build the new declaration.
1462 /// Subclasses may override this routine to provide different behavior.
1463 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1464 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001465 return getSema().BuildObjCExceptionDecl(TInfo, T,
1466 ExceptionDecl->getInnerLocStart(),
1467 ExceptionDecl->getLocation(),
1468 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001470
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001471 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001472 ///
1473 /// By default, performs semantic analysis to build the new statement.
1474 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001475 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001476 SourceLocation RParenLoc,
1477 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001478 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001479 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001480 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001481 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001482
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001483 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001484 ///
1485 /// By default, performs semantic analysis to build the new statement.
1486 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001487 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001488 Stmt *Body) {
1489 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001490 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001491
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001492 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001493 ///
1494 /// By default, performs semantic analysis to build the new statement.
1495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001496 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001497 Expr *Operand) {
1498 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001500
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001501 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001502 ///
1503 /// By default, performs semantic analysis to build the new statement.
1504 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001505 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001506 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001507 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001508 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001509 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001510 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001511 return getSema().ActOnOpenMPExecutableDirective(
1512 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001513 }
1514
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001515 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001516 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001517 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001518 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001519 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1520 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001521 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001522 SourceLocation NameModifierLoc,
1523 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001524 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001525 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1526 LParenLoc, NameModifierLoc, ColonLoc,
1527 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001528 }
1529
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001530 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1538 EndLoc);
1539 }
1540
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001541 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001542 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001543 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001544 /// Subclasses may override this routine to provide different behavior.
1545 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1546 SourceLocation StartLoc,
1547 SourceLocation LParenLoc,
1548 SourceLocation EndLoc) {
1549 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1550 LParenLoc, EndLoc);
1551 }
1552
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001553 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001554 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001555 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001556 /// Subclasses may override this routine to provide different behavior.
1557 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1561 }
1562
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001563 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001564 ///
1565 /// By default, performs semantic analysis to build the new OpenMP clause.
1566 /// Subclasses may override this routine to provide different behavior.
1567 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1568 SourceLocation LParenLoc,
1569 SourceLocation EndLoc) {
1570 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1571 }
1572
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001573 /// Build a new OpenMP 'allocator' clause.
1574 ///
1575 /// By default, performs semantic analysis to build the new OpenMP clause.
1576 /// Subclasses may override this routine to provide different behavior.
1577 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
1578 SourceLocation LParenLoc,
1579 SourceLocation EndLoc) {
1580 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1581 }
1582
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001583 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001584 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001585 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001586 /// Subclasses may override this routine to provide different behavior.
1587 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1588 SourceLocation LParenLoc,
1589 SourceLocation EndLoc) {
1590 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1591 EndLoc);
1592 }
1593
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001594 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001595 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001596 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001597 /// Subclasses may override this routine to provide different behavior.
1598 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1599 SourceLocation KindKwLoc,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1604 StartLoc, LParenLoc, EndLoc);
1605 }
1606
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001607 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001608 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001609 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1612 SourceLocation KindKwLoc,
1613 SourceLocation StartLoc,
1614 SourceLocation LParenLoc,
1615 SourceLocation EndLoc) {
1616 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1617 StartLoc, LParenLoc, EndLoc);
1618 }
1619
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001620 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001621 ///
1622 /// By default, performs semantic analysis to build the new OpenMP clause.
1623 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001624 OMPClause *RebuildOMPScheduleClause(
1625 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1626 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1627 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1628 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001629 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001630 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1631 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001632 }
1633
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001634 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001635 ///
1636 /// By default, performs semantic analysis to build the new OpenMP clause.
1637 /// Subclasses may override this routine to provide different behavior.
1638 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1639 SourceLocation EndLoc,
1640 SourceLocation LParenLoc, Expr *Num) {
1641 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1642 }
1643
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001644 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001645 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001646 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001647 /// Subclasses may override this routine to provide different behavior.
1648 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1649 SourceLocation StartLoc,
1650 SourceLocation LParenLoc,
1651 SourceLocation EndLoc) {
1652 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1653 EndLoc);
1654 }
1655
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001656 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001657 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001658 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001659 /// Subclasses may override this routine to provide different behavior.
1660 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1661 SourceLocation StartLoc,
1662 SourceLocation LParenLoc,
1663 SourceLocation EndLoc) {
1664 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1665 EndLoc);
1666 }
1667
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001668 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001669 ///
1670 /// By default, performs semantic analysis to build the new OpenMP clause.
1671 /// Subclasses may override this routine to provide different behavior.
1672 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1673 SourceLocation StartLoc,
1674 SourceLocation LParenLoc,
1675 SourceLocation EndLoc) {
1676 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1677 EndLoc);
1678 }
1679
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001680 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001681 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001682 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001683 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001684 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1685 SourceLocation StartLoc,
1686 SourceLocation LParenLoc,
1687 SourceLocation EndLoc) {
1688 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1689 EndLoc);
1690 }
1691
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001692 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1696 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1697 SourceLocation StartLoc,
1698 SourceLocation LParenLoc,
1699 SourceLocation ColonLoc,
1700 SourceLocation EndLoc,
1701 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001702 const DeclarationNameInfo &ReductionId,
1703 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001704 return getSema().ActOnOpenMPReductionClause(
1705 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001706 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001707 }
1708
Alexey Bataev169d96a2017-07-18 20:17:46 +00001709 /// Build a new OpenMP 'task_reduction' clause.
1710 ///
1711 /// By default, performs semantic analysis to build the new statement.
1712 /// Subclasses may override this routine to provide different behavior.
1713 OMPClause *RebuildOMPTaskReductionClause(
1714 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1715 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1716 CXXScopeSpec &ReductionIdScopeSpec,
1717 const DeclarationNameInfo &ReductionId,
1718 ArrayRef<Expr *> UnresolvedReductions) {
1719 return getSema().ActOnOpenMPTaskReductionClause(
1720 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1721 ReductionId, UnresolvedReductions);
1722 }
1723
Alexey Bataevfa312f32017-07-21 18:48:21 +00001724 /// Build a new OpenMP 'in_reduction' clause.
1725 ///
1726 /// By default, performs semantic analysis to build the new statement.
1727 /// Subclasses may override this routine to provide different behavior.
1728 OMPClause *
1729 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1730 SourceLocation LParenLoc, SourceLocation ColonLoc,
1731 SourceLocation EndLoc,
1732 CXXScopeSpec &ReductionIdScopeSpec,
1733 const DeclarationNameInfo &ReductionId,
1734 ArrayRef<Expr *> UnresolvedReductions) {
1735 return getSema().ActOnOpenMPInReductionClause(
1736 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1737 ReductionId, UnresolvedReductions);
1738 }
1739
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001740 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001741 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001742 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001743 /// Subclasses may override this routine to provide different behavior.
1744 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1745 SourceLocation StartLoc,
1746 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001747 OpenMPLinearClauseKind Modifier,
1748 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001749 SourceLocation ColonLoc,
1750 SourceLocation EndLoc) {
1751 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001752 Modifier, ModifierLoc, ColonLoc,
1753 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001754 }
1755
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001756 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001757 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001758 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001759 /// Subclasses may override this routine to provide different behavior.
1760 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1761 SourceLocation StartLoc,
1762 SourceLocation LParenLoc,
1763 SourceLocation ColonLoc,
1764 SourceLocation EndLoc) {
1765 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1766 LParenLoc, ColonLoc, EndLoc);
1767 }
1768
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001769 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001770 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001771 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001772 /// Subclasses may override this routine to provide different behavior.
1773 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1774 SourceLocation StartLoc,
1775 SourceLocation LParenLoc,
1776 SourceLocation EndLoc) {
1777 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1778 EndLoc);
1779 }
1780
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001781 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001782 ///
1783 /// By default, performs semantic analysis to build the new OpenMP clause.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1786 SourceLocation StartLoc,
1787 SourceLocation LParenLoc,
1788 SourceLocation EndLoc) {
1789 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1790 EndLoc);
1791 }
1792
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001793 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001794 ///
1795 /// By default, performs semantic analysis to build the new OpenMP clause.
1796 /// Subclasses may override this routine to provide different behavior.
1797 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1798 SourceLocation StartLoc,
1799 SourceLocation LParenLoc,
1800 SourceLocation EndLoc) {
1801 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1802 EndLoc);
1803 }
1804
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001805 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001806 ///
1807 /// By default, performs semantic analysis to build the new OpenMP clause.
1808 /// Subclasses may override this routine to provide different behavior.
1809 OMPClause *
1810 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1811 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1812 SourceLocation StartLoc, SourceLocation LParenLoc,
1813 SourceLocation EndLoc) {
1814 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1815 StartLoc, LParenLoc, EndLoc);
1816 }
1817
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001818 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001819 ///
1820 /// By default, performs semantic analysis to build the new statement.
1821 /// Subclasses may override this routine to provide different behavior.
1822 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1823 SourceLocation LParenLoc,
1824 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001825 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001826 EndLoc);
1827 }
1828
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001829 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001830 ///
1831 /// By default, performs semantic analysis to build the new OpenMP clause.
1832 /// Subclasses may override this routine to provide different behavior.
Michael Kruse4304e9d2019-02-19 16:38:20 +00001833 OMPClause *RebuildOMPMapClause(
1834 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1835 ArrayRef<SourceLocation> MapTypeModifiersLoc,
1836 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1837 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1838 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1839 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
Kelvin Lief579432018-12-18 22:18:41 +00001840 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001841 MapperIdScopeSpec, MapperId, MapType,
1842 IsMapTypeImplicit, MapLoc, ColonLoc,
1843 VarList, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001844 }
1845
Alexey Bataeve04483e2019-03-27 14:14:31 +00001846 /// Build a new OpenMP 'allocate' clause.
1847 ///
1848 /// By default, performs semantic analysis to build the new OpenMP clause.
1849 /// Subclasses may override this routine to provide different behavior.
1850 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
1851 SourceLocation StartLoc,
1852 SourceLocation LParenLoc,
1853 SourceLocation ColonLoc,
1854 SourceLocation EndLoc) {
1855 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1856 LParenLoc, ColonLoc, EndLoc);
1857 }
1858
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001859 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001860 ///
1861 /// By default, performs semantic analysis to build the new statement.
1862 /// Subclasses may override this routine to provide different behavior.
1863 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1864 SourceLocation LParenLoc,
1865 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001866 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001867 EndLoc);
1868 }
1869
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001870 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001871 ///
1872 /// By default, performs semantic analysis to build the new statement.
1873 /// Subclasses may override this routine to provide different behavior.
1874 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1875 SourceLocation StartLoc,
1876 SourceLocation LParenLoc,
1877 SourceLocation EndLoc) {
1878 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1879 LParenLoc, EndLoc);
1880 }
1881
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001882 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001883 ///
1884 /// By default, performs semantic analysis to build the new statement.
1885 /// Subclasses may override this routine to provide different behavior.
1886 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1887 SourceLocation LParenLoc,
1888 SourceLocation EndLoc) {
1889 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1890 EndLoc);
1891 }
1892
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001893 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001894 ///
1895 /// By default, performs semantic analysis to build the new statement.
1896 /// Subclasses may override this routine to provide different behavior.
1897 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1898 SourceLocation LParenLoc,
1899 SourceLocation EndLoc) {
1900 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1901 EndLoc);
1902 }
1903
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001904 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001905 ///
1906 /// By default, performs semantic analysis to build the new statement.
1907 /// Subclasses may override this routine to provide different behavior.
1908 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1909 SourceLocation LParenLoc,
1910 SourceLocation EndLoc) {
1911 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1912 EndLoc);
1913 }
1914
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001915 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001916 ///
1917 /// By default, performs semantic analysis to build the new statement.
1918 /// Subclasses may override this routine to provide different behavior.
1919 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1920 SourceLocation LParenLoc,
1921 SourceLocation EndLoc) {
1922 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1923 }
1924
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001925 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001926 ///
1927 /// By default, performs semantic analysis to build the new OpenMP clause.
1928 /// Subclasses may override this routine to provide different behavior.
1929 OMPClause *
1930 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1931 Expr *ChunkSize, SourceLocation StartLoc,
1932 SourceLocation LParenLoc, SourceLocation KindLoc,
1933 SourceLocation CommaLoc, SourceLocation EndLoc) {
1934 return getSema().ActOnOpenMPDistScheduleClause(
1935 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1936 }
1937
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001938 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001939 ///
1940 /// By default, performs semantic analysis to build the new statement.
1941 /// Subclasses may override this routine to provide different behavior.
1942 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
Michael Kruse01f670d2019-02-22 22:29:42 +00001943 CXXScopeSpec &MapperIdScopeSpec,
1944 DeclarationNameInfo &MapperId,
1945 const OMPVarListLocTy &Locs,
1946 ArrayRef<Expr *> UnresolvedMappers) {
1947 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1948 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00001949 }
1950
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001951 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001952 ///
1953 /// By default, performs semantic analysis to build the new statement.
1954 /// Subclasses may override this routine to provide different behavior.
1955 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
Michael Kruse0336c752019-02-25 20:34:15 +00001956 CXXScopeSpec &MapperIdScopeSpec,
1957 DeclarationNameInfo &MapperId,
1958 const OMPVarListLocTy &Locs,
1959 ArrayRef<Expr *> UnresolvedMappers) {
1960 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1961 Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00001962 }
1963
Carlo Bertolli2404b172016-07-13 15:37:16 +00001964 /// Build a new OpenMP 'use_device_ptr' clause.
1965 ///
1966 /// By default, performs semantic analysis to build the new OpenMP clause.
1967 /// Subclasses may override this routine to provide different behavior.
1968 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001969 const OMPVarListLocTy &Locs) {
1970 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001971 }
1972
Carlo Bertolli70594e92016-07-13 17:16:49 +00001973 /// Build a new OpenMP 'is_device_ptr' clause.
1974 ///
1975 /// By default, performs semantic analysis to build the new OpenMP clause.
1976 /// Subclasses may override this routine to provide different behavior.
1977 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001978 const OMPVarListLocTy &Locs) {
1979 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001980 }
1981
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001982 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001983 ///
1984 /// By default, performs semantic analysis to build the new statement.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1987 Expr *object) {
1988 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1989 }
1990
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001991 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001992 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001993 /// By default, performs semantic analysis to build the new statement.
1994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001995 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001996 Expr *Object, Stmt *Body) {
1997 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001998 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001999
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002000 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00002001 ///
2002 /// By default, performs semantic analysis to build the new statement.
2003 /// Subclasses may override this routine to provide different behavior.
2004 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
2005 Stmt *Body) {
2006 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2007 }
John McCall53848232011-07-27 01:07:15 +00002008
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002009 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00002010 ///
2011 /// By default, performs semantic analysis to build the new statement.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002014 Stmt *Element,
2015 Expr *Collection,
2016 SourceLocation RParenLoc,
2017 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00002018 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002019 Element,
John McCallb268a282010-08-23 23:25:46 +00002020 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002021 RParenLoc);
2022 if (ForEachStmt.isInvalid())
2023 return StmtError();
2024
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002025 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00002026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002027
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002028 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00002029 ///
2030 /// By default, performs semantic analysis to build the new decaration.
2031 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00002032 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00002033 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00002034 SourceLocation StartLoc,
2035 SourceLocation IdLoc,
2036 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002037 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002038 StartLoc, IdLoc, Id);
2039 if (Var)
2040 getSema().CurContext->addDecl(Var);
2041 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002042 }
2043
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002044 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002045 ///
2046 /// By default, performs semantic analysis to build the new statement.
2047 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002048 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002049 VarDecl *ExceptionDecl,
2050 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002051 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2052 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002053 }
Mike Stump11289f42009-09-09 15:08:12 +00002054
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002055 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002056 ///
2057 /// By default, performs semantic analysis to build the new statement.
2058 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002059 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2060 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002061 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002062 }
Mike Stump11289f42009-09-09 15:08:12 +00002063
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002064 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002065 ///
2066 /// By default, performs semantic analysis to build the new statement.
2067 /// Subclasses may override this routine to provide different behavior.
2068 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002069 SourceLocation CoawaitLoc, Stmt *Init,
2070 SourceLocation ColonLoc, Stmt *Range,
2071 Stmt *Begin, Stmt *End, Expr *Cond,
2072 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002073 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002074 // If we've just learned that the range is actually an Objective-C
2075 // collection, treat this as an Objective-C fast enumeration loop.
2076 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2077 if (RangeStmt->isSingleDecl()) {
2078 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002079 if (RangeVar->isInvalidDecl())
2080 return StmtError();
2081
Douglas Gregorf7106af2013-04-08 18:40:13 +00002082 Expr *RangeExpr = RangeVar->getInit();
2083 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002084 RangeExpr->getType()->isObjCObjectPointerType()) {
2085 // FIXME: Support init-statements in Objective-C++20 ranged for
2086 // statement.
2087 if (Init) {
2088 return SemaRef.Diag(Init->getBeginLoc(),
2089 diag::err_objc_for_range_init_stmt)
2090 << Init->getSourceRange();
2091 }
2092 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2093 RangeExpr, RParenLoc);
2094 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002095 }
2096 }
2097 }
2098
Richard Smith8baa5002018-09-28 18:44:09 +00002099 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2100 Range, Begin, End, Cond, Inc, LoopVar,
2101 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002102 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002103
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002104 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002105 ///
2106 /// By default, performs semantic analysis to build the new statement.
2107 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002108 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002109 bool IsIfExists,
2110 NestedNameSpecifierLoc QualifierLoc,
2111 DeclarationNameInfo NameInfo,
2112 Stmt *Nested) {
2113 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2114 QualifierLoc, NameInfo, Nested);
2115 }
2116
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002117 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002118 ///
2119 /// By default, performs semantic analysis to finish the new statement.
2120 /// Subclasses may override this routine to provide different behavior.
2121 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2122 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2123 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002124
David Majnemerfad8f482013-10-15 09:33:02 +00002125 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002126 Stmt *TryBlock, Stmt *Handler) {
2127 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002128 }
2129
David Majnemerfad8f482013-10-15 09:33:02 +00002130 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002131 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002132 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002133 }
2134
David Majnemerfad8f482013-10-15 09:33:02 +00002135 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002136 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002137 }
2138
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002139 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002140 ///
2141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
2143 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002144 PredefinedExpr::IdentKind IK) {
2145 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002146 }
2147
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002148 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 ///
2150 /// By default, performs semantic analysis to build the new expression.
2151 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002152 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002153 LookupResult &R,
2154 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002155 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2156 }
2157
2158
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002159 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002163 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002164 ValueDecl *VD,
2165 const DeclarationNameInfo &NameInfo,
2166 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002167 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002168 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002169
2170 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002171
2172 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002175 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002176 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002179 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002181 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 }
2183
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002184 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002185 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002186 /// By default, performs semantic analysis to build the new expression.
2187 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002188 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002189 SourceLocation OperatorLoc,
2190 bool isArrow,
2191 CXXScopeSpec &SS,
2192 TypeSourceInfo *ScopeType,
2193 SourceLocation CCLoc,
2194 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002195 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002196
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002197 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002198 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002201 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002202 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002203 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002204 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 }
Mike Stump11289f42009-09-09 15:08:12 +00002206
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002207 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002208 ///
2209 /// By default, performs semantic analysis to build the new expression.
2210 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002211 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002212 TypeSourceInfo *Type,
2213 ArrayRef<Sema::OffsetOfComponent> Components,
2214 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002215 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002216 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002217 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002218
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002219 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002220 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 /// By default, performs semantic analysis to build the new expression.
2223 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002224 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2225 SourceLocation OpLoc,
2226 UnaryExprOrTypeTrait ExprKind,
2227 SourceRange R) {
2228 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 }
2230
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002231 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002232 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002233 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 /// By default, performs semantic analysis to build the new expression.
2235 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002236 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2237 UnaryExprOrTypeTrait ExprKind,
2238 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002240 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002242 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002243
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002244 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 }
Mike Stump11289f42009-09-09 15:08:12 +00002246
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002247 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002248 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 /// By default, performs semantic analysis to build the new expression.
2250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002251 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002253 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002255 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002256 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 RBracketLoc);
2258 }
2259
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002260 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002261 ///
2262 /// By default, performs semantic analysis to build the new expression.
2263 /// Subclasses may override this routine to provide different behavior.
2264 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2265 Expr *LowerBound,
2266 SourceLocation ColonLoc, Expr *Length,
2267 SourceLocation RBracketLoc) {
2268 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2269 ColonLoc, Length, RBracketLoc);
2270 }
2271
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002272 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002273 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 /// By default, performs semantic analysis to build the new expression.
2275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002276 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002278 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002279 Expr *ExecConfig = nullptr) {
Richard Smith255b85f2019-05-08 01:36:36 +00002280 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args,
2281 RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 }
2283
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002284 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002285 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 /// By default, performs semantic analysis to build the new expression.
2287 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002288 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002289 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002290 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002291 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002292 const DeclarationNameInfo &MemberNameInfo,
2293 ValueDecl *Member,
2294 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002295 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002296 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002297 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2298 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002299 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002300 // We have a reference to an unnamed field. This is always the
2301 // base of an anonymous struct/union member access, i.e. the
2302 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002303 assert(Member->getType()->isRecordType() &&
2304 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002305
Richard Smithcab9a7d2011-10-26 19:06:56 +00002306 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002307 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002308 QualifierLoc.getNestedNameSpecifier(),
2309 FoundDecl, Member);
2310 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002311 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002312 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002313
2314 CXXScopeSpec EmptySS;
2315 return getSema().BuildFieldReferenceExpr(
2316 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2317 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002318 }
Mike Stump11289f42009-09-09 15:08:12 +00002319
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002320 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002321 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002322
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002323 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002324 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002325
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002326 if (isArrow && !BaseType->isPointerType())
2327 return ExprError();
2328
John McCall16df1e52010-03-30 21:47:33 +00002329 // FIXME: this involves duplicating earlier analysis in a lot of
2330 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002331 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002332 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002333 R.resolveKind();
2334
John McCallb268a282010-08-23 23:25:46 +00002335 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002336 SS, TemplateKWLoc,
2337 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002338 R, ExplicitTemplateArgs,
2339 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 }
Mike Stump11289f42009-09-09 15:08:12 +00002341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002342 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002346 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002347 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002348 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002349 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 }
2351
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002352 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 /// By default, performs semantic analysis to build the new expression.
2355 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002356 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002357 SourceLocation QuestionLoc,
2358 Expr *LHS,
2359 SourceLocation ColonLoc,
2360 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002361 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2362 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002363 }
2364
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002365 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002366 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 /// By default, performs semantic analysis to build the new expression.
2368 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002369 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002370 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002372 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002373 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002374 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 }
Mike Stump11289f42009-09-09 15:08:12 +00002376
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002377 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002378 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 /// By default, performs semantic analysis to build the new expression.
2380 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002381 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002382 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002384 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002385 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002386 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 }
Mike Stump11289f42009-09-09 15:08:12 +00002388
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002389 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002390 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 SourceLocation OpLoc,
2395 SourceLocation AccessorLoc,
2396 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002397
John McCall10eae182009-11-30 22:42:35 +00002398 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002399 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002400 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002401 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002402 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002403 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002404 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002405 /* TemplateArgs */ nullptr,
2406 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002407 }
Mike Stump11289f42009-09-09 15:08:12 +00002408
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002409 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002410 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 /// By default, performs semantic analysis to build the new expression.
2412 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002413 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002414 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002415 SourceLocation RBraceLoc) {
2416 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
Mike Stump11289f42009-09-09 15:08:12 +00002418
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002419 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002420 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 MultiExprArg ArrayExprs,
2425 SourceLocation EqualOrColonLoc,
2426 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002427 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002430 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002432 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002433
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002434 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 }
Mike Stump11289f42009-09-09 15:08:12 +00002436
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002437 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002438 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 /// By default, builds the implicit value initialization without performing
2440 /// any semantic analysis. Subclasses may override this routine to provide
2441 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002442 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002443 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 }
Mike Stump11289f42009-09-09 15:08:12 +00002445
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002446 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002447 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002448 /// By default, performs semantic analysis to build the new expression.
2449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002450 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002451 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002452 SourceLocation RParenLoc) {
2453 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002454 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002455 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002456 }
2457
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002458 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002459 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 /// By default, performs semantic analysis to build the new expression.
2461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002462 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002463 MultiExprArg SubExprs,
2464 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002465 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 }
Mike Stump11289f42009-09-09 15:08:12 +00002467
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002468 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002469 ///
2470 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 /// rather than attempting to map the label statement itself.
2472 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002473 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002474 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002475 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002476 }
Mike Stump11289f42009-09-09 15:08:12 +00002477
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002478 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002479 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 /// By default, performs semantic analysis to build the new expression.
2481 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002482 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002483 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002485 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 }
Mike Stump11289f42009-09-09 15:08:12 +00002487
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002488 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 ///
2490 /// By default, performs semantic analysis to build the new expression.
2491 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002492 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002493 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 SourceLocation RParenLoc) {
2495 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002496 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 RParenLoc);
2498 }
Mike Stump11289f42009-09-09 15:08:12 +00002499
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002500 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002501 ///
2502 /// By default, performs semantic analysis to build the new expression.
2503 /// Subclasses may override this routine to provide different behavior.
2504 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2505 SourceLocation DefaultLoc,
2506 SourceLocation RParenLoc,
2507 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002508 ArrayRef<TypeSourceInfo *> Types,
2509 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002510 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002511 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002512 }
2513
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002514 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 ///
2516 /// By default, performs semantic analysis to build the new expression.
2517 /// The semantic analysis provides the behavior of template instantiation,
2518 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002519 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002520 /// argument-dependent lookup, etc. Subclasses may override this routine to
2521 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002522 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002524 Expr *Callee,
2525 Expr *First,
2526 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002527
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002528 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 /// reinterpret_cast.
2530 ///
2531 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002532 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002534 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 Stmt::StmtClass Class,
2536 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002537 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002538 SourceLocation RAngleLoc,
2539 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002540 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 SourceLocation RParenLoc) {
2542 switch (Class) {
2543 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002544 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002545 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002546 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002547
2548 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002549 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002550 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002551 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002554 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002555 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002556 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002558
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002560 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002561 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002562 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002563
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002565 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002566 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 }
Mike Stump11289f42009-09-09 15:08:12 +00002568
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002569 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 ///
2571 /// By default, performs semantic analysis to build the new expression.
2572 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002573 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002575 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002576 SourceLocation RAngleLoc,
2577 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002578 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002580 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002581 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002582 SourceRange(LAngleLoc, RAngleLoc),
2583 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002584 }
2585
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002586 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002587 ///
2588 /// By default, performs semantic analysis to build the new expression.
2589 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002590 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002592 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002593 SourceLocation RAngleLoc,
2594 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002595 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002596 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002597 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002598 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002599 SourceRange(LAngleLoc, RAngleLoc),
2600 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 }
2602
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002603 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 ///
2605 /// By default, performs semantic analysis to build the new expression.
2606 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002607 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002609 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002610 SourceLocation RAngleLoc,
2611 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002612 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002614 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002615 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002616 SourceRange(LAngleLoc, RAngleLoc),
2617 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002618 }
2619
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002620 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002621 ///
2622 /// By default, performs semantic analysis to build the new expression.
2623 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002624 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002626 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002627 SourceLocation RAngleLoc,
2628 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002629 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002630 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002631 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002632 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002633 SourceRange(LAngleLoc, RAngleLoc),
2634 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002635 }
Mike Stump11289f42009-09-09 15:08:12 +00002636
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002637 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002638 ///
2639 /// By default, performs semantic analysis to build the new expression.
2640 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002641 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2642 SourceLocation LParenLoc,
2643 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002644 SourceLocation RParenLoc,
2645 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002646 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002647 MultiExprArg(&Sub, 1), RParenLoc,
2648 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002649 }
Mike Stump11289f42009-09-09 15:08:12 +00002650
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002651 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002652 ///
2653 /// By default, performs semantic analysis to build the new expression.
2654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002655 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002656 SourceLocation TypeidLoc,
2657 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002658 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002659 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002660 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002661 }
Mike Stump11289f42009-09-09 15:08:12 +00002662
Francois Pichet9f4f2072010-09-08 12:20:18 +00002663
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002664 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 ///
2666 /// By default, performs semantic analysis to build the new expression.
2667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002668 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002669 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002670 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002672 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002673 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002674 }
2675
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002676 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002677 ///
2678 /// By default, performs semantic analysis to build the new expression.
2679 /// Subclasses may override this routine to provide different behavior.
2680 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2681 SourceLocation TypeidLoc,
2682 TypeSourceInfo *Operand,
2683 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002684 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002685 RParenLoc);
2686 }
2687
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002688 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002689 ///
2690 /// By default, performs semantic analysis to build the new expression.
2691 /// Subclasses may override this routine to provide different behavior.
2692 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2693 SourceLocation TypeidLoc,
2694 Expr *Operand,
2695 SourceLocation RParenLoc) {
2696 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2697 RParenLoc);
2698 }
2699
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002700 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002701 ///
2702 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002703 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002704 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002705 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002706 QualType ThisType,
2707 bool isImplicit) {
Richard Smith8458c9e2019-05-24 01:35:07 +00002708 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002709 }
2710
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002711 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002712 ///
2713 /// By default, performs semantic analysis to build the new expression.
2714 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002715 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2716 bool IsThrownVariableInScope) {
2717 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002718 }
2719
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002720 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002721 ///
2722 /// By default, builds a new default-argument expression, which does not
2723 /// require any semantic analysis. Subclasses may override this routine to
2724 /// provide different behavior.
Eric Fiselier708afb52019-05-16 21:04:15 +00002725 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
2726 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2727 getSema().CurContext);
Douglas Gregora16548e2009-08-11 05:31:07 +00002728 }
2729
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002730 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002731 ///
2732 /// By default, builds a new default field initialization expression, which
2733 /// does not require any semantic analysis. Subclasses may override this
2734 /// routine to provide different behavior.
2735 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2736 FieldDecl *Field) {
Eric Fiselier708afb52019-05-16 21:04:15 +00002737 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2738 getSema().CurContext);
Richard Smith852c9db2013-04-20 22:23:05 +00002739 }
2740
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002741 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 ///
2743 /// By default, performs semantic analysis to build the new expression.
2744 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002745 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2746 SourceLocation LParenLoc,
2747 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002748 return getSema().BuildCXXTypeConstructExpr(
2749 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002750 }
Mike Stump11289f42009-09-09 15:08:12 +00002751
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002752 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002756 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002757 bool UseGlobal,
2758 SourceLocation PlacementLParen,
2759 MultiExprArg PlacementArgs,
2760 SourceLocation PlacementRParen,
2761 SourceRange TypeIdParens,
2762 QualType AllocatedType,
2763 TypeSourceInfo *AllocatedTypeInfo,
Richard Smithb9fb1212019-05-06 03:47:15 +00002764 Optional<Expr *> ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002765 SourceRange DirectInitRange,
2766 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002767 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002768 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002769 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002770 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002771 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002772 AllocatedType,
2773 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002774 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002775 DirectInitRange,
2776 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 }
Mike Stump11289f42009-09-09 15:08:12 +00002778
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002779 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002780 ///
2781 /// By default, performs semantic analysis to build the new expression.
2782 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002783 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002784 bool IsGlobalDelete,
2785 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002786 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002787 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002788 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002789 }
Mike Stump11289f42009-09-09 15:08:12 +00002790
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002791 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002792 ///
2793 /// By default, performs semantic analysis to build the new expression.
2794 /// Subclasses may override this routine to provide different behavior.
2795 ExprResult RebuildTypeTrait(TypeTrait Trait,
2796 SourceLocation StartLoc,
2797 ArrayRef<TypeSourceInfo *> Args,
2798 SourceLocation RParenLoc) {
2799 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002802 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002803 ///
2804 /// By default, performs semantic analysis to build the new expression.
2805 /// Subclasses may override this routine to provide different behavior.
2806 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2807 SourceLocation StartLoc,
2808 TypeSourceInfo *TSInfo,
2809 Expr *DimExpr,
2810 SourceLocation RParenLoc) {
2811 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2812 }
2813
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002814 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002815 ///
2816 /// By default, performs semantic analysis to build the new expression.
2817 /// Subclasses may override this routine to provide different behavior.
2818 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2819 SourceLocation StartLoc,
2820 Expr *Queried,
2821 SourceLocation RParenLoc) {
2822 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2823 }
2824
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002825 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002826 /// expression.
2827 ///
2828 /// By default, performs semantic analysis to build the new expression.
2829 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002830 ExprResult RebuildDependentScopeDeclRefExpr(
2831 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002832 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002833 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002834 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002835 bool IsAddressOfOperand,
2836 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002837 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002838 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002839
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002840 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002841 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2842 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002843
Reid Kleckner32506ed2014-06-12 23:03:48 +00002844 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002845 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002846 }
2847
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002848 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002849 ///
2850 /// By default, performs semantic analysis to build the new expression.
2851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002852 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002853 SourceLocation TemplateKWLoc,
2854 LookupResult &R,
2855 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002856 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002857 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2858 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002859 }
2860
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002861 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002862 ///
2863 /// By default, performs semantic analysis to build the new expression.
2864 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002865 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002866 SourceLocation Loc,
2867 CXXConstructorDecl *Constructor,
2868 bool IsElidable,
2869 MultiExprArg Args,
2870 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002871 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002872 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002873 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002874 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002875 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002876 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002877 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002878 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002879 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002880
Richard Smithc83bf822016-06-10 00:58:19 +00002881 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002882 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002883 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002884 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002885 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002886 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002887 RequiresZeroInit, ConstructKind,
2888 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002889 }
2890
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002891 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002892 /// expression.
2893 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2894 CXXConstructorDecl *Constructor,
2895 bool ConstructsVBase,
2896 bool InheritedFromVBase) {
2897 return new (getSema().Context) CXXInheritedCtorInitExpr(
2898 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2899 }
2900
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002901 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002902 ///
2903 /// By default, performs semantic analysis to build the new expression.
2904 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002905 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002906 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002907 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002908 SourceLocation RParenOrBraceLoc,
2909 bool ListInitialization) {
2910 return getSema().BuildCXXTypeConstructExpr(
2911 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002912 }
2913
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002914 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002915 ///
2916 /// By default, performs semantic analysis to build the new expression.
2917 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002918 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2919 SourceLocation LParenLoc,
2920 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002921 SourceLocation RParenLoc,
2922 bool ListInitialization) {
2923 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2924 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002925 }
Mike Stump11289f42009-09-09 15:08:12 +00002926
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002927 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002928 ///
2929 /// By default, performs semantic analysis to build the new expression.
2930 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002931 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002932 QualType BaseType,
2933 bool IsArrow,
2934 SourceLocation OperatorLoc,
2935 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002936 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002937 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002938 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002939 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002940 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002941 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002942
John McCallb268a282010-08-23 23:25:46 +00002943 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002944 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002945 SS, TemplateKWLoc,
2946 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002947 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002948 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002949 }
2950
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002951 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002952 ///
2953 /// By default, performs semantic analysis to build the new expression.
2954 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002955 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2956 SourceLocation OperatorLoc,
2957 bool IsArrow,
2958 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002959 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002960 NamedDecl *FirstQualifierInScope,
2961 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002962 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002963 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002964 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002965
John McCallb268a282010-08-23 23:25:46 +00002966 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002967 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002968 SS, TemplateKWLoc,
2969 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002970 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002971 }
Mike Stump11289f42009-09-09 15:08:12 +00002972
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002973 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002974 ///
2975 /// By default, performs semantic analysis to build the new expression.
2976 /// Subclasses may override this routine to provide different behavior.
2977 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2978 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2979 }
2980
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002981 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002982 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2983 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002984 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002985 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002986 Optional<unsigned> Length,
2987 ArrayRef<TemplateArgument> PartialArgs) {
2988 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2989 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002990 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002991
Eric Fiselier708afb52019-05-16 21:04:15 +00002992 /// Build a new expression representing a call to a source location
2993 /// builtin.
2994 ///
2995 /// By default, performs semantic analysis to build the new expression.
2996 /// Subclasses may override this routine to provide different behavior.
2997 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
2998 SourceLocation BuiltinLoc,
2999 SourceLocation RPLoc,
3000 DeclContext *ParentContext) {
3001 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3002 }
3003
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003004 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00003005 ///
3006 /// By default, performs semantic analysis to build the new expression.
3007 /// Subclasses may override this routine to provide different behavior.
3008 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
3009 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3010 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003011
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003012 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003013 ///
3014 /// By default, performs semantic analysis to build the new expression.
3015 /// Subclasses may override this routine to provide different behavior.
3016 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
3017 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003018 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003019 MultiExprArg(Elements, NumElements));
3020 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003021
3022 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003023 Expr *Base, Expr *Key,
3024 ObjCMethodDecl *getterMethod,
3025 ObjCMethodDecl *setterMethod) {
3026 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3027 getterMethod, setterMethod);
3028 }
3029
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003030 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003031 ///
3032 /// By default, performs semantic analysis to build the new expression.
3033 /// Subclasses may override this routine to provide different behavior.
3034 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00003035 MutableArrayRef<ObjCDictionaryElement> Elements) {
3036 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00003037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003038
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003039 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003040 ///
3041 /// By default, performs semantic analysis to build the new expression.
3042 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003043 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00003044 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00003045 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003046 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003047 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003048
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003049 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003050 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003051 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003052 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003053 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003054 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003055 MultiExprArg Args,
3056 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003057 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3058 ReceiverTypeInfo->getType(),
3059 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003060 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003061 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003062 }
3063
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003064 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003065 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003066 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003067 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003068 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003070 MultiExprArg Args,
3071 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003072 return SemaRef.BuildInstanceMessage(Receiver,
3073 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003074 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003075 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003076 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003077 }
3078
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003079 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003080 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3081 Selector Sel,
3082 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003083 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003084 ObjCMethodDecl *Method,
3085 SourceLocation LBracLoc,
3086 MultiExprArg Args,
3087 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003088 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003089 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003090 SuperLoc,
3091 Sel, Method, LBracLoc, SelectorLocs,
3092 RBracLoc, Args)
3093 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003094 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003095 SuperLoc,
3096 Sel, Method, LBracLoc, SelectorLocs,
3097 RBracLoc, Args);
3098
Fangrui Song6907ce22018-07-30 19:24:48 +00003099
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003100 }
3101
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003102 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003106 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003107 SourceLocation IvarLoc,
3108 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003109 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003110 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003111 ExprResult Result = getSema().BuildMemberReferenceExpr(
3112 BaseArg, BaseArg->getType(),
3113 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3114 /*FirstQualifierInScope=*/nullptr, NameInfo,
3115 /*TemplateArgs=*/nullptr,
3116 /*S=*/nullptr);
3117 if (IsFreeIvar && Result.isUsable())
3118 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3119 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003120 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003121
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003122 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003123 ///
3124 /// By default, performs semantic analysis to build the new expression.
3125 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003126 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003127 ObjCPropertyDecl *Property,
3128 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003129 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003130 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3131 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3132 /*FIXME:*/PropertyLoc,
3133 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003134 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003135 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003136 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003137 /*TemplateArgs=*/nullptr,
3138 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003139 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003141 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003142 ///
3143 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003144 /// Subclasses may override this routine to provide different behavior.
3145 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3146 ObjCMethodDecl *Getter,
3147 ObjCMethodDecl *Setter,
3148 SourceLocation PropertyLoc) {
3149 // Since these expressions can only be value-dependent, we do not
3150 // need to perform semantic analysis again.
3151 return Owned(
3152 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3153 VK_LValue, OK_ObjCProperty,
3154 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003155 }
3156
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003157 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003158 ///
3159 /// By default, performs semantic analysis to build the new expression.
3160 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003161 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003162 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003163 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003164 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3165 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003166 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003167 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003168 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003169 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003170 /*TemplateArgs=*/nullptr,
3171 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003174 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003175 ///
3176 /// By default, performs semantic analysis to build the new expression.
3177 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003178 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003179 MultiExprArg SubExprs,
3180 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003181 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003182 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003183 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3184 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3185 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003186 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003187
Douglas Gregora16548e2009-08-11 05:31:07 +00003188 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003189 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003190 Expr *Callee = new (SemaRef.Context)
3191 DeclRefExpr(SemaRef.Context, Builtin, false,
3192 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003193 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3194 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003195 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003196
3197 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003198 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003199 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003200 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregora16548e2009-08-11 05:31:07 +00003202 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003203 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003204 }
John McCall31f82722010-11-12 08:19:04 +00003205
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003206 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003207 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3208 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3209 SourceLocation RParenLoc) {
3210 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3211 BuiltinLoc, RParenLoc);
3212 }
3213
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003214 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003215 ///
3216 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003217 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003218 /// different behavior.
3219 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003220 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003221 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003222 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003223 case TemplateArgument::Expression: {
3224 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003225 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3226 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003227 if (Result.isInvalid())
3228 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003229
Douglas Gregor98318c22011-01-03 21:37:45 +00003230 return TemplateArgumentLoc(Result.get(), Result.get());
3231 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003233 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003234 return TemplateArgumentLoc(TemplateArgument(
3235 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003236 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003237 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003238 Pattern.getTemplateNameLoc(),
3239 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003240
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003241 case TemplateArgument::Null:
3242 case TemplateArgument::Integral:
3243 case TemplateArgument::Declaration:
3244 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003245 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003246 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003247 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003248
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003249 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003250 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003251 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003252 EllipsisLoc,
3253 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003254 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3255 Expansion);
3256 break;
3257 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003258
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003259 return TemplateArgumentLoc();
3260 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003261
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003262 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003263 ///
3264 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003265 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003266 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003267 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003268 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003269 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003270 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003271
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003272 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003273 ///
3274 /// By default, performs semantic analysis in order to build a new fold
3275 /// expression.
3276 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3277 BinaryOperatorKind Operator,
3278 SourceLocation EllipsisLoc, Expr *RHS,
Richard Smithc7214f62019-05-13 08:31:14 +00003279 SourceLocation RParenLoc,
3280 Optional<unsigned> NumExpansions) {
Richard Smith0f0af192014-11-08 05:07:16 +00003281 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
Richard Smithc7214f62019-05-13 08:31:14 +00003282 RHS, RParenLoc, NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +00003283 }
3284
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003285 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003286 ///
3287 /// By default, produces the fallback value for the fold-expression, or
3288 /// produce an error if there is no fallback value.
3289 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3290 BinaryOperatorKind Operator) {
3291 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3292 }
3293
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003294 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003295 ///
3296 /// By default, performs semantic analysis to build the new expression.
3297 /// Subclasses may override this routine to provide different behavior.
3298 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3299 MultiExprArg SubExprs,
3300 QualType RetTy,
3301 AtomicExpr::AtomicOp Op,
3302 SourceLocation RParenLoc) {
3303 // Just create the expression; there is not any interesting semantic
3304 // analysis here because we can't actually build an AtomicExpr until
3305 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003306 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003307 RParenLoc);
3308 }
3309
John McCall31f82722010-11-12 08:19:04 +00003310private:
Douglas Gregor14454802011-02-25 02:25:35 +00003311 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3312 QualType ObjectType,
3313 NamedDecl *FirstQualifierInScope,
3314 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003315
3316 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3317 QualType ObjectType,
3318 NamedDecl *FirstQualifierInScope,
3319 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003320
3321 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3322 NamedDecl *FirstQualifierInScope,
3323 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003324
3325 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3326 DependentNameTypeLoc TL,
3327 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328};
Douglas Gregora16548e2009-08-11 05:31:07 +00003329
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003330template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003331StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003332 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003333 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregorebe10102009-08-20 07:17:43 +00003335 switch (S->getStmtClass()) {
3336 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003337
Douglas Gregorebe10102009-08-20 07:17:43 +00003338 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003339 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003340#define STMT(Node, Parent) \
3341 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003342#define VALUESTMT(Node, Parent) \
3343 case Stmt::Node##Class: \
3344 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003345#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003346#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003347#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 // Transform expressions by calling TransformExpr.
3350#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003351#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003352#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003353#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003354 {
John McCalldadc5752010-08-24 06:29:42 +00003355 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003356
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003357 if (SDK == SDK_StmtExprResult)
3358 E = getSema().ActOnStmtExprResult(E);
3359 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003360 }
Mike Stump11289f42009-09-09 15:08:12 +00003361 }
3362
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003363 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003364}
Mike Stump11289f42009-09-09 15:08:12 +00003365
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003366template<typename Derived>
3367OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3368 if (!S)
3369 return S;
3370
3371 switch (S->getClauseKind()) {
3372 default: break;
3373 // Transform individual clause nodes
3374#define OPENMP_CLAUSE(Name, Class) \
3375 case OMPC_ ## Name : \
3376 return getDerived().Transform ## Class(cast<Class>(S));
3377#include "clang/Basic/OpenMPKinds.def"
3378 }
3379
3380 return S;
3381}
3382
Mike Stump11289f42009-09-09 15:08:12 +00003383
Douglas Gregore922c772009-08-04 22:27:00 +00003384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003385ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003386 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003387 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003388
3389 switch (E->getStmtClass()) {
3390 case Stmt::NoStmtClass: break;
3391#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003392#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003393#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003394 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003395#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003396 }
3397
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003398 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003399}
3400
3401template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003402ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003403 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003404 // Initializers are instantiated like expressions, except that various outer
3405 // layers are stripped.
3406 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003407 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003408
Bill Wendling7c44da22018-10-31 03:48:47 +00003409 if (auto *FE = dyn_cast<FullExpr>(Init))
3410 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003411
Richard Smith410306b2016-12-12 02:53:20 +00003412 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3413 Init = AIL->getCommonExpr();
3414
Richard Smithe6ca4752013-05-30 22:40:16 +00003415 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3416 Init = MTE->GetTemporaryExpr();
3417
Richard Smithd59b8322012-12-19 01:39:02 +00003418 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3419 Init = Binder->getSubExpr();
3420
3421 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3422 Init = ICE->getSubExprAsWritten();
3423
Richard Smithcc1b96d2013-06-12 22:31:48 +00003424 if (CXXStdInitializerListExpr *ILE =
3425 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003426 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003427
Richard Smithc6abd962014-07-25 01:12:44 +00003428 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003429 // InitListExprs. Other forms of copy-initialization will be a no-op if
3430 // the initializer is already the right type.
3431 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003432 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003433 return getDerived().TransformExpr(Init);
3434
3435 // Revert value-initialization back to empty parens.
3436 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3437 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003438 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003439 Parens.getEnd());
3440 }
3441
3442 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3443 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003444 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003445 SourceLocation());
3446
3447 // Revert initialization by constructor back to a parenthesized or braced list
3448 // of expressions. Any other form of initializer can just be reused directly.
3449 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003450 return getDerived().TransformExpr(Init);
3451
Richard Smithf8adcdc2014-07-17 05:12:35 +00003452 // If the initialization implicitly converted an initializer list to a
3453 // std::initializer_list object, unwrap the std::initializer_list too.
3454 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003455 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003456
Richard Smith12938cf2018-09-26 04:36:55 +00003457 // Enter a list-init context if this was list initialization.
3458 EnterExpressionEvaluationContext Context(
3459 getSema(), EnterExpressionEvaluationContext::InitList,
3460 Construct->isListInitialization());
3461
Richard Smithd59b8322012-12-19 01:39:02 +00003462 SmallVector<Expr*, 8> NewArgs;
3463 bool ArgChanged = false;
3464 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003465 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003466 return ExprError();
3467
Richard Smithd1036122018-01-12 22:21:33 +00003468 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003469 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003470 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003471 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003472
Richard Smithd59b8322012-12-19 01:39:02 +00003473 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003474 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003475 if (Parens.isInvalid()) {
3476 // This was a variable declaration's initialization for which no initializer
3477 // was specified.
3478 assert(NewArgs.empty() &&
3479 "no parens or braces but have direct init with arguments?");
3480 return ExprEmpty();
3481 }
Richard Smithd59b8322012-12-19 01:39:02 +00003482 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3483 Parens.getEnd());
3484}
3485
3486template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003487bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003488 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003489 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003490 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003491 bool *ArgChanged) {
3492 for (unsigned I = 0; I != NumInputs; ++I) {
3493 // If requested, drop call arguments that need to be dropped.
3494 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3495 if (ArgChanged)
3496 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
Douglas Gregora3efea12011-01-03 19:04:46 +00003498 break;
3499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003500
Douglas Gregor968f23a2011-01-03 19:31:53 +00003501 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3502 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003503
Chris Lattner01cf8db2011-07-20 06:58:45 +00003504 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003505 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3506 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregor968f23a2011-01-03 19:31:53 +00003508 // Determine whether the set of unexpanded parameter packs can and should
3509 // be expanded.
3510 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003511 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003512 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3513 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003514 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3515 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003516 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003517 Expand, RetainExpansion,
3518 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003519 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003520
Douglas Gregor968f23a2011-01-03 19:31:53 +00003521 if (!Expand) {
3522 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003523 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003524 // expansion.
3525 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3526 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3527 if (OutPattern.isInvalid())
3528 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003529
3530 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003531 Expansion->getEllipsisLoc(),
3532 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003533 if (Out.isInvalid())
3534 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregor968f23a2011-01-03 19:31:53 +00003536 if (ArgChanged)
3537 *ArgChanged = true;
3538 Outputs.push_back(Out.get());
3539 continue;
3540 }
John McCall542e7c62011-07-06 07:30:07 +00003541
3542 // Record right away that the argument was changed. This needs
3543 // to happen even if the array expands to nothing.
3544 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
Douglas Gregor968f23a2011-01-03 19:31:53 +00003546 // The transform has determined that we should perform an elementwise
3547 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003548 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003549 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3550 ExprResult Out = getDerived().TransformExpr(Pattern);
3551 if (Out.isInvalid())
3552 return true;
3553
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003554 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003555 Out = getDerived().RebuildPackExpansion(
3556 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003557 if (Out.isInvalid())
3558 return true;
3559 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003560
Douglas Gregor968f23a2011-01-03 19:31:53 +00003561 Outputs.push_back(Out.get());
3562 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003563
Richard Smith9467be42014-06-06 17:33:35 +00003564 // If we're supposed to retain a pack expansion, do so by temporarily
3565 // forgetting the partially-substituted parameter pack.
3566 if (RetainExpansion) {
3567 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3568
3569 ExprResult Out = getDerived().TransformExpr(Pattern);
3570 if (Out.isInvalid())
3571 return true;
3572
3573 Out = getDerived().RebuildPackExpansion(
3574 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3575 if (Out.isInvalid())
3576 return true;
3577
3578 Outputs.push_back(Out.get());
3579 }
3580
Douglas Gregor968f23a2011-01-03 19:31:53 +00003581 continue;
3582 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003583
Richard Smithd59b8322012-12-19 01:39:02 +00003584 ExprResult Result =
3585 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3586 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003587 if (Result.isInvalid())
3588 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003589
Douglas Gregora3efea12011-01-03 19:04:46 +00003590 if (Result.get() != Inputs[I] && ArgChanged)
3591 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
3593 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003594 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003595
Douglas Gregora3efea12011-01-03 19:04:46 +00003596 return false;
3597}
3598
Richard Smith03a4aa32016-06-23 19:02:52 +00003599template <typename Derived>
3600Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3601 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3602 if (Var) {
3603 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3604 getDerived().TransformDefinition(Var->getLocation(), Var));
3605
3606 if (!ConditionVar)
3607 return Sema::ConditionError();
3608
3609 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3610 }
3611
3612 if (Expr) {
3613 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3614
3615 if (CondExpr.isInvalid())
3616 return Sema::ConditionError();
3617
3618 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3619 }
3620
3621 return Sema::ConditionResult();
3622}
3623
Douglas Gregora3efea12011-01-03 19:04:46 +00003624template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003625NestedNameSpecifierLoc
3626TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3627 NestedNameSpecifierLoc NNS,
3628 QualType ObjectType,
3629 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003630 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003631 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003632 Qualifier = Qualifier.getPrefix())
3633 Qualifiers.push_back(Qualifier);
3634
3635 CXXScopeSpec SS;
3636 while (!Qualifiers.empty()) {
3637 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3638 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor14454802011-02-25 02:25:35 +00003640 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003641 case NestedNameSpecifier::Identifier: {
3642 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3643 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3644 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3645 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003646 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003647 }
Douglas Gregor14454802011-02-25 02:25:35 +00003648 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003649
Douglas Gregor14454802011-02-25 02:25:35 +00003650 case NestedNameSpecifier::Namespace: {
3651 NamespaceDecl *NS
3652 = cast_or_null<NamespaceDecl>(
3653 getDerived().TransformDecl(
3654 Q.getLocalBeginLoc(),
3655 QNNS->getAsNamespace()));
3656 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3657 break;
3658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003659
Douglas Gregor14454802011-02-25 02:25:35 +00003660 case NestedNameSpecifier::NamespaceAlias: {
3661 NamespaceAliasDecl *Alias
3662 = cast_or_null<NamespaceAliasDecl>(
3663 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3664 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003665 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003666 Q.getLocalEndLoc());
3667 break;
3668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003669
Douglas Gregor14454802011-02-25 02:25:35 +00003670 case NestedNameSpecifier::Global:
3671 // There is no meaningful transformation that one could perform on the
3672 // global scope.
3673 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3674 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Nikola Smiljanic67860242014-09-26 00:28:20 +00003676 case NestedNameSpecifier::Super: {
3677 CXXRecordDecl *RD =
3678 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3679 SourceLocation(), QNNS->getAsRecordDecl()));
3680 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3681 break;
3682 }
3683
Douglas Gregor14454802011-02-25 02:25:35 +00003684 case NestedNameSpecifier::TypeSpecWithTemplate:
3685 case NestedNameSpecifier::TypeSpec: {
3686 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3687 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003688
Douglas Gregor14454802011-02-25 02:25:35 +00003689 if (!TL)
3690 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor14454802011-02-25 02:25:35 +00003692 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003693 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003694 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003695 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003696 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003697 if (TL.getType()->isEnumeralType())
3698 SemaRef.Diag(TL.getBeginLoc(),
3699 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003700 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3701 Q.getLocalEndLoc());
3702 break;
3703 }
Richard Trieude756fb2011-05-07 01:36:37 +00003704 // If the nested-name-specifier is an invalid type def, don't emit an
3705 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003706 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3707 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003708 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003709 << TL.getType() << SS.getRange();
3710 }
Douglas Gregor14454802011-02-25 02:25:35 +00003711 return NestedNameSpecifierLoc();
3712 }
Douglas Gregore16af532011-02-28 18:50:33 +00003713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003714
Douglas Gregore16af532011-02-28 18:50:33 +00003715 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003716 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003717 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003718 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003719
Douglas Gregor14454802011-02-25 02:25:35 +00003720 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003721 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003722 !getDerived().AlwaysRebuild())
3723 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
3725 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003726 // nested-name-specifier, do so.
3727 if (SS.location_size() == NNS.getDataLength() &&
3728 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3729 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3730
3731 // Allocate new nested-name-specifier location information.
3732 return SS.getWithLocInContext(SemaRef.Context);
3733}
3734
3735template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003736DeclarationNameInfo
3737TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003738::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003739 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003740 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003741 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003742
3743 switch (Name.getNameKind()) {
3744 case DeclarationName::Identifier:
3745 case DeclarationName::ObjCZeroArgSelector:
3746 case DeclarationName::ObjCOneArgSelector:
3747 case DeclarationName::ObjCMultiArgSelector:
3748 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003749 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003750 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003751 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003752
Richard Smith35845152017-02-07 01:37:30 +00003753 case DeclarationName::CXXDeductionGuideName: {
3754 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3755 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3756 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3757 if (!NewTemplate)
3758 return DeclarationNameInfo();
3759
3760 DeclarationNameInfo NewNameInfo(NameInfo);
3761 NewNameInfo.setName(
3762 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3763 return NewNameInfo;
3764 }
3765
Douglas Gregorf816bd72009-09-03 22:13:48 +00003766 case DeclarationName::CXXConstructorName:
3767 case DeclarationName::CXXDestructorName:
3768 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003769 TypeSourceInfo *NewTInfo;
3770 CanQualType NewCanTy;
3771 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003772 NewTInfo = getDerived().TransformType(OldTInfo);
3773 if (!NewTInfo)
3774 return DeclarationNameInfo();
3775 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003776 }
3777 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003778 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003779 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003780 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003781 if (NewT.isNull())
3782 return DeclarationNameInfo();
3783 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3784 }
Mike Stump11289f42009-09-09 15:08:12 +00003785
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003786 DeclarationName NewName
3787 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3788 NewCanTy);
3789 DeclarationNameInfo NewNameInfo(NameInfo);
3790 NewNameInfo.setName(NewName);
3791 NewNameInfo.setNamedTypeInfo(NewTInfo);
3792 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003793 }
Mike Stump11289f42009-09-09 15:08:12 +00003794 }
3795
David Blaikie83d382b2011-09-23 05:06:16 +00003796 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003797}
3798
3799template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003800TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003801TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3802 TemplateName Name,
3803 SourceLocation NameLoc,
3804 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003805 NamedDecl *FirstQualifierInScope,
3806 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003807 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3808 TemplateDecl *Template = QTN->getTemplateDecl();
3809 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003810
Douglas Gregor9db53502011-03-02 18:07:45 +00003811 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003812 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003813 Template));
3814 if (!TransTemplate)
3815 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregor9db53502011-03-02 18:07:45 +00003817 if (!getDerived().AlwaysRebuild() &&
3818 SS.getScopeRep() == QTN->getQualifier() &&
3819 TransTemplate == Template)
3820 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003821
Douglas Gregor9db53502011-03-02 18:07:45 +00003822 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3823 TransTemplate);
3824 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor9db53502011-03-02 18:07:45 +00003826 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3827 if (SS.getScopeRep()) {
3828 // These apply to the scope specifier, not the template.
3829 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003830 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003831 }
3832
Douglas Gregor9db53502011-03-02 18:07:45 +00003833 if (!getDerived().AlwaysRebuild() &&
3834 SS.getScopeRep() == DTN->getQualifier() &&
3835 ObjectType.isNull())
3836 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003837
Richard Smith79810042018-05-11 02:43:08 +00003838 // FIXME: Preserve the location of the "template" keyword.
3839 SourceLocation TemplateKWLoc = NameLoc;
3840
Douglas Gregor9db53502011-03-02 18:07:45 +00003841 if (DTN->isIdentifier()) {
3842 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003843 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003844 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003845 NameLoc,
3846 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003847 FirstQualifierInScope,
3848 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003849 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003850
Richard Smith79810042018-05-11 02:43:08 +00003851 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3852 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003853 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003854 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003855
Douglas Gregor9db53502011-03-02 18:07:45 +00003856 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3857 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003858 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003859 Template));
3860 if (!TransTemplate)
3861 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
Douglas Gregor9db53502011-03-02 18:07:45 +00003863 if (!getDerived().AlwaysRebuild() &&
3864 TransTemplate == Template)
3865 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
Douglas Gregor9db53502011-03-02 18:07:45 +00003867 return TemplateName(TransTemplate);
3868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003869
Douglas Gregor9db53502011-03-02 18:07:45 +00003870 if (SubstTemplateTemplateParmPackStorage *SubstPack
3871 = Name.getAsSubstTemplateTemplateParmPack()) {
3872 TemplateTemplateParmDecl *TransParam
3873 = cast_or_null<TemplateTemplateParmDecl>(
3874 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3875 if (!TransParam)
3876 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregor9db53502011-03-02 18:07:45 +00003878 if (!getDerived().AlwaysRebuild() &&
3879 TransParam == SubstPack->getParameterPack())
3880 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
3882 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003883 SubstPack->getArgumentPack());
3884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003885
Douglas Gregor9db53502011-03-02 18:07:45 +00003886 // These should be getting filtered out before they reach the AST.
3887 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003888}
3889
3890template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003891void TreeTransform<Derived>::InventTemplateArgumentLoc(
3892 const TemplateArgument &Arg,
3893 TemplateArgumentLoc &Output) {
3894 SourceLocation Loc = getDerived().getBaseLocation();
3895 switch (Arg.getKind()) {
3896 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003897 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003898 break;
3899
3900 case TemplateArgument::Type:
3901 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003902 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
John McCall0ad16662009-10-29 08:12:44 +00003904 break;
3905
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003906 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003907 case TemplateArgument::TemplateExpansion: {
3908 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003909 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003910 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3911 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3912 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3913 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregor9d802122011-03-02 17:09:35 +00003915 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003916 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003917 Builder.getWithLocInContext(SemaRef.Context),
3918 Loc);
3919 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003920 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003921 Builder.getWithLocInContext(SemaRef.Context),
3922 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003924 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003925 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003926
John McCall0ad16662009-10-29 08:12:44 +00003927 case TemplateArgument::Expression:
3928 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3929 break;
3930
3931 case TemplateArgument::Declaration:
3932 case TemplateArgument::Integral:
3933 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003934 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003935 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003936 break;
3937 }
3938}
3939
3940template<typename Derived>
3941bool TreeTransform<Derived>::TransformTemplateArgument(
3942 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003943 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003944 EnterExpressionEvaluationContext EEEC(
3945 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3946 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3947 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003948 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003949 switch (Arg.getKind()) {
3950 case TemplateArgument::Null:
3951 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003952 case TemplateArgument::Pack:
3953 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003954 case TemplateArgument::NullPtr:
3955 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregore922c772009-08-04 22:27:00 +00003957 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003958 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003959 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003960 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003961
3962 DI = getDerived().TransformType(DI);
3963 if (!DI) return true;
3964
3965 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3966 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003967 }
Mike Stump11289f42009-09-09 15:08:12 +00003968
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003969 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003970 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3971 if (QualifierLoc) {
3972 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3973 if (!QualifierLoc)
3974 return true;
3975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003976
Douglas Gregordf846d12011-03-02 18:46:51 +00003977 CXXScopeSpec SS;
3978 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003979 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003980 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3981 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003982 if (Template.isNull())
3983 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003984
Douglas Gregor9d802122011-03-02 17:09:35 +00003985 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003986 Input.getTemplateNameLoc());
3987 return false;
3988 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003989
3990 case TemplateArgument::TemplateExpansion:
3991 llvm_unreachable("Caller should expand pack expansions");
3992
Douglas Gregore922c772009-08-04 22:27:00 +00003993 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003994 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003995 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003996 getSema(), Uneval
3997 ? Sema::ExpressionEvaluationContext::Unevaluated
3998 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003999
John McCall0ad16662009-10-29 08:12:44 +00004000 Expr *InputExpr = Input.getSourceExpression();
4001 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4002
Chris Lattnercdb591a2011-04-25 20:37:58 +00004003 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004004 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00004005 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004006 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00004007 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004008 }
Douglas Gregore922c772009-08-04 22:27:00 +00004009 }
Mike Stump11289f42009-09-09 15:08:12 +00004010
Douglas Gregore922c772009-08-04 22:27:00 +00004011 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00004012 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00004013}
4014
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004015/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00004016/// for each of the template arguments in its underlying iterator.
4017template<typename Derived, typename InputIterator>
4018class TemplateArgumentLocInventIterator {
4019 TreeTransform<Derived> &Self;
4020 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00004021
Douglas Gregorfe921a72010-12-20 23:36:19 +00004022public:
4023 typedef TemplateArgumentLoc value_type;
4024 typedef TemplateArgumentLoc reference;
4025 typedef typename std::iterator_traits<InputIterator>::difference_type
4026 difference_type;
4027 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004028
Douglas Gregorfe921a72010-12-20 23:36:19 +00004029 class pointer {
4030 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004031
Douglas Gregorfe921a72010-12-20 23:36:19 +00004032 public:
4033 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004034
Douglas Gregorfe921a72010-12-20 23:36:19 +00004035 const TemplateArgumentLoc *operator->() const { return &Arg; }
4036 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004037
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00004038 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004039
Douglas Gregorfe921a72010-12-20 23:36:19 +00004040 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4041 InputIterator Iter)
4042 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004043
Douglas Gregorfe921a72010-12-20 23:36:19 +00004044 TemplateArgumentLocInventIterator &operator++() {
4045 ++Iter;
4046 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004048
Douglas Gregorfe921a72010-12-20 23:36:19 +00004049 TemplateArgumentLocInventIterator operator++(int) {
4050 TemplateArgumentLocInventIterator Old(*this);
4051 ++(*this);
4052 return Old;
4053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004054
Douglas Gregorfe921a72010-12-20 23:36:19 +00004055 reference operator*() const {
4056 TemplateArgumentLoc Result;
4057 Self.InventTemplateArgumentLoc(*Iter, Result);
4058 return Result;
4059 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004060
Douglas Gregorfe921a72010-12-20 23:36:19 +00004061 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Douglas Gregorfe921a72010-12-20 23:36:19 +00004063 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4064 const TemplateArgumentLocInventIterator &Y) {
4065 return X.Iter == Y.Iter;
4066 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004067
Douglas Gregorfe921a72010-12-20 23:36:19 +00004068 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4069 const TemplateArgumentLocInventIterator &Y) {
4070 return X.Iter != Y.Iter;
4071 }
4072};
Chad Rosier1dcde962012-08-08 18:46:20 +00004073
Douglas Gregor42cafa82010-12-20 17:42:22 +00004074template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004075template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004076bool TreeTransform<Derived>::TransformTemplateArguments(
4077 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4078 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004079 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004080 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004081 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004082
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004083 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4084 // Unpack argument packs, which we translate them into separate
4085 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004086 // FIXME: We could do much better if we could guarantee that the
4087 // TemplateArgumentLocInfo for the pack expansion would be usable for
4088 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004089 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004090 TemplateArgument::pack_iterator>
4091 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004092 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004093 In.getArgument().pack_begin()),
4094 PackLocIterator(*this,
4095 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004096 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004097 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004098
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004099 continue;
4100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004101
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004102 if (In.getArgument().isPackExpansion()) {
4103 // We have a pack expansion, for which we will be substituting into
4104 // the pattern.
4105 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004106 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004107 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004108 = getSema().getTemplateArgumentPackExpansionPattern(
4109 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Chris Lattner01cf8db2011-07-20 06:58:45 +00004111 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004112 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4113 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004114
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004115 // Determine whether the set of unexpanded parameter packs can and should
4116 // be expanded.
4117 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004118 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004119 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004120 if (getDerived().TryExpandParameterPacks(Ellipsis,
4121 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004122 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004123 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004124 RetainExpansion,
4125 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004126 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004127
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004128 if (!Expand) {
4129 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004130 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004131 // expansion.
4132 TemplateArgumentLoc OutPattern;
4133 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004134 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004135 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004136
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004137 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4138 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004139 if (Out.getArgument().isNull())
4140 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004141
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004142 Outputs.addArgument(Out);
4143 continue;
4144 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004145
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004146 // The transform has determined that we should perform an elementwise
4147 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004148 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004149 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4150
Richard Smithd784e682015-09-23 21:41:42 +00004151 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004152 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004153
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004154 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004155 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4156 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004157 if (Out.getArgument().isNull())
4158 return true;
4159 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004160
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004161 Outputs.addArgument(Out);
4162 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004163
Douglas Gregor48d24112011-01-10 20:53:55 +00004164 // If we're supposed to retain a pack expansion, do so by temporarily
4165 // forgetting the partially-substituted parameter pack.
4166 if (RetainExpansion) {
4167 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004168
Richard Smithd784e682015-09-23 21:41:42 +00004169 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004170 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004171
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004172 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4173 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004174 if (Out.getArgument().isNull())
4175 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004176
Douglas Gregor48d24112011-01-10 20:53:55 +00004177 Outputs.addArgument(Out);
4178 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004179
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004180 continue;
4181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004182
4183 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004184 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004185 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004186
Douglas Gregor42cafa82010-12-20 17:42:22 +00004187 Outputs.addArgument(Out);
4188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004189
Douglas Gregor42cafa82010-12-20 17:42:22 +00004190 return false;
4191
4192}
4193
Douglas Gregord6ff3322009-08-04 16:50:30 +00004194//===----------------------------------------------------------------------===//
4195// Type transformation
4196//===----------------------------------------------------------------------===//
4197
4198template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004199QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004200 if (getDerived().AlreadyTransformed(T))
4201 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004202
John McCall550e0c22009-10-21 00:40:46 +00004203 // Temporary workaround. All of these transformations should
4204 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004205 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4206 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004207
John McCall31f82722010-11-12 08:19:04 +00004208 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004209
John McCall550e0c22009-10-21 00:40:46 +00004210 if (!NewDI)
4211 return QualType();
4212
4213 return NewDI->getType();
4214}
4215
4216template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004217TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004218 // Refine the base location to the type's location.
4219 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4220 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004221 if (getDerived().AlreadyTransformed(DI->getType()))
4222 return DI;
4223
4224 TypeLocBuilder TLB;
4225
4226 TypeLoc TL = DI->getTypeLoc();
4227 TLB.reserve(TL.getFullDataSize());
4228
John McCall31f82722010-11-12 08:19:04 +00004229 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004230 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004231 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004232
John McCallbcd03502009-12-07 02:54:59 +00004233 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004234}
4235
4236template<typename Derived>
4237QualType
John McCall31f82722010-11-12 08:19:04 +00004238TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004239 switch (T.getTypeLocClass()) {
4240#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004241#define TYPELOC(CLASS, PARENT) \
4242 case TypeLoc::CLASS: \
4243 return getDerived().Transform##CLASS##Type(TLB, \
4244 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004245#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004246 }
Mike Stump11289f42009-09-09 15:08:12 +00004247
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004248 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004249}
4250
Richard Smithee579842017-01-30 20:39:26 +00004251template<typename Derived>
4252QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4253 if (!isa<DependentNameType>(T))
4254 return TransformType(T);
4255
4256 if (getDerived().AlreadyTransformed(T))
4257 return T;
4258 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4259 getDerived().getBaseLocation());
4260 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4261 return NewDI ? NewDI->getType() : QualType();
4262}
4263
4264template<typename Derived>
4265TypeSourceInfo *
4266TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4267 if (!isa<DependentNameType>(DI->getType()))
4268 return TransformType(DI);
4269
4270 // Refine the base location to the type's location.
4271 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4272 getDerived().getBaseEntity());
4273 if (getDerived().AlreadyTransformed(DI->getType()))
4274 return DI;
4275
4276 TypeLocBuilder TLB;
4277
4278 TypeLoc TL = DI->getTypeLoc();
4279 TLB.reserve(TL.getFullDataSize());
4280
Richard Smithee579842017-01-30 20:39:26 +00004281 auto QTL = TL.getAs<QualifiedTypeLoc>();
4282 if (QTL)
4283 TL = QTL.getUnqualifiedLoc();
4284
4285 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4286
4287 QualType Result = getDerived().TransformDependentNameType(
4288 TLB, DNTL, /*DeducedTSTContext*/true);
4289 if (Result.isNull())
4290 return nullptr;
4291
4292 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004293 Result = getDerived().RebuildQualifiedType(Result, QTL);
4294 if (Result.isNull())
4295 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004296 TLB.TypeWasModifiedSafely(Result);
4297 }
4298
4299 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4300}
4301
John McCall550e0c22009-10-21 00:40:46 +00004302template<typename Derived>
4303QualType
4304TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004305 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004306 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004307 if (Result.isNull())
4308 return QualType();
4309
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004310 Result = getDerived().RebuildQualifiedType(Result, T);
4311
4312 if (Result.isNull())
4313 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004314
4315 // RebuildQualifiedType might have updated the type, but not in a way
4316 // that invalidates the TypeLoc. (There's no location information for
4317 // qualifiers.)
4318 TLB.TypeWasModifiedSafely(Result);
4319
4320 return Result;
4321}
4322
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004323template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004324QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004325 QualifiedTypeLoc TL) {
4326
4327 SourceLocation Loc = TL.getBeginLoc();
4328 Qualifiers Quals = TL.getType().getLocalQualifiers();
4329
4330 if (((T.getAddressSpace() != LangAS::Default &&
4331 Quals.getAddressSpace() != LangAS::Default)) &&
4332 T.getAddressSpace() != Quals.getAddressSpace()) {
4333 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4334 << TL.getType() << T;
4335 return QualType();
4336 }
4337
Richard Smithee579842017-01-30 20:39:26 +00004338 // C++ [dcl.fct]p7:
4339 // [When] adding cv-qualifications on top of the function type [...] the
4340 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004341 if (T->isFunctionType()) {
4342 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4343 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004344 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004345 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004346
Richard Smithee579842017-01-30 20:39:26 +00004347 // C++ [dcl.ref]p1:
4348 // when the cv-qualifiers are introduced through the use of a typedef-name
4349 // or decltype-specifier [...] the cv-qualifiers are ignored.
4350 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4351 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004352 if (T->isReferenceType()) {
4353 // The only qualifier that applies to a reference type is restrict.
4354 if (!Quals.hasRestrict())
4355 return T;
4356 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4357 }
Mike Stump11289f42009-09-09 15:08:12 +00004358
John McCall31168b02011-06-15 23:02:42 +00004359 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004360 // resulting type.
4361 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004362 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004363 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004364 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004365 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004366 // A lifetime qualifier applied to a substituted template parameter
4367 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004368 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004369 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004370 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004371 QualType Replacement = SubstTypeParam->getReplacementType();
4372 Qualifiers Qs = Replacement.getQualifiers();
4373 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004374 Replacement = SemaRef.Context.getQualifiedType(
4375 Replacement.getUnqualifiedType(), Qs);
4376 T = SemaRef.Context.getSubstTemplateTypeParmType(
4377 SubstTypeParam->getReplacedParameter(), Replacement);
4378 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004379 // 'auto' types behave the same way as template parameters.
4380 QualType Deduced = AutoTy->getDeducedType();
4381 Qualifiers Qs = Deduced.getQualifiers();
4382 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004383 Deduced =
4384 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4385 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4386 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004387 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004388 // Otherwise, complain about the addition of a qualifier to an
4389 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004390 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4391 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004392 Quals.removeObjCLifetime();
4393 }
4394 }
4395 }
John McCall550e0c22009-10-21 00:40:46 +00004396
Richard Smithee579842017-01-30 20:39:26 +00004397 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004398}
4399
Douglas Gregor14454802011-02-25 02:25:35 +00004400template<typename Derived>
4401TypeLoc
4402TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4403 QualType ObjectType,
4404 NamedDecl *UnqualLookup,
4405 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004406 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004407 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004408
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004409 TypeSourceInfo *TSI =
4410 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4411 if (TSI)
4412 return TSI->getTypeLoc();
4413 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004414}
4415
Douglas Gregor579c15f2011-03-02 18:32:08 +00004416template<typename Derived>
4417TypeSourceInfo *
4418TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4419 QualType ObjectType,
4420 NamedDecl *UnqualLookup,
4421 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004422 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004423 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004425 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4426 UnqualLookup, SS);
4427}
4428
4429template <typename Derived>
4430TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4431 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4432 CXXScopeSpec &SS) {
4433 QualType T = TL.getType();
4434 assert(!getDerived().AlreadyTransformed(T));
4435
Douglas Gregor579c15f2011-03-02 18:32:08 +00004436 TypeLocBuilder TLB;
4437 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004438
Douglas Gregor579c15f2011-03-02 18:32:08 +00004439 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004440 TemplateSpecializationTypeLoc SpecTL =
4441 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004442
Richard Smithfd3dae02017-01-20 00:20:39 +00004443 TemplateName Template = getDerived().TransformTemplateName(
4444 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4445 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004446 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004447 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004448
4449 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004450 Template);
4451 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004452 DependentTemplateSpecializationTypeLoc SpecTL =
4453 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
Douglas Gregor579c15f2011-03-02 18:32:08 +00004455 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004456 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004457 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004458 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004459 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004460 ObjectType, UnqualLookup,
4461 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004462 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004463 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004464
4465 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004466 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004467 Template,
4468 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004469 } else {
4470 // Nothing special needs to be done for these.
4471 Result = getDerived().TransformType(TLB, TL);
4472 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004473
4474 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004475 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004476
Douglas Gregor579c15f2011-03-02 18:32:08 +00004477 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4478}
4479
John McCall550e0c22009-10-21 00:40:46 +00004480template <class TyLoc> static inline
4481QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4482 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4483 NewT.setNameLoc(T.getNameLoc());
4484 return T.getType();
4485}
4486
John McCall550e0c22009-10-21 00:40:46 +00004487template<typename Derived>
4488QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004489 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004490 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4491 NewT.setBuiltinLoc(T.getBuiltinLoc());
4492 if (T.needsExtraLocalData())
4493 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4494 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495}
Mike Stump11289f42009-09-09 15:08:12 +00004496
Douglas Gregord6ff3322009-08-04 16:50:30 +00004497template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004498QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004499 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004500 // FIXME: recurse?
4501 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
Reid Kleckner0503a872013-12-05 01:23:43 +00004504template <typename Derived>
4505QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4506 AdjustedTypeLoc TL) {
4507 // Adjustments applied during transformation are handled elsewhere.
4508 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4509}
4510
Douglas Gregord6ff3322009-08-04 16:50:30 +00004511template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004512QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4513 DecayedTypeLoc TL) {
4514 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4515 if (OriginalType.isNull())
4516 return QualType();
4517
4518 QualType Result = TL.getType();
4519 if (getDerived().AlwaysRebuild() ||
4520 OriginalType != TL.getOriginalLoc().getType())
4521 Result = SemaRef.Context.getDecayedType(OriginalType);
4522 TLB.push<DecayedTypeLoc>(Result);
4523 // Nothing to set for DecayedTypeLoc.
4524 return Result;
4525}
4526
4527template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004528QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004529 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004530 QualType PointeeType
4531 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004532 if (PointeeType.isNull())
4533 return QualType();
4534
4535 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004536 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004537 // A dependent pointer type 'T *' has is being transformed such
4538 // that an Objective-C class type is being replaced for 'T'. The
4539 // resulting pointer type is an ObjCObjectPointerType, not a
4540 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004541 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004542
John McCall8b07ec22010-05-15 11:32:37 +00004543 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4544 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004545 return Result;
4546 }
John McCall31f82722010-11-12 08:19:04 +00004547
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004548 if (getDerived().AlwaysRebuild() ||
4549 PointeeType != TL.getPointeeLoc().getType()) {
4550 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4551 if (Result.isNull())
4552 return QualType();
4553 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004554
John McCall31168b02011-06-15 23:02:42 +00004555 // Objective-C ARC can add lifetime qualifiers to the type that we're
4556 // pointing to.
4557 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004559 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4560 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004562}
Mike Stump11289f42009-09-09 15:08:12 +00004563
4564template<typename Derived>
4565QualType
John McCall550e0c22009-10-21 00:40:46 +00004566TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004567 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004568 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004569 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4570 if (PointeeType.isNull())
4571 return QualType();
4572
4573 QualType Result = TL.getType();
4574 if (getDerived().AlwaysRebuild() ||
4575 PointeeType != TL.getPointeeLoc().getType()) {
4576 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004577 TL.getSigilLoc());
4578 if (Result.isNull())
4579 return QualType();
4580 }
4581
Douglas Gregor049211a2010-04-22 16:50:51 +00004582 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004583 NewT.setSigilLoc(TL.getSigilLoc());
4584 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585}
4586
John McCall70dd5f62009-10-30 00:06:24 +00004587/// Transforms a reference type. Note that somewhat paradoxically we
4588/// don't care whether the type itself is an l-value type or an r-value
4589/// type; we only care if the type was *written* as an l-value type
4590/// or an r-value type.
4591template<typename Derived>
4592QualType
4593TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004594 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004595 const ReferenceType *T = TL.getTypePtr();
4596
4597 // Note that this works with the pointee-as-written.
4598 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4599 if (PointeeType.isNull())
4600 return QualType();
4601
4602 QualType Result = TL.getType();
4603 if (getDerived().AlwaysRebuild() ||
4604 PointeeType != T->getPointeeTypeAsWritten()) {
4605 Result = getDerived().RebuildReferenceType(PointeeType,
4606 T->isSpelledAsLValue(),
4607 TL.getSigilLoc());
4608 if (Result.isNull())
4609 return QualType();
4610 }
4611
John McCall31168b02011-06-15 23:02:42 +00004612 // Objective-C ARC can add lifetime qualifiers to the type that we're
4613 // referring to.
4614 TLB.TypeWasModifiedSafely(
4615 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4616
John McCall70dd5f62009-10-30 00:06:24 +00004617 // r-value references can be rebuilt as l-value references.
4618 ReferenceTypeLoc NewTL;
4619 if (isa<LValueReferenceType>(Result))
4620 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4621 else
4622 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4623 NewTL.setSigilLoc(TL.getSigilLoc());
4624
4625 return Result;
4626}
4627
Mike Stump11289f42009-09-09 15:08:12 +00004628template<typename Derived>
4629QualType
John McCall550e0c22009-10-21 00:40:46 +00004630TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004631 LValueReferenceTypeLoc TL) {
4632 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004633}
4634
Mike Stump11289f42009-09-09 15:08:12 +00004635template<typename Derived>
4636QualType
John McCall550e0c22009-10-21 00:40:46 +00004637TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004638 RValueReferenceTypeLoc TL) {
4639 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004640}
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregord6ff3322009-08-04 16:50:30 +00004642template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004643QualType
John McCall550e0c22009-10-21 00:40:46 +00004644TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004645 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004646 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004647 if (PointeeType.isNull())
4648 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004649
Abramo Bagnara509357842011-03-05 14:42:21 +00004650 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004651 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004652 if (OldClsTInfo) {
4653 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4654 if (!NewClsTInfo)
4655 return QualType();
4656 }
4657
4658 const MemberPointerType *T = TL.getTypePtr();
4659 QualType OldClsType = QualType(T->getClass(), 0);
4660 QualType NewClsType;
4661 if (NewClsTInfo)
4662 NewClsType = NewClsTInfo->getType();
4663 else {
4664 NewClsType = getDerived().TransformType(OldClsType);
4665 if (NewClsType.isNull())
4666 return QualType();
4667 }
Mike Stump11289f42009-09-09 15:08:12 +00004668
John McCall550e0c22009-10-21 00:40:46 +00004669 QualType Result = TL.getType();
4670 if (getDerived().AlwaysRebuild() ||
4671 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004672 NewClsType != OldClsType) {
4673 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004674 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004675 if (Result.isNull())
4676 return QualType();
4677 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004678
Reid Kleckner0503a872013-12-05 01:23:43 +00004679 // If we had to adjust the pointee type when building a member pointer, make
4680 // sure to push TypeLoc info for it.
4681 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4682 if (MPT && PointeeType != MPT->getPointeeType()) {
4683 assert(isa<AdjustedType>(MPT->getPointeeType()));
4684 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4685 }
4686
John McCall550e0c22009-10-21 00:40:46 +00004687 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4688 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004689 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004690
4691 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004692}
4693
Mike Stump11289f42009-09-09 15:08:12 +00004694template<typename Derived>
4695QualType
John McCall550e0c22009-10-21 00:40:46 +00004696TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004697 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004698 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004700 if (ElementType.isNull())
4701 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004702
John McCall550e0c22009-10-21 00:40:46 +00004703 QualType Result = TL.getType();
4704 if (getDerived().AlwaysRebuild() ||
4705 ElementType != T->getElementType()) {
4706 Result = getDerived().RebuildConstantArrayType(ElementType,
4707 T->getSizeModifier(),
4708 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004709 T->getIndexTypeCVRQualifiers(),
4710 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004711 if (Result.isNull())
4712 return QualType();
4713 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004714
4715 // We might have either a ConstantArrayType or a VariableArrayType now:
4716 // a ConstantArrayType is allowed to have an element type which is a
4717 // VariableArrayType if the type is dependent. Fortunately, all array
4718 // types have the same location layout.
4719 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004720 NewTL.setLBracketLoc(TL.getLBracketLoc());
4721 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004722
John McCall550e0c22009-10-21 00:40:46 +00004723 Expr *Size = TL.getSizeExpr();
4724 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004725 EnterExpressionEvaluationContext Unevaluated(
4726 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004727 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4728 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004729 }
4730 NewTL.setSizeExpr(Size);
4731
4732 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004733}
Mike Stump11289f42009-09-09 15:08:12 +00004734
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004736QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004737 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004738 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004739 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004740 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741 if (ElementType.isNull())
4742 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004743
John McCall550e0c22009-10-21 00:40:46 +00004744 QualType Result = TL.getType();
4745 if (getDerived().AlwaysRebuild() ||
4746 ElementType != T->getElementType()) {
4747 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004748 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004749 T->getIndexTypeCVRQualifiers(),
4750 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004751 if (Result.isNull())
4752 return QualType();
4753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004754
John McCall550e0c22009-10-21 00:40:46 +00004755 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4756 NewTL.setLBracketLoc(TL.getLBracketLoc());
4757 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004758 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004759
4760 return Result;
4761}
4762
4763template<typename Derived>
4764QualType
4765TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004766 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004767 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004768 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4769 if (ElementType.isNull())
4770 return QualType();
4771
Tim Shenb34d0ef2017-02-14 23:46:37 +00004772 ExprResult SizeResult;
4773 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004774 EnterExpressionEvaluationContext Context(
4775 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004776 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4777 }
4778 if (SizeResult.isInvalid())
4779 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004780 SizeResult =
4781 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004782 if (SizeResult.isInvalid())
4783 return QualType();
4784
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004785 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004786
4787 QualType Result = TL.getType();
4788 if (getDerived().AlwaysRebuild() ||
4789 ElementType != T->getElementType() ||
4790 Size != T->getSizeExpr()) {
4791 Result = getDerived().RebuildVariableArrayType(ElementType,
4792 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004793 Size,
John McCall550e0c22009-10-21 00:40:46 +00004794 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004795 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004796 if (Result.isNull())
4797 return QualType();
4798 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004799
Serge Pavlov774c6d02014-02-06 03:49:11 +00004800 // We might have constant size array now, but fortunately it has the same
4801 // location layout.
4802 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004803 NewTL.setLBracketLoc(TL.getLBracketLoc());
4804 NewTL.setRBracketLoc(TL.getRBracketLoc());
4805 NewTL.setSizeExpr(Size);
4806
4807 return Result;
4808}
4809
4810template<typename Derived>
4811QualType
4812TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004813 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004814 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004815 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4816 if (ElementType.isNull())
4817 return QualType();
4818
Richard Smith764d2fe2011-12-20 02:08:33 +00004819 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004820 EnterExpressionEvaluationContext Unevaluated(
4821 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004822
John McCall33ddac02011-01-19 10:06:00 +00004823 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4824 Expr *origSize = TL.getSizeExpr();
4825 if (!origSize) origSize = T->getSizeExpr();
4826
4827 ExprResult sizeResult
4828 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004829 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004830 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004831 return QualType();
4832
John McCall33ddac02011-01-19 10:06:00 +00004833 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004834
4835 QualType Result = TL.getType();
4836 if (getDerived().AlwaysRebuild() ||
4837 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004838 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004839 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4840 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004841 size,
John McCall550e0c22009-10-21 00:40:46 +00004842 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004843 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004844 if (Result.isNull())
4845 return QualType();
4846 }
John McCall550e0c22009-10-21 00:40:46 +00004847
4848 // We might have any sort of array type now, but fortunately they
4849 // all have the same location layout.
4850 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4851 NewTL.setLBracketLoc(TL.getLBracketLoc());
4852 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004853 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004854
4855 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004856}
Mike Stump11289f42009-09-09 15:08:12 +00004857
Erich Keanef702b022018-07-13 19:46:04 +00004858template <typename Derived>
4859QualType TreeTransform<Derived>::TransformDependentVectorType(
4860 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4861 const DependentVectorType *T = TL.getTypePtr();
4862 QualType ElementType = getDerived().TransformType(T->getElementType());
4863 if (ElementType.isNull())
4864 return QualType();
4865
4866 EnterExpressionEvaluationContext Unevaluated(
4867 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4868
4869 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4870 Size = SemaRef.ActOnConstantExpression(Size);
4871 if (Size.isInvalid())
4872 return QualType();
4873
4874 QualType Result = TL.getType();
4875 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4876 Size.get() != T->getSizeExpr()) {
4877 Result = getDerived().RebuildDependentVectorType(
4878 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4879 if (Result.isNull())
4880 return QualType();
4881 }
4882
4883 // Result might be dependent or not.
4884 if (isa<DependentVectorType>(Result)) {
4885 DependentVectorTypeLoc NewTL =
4886 TLB.push<DependentVectorTypeLoc>(Result);
4887 NewTL.setNameLoc(TL.getNameLoc());
4888 } else {
4889 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4890 NewTL.setNameLoc(TL.getNameLoc());
4891 }
4892
4893 return Result;
4894}
4895
Mike Stump11289f42009-09-09 15:08:12 +00004896template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004897QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004898 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004899 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004900 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004901
4902 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004903 QualType ElementType = getDerived().TransformType(T->getElementType());
4904 if (ElementType.isNull())
4905 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004906
Richard Smith764d2fe2011-12-20 02:08:33 +00004907 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004908 EnterExpressionEvaluationContext Unevaluated(
4909 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004910
John McCalldadc5752010-08-24 06:29:42 +00004911 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004912 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004913 if (Size.isInvalid())
4914 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004915
John McCall550e0c22009-10-21 00:40:46 +00004916 QualType Result = TL.getType();
4917 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004918 ElementType != T->getElementType() ||
4919 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004920 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004921 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004922 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004923 if (Result.isNull())
4924 return QualType();
4925 }
John McCall550e0c22009-10-21 00:40:46 +00004926
4927 // Result might be dependent or not.
4928 if (isa<DependentSizedExtVectorType>(Result)) {
4929 DependentSizedExtVectorTypeLoc NewTL
4930 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4931 NewTL.setNameLoc(TL.getNameLoc());
4932 } else {
4933 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4934 NewTL.setNameLoc(TL.getNameLoc());
4935 }
4936
4937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004938}
Mike Stump11289f42009-09-09 15:08:12 +00004939
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004940template <typename Derived>
4941QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4942 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4943 const DependentAddressSpaceType *T = TL.getTypePtr();
4944
4945 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4946
4947 if (pointeeType.isNull())
4948 return QualType();
4949
4950 // Address spaces are constant expressions.
4951 EnterExpressionEvaluationContext Unevaluated(
4952 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4953
4954 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4955 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4956 if (AddrSpace.isInvalid())
4957 return QualType();
4958
4959 QualType Result = TL.getType();
4960 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4961 AddrSpace.get() != T->getAddrSpaceExpr()) {
4962 Result = getDerived().RebuildDependentAddressSpaceType(
4963 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4964 if (Result.isNull())
4965 return QualType();
4966 }
4967
4968 // Result might be dependent or not.
4969 if (isa<DependentAddressSpaceType>(Result)) {
4970 DependentAddressSpaceTypeLoc NewTL =
4971 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4972
4973 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4974 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4975 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4976
4977 } else {
4978 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4979 Result, getDerived().getBaseLocation());
4980 TransformType(TLB, DI->getTypeLoc());
4981 }
4982
4983 return Result;
4984}
4985
4986template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004987QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004988 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004989 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004990 QualType ElementType = getDerived().TransformType(T->getElementType());
4991 if (ElementType.isNull())
4992 return QualType();
4993
John McCall550e0c22009-10-21 00:40:46 +00004994 QualType Result = TL.getType();
4995 if (getDerived().AlwaysRebuild() ||
4996 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004997 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004998 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004999 if (Result.isNull())
5000 return QualType();
5001 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
John McCall550e0c22009-10-21 00:40:46 +00005003 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5004 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005005
John McCall550e0c22009-10-21 00:40:46 +00005006 return Result;
5007}
5008
5009template<typename Derived>
5010QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005011 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005012 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005013 QualType ElementType = getDerived().TransformType(T->getElementType());
5014 if (ElementType.isNull())
5015 return QualType();
5016
5017 QualType Result = TL.getType();
5018 if (getDerived().AlwaysRebuild() ||
5019 ElementType != T->getElementType()) {
5020 Result = getDerived().RebuildExtVectorType(ElementType,
5021 T->getNumElements(),
5022 /*FIXME*/ SourceLocation());
5023 if (Result.isNull())
5024 return QualType();
5025 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005026
John McCall550e0c22009-10-21 00:40:46 +00005027 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5028 NewTL.setNameLoc(TL.getNameLoc());
5029
5030 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
David Blaikie05785d12013-02-20 22:23:23 +00005033template <typename Derived>
5034ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
5035 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5036 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00005037 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00005038 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005039
Douglas Gregor715e4612011-01-14 22:40:04 +00005040 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005041 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005042 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00005043 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005044 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00005045
Douglas Gregor715e4612011-01-14 22:40:04 +00005046 TypeLocBuilder TLB;
5047 TypeLoc NewTL = OldDI->getTypeLoc();
5048 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
5050 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005051 OldExpansionTL.getPatternLoc());
5052 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005053 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005054
5055 Result = RebuildPackExpansionType(Result,
5056 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005057 OldExpansionTL.getEllipsisLoc(),
5058 NumExpansions);
5059 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005060 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005061
Douglas Gregor715e4612011-01-14 22:40:04 +00005062 PackExpansionTypeLoc NewExpansionTL
5063 = TLB.push<PackExpansionTypeLoc>(Result);
5064 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5065 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5066 } else
5067 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005068 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005069 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005070
John McCall8fb0d9d2011-05-01 22:35:37 +00005071 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005072 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005073
5074 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5075 OldParm->getDeclContext(),
5076 OldParm->getInnerLocStart(),
5077 OldParm->getLocation(),
5078 OldParm->getIdentifier(),
5079 NewDI->getType(),
5080 NewDI,
5081 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005082 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005083 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5084 OldParm->getFunctionScopeIndex() + indexAdjustment);
5085 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005086}
5087
David Majnemer59f77922016-06-24 04:05:48 +00005088template <typename Derived>
5089bool TreeTransform<Derived>::TransformFunctionTypeParams(
5090 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5091 const QualType *ParamTypes,
5092 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5093 SmallVectorImpl<QualType> &OutParamTypes,
5094 SmallVectorImpl<ParmVarDecl *> *PVars,
5095 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005096 int indexAdjustment = 0;
5097
David Majnemer59f77922016-06-24 04:05:48 +00005098 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005099 for (unsigned i = 0; i != NumParams; ++i) {
5100 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005101 assert(OldParm->getFunctionScopeIndex() == i);
5102
David Blaikie05785d12013-02-20 22:23:23 +00005103 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005104 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005105 if (OldParm->isParameterPack()) {
5106 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005107 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005108
Douglas Gregor5499af42011-01-05 23:12:31 +00005109 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005110 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005111 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005112 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5113 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005114 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5115
Douglas Gregor5499af42011-01-05 23:12:31 +00005116 // Determine whether we should expand the parameter packs.
5117 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005118 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005119 Optional<unsigned> OrigNumExpansions =
5120 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005121 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005122 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5123 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005124 Unexpanded,
5125 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005126 RetainExpansion,
5127 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005128 return true;
5129 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005130
Douglas Gregor5499af42011-01-05 23:12:31 +00005131 if (ShouldExpand) {
5132 // Expand the function parameter pack into multiple, separate
5133 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005134 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005135 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005137 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005138 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005139 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005140 OrigNumExpansions,
5141 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005142 if (!NewParm)
5143 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005144
John McCallc8e321d2016-03-01 02:09:25 +00005145 if (ParamInfos)
5146 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005147 OutParamTypes.push_back(NewParm->getType());
5148 if (PVars)
5149 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005150 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005151
5152 // If we're supposed to retain a pack expansion, do so by temporarily
5153 // forgetting the partially-substituted parameter pack.
5154 if (RetainExpansion) {
5155 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005156 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005157 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005158 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005159 OrigNumExpansions,
5160 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005161 if (!NewParm)
5162 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005163
John McCallc8e321d2016-03-01 02:09:25 +00005164 if (ParamInfos)
5165 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005166 OutParamTypes.push_back(NewParm->getType());
5167 if (PVars)
5168 PVars->push_back(NewParm);
5169 }
5170
John McCall8fb0d9d2011-05-01 22:35:37 +00005171 // The next parameter should have the same adjustment as the
5172 // last thing we pushed, but we post-incremented indexAdjustment
5173 // on every push. Also, if we push nothing, the adjustment should
5174 // go down by one.
5175 indexAdjustment--;
5176
Douglas Gregor5499af42011-01-05 23:12:31 +00005177 // We're done with the pack expansion.
5178 continue;
5179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005180
5181 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005182 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005183 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5184 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005185 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005186 NumExpansions,
5187 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005188 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005189 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005190 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005191 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005192
John McCall58f10c32010-03-11 09:03:00 +00005193 if (!NewParm)
5194 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005195
John McCallc8e321d2016-03-01 02:09:25 +00005196 if (ParamInfos)
5197 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005198 OutParamTypes.push_back(NewParm->getType());
5199 if (PVars)
5200 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005201 continue;
5202 }
John McCall58f10c32010-03-11 09:03:00 +00005203
5204 // Deal with the possibility that we don't have a parameter
5205 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005206 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005207 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005208 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005209 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005210 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005211 = dyn_cast<PackExpansionType>(OldType)) {
5212 // We have a function parameter pack that may need to be expanded.
5213 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005214 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005215 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005216
Douglas Gregor5499af42011-01-05 23:12:31 +00005217 // Determine whether we should expand the parameter packs.
5218 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005219 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005220 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005221 Unexpanded,
5222 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005223 RetainExpansion,
5224 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005225 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005226 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005227
Douglas Gregor5499af42011-01-05 23:12:31 +00005228 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005229 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005230 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005231 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005232 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5233 QualType NewType = getDerived().TransformType(Pattern);
5234 if (NewType.isNull())
5235 return true;
John McCall58f10c32010-03-11 09:03:00 +00005236
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005237 if (NewType->containsUnexpandedParameterPack()) {
5238 NewType =
5239 getSema().getASTContext().getPackExpansionType(NewType, None);
5240
5241 if (NewType.isNull())
5242 return true;
5243 }
5244
John McCallc8e321d2016-03-01 02:09:25 +00005245 if (ParamInfos)
5246 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005247 OutParamTypes.push_back(NewType);
5248 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005249 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005250 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005251
Douglas Gregor5499af42011-01-05 23:12:31 +00005252 // We're done with the pack expansion.
5253 continue;
5254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005255
Douglas Gregor48d24112011-01-10 20:53:55 +00005256 // If we're supposed to retain a pack expansion, do so by temporarily
5257 // forgetting the partially-substituted parameter pack.
5258 if (RetainExpansion) {
5259 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5260 QualType NewType = getDerived().TransformType(Pattern);
5261 if (NewType.isNull())
5262 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005263
John McCallc8e321d2016-03-01 02:09:25 +00005264 if (ParamInfos)
5265 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005266 OutParamTypes.push_back(NewType);
5267 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005268 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005269 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005270
Chad Rosier1dcde962012-08-08 18:46:20 +00005271 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005272 // expansion.
5273 OldType = Expansion->getPattern();
5274 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005275 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5276 NewType = getDerived().TransformType(OldType);
5277 } else {
5278 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregor5499af42011-01-05 23:12:31 +00005281 if (NewType.isNull())
5282 return true;
5283
5284 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005285 NewType = getSema().Context.getPackExpansionType(NewType,
5286 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
John McCallc8e321d2016-03-01 02:09:25 +00005288 if (ParamInfos)
5289 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005290 OutParamTypes.push_back(NewType);
5291 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005292 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005293 }
5294
John McCall8fb0d9d2011-05-01 22:35:37 +00005295#ifndef NDEBUG
5296 if (PVars) {
5297 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5298 if (ParmVarDecl *parm = (*PVars)[i])
5299 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005300 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005301#endif
5302
5303 return false;
5304}
John McCall58f10c32010-03-11 09:03:00 +00005305
5306template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005307QualType
John McCall550e0c22009-10-21 00:40:46 +00005308TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005309 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005310 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005311 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005312 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005313 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005314 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5315 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5316 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005317 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005318}
5319
Richard Smith2e321552014-11-12 02:00:47 +00005320template<typename Derived> template<typename Fn>
5321QualType TreeTransform<Derived>::TransformFunctionProtoType(
5322 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005323 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005324
Douglas Gregor4afc2362010-08-31 00:26:14 +00005325 // Transform the parameters and return type.
5326 //
Richard Smithf623c962012-04-17 00:58:00 +00005327 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005328 // When the function has a trailing return type, we instantiate the
5329 // parameters before the return type, since the return type can then refer
5330 // to the parameters themselves (via decltype, sizeof, etc.).
5331 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005332 SmallVector<QualType, 4> ParamTypes;
5333 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005334 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005335 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005336
Douglas Gregor7fb25412010-10-01 18:44:50 +00005337 QualType ResultType;
5338
Richard Smith1226c602012-08-14 22:51:13 +00005339 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005340 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005341 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005342 TL.getTypePtr()->param_type_begin(),
5343 T->getExtParameterInfosOrNull(),
5344 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005345 return QualType();
5346
Douglas Gregor3024f072012-04-16 07:05:22 +00005347 {
5348 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005349 // If a declaration declares a member function or member function
5350 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005351 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005352 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005353 // declarator.
5354 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005355
Alp Toker42a16a62014-01-25 23:51:36 +00005356 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005357 if (ResultType.isNull())
5358 return QualType();
5359 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005360 }
5361 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005362 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005363 if (ResultType.isNull())
5364 return QualType();
5365
Anastasia Stulova6a4c3462018-11-29 14:11:15 +00005366 // Return type can not be qualified with an address space.
5367 if (ResultType.getAddressSpace() != LangAS::Default) {
5368 SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5369 diag::err_attribute_address_function_type);
5370 return QualType();
5371 }
5372
Alp Toker9cacbab2014-01-20 20:26:09 +00005373 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005374 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005375 TL.getTypePtr()->param_type_begin(),
5376 T->getExtParameterInfosOrNull(),
5377 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005378 return QualType();
5379 }
5380
Richard Smith2e321552014-11-12 02:00:47 +00005381 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5382
5383 bool EPIChanged = false;
5384 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5385 return QualType();
5386
John McCallc8e321d2016-03-01 02:09:25 +00005387 // Handle extended parameter information.
5388 if (auto NewExtParamInfos =
5389 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5390 if (!EPI.ExtParameterInfos ||
5391 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5392 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5393 EPIChanged = true;
5394 }
5395 EPI.ExtParameterInfos = NewExtParamInfos;
5396 } else if (EPI.ExtParameterInfos) {
5397 EPIChanged = true;
5398 EPI.ExtParameterInfos = nullptr;
5399 }
Richard Smithf623c962012-04-17 00:58:00 +00005400
John McCall550e0c22009-10-21 00:40:46 +00005401 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005402 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005403 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005404 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005405 if (Result.isNull())
5406 return QualType();
5407 }
Mike Stump11289f42009-09-09 15:08:12 +00005408
John McCall550e0c22009-10-21 00:40:46 +00005409 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005410 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005411 NewTL.setLParenLoc(TL.getLParenLoc());
5412 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005413 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005414 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005415 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5416 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005417
5418 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419}
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005422bool TreeTransform<Derived>::TransformExceptionSpec(
5423 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5424 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5425 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5426
5427 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005428 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005429 EnterExpressionEvaluationContext Unevaluated(
5430 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005431 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5432 if (NoexceptExpr.isInvalid())
5433 return true;
5434
Richard Smitheaf11ad2018-05-03 03:58:32 +00005435 ExceptionSpecificationType EST = ESI.Type;
5436 NoexceptExpr =
5437 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005438 if (NoexceptExpr.isInvalid())
5439 return true;
5440
Richard Smitheaf11ad2018-05-03 03:58:32 +00005441 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005442 Changed = true;
5443 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005444 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005445 }
5446
5447 if (ESI.Type != EST_Dynamic)
5448 return false;
5449
5450 // Instantiate a dynamic exception specification's type.
5451 for (QualType T : ESI.Exceptions) {
5452 if (const PackExpansionType *PackExpansion =
5453 T->getAs<PackExpansionType>()) {
5454 Changed = true;
5455
5456 // We have a pack expansion. Instantiate it.
5457 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5458 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5459 Unexpanded);
5460 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5461
5462 // Determine whether the set of unexpanded parameter packs can and
5463 // should
5464 // be expanded.
5465 bool Expand = false;
5466 bool RetainExpansion = false;
5467 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5468 // FIXME: Track the location of the ellipsis (and track source location
5469 // information for the types in the exception specification in general).
5470 if (getDerived().TryExpandParameterPacks(
5471 Loc, SourceRange(), Unexpanded, Expand,
5472 RetainExpansion, NumExpansions))
5473 return true;
5474
5475 if (!Expand) {
5476 // We can't expand this pack expansion into separate arguments yet;
5477 // just substitute into the pattern and create a new pack expansion
5478 // type.
5479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5480 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5481 if (U.isNull())
5482 return true;
5483
5484 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5485 Exceptions.push_back(U);
5486 continue;
5487 }
5488
5489 // Substitute into the pack expansion pattern for each slice of the
5490 // pack.
5491 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5492 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5493
5494 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5495 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5496 return true;
5497
5498 Exceptions.push_back(U);
5499 }
5500 } else {
5501 QualType U = getDerived().TransformType(T);
5502 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5503 return true;
5504 if (T != U)
5505 Changed = true;
5506
5507 Exceptions.push_back(U);
5508 }
5509 }
5510
5511 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005512 if (ESI.Exceptions.empty())
5513 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005514 return false;
5515}
5516
5517template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005518QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005519 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005520 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005521 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005522 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005523 if (ResultType.isNull())
5524 return QualType();
5525
5526 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005527 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005528 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5529
5530 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005531 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005532 NewTL.setLParenLoc(TL.getLParenLoc());
5533 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005534 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005535
5536 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005537}
Mike Stump11289f42009-09-09 15:08:12 +00005538
John McCallb96ec562009-12-04 22:46:56 +00005539template<typename Derived> QualType
5540TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005541 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005542 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005543 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005544 if (!D)
5545 return QualType();
5546
5547 QualType Result = TL.getType();
5548 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005549 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005550 if (Result.isNull())
5551 return QualType();
5552 }
5553
5554 // We might get an arbitrary type spec type back. We should at
5555 // least always get a type spec type, though.
5556 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5557 NewTL.setNameLoc(TL.getNameLoc());
5558
5559 return Result;
5560}
5561
Douglas Gregord6ff3322009-08-04 16:50:30 +00005562template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005563QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005564 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005565 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005566 TypedefNameDecl *Typedef
5567 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5568 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005569 if (!Typedef)
5570 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005571
John McCall550e0c22009-10-21 00:40:46 +00005572 QualType Result = TL.getType();
5573 if (getDerived().AlwaysRebuild() ||
5574 Typedef != T->getDecl()) {
5575 Result = getDerived().RebuildTypedefType(Typedef);
5576 if (Result.isNull())
5577 return QualType();
5578 }
Mike Stump11289f42009-09-09 15:08:12 +00005579
John McCall550e0c22009-10-21 00:40:46 +00005580 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5581 NewTL.setNameLoc(TL.getNameLoc());
5582
5583 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005584}
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregord6ff3322009-08-04 16:50:30 +00005586template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005587QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005588 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005589 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005590 EnterExpressionEvaluationContext Unevaluated(
5591 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5592 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005593
John McCalldadc5752010-08-24 06:29:42 +00005594 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005595 if (E.isInvalid())
5596 return QualType();
5597
Eli Friedmane4f22df2012-02-29 04:03:55 +00005598 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5599 if (E.isInvalid())
5600 return QualType();
5601
John McCall550e0c22009-10-21 00:40:46 +00005602 QualType Result = TL.getType();
5603 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005604 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005605 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005606 if (Result.isNull())
5607 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005608 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005609 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005610
John McCall550e0c22009-10-21 00:40:46 +00005611 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005612 NewTL.setTypeofLoc(TL.getTypeofLoc());
5613 NewTL.setLParenLoc(TL.getLParenLoc());
5614 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005615
5616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005617}
Mike Stump11289f42009-09-09 15:08:12 +00005618
5619template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005620QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005621 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005622 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5623 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5624 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005625 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005626
John McCall550e0c22009-10-21 00:40:46 +00005627 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005628 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5629 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005630 if (Result.isNull())
5631 return QualType();
5632 }
Mike Stump11289f42009-09-09 15:08:12 +00005633
John McCall550e0c22009-10-21 00:40:46 +00005634 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005635 NewTL.setTypeofLoc(TL.getTypeofLoc());
5636 NewTL.setLParenLoc(TL.getLParenLoc());
5637 NewTL.setRParenLoc(TL.getRParenLoc());
5638 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005639
5640 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005641}
Mike Stump11289f42009-09-09 15:08:12 +00005642
5643template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005644QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005645 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005646 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005647
Douglas Gregore922c772009-08-04 22:27:00 +00005648 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005649 EnterExpressionEvaluationContext Unevaluated(
5650 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005651 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCalldadc5752010-08-24 06:29:42 +00005653 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005654 if (E.isInvalid())
5655 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005656
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005657 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005658 if (E.isInvalid())
5659 return QualType();
5660
John McCall550e0c22009-10-21 00:40:46 +00005661 QualType Result = TL.getType();
5662 if (getDerived().AlwaysRebuild() ||
5663 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005664 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005665 if (Result.isNull())
5666 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005667 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005668 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005669
John McCall550e0c22009-10-21 00:40:46 +00005670 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5671 NewTL.setNameLoc(TL.getNameLoc());
5672
5673 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005674}
5675
5676template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005677QualType TreeTransform<Derived>::TransformUnaryTransformType(
5678 TypeLocBuilder &TLB,
5679 UnaryTransformTypeLoc TL) {
5680 QualType Result = TL.getType();
5681 if (Result->isDependentType()) {
5682 const UnaryTransformType *T = TL.getTypePtr();
5683 QualType NewBase =
5684 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5685 Result = getDerived().RebuildUnaryTransformType(NewBase,
5686 T->getUTTKind(),
5687 TL.getKWLoc());
5688 if (Result.isNull())
5689 return QualType();
5690 }
5691
5692 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5693 NewTL.setKWLoc(TL.getKWLoc());
5694 NewTL.setParensRange(TL.getParensRange());
5695 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5696 return Result;
5697}
5698
5699template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005700QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5701 AutoTypeLoc TL) {
5702 const AutoType *T = TL.getTypePtr();
5703 QualType OldDeduced = T->getDeducedType();
5704 QualType NewDeduced;
5705 if (!OldDeduced.isNull()) {
5706 NewDeduced = getDerived().TransformType(OldDeduced);
5707 if (NewDeduced.isNull())
5708 return QualType();
5709 }
5710
5711 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005712 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5713 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005714 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005715 if (Result.isNull())
5716 return QualType();
5717 }
5718
5719 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5720 NewTL.setNameLoc(TL.getNameLoc());
5721
5722 return Result;
5723}
5724
5725template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005726QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5727 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5728 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5729
5730 CXXScopeSpec SS;
5731 TemplateName TemplateName = getDerived().TransformTemplateName(
5732 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5733 if (TemplateName.isNull())
5734 return QualType();
5735
5736 QualType OldDeduced = T->getDeducedType();
5737 QualType NewDeduced;
5738 if (!OldDeduced.isNull()) {
5739 NewDeduced = getDerived().TransformType(OldDeduced);
5740 if (NewDeduced.isNull())
5741 return QualType();
5742 }
5743
5744 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5745 TemplateName, NewDeduced);
5746 if (Result.isNull())
5747 return QualType();
5748
5749 DeducedTemplateSpecializationTypeLoc NewTL =
5750 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5751 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5752
5753 return Result;
5754}
5755
5756template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005757QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005758 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005759 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005760 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005761 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5762 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005763 if (!Record)
5764 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005765
John McCall550e0c22009-10-21 00:40:46 +00005766 QualType Result = TL.getType();
5767 if (getDerived().AlwaysRebuild() ||
5768 Record != T->getDecl()) {
5769 Result = getDerived().RebuildRecordType(Record);
5770 if (Result.isNull())
5771 return QualType();
5772 }
Mike Stump11289f42009-09-09 15:08:12 +00005773
John McCall550e0c22009-10-21 00:40:46 +00005774 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5775 NewTL.setNameLoc(TL.getNameLoc());
5776
5777 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005778}
Mike Stump11289f42009-09-09 15:08:12 +00005779
5780template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005781QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005782 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005783 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005784 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005785 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5786 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005787 if (!Enum)
5788 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005789
John McCall550e0c22009-10-21 00:40:46 +00005790 QualType Result = TL.getType();
5791 if (getDerived().AlwaysRebuild() ||
5792 Enum != T->getDecl()) {
5793 Result = getDerived().RebuildEnumType(Enum);
5794 if (Result.isNull())
5795 return QualType();
5796 }
Mike Stump11289f42009-09-09 15:08:12 +00005797
John McCall550e0c22009-10-21 00:40:46 +00005798 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5799 NewTL.setNameLoc(TL.getNameLoc());
5800
5801 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005802}
John McCallfcc33b02009-09-05 00:15:47 +00005803
John McCalle78aac42010-03-10 03:28:59 +00005804template<typename Derived>
5805QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5806 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005807 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005808 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5809 TL.getTypePtr()->getDecl());
5810 if (!D) return QualType();
5811
5812 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5813 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5814 return T;
5815}
5816
Douglas Gregord6ff3322009-08-04 16:50:30 +00005817template<typename Derived>
5818QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005819 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005820 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005821 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005822}
5823
Mike Stump11289f42009-09-09 15:08:12 +00005824template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005825QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005826 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005827 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005828 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005829
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005830 // Substitute into the replacement type, which itself might involve something
5831 // that needs to be transformed. This only tends to occur with default
5832 // template arguments of template template parameters.
5833 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5834 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5835 if (Replacement.isNull())
5836 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005837
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005838 // Always canonicalize the replacement type.
5839 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5840 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005841 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005842 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005843
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005844 // Propagate type-source information.
5845 SubstTemplateTypeParmTypeLoc NewTL
5846 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5847 NewTL.setNameLoc(TL.getNameLoc());
5848 return Result;
5849
John McCallcebee162009-10-18 09:09:24 +00005850}
5851
5852template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005853QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5854 TypeLocBuilder &TLB,
5855 SubstTemplateTypeParmPackTypeLoc TL) {
5856 return TransformTypeSpecType(TLB, TL);
5857}
5858
5859template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005860QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005861 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005862 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005863 const TemplateSpecializationType *T = TL.getTypePtr();
5864
Douglas Gregordf846d12011-03-02 18:46:51 +00005865 // The nested-name-specifier never matters in a TemplateSpecializationType,
5866 // because we can't have a dependent nested-name-specifier anyway.
5867 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005868 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005869 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5870 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005871 if (Template.isNull())
5872 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005873
John McCall31f82722010-11-12 08:19:04 +00005874 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5875}
5876
Eli Friedman0dfb8892011-10-06 23:00:33 +00005877template<typename Derived>
5878QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5879 AtomicTypeLoc TL) {
5880 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5881 if (ValueType.isNull())
5882 return QualType();
5883
5884 QualType Result = TL.getType();
5885 if (getDerived().AlwaysRebuild() ||
5886 ValueType != TL.getValueLoc().getType()) {
5887 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5888 if (Result.isNull())
5889 return QualType();
5890 }
5891
5892 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5893 NewTL.setKWLoc(TL.getKWLoc());
5894 NewTL.setLParenLoc(TL.getLParenLoc());
5895 NewTL.setRParenLoc(TL.getRParenLoc());
5896
5897 return Result;
5898}
5899
Xiuli Pan9c14e282016-01-09 12:53:17 +00005900template <typename Derived>
5901QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5902 PipeTypeLoc TL) {
5903 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5904 if (ValueType.isNull())
5905 return QualType();
5906
5907 QualType Result = TL.getType();
5908 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005909 const PipeType *PT = Result->getAs<PipeType>();
5910 bool isReadPipe = PT->isReadOnly();
5911 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005912 if (Result.isNull())
5913 return QualType();
5914 }
5915
5916 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5917 NewTL.setKWLoc(TL.getKWLoc());
5918
5919 return Result;
5920}
5921
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005922 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005923 /// container that provides a \c getArgLoc() member function.
5924 ///
5925 /// This iterator is intended to be used with the iterator form of
5926 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5927 template<typename ArgLocContainer>
5928 class TemplateArgumentLocContainerIterator {
5929 ArgLocContainer *Container;
5930 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005931
Douglas Gregorfe921a72010-12-20 23:36:19 +00005932 public:
5933 typedef TemplateArgumentLoc value_type;
5934 typedef TemplateArgumentLoc reference;
5935 typedef int difference_type;
5936 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005937
Douglas Gregorfe921a72010-12-20 23:36:19 +00005938 class pointer {
5939 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005940
Douglas Gregorfe921a72010-12-20 23:36:19 +00005941 public:
5942 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Douglas Gregorfe921a72010-12-20 23:36:19 +00005944 const TemplateArgumentLoc *operator->() const {
5945 return &Arg;
5946 }
5947 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005948
5949
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005950 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005951
Douglas Gregorfe921a72010-12-20 23:36:19 +00005952 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5953 unsigned Index)
5954 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Douglas Gregorfe921a72010-12-20 23:36:19 +00005956 TemplateArgumentLocContainerIterator &operator++() {
5957 ++Index;
5958 return *this;
5959 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005960
Douglas Gregorfe921a72010-12-20 23:36:19 +00005961 TemplateArgumentLocContainerIterator operator++(int) {
5962 TemplateArgumentLocContainerIterator Old(*this);
5963 ++(*this);
5964 return Old;
5965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005966
Douglas Gregorfe921a72010-12-20 23:36:19 +00005967 TemplateArgumentLoc operator*() const {
5968 return Container->getArgLoc(Index);
5969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
Douglas Gregorfe921a72010-12-20 23:36:19 +00005971 pointer operator->() const {
5972 return pointer(Container->getArgLoc(Index));
5973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005974
Douglas Gregorfe921a72010-12-20 23:36:19 +00005975 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005976 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005977 return X.Container == Y.Container && X.Index == Y.Index;
5978 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005979
Douglas Gregorfe921a72010-12-20 23:36:19 +00005980 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005981 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005982 return !(X == Y);
5983 }
5984 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005985
5986
John McCall31f82722010-11-12 08:19:04 +00005987template <typename Derived>
5988QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5989 TypeLocBuilder &TLB,
5990 TemplateSpecializationTypeLoc TL,
5991 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005992 TemplateArgumentListInfo NewTemplateArgs;
5993 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5994 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005995 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5996 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005997 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005998 ArgIterator(TL, TL.getNumArgs()),
5999 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00006000 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006001
John McCall0ad16662009-10-29 08:12:44 +00006002 // FIXME: maybe don't rebuild if all the template arguments are the same.
6003
6004 QualType Result =
6005 getDerived().RebuildTemplateSpecializationType(Template,
6006 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00006007 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00006008
6009 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00006010 // Specializations of template template parameters are represented as
6011 // TemplateSpecializationTypes, and substitution of type alias templates
6012 // within a dependent context can transform them into
6013 // DependentTemplateSpecializationTypes.
6014 if (isa<DependentTemplateSpecializationType>(Result)) {
6015 DependentTemplateSpecializationTypeLoc NewTL
6016 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006017 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006018 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006019 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006020 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006021 NewTL.setLAngleLoc(TL.getLAngleLoc());
6022 NewTL.setRAngleLoc(TL.getRAngleLoc());
6023 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6024 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6025 return Result;
6026 }
6027
John McCall0ad16662009-10-29 08:12:44 +00006028 TemplateSpecializationTypeLoc NewTL
6029 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006030 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00006031 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6032 NewTL.setLAngleLoc(TL.getLAngleLoc());
6033 NewTL.setRAngleLoc(TL.getRAngleLoc());
6034 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6035 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006036 }
Mike Stump11289f42009-09-09 15:08:12 +00006037
John McCall0ad16662009-10-29 08:12:44 +00006038 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006039}
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregor5a064722011-02-28 17:23:35 +00006041template <typename Derived>
6042QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6043 TypeLocBuilder &TLB,
6044 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00006045 TemplateName Template,
6046 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006047 TemplateArgumentListInfo NewTemplateArgs;
6048 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6049 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6050 typedef TemplateArgumentLocContainerIterator<
6051 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006052 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006053 ArgIterator(TL, TL.getNumArgs()),
6054 NewTemplateArgs))
6055 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006056
Douglas Gregor5a064722011-02-28 17:23:35 +00006057 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006058
Douglas Gregor5a064722011-02-28 17:23:35 +00006059 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6060 QualType Result
6061 = getSema().Context.getDependentTemplateSpecializationType(
6062 TL.getTypePtr()->getKeyword(),
6063 DTN->getQualifier(),
6064 DTN->getIdentifier(),
6065 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006066
Douglas Gregor5a064722011-02-28 17:23:35 +00006067 DependentTemplateSpecializationTypeLoc NewTL
6068 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006069 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006070 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006071 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006072 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006073 NewTL.setLAngleLoc(TL.getLAngleLoc());
6074 NewTL.setRAngleLoc(TL.getRAngleLoc());
6075 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6076 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6077 return Result;
6078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
6080 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006081 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006082 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006083 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006084
Douglas Gregor5a064722011-02-28 17:23:35 +00006085 if (!Result.isNull()) {
6086 /// FIXME: Wrap this in an elaborated-type-specifier?
6087 TemplateSpecializationTypeLoc NewTL
6088 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006089 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006090 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006091 NewTL.setLAngleLoc(TL.getLAngleLoc());
6092 NewTL.setRAngleLoc(TL.getRAngleLoc());
6093 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6094 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6095 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006096
Douglas Gregor5a064722011-02-28 17:23:35 +00006097 return Result;
6098}
6099
Mike Stump11289f42009-09-09 15:08:12 +00006100template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006101QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006102TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006103 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006104 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006105
Douglas Gregor844cb502011-03-01 18:12:44 +00006106 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006107 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006108 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006109 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006110 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6111 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006112 return QualType();
6113 }
Mike Stump11289f42009-09-09 15:08:12 +00006114
John McCall31f82722010-11-12 08:19:04 +00006115 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6116 if (NamedT.isNull())
6117 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006118
Richard Smith3f1b5d02011-05-05 21:57:07 +00006119 // C++0x [dcl.type.elab]p2:
6120 // If the identifier resolves to a typedef-name or the simple-template-id
6121 // resolves to an alias template specialization, the
6122 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006123 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6124 if (const TemplateSpecializationType *TST =
6125 NamedT->getAs<TemplateSpecializationType>()) {
6126 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006127 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6128 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006129 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006130 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006131 << TAT << Sema::NTK_TypeAliasTemplate
6132 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006133 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6134 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006135 }
6136 }
6137
John McCall550e0c22009-10-21 00:40:46 +00006138 QualType Result = TL.getType();
6139 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006140 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006141 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006142 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006143 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006144 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006145 if (Result.isNull())
6146 return QualType();
6147 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006148
Abramo Bagnara6150c882010-05-11 21:36:43 +00006149 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006150 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006151 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006152 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006153}
Mike Stump11289f42009-09-09 15:08:12 +00006154
6155template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006156QualType TreeTransform<Derived>::TransformAttributedType(
6157 TypeLocBuilder &TLB,
6158 AttributedTypeLoc TL) {
6159 const AttributedType *oldType = TL.getTypePtr();
6160 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6161 if (modifiedType.isNull())
6162 return QualType();
6163
Richard Smithe43e2b32018-08-20 21:47:29 +00006164 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6165 const Attr *oldAttr = TL.getAttr();
6166 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6167 if (oldAttr && !newAttr)
6168 return QualType();
6169
John McCall81904512011-01-06 01:58:22 +00006170 QualType result = TL.getType();
6171
6172 // FIXME: dependent operand expressions?
6173 if (getDerived().AlwaysRebuild() ||
6174 modifiedType != oldType->getModifiedType()) {
6175 // TODO: this is really lame; we should really be rebuilding the
6176 // equivalent type from first principles.
6177 QualType equivalentType
6178 = getDerived().TransformType(oldType->getEquivalentType());
6179 if (equivalentType.isNull())
6180 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006181
6182 // Check whether we can add nullability; it is only represented as
6183 // type sugar, and therefore cannot be diagnosed in any other way.
6184 if (auto nullability = oldType->getImmediateNullability()) {
6185 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006186 SemaRef.Diag(TL.getAttr()->getLocation(),
6187 diag::err_nullability_nonpointer)
6188 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006189 return QualType();
6190 }
6191 }
6192
Richard Smithe43e2b32018-08-20 21:47:29 +00006193 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006194 modifiedType,
6195 equivalentType);
6196 }
6197
6198 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006199 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006200 return result;
6201}
6202
6203template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006204QualType
6205TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6206 ParenTypeLoc TL) {
6207 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6208 if (Inner.isNull())
6209 return QualType();
6210
6211 QualType Result = TL.getType();
6212 if (getDerived().AlwaysRebuild() ||
6213 Inner != TL.getInnerLoc().getType()) {
6214 Result = getDerived().RebuildParenType(Inner);
6215 if (Result.isNull())
6216 return QualType();
6217 }
6218
6219 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6220 NewTL.setLParenLoc(TL.getLParenLoc());
6221 NewTL.setRParenLoc(TL.getRParenLoc());
6222 return Result;
6223}
6224
Leonard Chanc72aaf62019-05-07 03:20:17 +00006225template <typename Derived>
6226QualType
6227TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6228 MacroQualifiedTypeLoc TL) {
6229 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6230 if (Inner.isNull())
6231 return QualType();
6232
6233 QualType Result = TL.getType();
6234 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6235 Result =
6236 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6237 if (Result.isNull())
6238 return QualType();
6239 }
6240
6241 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6242 NewTL.setExpansionLoc(TL.getExpansionLoc());
6243 return Result;
6244}
6245
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006246template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006247QualType TreeTransform<Derived>::TransformDependentNameType(
6248 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6249 return TransformDependentNameType(TLB, TL, false);
6250}
6251
6252template<typename Derived>
6253QualType TreeTransform<Derived>::TransformDependentNameType(
6254 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006255 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006256
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006257 NestedNameSpecifierLoc QualifierLoc
6258 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6259 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006261
John McCallc392f372010-06-11 00:33:02 +00006262 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006263 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006264 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006265 QualifierLoc,
6266 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006267 TL.getNameLoc(),
6268 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006269 if (Result.isNull())
6270 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006271
Abramo Bagnarad7548482010-05-19 21:37:53 +00006272 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6273 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006274 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6275
Abramo Bagnarad7548482010-05-19 21:37:53 +00006276 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006277 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006278 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006279 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006280 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006281 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006282 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006283 NewTL.setNameLoc(TL.getNameLoc());
6284 }
John McCall550e0c22009-10-21 00:40:46 +00006285 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006286}
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregord6ff3322009-08-04 16:50:30 +00006288template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006289QualType TreeTransform<Derived>::
6290 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006291 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006292 NestedNameSpecifierLoc QualifierLoc;
6293 if (TL.getQualifierLoc()) {
6294 QualifierLoc
6295 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6296 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006297 return QualType();
6298 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006299
John McCall31f82722010-11-12 08:19:04 +00006300 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006301 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006302}
6303
6304template<typename Derived>
6305QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006306TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6307 DependentTemplateSpecializationTypeLoc TL,
6308 NestedNameSpecifierLoc QualifierLoc) {
6309 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006310
Douglas Gregora7a795b2011-03-01 20:11:18 +00006311 TemplateArgumentListInfo NewTemplateArgs;
6312 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6313 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006314
Douglas Gregora7a795b2011-03-01 20:11:18 +00006315 typedef TemplateArgumentLocContainerIterator<
6316 DependentTemplateSpecializationTypeLoc> ArgIterator;
6317 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6318 ArgIterator(TL, TL.getNumArgs()),
6319 NewTemplateArgs))
6320 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
Richard Smithfd3dae02017-01-20 00:20:39 +00006322 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006323 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6324 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006325 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006326 if (Result.isNull())
6327 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006328
Douglas Gregora7a795b2011-03-01 20:11:18 +00006329 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6330 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006331
Douglas Gregora7a795b2011-03-01 20:11:18 +00006332 // Copy information relevant to the template specialization.
6333 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006334 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006335 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006336 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006337 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6338 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006339 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006340 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006341
Douglas Gregora7a795b2011-03-01 20:11:18 +00006342 // Copy information relevant to the elaborated type.
6343 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006344 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006345 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006346 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6347 DependentTemplateSpecializationTypeLoc SpecTL
6348 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006349 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006350 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006351 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006352 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006353 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6354 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006355 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006356 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006357 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006358 TemplateSpecializationTypeLoc SpecTL
6359 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006360 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006361 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006362 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6363 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006364 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006365 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006366 }
6367 return Result;
6368}
6369
6370template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006371QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6372 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006373 QualType Pattern
6374 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006375 if (Pattern.isNull())
6376 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006377
6378 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006379 if (getDerived().AlwaysRebuild() ||
6380 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006381 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006382 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006383 TL.getEllipsisLoc(),
6384 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006385 if (Result.isNull())
6386 return QualType();
6387 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006388
Douglas Gregor822d0302011-01-12 17:07:58 +00006389 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6390 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6391 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006392}
6393
6394template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006395QualType
6396TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006397 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006398 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006399 TLB.pushFullCopy(TL);
6400 return TL.getType();
6401}
6402
6403template<typename Derived>
6404QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006405TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6406 ObjCTypeParamTypeLoc TL) {
6407 const ObjCTypeParamType *T = TL.getTypePtr();
6408 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6409 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6410 if (!OTP)
6411 return QualType();
6412
6413 QualType Result = TL.getType();
6414 if (getDerived().AlwaysRebuild() ||
6415 OTP != T->getDecl()) {
6416 Result = getDerived().RebuildObjCTypeParamType(OTP,
6417 TL.getProtocolLAngleLoc(),
6418 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6419 TL.getNumProtocols()),
6420 TL.getProtocolLocs(),
6421 TL.getProtocolRAngleLoc());
6422 if (Result.isNull())
6423 return QualType();
6424 }
6425
6426 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6427 if (TL.getNumProtocols()) {
6428 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6429 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6430 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6431 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6432 }
6433 return Result;
6434}
6435
6436template<typename Derived>
6437QualType
John McCall8b07ec22010-05-15 11:32:37 +00006438TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006439 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006440 // Transform base type.
6441 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6442 if (BaseType.isNull())
6443 return QualType();
6444
6445 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6446
6447 // Transform type arguments.
6448 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6449 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6450 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6451 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6452 QualType TypeArg = TypeArgInfo->getType();
6453 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6454 AnyChanged = true;
6455
6456 // We have a pack expansion. Instantiate it.
6457 const auto *PackExpansion = PackExpansionLoc.getType()
6458 ->castAs<PackExpansionType>();
6459 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6460 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6461 Unexpanded);
6462 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6463
6464 // Determine whether the set of unexpanded parameter packs can
6465 // and should be expanded.
6466 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6467 bool Expand = false;
6468 bool RetainExpansion = false;
6469 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6470 if (getDerived().TryExpandParameterPacks(
6471 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6472 Unexpanded, Expand, RetainExpansion, NumExpansions))
6473 return QualType();
6474
6475 if (!Expand) {
6476 // We can't expand this pack expansion into separate arguments yet;
6477 // just substitute into the pattern and create a new pack expansion
6478 // type.
6479 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6480
6481 TypeLocBuilder TypeArgBuilder;
6482 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006483 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006484 PatternLoc);
6485 if (NewPatternType.isNull())
6486 return QualType();
6487
6488 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6489 NewPatternType, NumExpansions);
6490 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6491 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6492 NewTypeArgInfos.push_back(
6493 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6494 continue;
6495 }
6496
6497 // Substitute into the pack expansion pattern for each slice of the
6498 // pack.
6499 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6500 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6501
6502 TypeLocBuilder TypeArgBuilder;
6503 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6504
6505 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6506 PatternLoc);
6507 if (NewTypeArg.isNull())
6508 return QualType();
6509
6510 NewTypeArgInfos.push_back(
6511 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6512 }
6513
6514 continue;
6515 }
6516
6517 TypeLocBuilder TypeArgBuilder;
6518 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6519 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6520 if (NewTypeArg.isNull())
6521 return QualType();
6522
6523 // If nothing changed, just keep the old TypeSourceInfo.
6524 if (NewTypeArg == TypeArg) {
6525 NewTypeArgInfos.push_back(TypeArgInfo);
6526 continue;
6527 }
6528
6529 NewTypeArgInfos.push_back(
6530 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6531 AnyChanged = true;
6532 }
6533
6534 QualType Result = TL.getType();
6535 if (getDerived().AlwaysRebuild() || AnyChanged) {
6536 // Rebuild the type.
6537 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006538 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6539 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6540 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6541 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006542
6543 if (Result.isNull())
6544 return QualType();
6545 }
6546
6547 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006548 NewT.setHasBaseTypeAsWritten(true);
6549 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6550 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6551 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6552 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6553 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6554 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6555 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6556 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6557 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006558}
Mike Stump11289f42009-09-09 15:08:12 +00006559
6560template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006561QualType
6562TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006563 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006564 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6565 if (PointeeType.isNull())
6566 return QualType();
6567
6568 QualType Result = TL.getType();
6569 if (getDerived().AlwaysRebuild() ||
6570 PointeeType != TL.getPointeeLoc().getType()) {
6571 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6572 TL.getStarLoc());
6573 if (Result.isNull())
6574 return QualType();
6575 }
6576
6577 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6578 NewT.setStarLoc(TL.getStarLoc());
6579 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006580}
6581
Douglas Gregord6ff3322009-08-04 16:50:30 +00006582//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006583// Statement transformation
6584//===----------------------------------------------------------------------===//
6585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006586StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006587TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006588 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006589}
6590
6591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006592StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006593TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6594 return getDerived().TransformCompoundStmt(S, false);
6595}
6596
6597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006598StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006599TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006601 Sema::CompoundScopeRAII CompoundScope(getSema());
6602
John McCall1ababa62010-08-27 19:56:05 +00006603 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006604 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006605 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006606 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006607 StmtResult Result = getDerived().TransformStmt(
6608 B,
6609 IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006610
John McCall1ababa62010-08-27 19:56:05 +00006611 if (Result.isInvalid()) {
6612 // Immediately fail if this was a DeclStmt, since it's very
6613 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006614 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006615 return StmtError();
6616
6617 // Otherwise, just keep processing substatements and fail later.
6618 SubStmtInvalid = true;
6619 continue;
6620 }
Mike Stump11289f42009-09-09 15:08:12 +00006621
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006622 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006623 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006624 }
Mike Stump11289f42009-09-09 15:08:12 +00006625
John McCall1ababa62010-08-27 19:56:05 +00006626 if (SubStmtInvalid)
6627 return StmtError();
6628
Douglas Gregorebe10102009-08-20 07:17:43 +00006629 if (!getDerived().AlwaysRebuild() &&
6630 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006631 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006632
6633 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006634 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006635 S->getRBracLoc(),
6636 IsStmtExpr);
6637}
Mike Stump11289f42009-09-09 15:08:12 +00006638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006640StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006641TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006642 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006643 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006644 EnterExpressionEvaluationContext Unevaluated(
6645 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006646
Eli Friedman06577382009-11-19 03:14:00 +00006647 // Transform the left-hand case value.
6648 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006649 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006650 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006652
Eli Friedman06577382009-11-19 03:14:00 +00006653 // Transform the right-hand case value (for the GNU case-range extension).
6654 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006655 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006656 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006657 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006658 }
Mike Stump11289f42009-09-09 15:08:12 +00006659
Douglas Gregorebe10102009-08-20 07:17:43 +00006660 // Build the case statement.
6661 // Case statements are always rebuilt so that they will attached to their
6662 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006663 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006664 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006665 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006666 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006667 S->getColonLoc());
6668 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006669 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006670
Douglas Gregorebe10102009-08-20 07:17:43 +00006671 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006672 StmtResult SubStmt =
6673 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006674 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006676
Douglas Gregorebe10102009-08-20 07:17:43 +00006677 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006678 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006679}
6680
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006681template <typename Derived>
6682StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006683 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006684 StmtResult SubStmt =
6685 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006686 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006687 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006688
Douglas Gregorebe10102009-08-20 07:17:43 +00006689 // Default statements are always rebuilt
6690 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006691 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006692}
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
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006696TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6697 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006698 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006700
Chris Lattnercab02a62011-02-17 20:34:02 +00006701 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6702 S->getDecl());
6703 if (!LD)
6704 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006705
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006706 // If we're transforming "in-place" (we're not creating new local
6707 // declarations), assume we're replacing the old label statement
6708 // and clear out the reference to it.
6709 if (LD == S->getDecl())
6710 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006711
Douglas Gregorebe10102009-08-20 07:17:43 +00006712 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006713 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006714 cast<LabelDecl>(LD), SourceLocation(),
6715 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006716}
Mike Stump11289f42009-09-09 15:08:12 +00006717
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006718template <typename Derived>
6719const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6720 if (!R)
6721 return R;
6722
6723 switch (R->getKind()) {
6724// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6725#define ATTR(X)
6726#define PRAGMA_SPELLING_ATTR(X) \
6727 case attr::X: \
6728 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6729#include "clang/Basic/AttrList.inc"
6730 default:
6731 return R;
6732 }
6733}
6734
6735template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006736StmtResult
6737TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6738 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006739 bool AttrsChanged = false;
6740 SmallVector<const Attr *, 1> Attrs;
6741
6742 // Visit attributes and keep track if any are transformed.
6743 for (const auto *I : S->getAttrs()) {
6744 const Attr *R = getDerived().TransformAttr(I);
6745 AttrsChanged |= (I != R);
6746 Attrs.push_back(R);
6747 }
6748
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006749 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006750 if (SubStmt.isInvalid())
6751 return StmtError();
6752
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006753 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006754 return S;
6755
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006756 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006757 SubStmt.get());
6758}
6759
6760template<typename Derived>
6761StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006762TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006763 // Transform the initialization statement
6764 StmtResult Init = getDerived().TransformStmt(S->getInit());
6765 if (Init.isInvalid())
6766 return StmtError();
6767
Douglas Gregorebe10102009-08-20 07:17:43 +00006768 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006769 Sema::ConditionResult Cond = getDerived().TransformCondition(
6770 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006771 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6772 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006773 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006774 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Richard Smithb130fe72016-06-23 19:16:49 +00006776 // If this is a constexpr if, determine which arm we should instantiate.
6777 llvm::Optional<bool> ConstexprConditionValue;
6778 if (S->isConstexpr())
6779 ConstexprConditionValue = Cond.getKnownValue();
6780
Douglas Gregorebe10102009-08-20 07:17:43 +00006781 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006782 StmtResult Then;
6783 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6784 Then = getDerived().TransformStmt(S->getThen());
6785 if (Then.isInvalid())
6786 return StmtError();
6787 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006788 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006789 }
Mike Stump11289f42009-09-09 15:08:12 +00006790
Douglas Gregorebe10102009-08-20 07:17:43 +00006791 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006792 StmtResult Else;
6793 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6794 Else = getDerived().TransformStmt(S->getElse());
6795 if (Else.isInvalid())
6796 return StmtError();
6797 }
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregorebe10102009-08-20 07:17:43 +00006799 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006800 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006801 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006802 Then.get() == S->getThen() &&
6803 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006804 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006805
Richard Smithb130fe72016-06-23 19:16:49 +00006806 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006807 Init.get(), Then.get(), S->getElseLoc(),
6808 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006809}
6810
6811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006812StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006813TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006814 // Transform the initialization statement
6815 StmtResult Init = getDerived().TransformStmt(S->getInit());
6816 if (Init.isInvalid())
6817 return StmtError();
6818
Douglas Gregorebe10102009-08-20 07:17:43 +00006819 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006820 Sema::ConditionResult Cond = getDerived().TransformCondition(
6821 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6822 Sema::ConditionKind::Switch);
6823 if (Cond.isInvalid())
6824 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006825
Douglas Gregorebe10102009-08-20 07:17:43 +00006826 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006827 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006828 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006829 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006830 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006831
Douglas Gregorebe10102009-08-20 07:17:43 +00006832 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006833 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006834 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006835 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006836
Douglas Gregorebe10102009-08-20 07:17:43 +00006837 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006838 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6839 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006840}
Mike Stump11289f42009-09-09 15:08:12 +00006841
Douglas Gregorebe10102009-08-20 07:17:43 +00006842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006843StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006844TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006845 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006846 Sema::ConditionResult Cond = getDerived().TransformCondition(
6847 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6848 Sema::ConditionKind::Boolean);
6849 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006850 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006851
Douglas Gregorebe10102009-08-20 07:17:43 +00006852 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006853 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006856
Douglas Gregorebe10102009-08-20 07:17:43 +00006857 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006858 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006859 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006860 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006861
Richard Smith03a4aa32016-06-23 19:02:52 +00006862 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006863}
Mike Stump11289f42009-09-09 15:08:12 +00006864
Douglas Gregorebe10102009-08-20 07:17:43 +00006865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006866StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006867TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006868 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006869 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006870 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006871 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006872
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006873 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006874 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006875 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006876 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006877
Douglas Gregorebe10102009-08-20 07:17:43 +00006878 if (!getDerived().AlwaysRebuild() &&
6879 Cond.get() == S->getCond() &&
6880 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006881 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006882
John McCallb268a282010-08-23 23:25:46 +00006883 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6884 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006885 S->getRParenLoc());
6886}
Mike Stump11289f42009-09-09 15:08:12 +00006887
Douglas Gregorebe10102009-08-20 07:17:43 +00006888template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006889StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006890TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006891 if (getSema().getLangOpts().OpenMP)
6892 getSema().startOpenMPLoop();
6893
Douglas Gregorebe10102009-08-20 07:17:43 +00006894 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006895 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006896 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006897 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006898
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006899 // In OpenMP loop region loop control variable must be captured and be
6900 // private. Perform analysis of first part (if any).
6901 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6902 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6903
Douglas Gregorebe10102009-08-20 07:17:43 +00006904 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006905 Sema::ConditionResult Cond = getDerived().TransformCondition(
6906 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6907 Sema::ConditionKind::Boolean);
6908 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006909 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006910
Douglas Gregorebe10102009-08-20 07:17:43 +00006911 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006912 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006913 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006914 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006915
Richard Smith945f8d32013-01-14 22:39:08 +00006916 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006917 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006919
Douglas Gregorebe10102009-08-20 07:17:43 +00006920 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006921 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006922 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006924
Douglas Gregorebe10102009-08-20 07:17:43 +00006925 if (!getDerived().AlwaysRebuild() &&
6926 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006927 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006928 Inc.get() == S->getInc() &&
6929 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006930 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006931
Douglas Gregorebe10102009-08-20 07:17:43 +00006932 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006933 Init.get(), Cond, FullInc,
6934 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006935}
6936
6937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006938StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006939TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006940 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6941 S->getLabel());
6942 if (!LD)
6943 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006944
Douglas Gregorebe10102009-08-20 07:17:43 +00006945 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006946 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006947 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006948}
6949
6950template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006951StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006952TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006953 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006954 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006955 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006956 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006957
Douglas Gregorebe10102009-08-20 07:17:43 +00006958 if (!getDerived().AlwaysRebuild() &&
6959 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006960 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006961
6962 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006963 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006964}
6965
6966template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006967StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006968TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006969 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006970}
Mike Stump11289f42009-09-09 15:08:12 +00006971
Douglas Gregorebe10102009-08-20 07:17:43 +00006972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006974TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006975 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006976}
Mike Stump11289f42009-09-09 15:08:12 +00006977
Douglas Gregorebe10102009-08-20 07:17:43 +00006978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006979StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006980TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006981 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6982 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006983 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006984 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006985
Mike Stump11289f42009-09-09 15:08:12 +00006986 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006987 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006988 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006989}
Mike Stump11289f42009-09-09 15:08:12 +00006990
Douglas Gregorebe10102009-08-20 07:17:43 +00006991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006992StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006993TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006994 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006995 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006996 for (auto *D : S->decls()) {
6997 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006998 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006999 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007000
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007001 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00007002 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00007003
Douglas Gregorebe10102009-08-20 07:17:43 +00007004 Decls.push_back(Transformed);
7005 }
Mike Stump11289f42009-09-09 15:08:12 +00007006
Douglas Gregorebe10102009-08-20 07:17:43 +00007007 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007008 return S;
Mike Stump11289f42009-09-09 15:08:12 +00007009
Stephen Kellya6e43582018-08-09 21:05:56 +00007010 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007011}
Mike Stump11289f42009-09-09 15:08:12 +00007012
Douglas Gregorebe10102009-08-20 07:17:43 +00007013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007014StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00007015TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007016
Benjamin Kramerf0623432012-08-23 22:51:59 +00007017 SmallVector<Expr*, 8> Constraints;
7018 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007019 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00007020
John McCalldadc5752010-08-24 06:29:42 +00007021 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007022 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007023
7024 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007025
Anders Carlssonaaeef072010-01-24 05:50:09 +00007026 // Go through the outputs.
7027 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007028 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007029
Anders Carlssonaaeef072010-01-24 05:50:09 +00007030 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007031 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007032
Anders Carlssonaaeef072010-01-24 05:50:09 +00007033 // Transform the output expr.
7034 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007035 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007036 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007037 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007038
Anders Carlssonaaeef072010-01-24 05:50:09 +00007039 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007040
John McCallb268a282010-08-23 23:25:46 +00007041 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007042 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007043
Anders Carlssonaaeef072010-01-24 05:50:09 +00007044 // Go through the inputs.
7045 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007046 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007047
Anders Carlssonaaeef072010-01-24 05:50:09 +00007048 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007049 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007050
Anders Carlssonaaeef072010-01-24 05:50:09 +00007051 // Transform the input expr.
7052 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007053 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007054 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007055 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007056
Anders Carlssonaaeef072010-01-24 05:50:09 +00007057 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007058
John McCallb268a282010-08-23 23:25:46 +00007059 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007060 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007061
Anders Carlssonaaeef072010-01-24 05:50:09 +00007062 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007063 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007064
7065 // Go through the clobbers.
7066 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00007067 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007068
7069 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007070 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007071 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7072 S->isVolatile(), S->getNumOutputs(),
7073 S->getNumInputs(), Names.data(),
7074 Constraints, Exprs, AsmString.get(),
Erich Keaned0f34fd2019-05-30 15:38:02 +00007075 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007076}
7077
Chad Rosier32503022012-06-11 20:47:18 +00007078template<typename Derived>
7079StmtResult
7080TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007081 ArrayRef<Token> AsmToks =
7082 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007083
John McCallf413f5e2013-05-03 00:10:13 +00007084 bool HadError = false, HadChange = false;
7085
7086 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7087 SmallVector<Expr*, 8> TransformedExprs;
7088 TransformedExprs.reserve(SrcExprs.size());
7089 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7090 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7091 if (!Result.isUsable()) {
7092 HadError = true;
7093 } else {
7094 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007095 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007096 }
7097 }
7098
7099 if (HadError) return StmtError();
7100 if (!HadChange && !getDerived().AlwaysRebuild())
7101 return Owned(S);
7102
Chad Rosierb6f46c12012-08-15 16:53:30 +00007103 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007104 AsmToks, S->getAsmString(),
7105 S->getNumOutputs(), S->getNumInputs(),
7106 S->getAllConstraints(), S->getClobbers(),
7107 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007108}
Douglas Gregorebe10102009-08-20 07:17:43 +00007109
Richard Smith9f690bd2015-10-27 06:02:45 +00007110// C++ Coroutines TS
7111
7112template<typename Derived>
7113StmtResult
7114TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007115 auto *ScopeInfo = SemaRef.getCurFunction();
7116 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007117 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007118 ScopeInfo->NeedsCoroutineSuspends &&
7119 ScopeInfo->CoroutineSuspends.first == nullptr &&
7120 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007121 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007122
7123 // Set that we have (possibly-invalid) suspend points before we do anything
7124 // that may fail.
7125 ScopeInfo->setNeedsCoroutineSuspends(false);
7126
7127 // The new CoroutinePromise object needs to be built and put into the current
7128 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007129 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7130 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007131 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7132 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007133 return StmtError();
Richard Smithb2997f52019-05-21 20:10:50 +00007134 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
Eric Fiselierbee782b2017-04-03 19:21:00 +00007135 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007136
7137 // Transform the implicit coroutine statements we built during the initial
7138 // parse.
7139 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7140 if (InitSuspend.isInvalid())
7141 return StmtError();
7142 StmtResult FinalSuspend =
7143 getDerived().TransformStmt(S->getFinalSuspendStmt());
7144 if (FinalSuspend.isInvalid())
7145 return StmtError();
7146 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7147 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007148
7149 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7150 if (BodyRes.isInvalid())
7151 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007152
Eric Fiselierbee782b2017-04-03 19:21:00 +00007153 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7154 if (Builder.isInvalid())
7155 return StmtError();
7156
7157 Expr *ReturnObject = S->getReturnValueInit();
7158 assert(ReturnObject && "the return object is expected to be valid");
7159 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7160 /*NoCopyInit*/ false);
7161 if (Res.isInvalid())
7162 return StmtError();
7163 Builder.ReturnValue = Res.get();
7164
7165 if (S->hasDependentPromiseType()) {
Brian Gesiak38f11822019-06-03 00:47:32 +00007166 // PR41909: We may find a generic coroutine lambda definition within a
7167 // template function that is being instantiated. In this case, the lambda
7168 // will have a dependent promise type, until it is used in an expression
7169 // that creates an instantiation with a non-dependent promise type. We
7170 // should not assert or build coroutine dependent statements for such a
7171 // generic lambda.
7172 auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD);
7173 if (!MD || !MD->getParent()->isGenericLambda()) {
7174 assert(!Promise->getType()->isDependentType() &&
7175 "the promise type must no longer be dependent");
7176 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7177 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7178 "these nodes should not have been built yet");
7179 if (!Builder.buildDependentStatements())
7180 return StmtError();
7181 }
Eric Fiselierbee782b2017-04-03 19:21:00 +00007182 } else {
7183 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7184 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7185 if (Res.isInvalid())
7186 return StmtError();
7187 Builder.OnFallthrough = Res.get();
7188 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007189
Eric Fiselierbee782b2017-04-03 19:21:00 +00007190 if (auto *OnException = S->getExceptionHandler()) {
7191 StmtResult Res = getDerived().TransformStmt(OnException);
7192 if (Res.isInvalid())
7193 return StmtError();
7194 Builder.OnException = Res.get();
7195 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007196
Eric Fiselierbee782b2017-04-03 19:21:00 +00007197 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7198 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7199 if (Res.isInvalid())
7200 return StmtError();
7201 Builder.ReturnStmtOnAllocFailure = Res.get();
7202 }
7203
7204 // Transform any additional statements we may have already built
7205 assert(S->getAllocate() && S->getDeallocate() &&
7206 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007207 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7208 if (AllocRes.isInvalid())
7209 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007210 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007211
7212 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7213 if (DeallocRes.isInvalid())
7214 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007215 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007216
7217 assert(S->getResultDecl() && "ResultDecl must already be built");
7218 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7219 if (ResultDecl.isInvalid())
7220 return StmtError();
7221 Builder.ResultDecl = ResultDecl.get();
7222
7223 if (auto *ReturnStmt = S->getReturnStmt()) {
7224 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7225 if (Res.isInvalid())
7226 return StmtError();
7227 Builder.ReturnStmt = Res.get();
7228 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007229 }
7230
Eric Fiselierbee782b2017-04-03 19:21:00 +00007231 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007232}
7233
7234template<typename Derived>
7235StmtResult
7236TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7237 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7238 /*NotCopyInit*/false);
7239 if (Result.isInvalid())
7240 return StmtError();
7241
7242 // Always rebuild; we don't know if this needs to be injected into a new
7243 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007244 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7245 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007246}
7247
7248template<typename Derived>
7249ExprResult
7250TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7251 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7252 /*NotCopyInit*/false);
7253 if (Result.isInvalid())
7254 return ExprError();
7255
7256 // Always rebuild; we don't know if this needs to be injected into a new
7257 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007258 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7259 E->isImplicit());
7260}
7261
7262template <typename Derived>
7263ExprResult
7264TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7265 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7266 /*NotCopyInit*/ false);
7267 if (OperandResult.isInvalid())
7268 return ExprError();
7269
7270 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7271 E->getOperatorCoawaitLookup());
7272
7273 if (LookupResult.isInvalid())
7274 return ExprError();
7275
7276 // Always rebuild; we don't know if this needs to be injected into a new
7277 // context or if the promise type has changed.
7278 return getDerived().RebuildDependentCoawaitExpr(
7279 E->getKeywordLoc(), OperandResult.get(),
7280 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007281}
7282
7283template<typename Derived>
7284ExprResult
7285TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7286 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7287 /*NotCopyInit*/false);
7288 if (Result.isInvalid())
7289 return ExprError();
7290
7291 // Always rebuild; we don't know if this needs to be injected into a new
7292 // context or if the promise type has changed.
7293 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7294}
7295
7296// Objective-C Statements.
7297
Douglas Gregorebe10102009-08-20 07:17:43 +00007298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007299StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007300TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007301 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007302 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007303 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007304 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007305
Douglas Gregor96c79492010-04-23 22:50:49 +00007306 // Transform the @catch statements (if present).
7307 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007308 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007309 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007310 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007311 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007312 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007313 if (Catch.get() != S->getCatchStmt(I))
7314 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007315 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007316 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007317
Douglas Gregor306de2f2010-04-22 23:59:56 +00007318 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007319 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007320 if (S->getFinallyStmt()) {
7321 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7322 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007323 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007324 }
7325
7326 // If nothing changed, just retain this statement.
7327 if (!getDerived().AlwaysRebuild() &&
7328 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007329 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007330 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007331 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007332
Douglas Gregor306de2f2010-04-22 23:59:56 +00007333 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007334 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007335 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007336}
Mike Stump11289f42009-09-09 15:08:12 +00007337
Douglas Gregorebe10102009-08-20 07:17:43 +00007338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007339StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007340TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007341 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007342 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007343 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007344 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007345 if (FromVar->getTypeSourceInfo()) {
7346 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7347 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007348 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007350
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007351 QualType T;
7352 if (TSInfo)
7353 T = TSInfo->getType();
7354 else {
7355 T = getDerived().TransformType(FromVar->getType());
7356 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007357 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007359
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007360 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7361 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007362 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007363 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007364
John McCalldadc5752010-08-24 06:29:42 +00007365 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007366 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007367 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007368
7369 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007370 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007371 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007372}
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregorebe10102009-08-20 07:17:43 +00007374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007375StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007376TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007377 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007378 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007379 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007380 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007381
Douglas Gregor306de2f2010-04-22 23:59:56 +00007382 // If nothing changed, just retain this statement.
7383 if (!getDerived().AlwaysRebuild() &&
7384 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007385 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007386
7387 // Build a new statement.
7388 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007389 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007390}
Mike Stump11289f42009-09-09 15:08:12 +00007391
Douglas Gregorebe10102009-08-20 07:17:43 +00007392template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007393StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007394TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007395 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007396 if (S->getThrowExpr()) {
7397 Operand = getDerived().TransformExpr(S->getThrowExpr());
7398 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007399 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007401
Douglas Gregor2900c162010-04-22 21:44:01 +00007402 if (!getDerived().AlwaysRebuild() &&
7403 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007404 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007405
John McCallb268a282010-08-23 23:25:46 +00007406 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007407}
Mike Stump11289f42009-09-09 15:08:12 +00007408
Douglas Gregorebe10102009-08-20 07:17:43 +00007409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007410StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007411TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007412 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007413 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007414 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007415 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007416 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007417 Object =
7418 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7419 Object.get());
7420 if (Object.isInvalid())
7421 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007422
Douglas Gregor6148de72010-04-22 22:01:21 +00007423 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007424 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007425 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007427
Douglas Gregor6148de72010-04-22 22:01:21 +00007428 // If nothing change, just retain the current statement.
7429 if (!getDerived().AlwaysRebuild() &&
7430 Object.get() == S->getSynchExpr() &&
7431 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007432 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007433
7434 // Build a new statement.
7435 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007436 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007437}
7438
7439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007440StmtResult
John McCall31168b02011-06-15 23:02:42 +00007441TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7442 ObjCAutoreleasePoolStmt *S) {
7443 // Transform the body.
7444 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7445 if (Body.isInvalid())
7446 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007447
John McCall31168b02011-06-15 23:02:42 +00007448 // If nothing changed, just retain this statement.
7449 if (!getDerived().AlwaysRebuild() &&
7450 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007451 return S;
John McCall31168b02011-06-15 23:02:42 +00007452
7453 // Build a new statement.
7454 return getDerived().RebuildObjCAutoreleasePoolStmt(
7455 S->getAtLoc(), Body.get());
7456}
7457
7458template<typename Derived>
7459StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007460TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007461 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007462 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007463 StmtResult Element =
7464 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007465 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007466 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007467
Douglas Gregorf68a5082010-04-22 23:10:45 +00007468 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007469 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007470 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007471 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007472
Douglas Gregorf68a5082010-04-22 23:10:45 +00007473 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007474 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007475 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007476 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007477
Douglas Gregorf68a5082010-04-22 23:10:45 +00007478 // If nothing changed, just retain this statement.
7479 if (!getDerived().AlwaysRebuild() &&
7480 Element.get() == S->getElement() &&
7481 Collection.get() == S->getCollection() &&
7482 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007483 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007484
Douglas Gregorf68a5082010-04-22 23:10:45 +00007485 // Build a new statement.
7486 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007487 Element.get(),
7488 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007489 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007490 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007491}
7492
David Majnemer5f7efef2013-10-15 09:50:08 +00007493template <typename Derived>
7494StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007495 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007496 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007497 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7498 TypeSourceInfo *T =
7499 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007500 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007501 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007502
David Majnemer5f7efef2013-10-15 09:50:08 +00007503 Var = getDerived().RebuildExceptionDecl(
7504 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7505 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007506 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007507 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007508 }
Mike Stump11289f42009-09-09 15:08:12 +00007509
Douglas Gregorebe10102009-08-20 07:17:43 +00007510 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007511 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007512 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007513 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007514
David Majnemer5f7efef2013-10-15 09:50:08 +00007515 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007516 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007517 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007518
David Majnemer5f7efef2013-10-15 09:50:08 +00007519 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007520}
Mike Stump11289f42009-09-09 15:08:12 +00007521
David Majnemer5f7efef2013-10-15 09:50:08 +00007522template <typename Derived>
7523StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007524 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007525 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007526 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007528
Douglas Gregorebe10102009-08-20 07:17:43 +00007529 // Transform the handlers.
7530 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007531 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007532 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007533 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007534 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007535 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007536
Douglas Gregorebe10102009-08-20 07:17:43 +00007537 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007538 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007539 }
Mike Stump11289f42009-09-09 15:08:12 +00007540
David Majnemer5f7efef2013-10-15 09:50:08 +00007541 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007542 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007543 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007544
John McCallb268a282010-08-23 23:25:46 +00007545 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007546 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007547}
Mike Stump11289f42009-09-09 15:08:12 +00007548
Richard Smith02e85f32011-04-14 22:09:26 +00007549template<typename Derived>
7550StmtResult
7551TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007552 StmtResult Init =
7553 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7554 if (Init.isInvalid())
7555 return StmtError();
7556
Richard Smith02e85f32011-04-14 22:09:26 +00007557 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7558 if (Range.isInvalid())
7559 return StmtError();
7560
Richard Smith01694c32016-03-20 10:33:40 +00007561 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7562 if (Begin.isInvalid())
7563 return StmtError();
7564 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7565 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007566 return StmtError();
7567
7568 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7569 if (Cond.isInvalid())
7570 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007571 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007572 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007573 if (Cond.isInvalid())
7574 return StmtError();
7575 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007576 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007577
7578 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7579 if (Inc.isInvalid())
7580 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007581 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007582 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007583
7584 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7585 if (LoopVar.isInvalid())
7586 return StmtError();
7587
7588 StmtResult NewStmt = S;
7589 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007590 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007591 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007592 Begin.get() != S->getBeginStmt() ||
7593 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007594 Cond.get() != S->getCond() ||
7595 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007596 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007597 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007598 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007599 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007600 Begin.get(), End.get(),
7601 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007602 Inc.get(), LoopVar.get(),
7603 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007604 if (NewStmt.isInvalid())
7605 return StmtError();
7606 }
Richard Smith02e85f32011-04-14 22:09:26 +00007607
7608 StmtResult Body = getDerived().TransformStmt(S->getBody());
7609 if (Body.isInvalid())
7610 return StmtError();
7611
7612 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7613 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007614 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007615 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007616 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007617 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007618 Begin.get(), End.get(),
7619 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007620 Inc.get(), LoopVar.get(),
7621 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007622 if (NewStmt.isInvalid())
7623 return StmtError();
7624 }
Richard Smith02e85f32011-04-14 22:09:26 +00007625
7626 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007627 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007628
7629 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7630}
7631
John Wiegley1c0675e2011-04-28 01:08:34 +00007632template<typename Derived>
7633StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007634TreeTransform<Derived>::TransformMSDependentExistsStmt(
7635 MSDependentExistsStmt *S) {
7636 // Transform the nested-name-specifier, if any.
7637 NestedNameSpecifierLoc QualifierLoc;
7638 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007639 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007640 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7641 if (!QualifierLoc)
7642 return StmtError();
7643 }
7644
7645 // Transform the declaration name.
7646 DeclarationNameInfo NameInfo = S->getNameInfo();
7647 if (NameInfo.getName()) {
7648 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7649 if (!NameInfo.getName())
7650 return StmtError();
7651 }
7652
7653 // Check whether anything changed.
7654 if (!getDerived().AlwaysRebuild() &&
7655 QualifierLoc == S->getQualifierLoc() &&
7656 NameInfo.getName() == S->getNameInfo().getName())
7657 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007658
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007659 // Determine whether this name exists, if we can.
7660 CXXScopeSpec SS;
7661 SS.Adopt(QualifierLoc);
7662 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007663 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007664 case Sema::IER_Exists:
7665 if (S->isIfExists())
7666 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007667
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007668 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7669
7670 case Sema::IER_DoesNotExist:
7671 if (S->isIfNotExists())
7672 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007673
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007674 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007675
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007676 case Sema::IER_Dependent:
7677 Dependent = true;
7678 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007679
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007680 case Sema::IER_Error:
7681 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007683
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007684 // We need to continue with the instantiation, so do so now.
7685 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7686 if (SubStmt.isInvalid())
7687 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007688
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007689 // If we have resolved the name, just transform to the substatement.
7690 if (!Dependent)
7691 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007692
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007693 // The name is still dependent, so build a dependent expression again.
7694 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7695 S->isIfExists(),
7696 QualifierLoc,
7697 NameInfo,
7698 SubStmt.get());
7699}
7700
7701template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007702ExprResult
7703TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7704 NestedNameSpecifierLoc QualifierLoc;
7705 if (E->getQualifierLoc()) {
7706 QualifierLoc
7707 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7708 if (!QualifierLoc)
7709 return ExprError();
7710 }
7711
7712 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7713 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7714 if (!PD)
7715 return ExprError();
7716
7717 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7718 if (Base.isInvalid())
7719 return ExprError();
7720
7721 return new (SemaRef.getASTContext())
7722 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7723 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7724 QualifierLoc, E->getMemberLoc());
7725}
7726
David Majnemerfad8f482013-10-15 09:33:02 +00007727template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007728ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7729 MSPropertySubscriptExpr *E) {
7730 auto BaseRes = getDerived().TransformExpr(E->getBase());
7731 if (BaseRes.isInvalid())
7732 return ExprError();
7733 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7734 if (IdxRes.isInvalid())
7735 return ExprError();
7736
7737 if (!getDerived().AlwaysRebuild() &&
7738 BaseRes.get() == E->getBase() &&
7739 IdxRes.get() == E->getIdx())
7740 return E;
7741
7742 return getDerived().RebuildArraySubscriptExpr(
7743 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7744}
7745
7746template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007747StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007748 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007749 if (TryBlock.isInvalid())
7750 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007751
7752 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007753 if (Handler.isInvalid())
7754 return StmtError();
7755
David Majnemerfad8f482013-10-15 09:33:02 +00007756 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7757 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007758 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007759
Warren Huntf6be4cb2014-07-25 20:52:51 +00007760 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7761 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007762}
7763
David Majnemerfad8f482013-10-15 09:33:02 +00007764template <typename Derived>
7765StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007766 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007767 if (Block.isInvalid())
7768 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007769
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007770 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007771}
7772
David Majnemerfad8f482013-10-15 09:33:02 +00007773template <typename Derived>
7774StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007775 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007776 if (FilterExpr.isInvalid())
7777 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007778
David Majnemer7e755502013-10-15 09:30:14 +00007779 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007780 if (Block.isInvalid())
7781 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007782
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007783 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7784 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007785}
7786
David Majnemerfad8f482013-10-15 09:33:02 +00007787template <typename Derived>
7788StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7789 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007790 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7791 else
7792 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7793}
7794
Nico Weber9b982072014-07-07 00:12:30 +00007795template<typename Derived>
7796StmtResult
7797TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7798 return S;
7799}
7800
Alexander Musman64d33f12014-06-04 07:53:32 +00007801//===----------------------------------------------------------------------===//
7802// OpenMP directive transformation
7803//===----------------------------------------------------------------------===//
7804template <typename Derived>
7805StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7806 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007807
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007808 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007809 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007810 ArrayRef<OMPClause *> Clauses = D->clauses();
7811 TClauses.reserve(Clauses.size());
7812 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7813 I != E; ++I) {
7814 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007815 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007816 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007817 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007818 if (Clause)
7819 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007820 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007821 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007822 }
7823 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007824 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007825 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007826 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7827 /*CurScope=*/nullptr);
7828 StmtResult Body;
7829 {
7830 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007831 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007832 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007833 }
7834 AssociatedStmt =
7835 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007836 if (AssociatedStmt.isInvalid()) {
7837 return StmtError();
7838 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007839 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007840 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007841 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007842 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007843
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007844 // Transform directive name for 'omp critical' directive.
7845 DeclarationNameInfo DirName;
7846 if (D->getDirectiveKind() == OMPD_critical) {
7847 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7848 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7849 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007850 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7851 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7852 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007853 } else if (D->getDirectiveKind() == OMPD_cancel) {
7854 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007855 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007856
Alexander Musman64d33f12014-06-04 07:53:32 +00007857 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007858 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007859 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007860}
7861
Alexander Musman64d33f12014-06-04 07:53:32 +00007862template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007863StmtResult
7864TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7865 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007866 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007867 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7869 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7870 return Res;
7871}
7872
Alexander Musman64d33f12014-06-04 07:53:32 +00007873template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007874StmtResult
7875TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7876 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007877 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007878 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007879 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7880 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007881 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007882}
7883
Alexey Bataevf29276e2014-06-18 04:14:57 +00007884template <typename Derived>
7885StmtResult
7886TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7887 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007888 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007889 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007890 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7891 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7892 return Res;
7893}
7894
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007895template <typename Derived>
7896StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007897TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7898 DeclarationNameInfo DirName;
7899 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007900 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7902 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7903 return Res;
7904}
7905
7906template <typename Derived>
7907StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007908TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7909 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007910 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007911 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7914 return Res;
7915}
7916
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007917template <typename Derived>
7918StmtResult
7919TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7920 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007921 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007922 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7925 return Res;
7926}
7927
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007928template <typename Derived>
7929StmtResult
7930TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7931 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007932 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007933 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7936 return Res;
7937}
7938
Alexey Bataev4acb8592014-07-07 13:01:15 +00007939template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007940StmtResult
7941TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7942 DeclarationNameInfo DirName;
7943 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007944 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7947 return Res;
7948}
7949
7950template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007951StmtResult
7952TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7953 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007954 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7956 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7957 return Res;
7958}
7959
7960template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007961StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7962 OMPParallelForDirective *D) {
7963 DeclarationNameInfo DirName;
7964 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007965 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7967 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7968 return Res;
7969}
7970
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007971template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007972StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7973 OMPParallelForSimdDirective *D) {
7974 DeclarationNameInfo DirName;
7975 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007976 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007977 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7978 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7979 return Res;
7980}
7981
7982template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007983StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7984 OMPParallelSectionsDirective *D) {
7985 DeclarationNameInfo DirName;
7986 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007987 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990 return Res;
7991}
7992
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007993template <typename Derived>
7994StmtResult
7995TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007998 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001 return Res;
8002}
8003
Alexey Bataev68446b72014-07-18 07:47:19 +00008004template <typename Derived>
8005StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8006 OMPTaskyieldDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008009 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00008010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8012 return Res;
8013}
8014
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008015template <typename Derived>
8016StmtResult
8017TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8018 DeclarationNameInfo DirName;
8019 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008020 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8023 return Res;
8024}
8025
Alexey Bataev2df347a2014-07-18 10:17:07 +00008026template <typename Derived>
8027StmtResult
8028TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8029 DeclarationNameInfo DirName;
8030 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008031 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00008032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8034 return Res;
8035}
8036
Alexey Bataev6125da92014-07-21 11:26:11 +00008037template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008038StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8039 OMPTaskgroupDirective *D) {
8040 DeclarationNameInfo DirName;
8041 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008042 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8045 return Res;
8046}
8047
8048template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00008049StmtResult
8050TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8051 DeclarationNameInfo DirName;
8052 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008053 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8056 return Res;
8057}
8058
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008059template <typename Derived>
8060StmtResult
8061TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8062 DeclarationNameInfo DirName;
8063 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008064 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8067 return Res;
8068}
8069
Alexey Bataev0162e452014-07-22 10:10:35 +00008070template <typename Derived>
8071StmtResult
8072TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8073 DeclarationNameInfo DirName;
8074 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008075 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00008076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8078 return Res;
8079}
8080
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008081template <typename Derived>
8082StmtResult
8083TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8084 DeclarationNameInfo DirName;
8085 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008086 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8089 return Res;
8090}
8091
Alexey Bataev13314bf2014-10-09 04:18:56 +00008092template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008093StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8094 OMPTargetDataDirective *D) {
8095 DeclarationNameInfo DirName;
8096 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008097 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8100 return Res;
8101}
8102
8103template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008104StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8105 OMPTargetEnterDataDirective *D) {
8106 DeclarationNameInfo DirName;
8107 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008108 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8111 return Res;
8112}
8113
8114template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008115StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8116 OMPTargetExitDataDirective *D) {
8117 DeclarationNameInfo DirName;
8118 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008119 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8122 return Res;
8123}
8124
8125template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008126StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8127 OMPTargetParallelDirective *D) {
8128 DeclarationNameInfo DirName;
8129 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008130 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8133 return Res;
8134}
8135
8136template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008137StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8138 OMPTargetParallelForDirective *D) {
8139 DeclarationNameInfo DirName;
8140 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008141 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8144 return Res;
8145}
8146
8147template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008148StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8149 OMPTargetUpdateDirective *D) {
8150 DeclarationNameInfo DirName;
8151 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008152 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8155 return Res;
8156}
8157
8158template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008159StmtResult
8160TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8161 DeclarationNameInfo DirName;
8162 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008163 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8166 return Res;
8167}
8168
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008169template <typename Derived>
8170StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8171 OMPCancellationPointDirective *D) {
8172 DeclarationNameInfo DirName;
8173 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008174 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8177 return Res;
8178}
8179
Alexey Bataev80909872015-07-02 11:25:17 +00008180template <typename Derived>
8181StmtResult
8182TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8183 DeclarationNameInfo DirName;
8184 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008185 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8188 return Res;
8189}
8190
Alexey Bataev49f6e782015-12-01 04:18:41 +00008191template <typename Derived>
8192StmtResult
8193TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8194 DeclarationNameInfo DirName;
8195 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008196 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8199 return Res;
8200}
8201
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008202template <typename Derived>
8203StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8204 OMPTaskLoopSimdDirective *D) {
8205 DeclarationNameInfo DirName;
8206 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008207 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8210 return Res;
8211}
8212
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008213template <typename Derived>
8214StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8215 OMPDistributeDirective *D) {
8216 DeclarationNameInfo DirName;
8217 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008218 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8221 return Res;
8222}
8223
Carlo Bertolli9925f152016-06-27 14:55:37 +00008224template <typename Derived>
8225StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8226 OMPDistributeParallelForDirective *D) {
8227 DeclarationNameInfo DirName;
8228 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008229 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8232 return Res;
8233}
8234
Kelvin Li4a39add2016-07-05 05:00:15 +00008235template <typename Derived>
8236StmtResult
8237TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8238 OMPDistributeParallelForSimdDirective *D) {
8239 DeclarationNameInfo DirName;
8240 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008241 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008242 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8243 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8244 return Res;
8245}
8246
Kelvin Li787f3fc2016-07-06 04:45:38 +00008247template <typename Derived>
8248StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8249 OMPDistributeSimdDirective *D) {
8250 DeclarationNameInfo DirName;
8251 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008252 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008253 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8254 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8255 return Res;
8256}
8257
Kelvin Lia579b912016-07-14 02:54:56 +00008258template <typename Derived>
8259StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8260 OMPTargetParallelForSimdDirective *D) {
8261 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008262 getDerived().getSema().StartOpenMPDSABlock(
8263 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008264 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8265 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8266 return Res;
8267}
8268
Kelvin Li986330c2016-07-20 22:57:10 +00008269template <typename Derived>
8270StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8271 OMPTargetSimdDirective *D) {
8272 DeclarationNameInfo DirName;
8273 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008274 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008275 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8276 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8277 return Res;
8278}
8279
Kelvin Li02532872016-08-05 14:37:37 +00008280template <typename Derived>
8281StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8282 OMPTeamsDistributeDirective *D) {
8283 DeclarationNameInfo DirName;
8284 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008285 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008286 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8287 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8288 return Res;
8289}
8290
Kelvin Li4e325f72016-10-25 12:50:55 +00008291template <typename Derived>
8292StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8293 OMPTeamsDistributeSimdDirective *D) {
8294 DeclarationNameInfo DirName;
8295 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008296 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008297 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8298 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8299 return Res;
8300}
8301
Kelvin Li579e41c2016-11-30 23:51:03 +00008302template <typename Derived>
8303StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8304 OMPTeamsDistributeParallelForSimdDirective *D) {
8305 DeclarationNameInfo DirName;
8306 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008307 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8308 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8310 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8311 return Res;
8312}
8313
Kelvin Li7ade93f2016-12-09 03:24:30 +00008314template <typename Derived>
8315StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8316 OMPTeamsDistributeParallelForDirective *D) {
8317 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008318 getDerived().getSema().StartOpenMPDSABlock(
8319 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008320 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8321 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8322 return Res;
8323}
8324
Kelvin Libf594a52016-12-17 05:48:59 +00008325template <typename Derived>
8326StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8327 OMPTargetTeamsDirective *D) {
8328 DeclarationNameInfo DirName;
8329 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008330 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008331 auto Res = getDerived().TransformOMPExecutableDirective(D);
8332 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8333 return Res;
8334}
Kelvin Li579e41c2016-11-30 23:51:03 +00008335
Kelvin Li83c451e2016-12-25 04:52:54 +00008336template <typename Derived>
8337StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8338 OMPTargetTeamsDistributeDirective *D) {
8339 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008340 getDerived().getSema().StartOpenMPDSABlock(
8341 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008342 auto Res = getDerived().TransformOMPExecutableDirective(D);
8343 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8344 return Res;
8345}
8346
Kelvin Li80e8f562016-12-29 22:16:30 +00008347template <typename Derived>
8348StmtResult
8349TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8350 OMPTargetTeamsDistributeParallelForDirective *D) {
8351 DeclarationNameInfo DirName;
8352 getDerived().getSema().StartOpenMPDSABlock(
8353 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008354 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008355 auto Res = getDerived().TransformOMPExecutableDirective(D);
8356 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8357 return Res;
8358}
8359
Kelvin Li1851df52017-01-03 05:23:48 +00008360template <typename Derived>
8361StmtResult TreeTransform<Derived>::
8362 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8363 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8364 DeclarationNameInfo DirName;
8365 getDerived().getSema().StartOpenMPDSABlock(
8366 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008367 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008368 auto Res = getDerived().TransformOMPExecutableDirective(D);
8369 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8370 return Res;
8371}
8372
Kelvin Lida681182017-01-10 18:08:18 +00008373template <typename Derived>
8374StmtResult
8375TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8376 OMPTargetTeamsDistributeSimdDirective *D) {
8377 DeclarationNameInfo DirName;
8378 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008379 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008380 auto Res = getDerived().TransformOMPExecutableDirective(D);
8381 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8382 return Res;
8383}
8384
Kelvin Li1851df52017-01-03 05:23:48 +00008385
Alexander Musman64d33f12014-06-04 07:53:32 +00008386//===----------------------------------------------------------------------===//
8387// OpenMP clause transformation
8388//===----------------------------------------------------------------------===//
8389template <typename Derived>
8390OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008391 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8392 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008393 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008394 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008395 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008396 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008397}
8398
Alexander Musman64d33f12014-06-04 07:53:32 +00008399template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008400OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8401 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8402 if (Cond.isInvalid())
8403 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008404 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008405 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008406}
8407
8408template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008409OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008410TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8411 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8412 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008413 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008414 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008415 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008416}
8417
Alexey Bataev62c87d22014-03-21 04:51:18 +00008418template <typename Derived>
8419OMPClause *
8420TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8421 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8422 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008423 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008424 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008425 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008426}
8427
Alexander Musman8bd31e62014-05-27 15:12:19 +00008428template <typename Derived>
8429OMPClause *
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00008430TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
8431 ExprResult E = getDerived().TransformExpr(C->getAllocator());
8432 if (E.isInvalid())
8433 return nullptr;
8434 return getDerived().RebuildOMPAllocatorClause(
8435 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
8436}
8437
8438template <typename Derived>
8439OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008440TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8441 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8442 if (E.isInvalid())
8443 return nullptr;
8444 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008445 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008446}
8447
8448template <typename Derived>
8449OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008450TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8451 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8452 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008453 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008454 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008455 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008456}
8457
Alexander Musman64d33f12014-06-04 07:53:32 +00008458template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008459OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008460TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008461 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008462 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008463 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008464}
8465
Alexander Musman64d33f12014-06-04 07:53:32 +00008466template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008467OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008468TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008469 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008470 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008471 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008472}
8473
Alexander Musman64d33f12014-06-04 07:53:32 +00008474template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008475OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008476TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8477 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8478 if (E.isInvalid())
8479 return nullptr;
8480 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008481 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008482 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008483 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008484 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008485}
8486
8487template <typename Derived>
8488OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008489TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008490 ExprResult E;
8491 if (auto *Num = C->getNumForLoops()) {
8492 E = getDerived().TransformExpr(Num);
8493 if (E.isInvalid())
8494 return nullptr;
8495 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008496 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008497 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008498}
8499
8500template <typename Derived>
8501OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008502TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8503 // No need to rebuild this clause, no template-dependent parameters.
8504 return C;
8505}
8506
8507template <typename Derived>
8508OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008509TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8510 // No need to rebuild this clause, no template-dependent parameters.
8511 return C;
8512}
8513
8514template <typename Derived>
8515OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008516TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8517 // No need to rebuild this clause, no template-dependent parameters.
8518 return C;
8519}
8520
8521template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008522OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8523 // No need to rebuild this clause, no template-dependent parameters.
8524 return C;
8525}
8526
8527template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008528OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8529 // No need to rebuild this clause, no template-dependent parameters.
8530 return C;
8531}
8532
8533template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008534OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008535TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8536 // No need to rebuild this clause, no template-dependent parameters.
8537 return C;
8538}
8539
8540template <typename Derived>
8541OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008542TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8543 // No need to rebuild this clause, no template-dependent parameters.
8544 return C;
8545}
8546
8547template <typename Derived>
8548OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008549TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8550 // No need to rebuild this clause, no template-dependent parameters.
8551 return C;
8552}
8553
8554template <typename Derived>
8555OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008556TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8557 // No need to rebuild this clause, no template-dependent parameters.
8558 return C;
8559}
8560
8561template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008562OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8563 // No need to rebuild this clause, no template-dependent parameters.
8564 return C;
8565}
8566
8567template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008568OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008569TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8570 // No need to rebuild this clause, no template-dependent parameters.
8571 return C;
8572}
8573
8574template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008575OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8576 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008577 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008578}
8579
8580template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008581OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8582 OMPUnifiedSharedMemoryClause *C) {
8583 llvm_unreachable(
8584 "unified_shared_memory clause cannot appear in dependent context");
8585}
8586
8587template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008588OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8589 OMPReverseOffloadClause *C) {
8590 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8591}
8592
8593template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008594OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8595 OMPDynamicAllocatorsClause *C) {
8596 llvm_unreachable(
8597 "dynamic_allocators clause cannot appear in dependent context");
8598}
8599
8600template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008601OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8602 OMPAtomicDefaultMemOrderClause *C) {
8603 llvm_unreachable(
8604 "atomic_default_mem_order clause cannot appear in dependent context");
8605}
8606
8607template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008608OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008609TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008610 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008611 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008612 for (auto *VE : C->varlists()) {
8613 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008614 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008615 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008616 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008617 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008618 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008619 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008620}
8621
Alexander Musman64d33f12014-06-04 07:53:32 +00008622template <typename Derived>
8623OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8624 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008625 llvm::SmallVector<Expr *, 16> Vars;
8626 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008627 for (auto *VE : C->varlists()) {
8628 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008629 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008630 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008631 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008632 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008633 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008634 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008635}
8636
Alexander Musman64d33f12014-06-04 07:53:32 +00008637template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008638OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008639TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8640 llvm::SmallVector<Expr *, 16> Vars;
8641 Vars.reserve(C->varlist_size());
8642 for (auto *VE : C->varlists()) {
8643 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8644 if (EVar.isInvalid())
8645 return nullptr;
8646 Vars.push_back(EVar.get());
8647 }
8648 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008649 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008650}
8651
8652template <typename Derived>
8653OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008654TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8655 llvm::SmallVector<Expr *, 16> Vars;
8656 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008657 for (auto *VE : C->varlists()) {
8658 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008659 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008660 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008661 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008662 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008663 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008664 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008665}
8666
Alexander Musman64d33f12014-06-04 07:53:32 +00008667template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008668OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008669TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8670 llvm::SmallVector<Expr *, 16> Vars;
8671 Vars.reserve(C->varlist_size());
8672 for (auto *VE : C->varlists()) {
8673 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8674 if (EVar.isInvalid())
8675 return nullptr;
8676 Vars.push_back(EVar.get());
8677 }
8678 CXXScopeSpec ReductionIdScopeSpec;
8679 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8680
8681 DeclarationNameInfo NameInfo = C->getNameInfo();
8682 if (NameInfo.getName()) {
8683 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8684 if (!NameInfo.getName())
8685 return nullptr;
8686 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008687 // Build a list of all UDR decls with the same names ranged by the Scopes.
8688 // The Scope boundary is a duplication of the previous decl.
8689 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8690 for (auto *E : C->reduction_ops()) {
8691 // Transform all the decls.
8692 if (E) {
8693 auto *ULE = cast<UnresolvedLookupExpr>(E);
8694 UnresolvedSet<8> Decls;
8695 for (auto *D : ULE->decls()) {
8696 NamedDecl *InstD =
8697 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8698 Decls.addDecl(InstD, InstD->getAccess());
8699 }
8700 UnresolvedReductions.push_back(
8701 UnresolvedLookupExpr::Create(
8702 SemaRef.Context, /*NamingClass=*/nullptr,
8703 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8704 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8705 Decls.begin(), Decls.end()));
8706 } else
8707 UnresolvedReductions.push_back(nullptr);
8708 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008709 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008710 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008711 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008712}
8713
8714template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008715OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8716 OMPTaskReductionClause *C) {
8717 llvm::SmallVector<Expr *, 16> Vars;
8718 Vars.reserve(C->varlist_size());
8719 for (auto *VE : C->varlists()) {
8720 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8721 if (EVar.isInvalid())
8722 return nullptr;
8723 Vars.push_back(EVar.get());
8724 }
8725 CXXScopeSpec ReductionIdScopeSpec;
8726 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8727
8728 DeclarationNameInfo NameInfo = C->getNameInfo();
8729 if (NameInfo.getName()) {
8730 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8731 if (!NameInfo.getName())
8732 return nullptr;
8733 }
8734 // Build a list of all UDR decls with the same names ranged by the Scopes.
8735 // The Scope boundary is a duplication of the previous decl.
8736 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8737 for (auto *E : C->reduction_ops()) {
8738 // Transform all the decls.
8739 if (E) {
8740 auto *ULE = cast<UnresolvedLookupExpr>(E);
8741 UnresolvedSet<8> Decls;
8742 for (auto *D : ULE->decls()) {
8743 NamedDecl *InstD =
8744 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8745 Decls.addDecl(InstD, InstD->getAccess());
8746 }
8747 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8748 SemaRef.Context, /*NamingClass=*/nullptr,
8749 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8750 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8751 } else
8752 UnresolvedReductions.push_back(nullptr);
8753 }
8754 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008755 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008756 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008757}
8758
8759template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008760OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008761TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8762 llvm::SmallVector<Expr *, 16> Vars;
8763 Vars.reserve(C->varlist_size());
8764 for (auto *VE : C->varlists()) {
8765 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8766 if (EVar.isInvalid())
8767 return nullptr;
8768 Vars.push_back(EVar.get());
8769 }
8770 CXXScopeSpec ReductionIdScopeSpec;
8771 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8772
8773 DeclarationNameInfo NameInfo = C->getNameInfo();
8774 if (NameInfo.getName()) {
8775 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8776 if (!NameInfo.getName())
8777 return nullptr;
8778 }
8779 // Build a list of all UDR decls with the same names ranged by the Scopes.
8780 // The Scope boundary is a duplication of the previous decl.
8781 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8782 for (auto *E : C->reduction_ops()) {
8783 // Transform all the decls.
8784 if (E) {
8785 auto *ULE = cast<UnresolvedLookupExpr>(E);
8786 UnresolvedSet<8> Decls;
8787 for (auto *D : ULE->decls()) {
8788 NamedDecl *InstD =
8789 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8790 Decls.addDecl(InstD, InstD->getAccess());
8791 }
8792 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8793 SemaRef.Context, /*NamingClass=*/nullptr,
8794 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8795 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8796 } else
8797 UnresolvedReductions.push_back(nullptr);
8798 }
8799 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008800 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008801 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008802}
8803
8804template <typename Derived>
8805OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008806TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8807 llvm::SmallVector<Expr *, 16> Vars;
8808 Vars.reserve(C->varlist_size());
8809 for (auto *VE : C->varlists()) {
8810 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8811 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008812 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008813 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008814 }
8815 ExprResult Step = getDerived().TransformExpr(C->getStep());
8816 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008817 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008818 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008819 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008820 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008821}
8822
Alexander Musman64d33f12014-06-04 07:53:32 +00008823template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008824OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008825TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8826 llvm::SmallVector<Expr *, 16> Vars;
8827 Vars.reserve(C->varlist_size());
8828 for (auto *VE : C->varlists()) {
8829 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8830 if (EVar.isInvalid())
8831 return nullptr;
8832 Vars.push_back(EVar.get());
8833 }
8834 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8835 if (Alignment.isInvalid())
8836 return nullptr;
8837 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008838 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008839 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008840}
8841
Alexander Musman64d33f12014-06-04 07:53:32 +00008842template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008843OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008844TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8845 llvm::SmallVector<Expr *, 16> Vars;
8846 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008847 for (auto *VE : C->varlists()) {
8848 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008849 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008850 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008851 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008852 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008853 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008854 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008855}
8856
Alexey Bataevbae9a792014-06-27 10:37:06 +00008857template <typename Derived>
8858OMPClause *
8859TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8860 llvm::SmallVector<Expr *, 16> Vars;
8861 Vars.reserve(C->varlist_size());
8862 for (auto *VE : C->varlists()) {
8863 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8864 if (EVar.isInvalid())
8865 return nullptr;
8866 Vars.push_back(EVar.get());
8867 }
8868 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008869 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008870}
8871
Alexey Bataev6125da92014-07-21 11:26:11 +00008872template <typename Derived>
8873OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8874 llvm::SmallVector<Expr *, 16> Vars;
8875 Vars.reserve(C->varlist_size());
8876 for (auto *VE : C->varlists()) {
8877 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8878 if (EVar.isInvalid())
8879 return nullptr;
8880 Vars.push_back(EVar.get());
8881 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008882 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008883 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008884}
8885
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008886template <typename Derived>
8887OMPClause *
8888TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8889 llvm::SmallVector<Expr *, 16> Vars;
8890 Vars.reserve(C->varlist_size());
8891 for (auto *VE : C->varlists()) {
8892 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8893 if (EVar.isInvalid())
8894 return nullptr;
8895 Vars.push_back(EVar.get());
8896 }
8897 return getDerived().RebuildOMPDependClause(
8898 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008899 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008900}
8901
Michael Wonge710d542015-08-07 16:16:36 +00008902template <typename Derived>
8903OMPClause *
8904TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8905 ExprResult E = getDerived().TransformExpr(C->getDevice());
8906 if (E.isInvalid())
8907 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008908 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008909 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008910}
8911
Michael Kruse01f670d2019-02-22 22:29:42 +00008912template <typename Derived, class T>
8913bool transformOMPMappableExprListClause(
8914 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
8915 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
8916 DeclarationNameInfo &MapperIdInfo,
8917 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
8918 // Transform expressions in the list.
Kelvin Li0bff7af2015-11-23 05:32:03 +00008919 Vars.reserve(C->varlist_size());
8920 for (auto *VE : C->varlists()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008921 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
Kelvin Li0bff7af2015-11-23 05:32:03 +00008922 if (EVar.isInvalid())
Michael Kruse01f670d2019-02-22 22:29:42 +00008923 return true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008924 Vars.push_back(EVar.get());
8925 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008926 // Transform mapper scope specifier and identifier.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008927 NestedNameSpecifierLoc QualifierLoc;
8928 if (C->getMapperQualifierLoc()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008929 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008930 C->getMapperQualifierLoc());
8931 if (!QualifierLoc)
Michael Kruse01f670d2019-02-22 22:29:42 +00008932 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008933 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00008934 MapperIdScopeSpec.Adopt(QualifierLoc);
Michael Kruse01f670d2019-02-22 22:29:42 +00008935 MapperIdInfo = C->getMapperIdInfo();
Michael Kruse4304e9d2019-02-19 16:38:20 +00008936 if (MapperIdInfo.getName()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008937 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
Michael Kruse4304e9d2019-02-19 16:38:20 +00008938 if (!MapperIdInfo.getName())
Michael Kruse01f670d2019-02-22 22:29:42 +00008939 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008940 }
8941 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
8942 // the previous user-defined mapper lookup in dependent environment.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008943 for (auto *E : C->mapperlists()) {
8944 // Transform all the decls.
8945 if (E) {
8946 auto *ULE = cast<UnresolvedLookupExpr>(E);
8947 UnresolvedSet<8> Decls;
8948 for (auto *D : ULE->decls()) {
8949 NamedDecl *InstD =
Michael Kruse01f670d2019-02-22 22:29:42 +00008950 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008951 Decls.addDecl(InstD, InstD->getAccess());
8952 }
8953 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
Michael Kruse01f670d2019-02-22 22:29:42 +00008954 TT.getSema().Context, /*NamingClass=*/nullptr,
8955 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
8956 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
8957 Decls.end()));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008958 } else {
8959 UnresolvedMappers.push_back(nullptr);
8960 }
8961 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008962 return false;
8963}
8964
8965template <typename Derived>
8966OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00008967 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00008968 llvm::SmallVector<Expr *, 16> Vars;
8969 CXXScopeSpec MapperIdScopeSpec;
8970 DeclarationNameInfo MapperIdInfo;
8971 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
8972 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
8973 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
8974 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008975 return getDerived().RebuildOMPMapClause(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008976 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
8977 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
8978 C->getColonLoc(), Vars, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00008979}
8980
Kelvin Li099bb8c2015-11-24 20:50:12 +00008981template <typename Derived>
8982OMPClause *
Alexey Bataeve04483e2019-03-27 14:14:31 +00008983TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
8984 Expr *Allocator = C->getAllocator();
8985 if (Allocator) {
8986 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
8987 if (AllocatorRes.isInvalid())
8988 return nullptr;
8989 Allocator = AllocatorRes.get();
8990 }
8991 llvm::SmallVector<Expr *, 16> Vars;
8992 Vars.reserve(C->varlist_size());
8993 for (auto *VE : C->varlists()) {
8994 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8995 if (EVar.isInvalid())
8996 return nullptr;
8997 Vars.push_back(EVar.get());
8998 }
8999 return getDerived().RebuildOMPAllocateClause(
9000 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
9001 C->getEndLoc());
9002}
9003
9004template <typename Derived>
9005OMPClause *
Kelvin Li099bb8c2015-11-24 20:50:12 +00009006TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
9007 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
9008 if (E.isInvalid())
9009 return nullptr;
9010 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009011 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00009012}
9013
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009014template <typename Derived>
9015OMPClause *
9016TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
9017 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
9018 if (E.isInvalid())
9019 return nullptr;
9020 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009021 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009022}
9023
Alexey Bataeva0569352015-12-01 10:17:31 +00009024template <typename Derived>
9025OMPClause *
9026TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
9027 ExprResult E = getDerived().TransformExpr(C->getPriority());
9028 if (E.isInvalid())
9029 return nullptr;
9030 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009031 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00009032}
9033
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009034template <typename Derived>
9035OMPClause *
9036TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
9037 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
9038 if (E.isInvalid())
9039 return nullptr;
9040 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009041 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009042}
9043
Alexey Bataev382967a2015-12-08 12:06:20 +00009044template <typename Derived>
9045OMPClause *
9046TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
9047 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
9048 if (E.isInvalid())
9049 return nullptr;
9050 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009051 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00009052}
9053
Alexey Bataev28c75412015-12-15 08:19:24 +00009054template <typename Derived>
9055OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
9056 ExprResult E = getDerived().TransformExpr(C->getHint());
9057 if (E.isInvalid())
9058 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009059 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009060 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00009061}
9062
Carlo Bertollib4adf552016-01-15 18:50:31 +00009063template <typename Derived>
9064OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
9065 OMPDistScheduleClause *C) {
9066 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9067 if (E.isInvalid())
9068 return nullptr;
9069 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009070 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009071 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00009072}
9073
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00009074template <typename Derived>
9075OMPClause *
9076TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
9077 return C;
9078}
9079
Samuel Antao661c0902016-05-26 17:39:58 +00009080template <typename Derived>
9081OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009082 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009083 llvm::SmallVector<Expr *, 16> Vars;
9084 CXXScopeSpec MapperIdScopeSpec;
9085 DeclarationNameInfo MapperIdInfo;
9086 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9087 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
9088 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9089 return nullptr;
9090 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo,
9091 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00009092}
9093
Samuel Antaoec172c62016-05-26 17:49:04 +00009094template <typename Derived>
9095OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009096 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse0336c752019-02-25 20:34:15 +00009097 llvm::SmallVector<Expr *, 16> Vars;
9098 CXXScopeSpec MapperIdScopeSpec;
9099 DeclarationNameInfo MapperIdInfo;
9100 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9101 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
9102 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9103 return nullptr;
9104 return getDerived().RebuildOMPFromClause(
9105 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00009106}
9107
Carlo Bertolli2404b172016-07-13 15:37:16 +00009108template <typename Derived>
9109OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
9110 OMPUseDevicePtrClause *C) {
9111 llvm::SmallVector<Expr *, 16> Vars;
9112 Vars.reserve(C->varlist_size());
9113 for (auto *VE : C->varlists()) {
9114 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9115 if (EVar.isInvalid())
9116 return nullptr;
9117 Vars.push_back(EVar.get());
9118 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009119 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9120 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00009121}
9122
Carlo Bertolli70594e92016-07-13 17:16:49 +00009123template <typename Derived>
9124OMPClause *
9125TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
9126 llvm::SmallVector<Expr *, 16> Vars;
9127 Vars.reserve(C->varlist_size());
9128 for (auto *VE : C->varlists()) {
9129 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9130 if (EVar.isInvalid())
9131 return nullptr;
9132 Vars.push_back(EVar.get());
9133 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009134 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9135 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00009136}
9137
Douglas Gregorebe10102009-08-20 07:17:43 +00009138//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00009139// Expression transformation
9140//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00009141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009142ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00009143TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
9144 return TransformExpr(E->getSubExpr());
9145}
9146
9147template<typename Derived>
9148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009149TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00009150 if (!E->isTypeDependent())
9151 return E;
9152
9153 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00009154 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00009155}
Mike Stump11289f42009-09-09 15:08:12 +00009156
9157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009159TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009160 NestedNameSpecifierLoc QualifierLoc;
9161 if (E->getQualifierLoc()) {
9162 QualifierLoc
9163 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9164 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009165 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009166 }
John McCallce546572009-12-08 09:08:17 +00009167
9168 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009169 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9170 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009171 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009173
John McCall815039a2010-08-17 21:27:17 +00009174 DeclarationNameInfo NameInfo = E->getNameInfo();
9175 if (NameInfo.getName()) {
9176 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9177 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009178 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009179 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009180
9181 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009182 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009183 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009184 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009185 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009186
9187 // Mark it referenced in the new context regardless.
9188 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009189 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009190
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009191 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009192 }
John McCallce546572009-12-08 09:08:17 +00009193
Craig Topperc3ec1492014-05-26 06:22:03 +00009194 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009195 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009196 TemplateArgs = &TransArgs;
9197 TransArgs.setLAngleLoc(E->getLAngleLoc());
9198 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009199 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9200 E->getNumTemplateArgs(),
9201 TransArgs))
9202 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009203 }
9204
Chad Rosier1dcde962012-08-08 18:46:20 +00009205 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009206 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009207}
Mike Stump11289f42009-09-09 15:08:12 +00009208
Douglas Gregora16548e2009-08-11 05:31:07 +00009209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009211TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009212 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009213}
Mike Stump11289f42009-09-09 15:08:12 +00009214
Leonard Chandb01c3a2018-06-20 17:19:40 +00009215template <typename Derived>
9216ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9217 FixedPointLiteral *E) {
9218 return E;
9219}
9220
Douglas Gregora16548e2009-08-11 05:31:07 +00009221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009223TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009225}
Mike Stump11289f42009-09-09 15:08:12 +00009226
Douglas Gregora16548e2009-08-11 05:31:07 +00009227template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009229TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009230 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009231}
Mike Stump11289f42009-09-09 15:08:12 +00009232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009236 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009237}
Mike Stump11289f42009-09-09 15:08:12 +00009238
Douglas Gregora16548e2009-08-11 05:31:07 +00009239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009241TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009242 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009243}
9244
9245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009246ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009247TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009248 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009249 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009250 return SemaRef.MaybeBindToTemporary(E);
9251}
9252
9253template<typename Derived>
9254ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009255TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9256 ExprResult ControllingExpr =
9257 getDerived().TransformExpr(E->getControllingExpr());
9258 if (ControllingExpr.isInvalid())
9259 return ExprError();
9260
Chris Lattner01cf8db2011-07-20 06:58:45 +00009261 SmallVector<Expr *, 4> AssocExprs;
9262 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009263 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9264 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9265 if (TSI) {
9266 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009267 if (!AssocType)
9268 return ExprError();
9269 AssocTypes.push_back(AssocType);
9270 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009271 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009272 }
9273
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009274 ExprResult AssocExpr =
9275 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009276 if (AssocExpr.isInvalid())
9277 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009278 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009279 }
9280
9281 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9282 E->getDefaultLoc(),
9283 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009284 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009285 AssocTypes,
9286 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009287}
9288
9289template<typename Derived>
9290ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009291TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009292 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009293 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009294 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009295
Douglas Gregora16548e2009-08-11 05:31:07 +00009296 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009297 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009298
John McCallb268a282010-08-23 23:25:46 +00009299 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009300 E->getRParen());
9301}
9302
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009303/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009304/// allowed to refer to a non-static member of a class even if there's no 'this'
9305/// object available.
9306template<typename Derived>
9307ExprResult
9308TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9309 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009310 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009311 else
9312 return getDerived().TransformExpr(E);
9313}
9314
Mike Stump11289f42009-09-09 15:08:12 +00009315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009316ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009317TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009318 ExprResult SubExpr;
9319 if (E->getOpcode() == UO_AddrOf)
9320 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9321 else
9322 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009323 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009325
Douglas Gregora16548e2009-08-11 05:31:07 +00009326 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009327 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009328
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9330 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009331 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009332}
Mike Stump11289f42009-09-09 15:08:12 +00009333
Douglas Gregora16548e2009-08-11 05:31:07 +00009334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009335ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009336TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9337 // Transform the type.
9338 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9339 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009340 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009341
Douglas Gregor882211c2010-04-28 22:16:22 +00009342 // Transform all of the components into components similar to what the
9343 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009344 // FIXME: It would be slightly more efficient in the non-dependent case to
9345 // just map FieldDecls, rather than requiring the rebuilder to look for
9346 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009347 // template code that we don't care.
9348 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009349 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009350 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009351 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009352 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009353 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009354 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009355 Comp.LocStart = ON.getSourceRange().getBegin();
9356 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009357 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009358 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009359 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009360 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009361 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009362 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009363
Douglas Gregor882211c2010-04-28 22:16:22 +00009364 ExprChanged = ExprChanged || Index.get() != FromIndex;
9365 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009366 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009367 break;
9368 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009369
James Y Knight7281c352015-12-29 22:31:18 +00009370 case OffsetOfNode::Field:
9371 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009372 Comp.isBrackets = false;
9373 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009374 if (!Comp.U.IdentInfo)
9375 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009376
Douglas Gregor882211c2010-04-28 22:16:22 +00009377 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009378
James Y Knight7281c352015-12-29 22:31:18 +00009379 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009380 // Will be recomputed during the rebuild.
9381 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009383
Douglas Gregor882211c2010-04-28 22:16:22 +00009384 Components.push_back(Comp);
9385 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009386
Douglas Gregor882211c2010-04-28 22:16:22 +00009387 // If nothing changed, retain the existing expression.
9388 if (!getDerived().AlwaysRebuild() &&
9389 Type == E->getTypeSourceInfo() &&
9390 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009391 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009392
Douglas Gregor882211c2010-04-28 22:16:22 +00009393 // Build a new offsetof expression.
9394 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009395 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009396}
9397
9398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009399ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009400TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009401 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009402 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009403 return E;
John McCall8d69a212010-11-15 23:31:06 +00009404}
9405
9406template<typename Derived>
9407ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009408TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9409 return E;
9410}
9411
9412template<typename Derived>
9413ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009414TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009415 // Rebuild the syntactic form. The original syntactic form has
9416 // opaque-value expressions in it, so strip those away and rebuild
9417 // the result. This is a really awful way of doing this, but the
9418 // better solution (rebuilding the semantic expressions and
9419 // rebinding OVEs as necessary) doesn't work; we'd need
9420 // TreeTransform to not strip away implicit conversions.
9421 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9422 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009423 if (result.isInvalid()) return ExprError();
9424
9425 // If that gives us a pseudo-object result back, the pseudo-object
9426 // expression must have been an lvalue-to-rvalue conversion which we
9427 // should reapply.
9428 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009429 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009430
9431 return result;
9432}
9433
9434template<typename Derived>
9435ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009436TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9437 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009438 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009439 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009440
John McCallbcd03502009-12-07 02:54:59 +00009441 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009442 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009444
John McCall4c98fd82009-11-04 07:28:41 +00009445 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009446 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009447
Peter Collingbournee190dee2011-03-11 19:24:49 +00009448 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9449 E->getKind(),
9450 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009451 }
Mike Stump11289f42009-09-09 15:08:12 +00009452
Eli Friedmane4f22df2012-02-29 04:03:55 +00009453 // C++0x [expr.sizeof]p1:
9454 // The operand is either an expression, which is an unevaluated operand
9455 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009456 EnterExpressionEvaluationContext Unevaluated(
9457 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9458 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009459
Reid Kleckner32506ed2014-06-12 23:03:48 +00009460 // Try to recover if we have something like sizeof(T::X) where X is a type.
9461 // Notably, there must be *exactly* one set of parens if X is a type.
9462 TypeSourceInfo *RecoveryTSI = nullptr;
9463 ExprResult SubExpr;
9464 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9465 if (auto *DRE =
9466 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9467 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9468 PE, DRE, false, &RecoveryTSI);
9469 else
9470 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9471
9472 if (RecoveryTSI) {
9473 return getDerived().RebuildUnaryExprOrTypeTrait(
9474 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9475 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009477
Eli Friedmane4f22df2012-02-29 04:03:55 +00009478 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009479 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009480
Peter Collingbournee190dee2011-03-11 19:24:49 +00009481 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9482 E->getOperatorLoc(),
9483 E->getKind(),
9484 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009485}
Mike Stump11289f42009-09-09 15:08:12 +00009486
Douglas Gregora16548e2009-08-11 05:31:07 +00009487template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009488ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009489TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009490 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009491 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009493
John McCalldadc5752010-08-24 06:29:42 +00009494 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009495 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009497
9498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499 if (!getDerived().AlwaysRebuild() &&
9500 LHS.get() == E->getLHS() &&
9501 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009502 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009503
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009504 return getDerived().RebuildArraySubscriptExpr(
9505 LHS.get(),
9506 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009507}
Mike Stump11289f42009-09-09 15:08:12 +00009508
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009509template <typename Derived>
9510ExprResult
9511TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9512 ExprResult Base = getDerived().TransformExpr(E->getBase());
9513 if (Base.isInvalid())
9514 return ExprError();
9515
9516 ExprResult LowerBound;
9517 if (E->getLowerBound()) {
9518 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9519 if (LowerBound.isInvalid())
9520 return ExprError();
9521 }
9522
9523 ExprResult Length;
9524 if (E->getLength()) {
9525 Length = getDerived().TransformExpr(E->getLength());
9526 if (Length.isInvalid())
9527 return ExprError();
9528 }
9529
9530 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9531 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9532 return E;
9533
9534 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009535 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009536 Length.get(), E->getRBracketLoc());
9537}
9538
Mike Stump11289f42009-09-09 15:08:12 +00009539template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009540ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009541TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009542 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009543 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009544 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009545 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009546
9547 // Transform arguments.
9548 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009549 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009550 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009551 &ArgChanged))
9552 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009553
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 if (!getDerived().AlwaysRebuild() &&
9555 Callee.get() == E->getCallee() &&
9556 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009557 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009558
Douglas Gregora16548e2009-08-11 05:31:07 +00009559 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009560 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009561 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009562 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009563 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009564 E->getRParenLoc());
9565}
Mike Stump11289f42009-09-09 15:08:12 +00009566
9567template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009568ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009569TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009570 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009571 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009572 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009573
Douglas Gregorea972d32011-02-28 21:54:11 +00009574 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009575 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009576 QualifierLoc
9577 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009578
Douglas Gregorea972d32011-02-28 21:54:11 +00009579 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009580 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009581 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009582 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009583
Eli Friedman2cfcef62009-12-04 06:40:45 +00009584 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009585 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9586 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009587 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009588 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009589
John McCall16df1e52010-03-30 21:47:33 +00009590 NamedDecl *FoundDecl = E->getFoundDecl();
9591 if (FoundDecl == E->getMemberDecl()) {
9592 FoundDecl = Member;
9593 } else {
9594 FoundDecl = cast_or_null<NamedDecl>(
9595 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9596 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009597 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009598 }
9599
Douglas Gregora16548e2009-08-11 05:31:07 +00009600 if (!getDerived().AlwaysRebuild() &&
9601 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009602 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009603 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009604 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009605 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009606
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009607 // Mark it referenced in the new context regardless.
9608 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009609 SemaRef.MarkMemberReferenced(E);
9610
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009611 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009612 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009613
John McCall6b51f282009-11-23 01:53:49 +00009614 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009615 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009616 TransArgs.setLAngleLoc(E->getLAngleLoc());
9617 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009618 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9619 E->getNumTemplateArgs(),
9620 TransArgs))
9621 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009622 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009623
Douglas Gregora16548e2009-08-11 05:31:07 +00009624 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009625 SourceLocation FakeOperatorLoc =
9626 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009627
John McCall38836f02010-01-15 08:34:02 +00009628 // FIXME: to do this check properly, we will need to preserve the
9629 // first-qualifier-in-scope here, just in case we had a dependent
9630 // base (and therefore couldn't do the check) and a
9631 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009632 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009633 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9634 if (MemberNameInfo.getName()) {
9635 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9636 if (!MemberNameInfo.getName())
9637 return ExprError();
9638 }
John McCall38836f02010-01-15 08:34:02 +00009639
John McCallb268a282010-08-23 23:25:46 +00009640 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009642 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009643 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009644 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009645 Member,
John McCall16df1e52010-03-30 21:47:33 +00009646 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009647 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009648 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009649 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009650}
Mike Stump11289f42009-09-09 15:08:12 +00009651
Douglas Gregora16548e2009-08-11 05:31:07 +00009652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009654TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009655 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009658
John McCalldadc5752010-08-24 06:29:42 +00009659 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009660 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009662
Douglas Gregora16548e2009-08-11 05:31:07 +00009663 if (!getDerived().AlwaysRebuild() &&
9664 LHS.get() == E->getLHS() &&
9665 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009666 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009667
Lang Hames5de91cc2012-10-02 04:45:10 +00009668 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009669 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009670
Douglas Gregora16548e2009-08-11 05:31:07 +00009671 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009672 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009673}
9674
Mike Stump11289f42009-09-09 15:08:12 +00009675template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009676ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009677TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009678 CompoundAssignOperator *E) {
9679 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009680}
Mike Stump11289f42009-09-09 15:08:12 +00009681
Douglas Gregora16548e2009-08-11 05:31:07 +00009682template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009683ExprResult TreeTransform<Derived>::
9684TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9685 // Just rebuild the common and RHS expressions and see whether we
9686 // get any changes.
9687
9688 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9689 if (commonExpr.isInvalid())
9690 return ExprError();
9691
9692 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9693 if (rhs.isInvalid())
9694 return ExprError();
9695
9696 if (!getDerived().AlwaysRebuild() &&
9697 commonExpr.get() == e->getCommon() &&
9698 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009699 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009700
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009701 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009702 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009703 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009704 e->getColonLoc(),
9705 rhs.get());
9706}
9707
9708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009709ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009710TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009711 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009714
John McCalldadc5752010-08-24 06:29:42 +00009715 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009716 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009718
John McCalldadc5752010-08-24 06:29:42 +00009719 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009720 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009722
Douglas Gregora16548e2009-08-11 05:31:07 +00009723 if (!getDerived().AlwaysRebuild() &&
9724 Cond.get() == E->getCond() &&
9725 LHS.get() == E->getLHS() &&
9726 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009727 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009728
John McCallb268a282010-08-23 23:25:46 +00009729 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009730 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009731 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009732 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009733 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009734}
Mike Stump11289f42009-09-09 15:08:12 +00009735
9736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009738TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009739 // Implicit casts are eliminated during transformation, since they
9740 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009741 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009742}
Mike Stump11289f42009-09-09 15:08:12 +00009743
Douglas Gregora16548e2009-08-11 05:31:07 +00009744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009746TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009747 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9748 if (!Type)
9749 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009750
John McCalldadc5752010-08-24 06:29:42 +00009751 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009752 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009755
Douglas Gregora16548e2009-08-11 05:31:07 +00009756 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009757 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009758 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009759 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009760
John McCall97513962010-01-15 18:39:57 +00009761 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009762 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009763 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009764 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009765}
Mike Stump11289f42009-09-09 15:08:12 +00009766
Douglas Gregora16548e2009-08-11 05:31:07 +00009767template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009769TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009770 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9771 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9772 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009774
John McCalldadc5752010-08-24 06:29:42 +00009775 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009780 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009782 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009783
John McCall5d7aa7f2010-01-19 22:33:45 +00009784 // Note: the expression type doesn't necessarily match the
9785 // type-as-written, but that's okay, because it should always be
9786 // derivable from the initializer.
9787
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009788 return getDerived().RebuildCompoundLiteralExpr(
9789 E->getLParenLoc(), NewT,
9790 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009791}
Mike Stump11289f42009-09-09 15:08:12 +00009792
Douglas Gregora16548e2009-08-11 05:31:07 +00009793template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009794ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009795TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009796 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009797 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009799
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 if (!getDerived().AlwaysRebuild() &&
9801 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009803
Douglas Gregora16548e2009-08-11 05:31:07 +00009804 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009805 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009806 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009807 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009808 E->getAccessorLoc(),
9809 E->getAccessor());
9810}
Mike Stump11289f42009-09-09 15:08:12 +00009811
Douglas Gregora16548e2009-08-11 05:31:07 +00009812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009813ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009814TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009815 if (InitListExpr *Syntactic = E->getSyntacticForm())
9816 E = Syntactic;
9817
Douglas Gregora16548e2009-08-11 05:31:07 +00009818 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009819
Richard Smith12938cf2018-09-26 04:36:55 +00009820 EnterExpressionEvaluationContext Context(
9821 getSema(), EnterExpressionEvaluationContext::InitList);
9822
Benjamin Kramerf0623432012-08-23 22:51:59 +00009823 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009824 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009825 Inits, &InitChanged))
9826 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009827
Richard Smith520449d2015-02-05 06:15:50 +00009828 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9829 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9830 // in some cases. We can't reuse it in general, because the syntactic and
9831 // semantic forms are linked, and we can't know that semantic form will
9832 // match even if the syntactic form does.
9833 }
Mike Stump11289f42009-09-09 15:08:12 +00009834
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009835 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009836 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009837}
Mike Stump11289f42009-09-09 15:08:12 +00009838
Douglas Gregora16548e2009-08-11 05:31:07 +00009839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009841TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009842 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009843
Douglas Gregorebe10102009-08-20 07:17:43 +00009844 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009845 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009846 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009848
Douglas Gregorebe10102009-08-20 07:17:43 +00009849 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009850 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009851 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009852 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9853 if (D.isFieldDesignator()) {
9854 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9855 D.getDotLoc(),
9856 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009857 if (D.getField()) {
9858 FieldDecl *Field = cast_or_null<FieldDecl>(
9859 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9860 if (Field != D.getField())
9861 // Rebuild the expression when the transformed FieldDecl is
9862 // different to the already assigned FieldDecl.
9863 ExprChanged = true;
9864 } else {
9865 // Ensure that the designator expression is rebuilt when there isn't
9866 // a resolved FieldDecl in the designator as we don't want to assign
9867 // a FieldDecl to a pattern designator that will be instantiated again.
9868 ExprChanged = true;
9869 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009870 continue;
9871 }
Mike Stump11289f42009-09-09 15:08:12 +00009872
David Majnemerf7e36092016-06-23 00:15:04 +00009873 if (D.isArrayDesignator()) {
9874 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009875 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009877
David Majnemerf7e36092016-06-23 00:15:04 +00009878 Desig.AddDesignator(
9879 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009880
David Majnemerf7e36092016-06-23 00:15:04 +00009881 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009882 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009883 continue;
9884 }
Mike Stump11289f42009-09-09 15:08:12 +00009885
David Majnemerf7e36092016-06-23 00:15:04 +00009886 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009887 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009888 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009889 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009891
David Majnemerf7e36092016-06-23 00:15:04 +00009892 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009893 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009895
9896 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009897 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009898 D.getLBracketLoc(),
9899 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009900
David Majnemerf7e36092016-06-23 00:15:04 +00009901 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9902 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009903
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009904 ArrayExprs.push_back(Start.get());
9905 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009906 }
Mike Stump11289f42009-09-09 15:08:12 +00009907
Douglas Gregora16548e2009-08-11 05:31:07 +00009908 if (!getDerived().AlwaysRebuild() &&
9909 Init.get() == E->getInit() &&
9910 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009911 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009912
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009913 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009914 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009915 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009916}
Mike Stump11289f42009-09-09 15:08:12 +00009917
Yunzhong Gaocb779302015-06-10 00:27:52 +00009918// Seems that if TransformInitListExpr() only works on the syntactic form of an
9919// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9920template<typename Derived>
9921ExprResult
9922TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9923 DesignatedInitUpdateExpr *E) {
9924 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9925 "initializer");
9926 return ExprError();
9927}
9928
9929template<typename Derived>
9930ExprResult
9931TreeTransform<Derived>::TransformNoInitExpr(
9932 NoInitExpr *E) {
9933 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9934 return ExprError();
9935}
9936
Douglas Gregora16548e2009-08-11 05:31:07 +00009937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009938ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009939TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9940 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9941 return ExprError();
9942}
9943
9944template<typename Derived>
9945ExprResult
9946TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9947 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9948 return ExprError();
9949}
9950
9951template<typename Derived>
9952ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009953TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009954 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009955 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009956
Douglas Gregor3da3c062009-10-28 00:29:27 +00009957 // FIXME: Will we ever have proper type location here? Will we actually
9958 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009959 QualType T = getDerived().TransformType(E->getType());
9960 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009961 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009962
Douglas Gregora16548e2009-08-11 05:31:07 +00009963 if (!getDerived().AlwaysRebuild() &&
9964 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009965 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009966
Douglas Gregora16548e2009-08-11 05:31:07 +00009967 return getDerived().RebuildImplicitValueInitExpr(T);
9968}
Mike Stump11289f42009-09-09 15:08:12 +00009969
Douglas Gregora16548e2009-08-11 05:31:07 +00009970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009972TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009973 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9974 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009976
John McCalldadc5752010-08-24 06:29:42 +00009977 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009978 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009979 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009980
Douglas Gregora16548e2009-08-11 05:31:07 +00009981 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009982 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009983 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009984 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009985
John McCallb268a282010-08-23 23:25:46 +00009986 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009987 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009988}
9989
9990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009992TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009993 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009994 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009995 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9996 &ArgumentChanged))
9997 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009998
Douglas Gregora16548e2009-08-11 05:31:07 +00009999 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010000 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +000010001 E->getRParenLoc());
10002}
Mike Stump11289f42009-09-09 15:08:12 +000010003
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010004/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010005///
10006/// By default, the transformation of an address-of-label expression always
10007/// rebuilds the expression, so that the label identifier can be resolved to
10008/// the corresponding label statement by semantic analysis.
10009template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010010ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010011TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +000010012 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
10013 E->getLabel());
10014 if (!LD)
10015 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010016
Douglas Gregora16548e2009-08-11 05:31:07 +000010017 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +000010018 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +000010019}
Mike Stump11289f42009-09-09 15:08:12 +000010020
10021template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010023TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +000010024 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +000010025 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +000010026 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +000010027 if (SubStmt.isInvalid()) {
10028 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +000010029 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +000010030 }
Mike Stump11289f42009-09-09 15:08:12 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +000010033 SubStmt.get() == E->getSubStmt()) {
10034 // Calling this an 'error' is unintuitive, but it does the right thing.
10035 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010036 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +000010037 }
Mike Stump11289f42009-09-09 15:08:12 +000010038
10039 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010040 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010041 E->getRParenLoc());
10042}
Mike Stump11289f42009-09-09 15:08:12 +000010043
Douglas Gregora16548e2009-08-11 05:31:07 +000010044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010046TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010047 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +000010048 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010050
John McCalldadc5752010-08-24 06:29:42 +000010051 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010052 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010054
John McCalldadc5752010-08-24 06:29:42 +000010055 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010056 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010058
Douglas Gregora16548e2009-08-11 05:31:07 +000010059 if (!getDerived().AlwaysRebuild() &&
10060 Cond.get() == E->getCond() &&
10061 LHS.get() == E->getLHS() &&
10062 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010063 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010064
Douglas Gregora16548e2009-08-11 05:31:07 +000010065 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +000010066 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010067 E->getRParenLoc());
10068}
Mike Stump11289f42009-09-09 15:08:12 +000010069
Douglas Gregora16548e2009-08-11 05:31:07 +000010070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010072TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010073 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010074}
10075
10076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010078TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010079 switch (E->getOperator()) {
10080 case OO_New:
10081 case OO_Delete:
10082 case OO_Array_New:
10083 case OO_Array_Delete:
10084 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +000010085
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010086 case OO_Call: {
10087 // This is a call to an object's operator().
10088 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
10089
10090 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +000010091 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010092 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010093 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010094
10095 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +000010096 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010097 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010098
10099 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010100 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010101 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +000010102 Args))
10103 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010104
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010105 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
10106 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010107 }
10108
10109#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
10110 case OO_##Name:
10111#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
10112#include "clang/Basic/OperatorKinds.def"
10113 case OO_Subscript:
10114 // Handled below.
10115 break;
10116
10117 case OO_Conditional:
10118 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010119
10120 case OO_None:
10121 case NUM_OVERLOADED_OPERATORS:
10122 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010123 }
10124
John McCalldadc5752010-08-24 06:29:42 +000010125 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +000010126 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010128
Richard Smithdb2630f2012-10-21 03:28:35 +000010129 ExprResult First;
10130 if (E->getOperator() == OO_Amp)
10131 First = getDerived().TransformAddressOfOperand(E->getArg(0));
10132 else
10133 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +000010134 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010135 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010136
John McCalldadc5752010-08-24 06:29:42 +000010137 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +000010138 if (E->getNumArgs() == 2) {
10139 Second = getDerived().TransformExpr(E->getArg(1));
10140 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010141 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010142 }
Mike Stump11289f42009-09-09 15:08:12 +000010143
Douglas Gregora16548e2009-08-11 05:31:07 +000010144 if (!getDerived().AlwaysRebuild() &&
10145 Callee.get() == E->getCallee() &&
10146 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +000010147 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010148 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +000010149
Lang Hames5de91cc2012-10-02 04:45:10 +000010150 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +000010151 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +000010152
Douglas Gregora16548e2009-08-11 05:31:07 +000010153 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
10154 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +000010155 Callee.get(),
10156 First.get(),
10157 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010158}
Mike Stump11289f42009-09-09 15:08:12 +000010159
Douglas Gregora16548e2009-08-11 05:31:07 +000010160template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010161ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010162TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10163 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010164}
Mike Stump11289f42009-09-09 15:08:12 +000010165
Eric Fiselier708afb52019-05-16 21:04:15 +000010166template <typename Derived>
10167ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
10168 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
10169 getSema().CurContext != E->getParentContext();
10170
10171 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
10172 return E;
10173
10174 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
10175 E->getEndLoc(),
10176 getSema().CurContext);
10177}
10178
Douglas Gregora16548e2009-08-11 05:31:07 +000010179template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010180ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +000010181TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10182 // Transform the callee.
10183 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10184 if (Callee.isInvalid())
10185 return ExprError();
10186
10187 // Transform exec config.
10188 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10189 if (EC.isInvalid())
10190 return ExprError();
10191
10192 // Transform arguments.
10193 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010194 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010195 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010196 &ArgChanged))
10197 return ExprError();
10198
10199 if (!getDerived().AlwaysRebuild() &&
10200 Callee.get() == E->getCallee() &&
10201 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010202 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010203
10204 // FIXME: Wrong source location information for the '('.
10205 SourceLocation FakeLParenLoc
10206 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10207 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010208 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010209 E->getRParenLoc(), EC.get());
10210}
10211
10212template<typename Derived>
10213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010214TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010215 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10216 if (!Type)
10217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010218
John McCalldadc5752010-08-24 06:29:42 +000010219 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010220 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010221 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010222 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010223
Douglas Gregora16548e2009-08-11 05:31:07 +000010224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010225 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010226 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010227 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010228 return getDerived().RebuildCXXNamedCastExpr(
10229 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10230 Type, E->getAngleBrackets().getEnd(),
10231 // FIXME. this should be '(' location
10232 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010233}
Mike Stump11289f42009-09-09 15:08:12 +000010234
Douglas Gregora16548e2009-08-11 05:31:07 +000010235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010237TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10238 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010239}
Mike Stump11289f42009-09-09 15:08:12 +000010240
10241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010243TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10244 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010245}
10246
Douglas Gregora16548e2009-08-11 05:31:07 +000010247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010248ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010249TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010250 CXXReinterpretCastExpr *E) {
10251 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010252}
Mike Stump11289f42009-09-09 15:08:12 +000010253
Douglas Gregora16548e2009-08-11 05:31:07 +000010254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010256TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10257 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010258}
Mike Stump11289f42009-09-09 15:08:12 +000010259
Douglas Gregora16548e2009-08-11 05:31:07 +000010260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010261ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010262TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010263 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010264 TypeSourceInfo *Type =
10265 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010266 if (!Type)
10267 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010268
John McCalldadc5752010-08-24 06:29:42 +000010269 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010270 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010271 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010273
Douglas Gregora16548e2009-08-11 05:31:07 +000010274 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010275 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010276 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010277 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010278
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010279 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010280 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010281 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010282 E->getRParenLoc(),
10283 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010284}
Mike Stump11289f42009-09-09 15:08:12 +000010285
Douglas Gregora16548e2009-08-11 05:31:07 +000010286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010287ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010288TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010289 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010290 TypeSourceInfo *TInfo
10291 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10292 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010294
Douglas Gregora16548e2009-08-11 05:31:07 +000010295 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010296 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010297 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010298
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010299 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010300 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010301 }
Mike Stump11289f42009-09-09 15:08:12 +000010302
Eli Friedman456f0182012-01-20 01:26:23 +000010303 // We don't know whether the subexpression is potentially evaluated until
10304 // after we perform semantic analysis. We speculatively assume it is
10305 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010306 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010307 EnterExpressionEvaluationContext Unevaluated(
10308 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10309 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010310
John McCalldadc5752010-08-24 06:29:42 +000010311 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010312 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010314
Douglas Gregora16548e2009-08-11 05:31:07 +000010315 if (!getDerived().AlwaysRebuild() &&
10316 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010317 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010318
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010319 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010320 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010321}
10322
10323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010324ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010325TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10326 if (E->isTypeOperand()) {
10327 TypeSourceInfo *TInfo
10328 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10329 if (!TInfo)
10330 return ExprError();
10331
10332 if (!getDerived().AlwaysRebuild() &&
10333 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010334 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010335
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010336 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010337 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010338 }
10339
Faisal Valid143a0c2017-04-01 21:30:49 +000010340 EnterExpressionEvaluationContext Unevaluated(
10341 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010342
10343 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10344 if (SubExpr.isInvalid())
10345 return ExprError();
10346
10347 if (!getDerived().AlwaysRebuild() &&
10348 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010349 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010350
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010351 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010352 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010353}
10354
10355template<typename Derived>
10356ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010357TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010358 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010359}
Mike Stump11289f42009-09-09 15:08:12 +000010360
Douglas Gregora16548e2009-08-11 05:31:07 +000010361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010362ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010363TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010364 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010365 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010366}
Mike Stump11289f42009-09-09 15:08:12 +000010367
Douglas Gregora16548e2009-08-11 05:31:07 +000010368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010370TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010371 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010372
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010373 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
Richard Smith8458c9e2019-05-24 01:35:07 +000010374 // Mark it referenced in the new context regardless.
10375 // FIXME: this is a bit instantiation-specific.
10376 getSema().MarkThisReferenced(E);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010377 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010378 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010379
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010380 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010381}
Mike Stump11289f42009-09-09 15:08:12 +000010382
Douglas Gregora16548e2009-08-11 05:31:07 +000010383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010385TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010386 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010387 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010389
Douglas Gregora16548e2009-08-11 05:31:07 +000010390 if (!getDerived().AlwaysRebuild() &&
10391 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010392 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010393
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010394 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10395 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010396}
Mike Stump11289f42009-09-09 15:08:12 +000010397
Douglas Gregora16548e2009-08-11 05:31:07 +000010398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010400TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010401 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10402 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010403 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010404 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010405
Eric Fiselier708afb52019-05-16 21:04:15 +000010406 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
10407 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010408 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010409
Douglas Gregor033f6752009-12-23 23:03:06 +000010410 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010411}
Mike Stump11289f42009-09-09 15:08:12 +000010412
Douglas Gregora16548e2009-08-11 05:31:07 +000010413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010414ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010415TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010416 FieldDecl *Field = cast_or_null<FieldDecl>(
10417 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010418 if (!Field)
10419 return ExprError();
10420
Eric Fiselier708afb52019-05-16 21:04:15 +000010421 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
10422 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010423 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010424
10425 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10426}
10427
10428template<typename Derived>
10429ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010430TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10431 CXXScalarValueInitExpr *E) {
10432 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10433 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010434 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010435
Douglas Gregora16548e2009-08-11 05:31:07 +000010436 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010437 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010438 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010439
Chad Rosier1dcde962012-08-08 18:46:20 +000010440 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010441 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010442 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010443}
Mike Stump11289f42009-09-09 15:08:12 +000010444
Douglas Gregora16548e2009-08-11 05:31:07 +000010445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010447TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010448 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010449 TypeSourceInfo *AllocTypeInfo =
10450 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010451 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010452 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010453
Douglas Gregora16548e2009-08-11 05:31:07 +000010454 // Transform the size of the array we're allocating (if any).
Richard Smithb9fb1212019-05-06 03:47:15 +000010455 Optional<Expr *> ArraySize;
10456 if (Optional<Expr *> OldArraySize = E->getArraySize()) {
10457 ExprResult NewArraySize;
10458 if (*OldArraySize) {
10459 NewArraySize = getDerived().TransformExpr(*OldArraySize);
10460 if (NewArraySize.isInvalid())
10461 return ExprError();
10462 }
10463 ArraySize = NewArraySize.get();
10464 }
Mike Stump11289f42009-09-09 15:08:12 +000010465
Douglas Gregora16548e2009-08-11 05:31:07 +000010466 // Transform the placement arguments (if any).
10467 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010468 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010469 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010470 E->getNumPlacementArgs(), true,
10471 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010472 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010473
Sebastian Redl6047f072012-02-16 12:22:20 +000010474 // Transform the initializer (if any).
10475 Expr *OldInit = E->getInitializer();
10476 ExprResult NewInit;
10477 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010478 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010479 if (NewInit.isInvalid())
10480 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010481
Sebastian Redl6047f072012-02-16 12:22:20 +000010482 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010483 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010484 if (E->getOperatorNew()) {
10485 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010486 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010487 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010488 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010489 }
10490
Craig Topperc3ec1492014-05-26 06:22:03 +000010491 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010492 if (E->getOperatorDelete()) {
10493 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010494 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010495 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010496 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010497 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010498
Douglas Gregora16548e2009-08-11 05:31:07 +000010499 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010500 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Richard Smithb9fb1212019-05-06 03:47:15 +000010501 ArraySize == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010502 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010503 OperatorNew == E->getOperatorNew() &&
10504 OperatorDelete == E->getOperatorDelete() &&
10505 !ArgumentChanged) {
10506 // Mark any declarations we need as referenced.
10507 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010508 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010509 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010510 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010511 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010512
Sebastian Redl6047f072012-02-16 12:22:20 +000010513 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010514 QualType ElementType
10515 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10516 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10517 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10518 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010519 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010520 }
10521 }
10522 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010523
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010524 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010525 }
Mike Stump11289f42009-09-09 15:08:12 +000010526
Douglas Gregor0744ef62010-09-07 21:49:58 +000010527 QualType AllocType = AllocTypeInfo->getType();
Richard Smithb9fb1212019-05-06 03:47:15 +000010528 if (!ArraySize) {
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010529 // If no array size was specified, but the new expression was
10530 // instantiated with an array type (e.g., "new T" where T is
10531 // instantiated with "int[4]"), extract the outer bound from the
10532 // array type as our array size. We do this with constant and
10533 // dependently-sized array types.
10534 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10535 if (!ArrayT) {
10536 // Do nothing
10537 } else if (const ConstantArrayType *ConsArrayT
10538 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010539 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10540 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010541 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010542 AllocType = ConsArrayT->getElementType();
10543 } else if (const DependentSizedArrayType *DepArrayT
10544 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10545 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010546 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010547 AllocType = DepArrayT->getElementType();
10548 }
10549 }
10550 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010551
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010552 return getDerived().RebuildCXXNewExpr(
10553 E->getBeginLoc(), E->isGlobalNew(),
10554 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10555 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
Richard Smithb9fb1212019-05-06 03:47:15 +000010556 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010557}
Mike Stump11289f42009-09-09 15:08:12 +000010558
Douglas Gregora16548e2009-08-11 05:31:07 +000010559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010561TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010562 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010563 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010564 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010565
Douglas Gregord2d9da02010-02-26 00:38:10 +000010566 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010567 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010568 if (E->getOperatorDelete()) {
10569 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010570 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010571 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010572 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010573 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010574
Douglas Gregora16548e2009-08-11 05:31:07 +000010575 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010576 Operand.get() == E->getArgument() &&
10577 OperatorDelete == E->getOperatorDelete()) {
10578 // Mark any declarations we need as referenced.
10579 // FIXME: instantiation-specific.
10580 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010581 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010582
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010583 if (!E->getArgument()->isTypeDependent()) {
10584 QualType Destroyed = SemaRef.Context.getBaseElementType(
10585 E->getDestroyedType());
10586 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10587 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010588 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010589 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010590 }
10591 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010592
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010593 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010594 }
Mike Stump11289f42009-09-09 15:08:12 +000010595
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010596 return getDerived().RebuildCXXDeleteExpr(
10597 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010598}
Mike Stump11289f42009-09-09 15:08:12 +000010599
Douglas Gregora16548e2009-08-11 05:31:07 +000010600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010601ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010602TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010603 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010604 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010605 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010607
John McCallba7bf592010-08-24 05:47:05 +000010608 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010609 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010610 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010611 E->getOperatorLoc(),
10612 E->isArrow()? tok::arrow : tok::period,
10613 ObjectTypePtr,
10614 MayBePseudoDestructor);
10615 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010616 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010617
John McCallba7bf592010-08-24 05:47:05 +000010618 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010619 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10620 if (QualifierLoc) {
10621 QualifierLoc
10622 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10623 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010624 return ExprError();
10625 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010626 CXXScopeSpec SS;
10627 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010628
Douglas Gregor678f90d2010-02-25 01:56:36 +000010629 PseudoDestructorTypeStorage Destroyed;
10630 if (E->getDestroyedTypeInfo()) {
10631 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010632 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010633 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010634 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010635 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010636 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010637 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010638 // We aren't likely to be able to resolve the identifier down to a type
10639 // now anyway, so just retain the identifier.
10640 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10641 E->getDestroyedTypeLoc());
10642 } else {
10643 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010644 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010645 *E->getDestroyedTypeIdentifier(),
10646 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010647 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010648 SS, ObjectTypePtr,
10649 false);
10650 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010652
Douglas Gregor678f90d2010-02-25 01:56:36 +000010653 Destroyed
10654 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10655 E->getDestroyedTypeLoc());
10656 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010657
Craig Topperc3ec1492014-05-26 06:22:03 +000010658 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010659 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010660 CXXScopeSpec EmptySS;
10661 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010662 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010663 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010664 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010665 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010666
John McCallb268a282010-08-23 23:25:46 +000010667 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010668 E->getOperatorLoc(),
10669 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010670 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010671 ScopeTypeInfo,
10672 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010673 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010674 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010675}
Mike Stump11289f42009-09-09 15:08:12 +000010676
Richard Smith151c4562016-12-20 21:35:28 +000010677template <typename Derived>
10678bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10679 bool RequiresADL,
10680 LookupResult &R) {
10681 // Transform all the decls.
10682 bool AllEmptyPacks = true;
10683 for (auto *OldD : Old->decls()) {
10684 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10685 if (!InstD) {
10686 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10687 // This can happen because of dependent hiding.
10688 if (isa<UsingShadowDecl>(OldD))
10689 continue;
10690 else {
10691 R.clear();
10692 return true;
10693 }
10694 }
10695
10696 // Expand using pack declarations.
10697 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10698 ArrayRef<NamedDecl*> Decls = SingleDecl;
10699 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10700 Decls = UPD->expansions();
10701
10702 // Expand using declarations.
10703 for (auto *D : Decls) {
10704 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10705 for (auto *SD : UD->shadows())
10706 R.addDecl(SD);
10707 } else {
10708 R.addDecl(D);
10709 }
10710 }
10711
10712 AllEmptyPacks &= Decls.empty();
10713 };
10714
10715 // C++ [temp.res]/8.4.2:
10716 // The program is ill-formed, no diagnostic required, if [...] lookup for
10717 // a name in the template definition found a using-declaration, but the
10718 // lookup in the corresponding scope in the instantiation odoes not find
10719 // any declarations because the using-declaration was a pack expansion and
10720 // the corresponding pack is empty
10721 if (AllEmptyPacks && !RequiresADL) {
10722 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010723 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010724 return true;
10725 }
10726
10727 // Resolve a kind, but don't do any further analysis. If it's
10728 // ambiguous, the callee needs to deal with it.
10729 R.resolveKind();
10730 return false;
10731}
10732
Douglas Gregorad8a3362009-09-04 17:36:40 +000010733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010734ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010735TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010736 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010737 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10738 Sema::LookupOrdinaryName);
10739
Richard Smith151c4562016-12-20 21:35:28 +000010740 // Transform the declaration set.
10741 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10742 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010743
10744 // Rebuild the nested-name qualifier, if present.
10745 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010746 if (Old->getQualifierLoc()) {
10747 NestedNameSpecifierLoc QualifierLoc
10748 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10749 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010750 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010751
Douglas Gregor0da1d432011-02-28 20:01:57 +000010752 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010753 }
10754
Douglas Gregor9262f472010-04-27 18:19:34 +000010755 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010756 CXXRecordDecl *NamingClass
10757 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10758 Old->getNameLoc(),
10759 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010760 if (!NamingClass) {
10761 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010762 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010763 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010764
Douglas Gregorda7be082010-04-27 16:10:10 +000010765 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010766 }
10767
Abramo Bagnara7945c982012-01-27 09:46:47 +000010768 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10769
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010770 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010771 // it's a normal declaration name or member reference.
10772 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10773 NamedDecl *D = R.getAsSingle<NamedDecl>();
10774 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10775 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10776 // give a good diagnostic.
10777 if (D && D->isCXXInstanceMember()) {
10778 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10779 /*TemplateArgs=*/nullptr,
10780 /*Scope=*/nullptr);
10781 }
10782
John McCalle66edc12009-11-24 19:00:30 +000010783 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010784 }
John McCalle66edc12009-11-24 19:00:30 +000010785
10786 // If we have template arguments, rebuild them, then rebuild the
10787 // templateid expression.
10788 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010789 if (Old->hasExplicitTemplateArgs() &&
10790 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010791 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010792 TransArgs)) {
10793 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010794 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010795 }
John McCalle66edc12009-11-24 19:00:30 +000010796
Abramo Bagnara7945c982012-01-27 09:46:47 +000010797 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010798 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010799}
Mike Stump11289f42009-09-09 15:08:12 +000010800
Douglas Gregora16548e2009-08-11 05:31:07 +000010801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010802ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010803TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10804 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010805 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010806 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10807 TypeSourceInfo *From = E->getArg(I);
10808 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010809 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010810 TypeLocBuilder TLB;
10811 TLB.reserve(FromTL.getFullDataSize());
10812 QualType To = getDerived().TransformType(TLB, FromTL);
10813 if (To.isNull())
10814 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010815
Douglas Gregor29c42f22012-02-24 07:38:34 +000010816 if (To == From->getType())
10817 Args.push_back(From);
10818 else {
10819 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10820 ArgChanged = true;
10821 }
10822 continue;
10823 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010824
Douglas Gregor29c42f22012-02-24 07:38:34 +000010825 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010826
Douglas Gregor29c42f22012-02-24 07:38:34 +000010827 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010828 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010829 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10830 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10831 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010832
Douglas Gregor29c42f22012-02-24 07:38:34 +000010833 // Determine whether the set of unexpanded parameter packs can and should
10834 // be expanded.
10835 bool Expand = true;
10836 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010837 Optional<unsigned> OrigNumExpansions =
10838 ExpansionTL.getTypePtr()->getNumExpansions();
10839 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010840 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10841 PatternTL.getSourceRange(),
10842 Unexpanded,
10843 Expand, RetainExpansion,
10844 NumExpansions))
10845 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010846
Douglas Gregor29c42f22012-02-24 07:38:34 +000010847 if (!Expand) {
10848 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010849 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010850 // expansion.
10851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010852
Douglas Gregor29c42f22012-02-24 07:38:34 +000010853 TypeLocBuilder TLB;
10854 TLB.reserve(From->getTypeLoc().getFullDataSize());
10855
10856 QualType To = getDerived().TransformType(TLB, PatternTL);
10857 if (To.isNull())
10858 return ExprError();
10859
Chad Rosier1dcde962012-08-08 18:46:20 +000010860 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010861 PatternTL.getSourceRange(),
10862 ExpansionTL.getEllipsisLoc(),
10863 NumExpansions);
10864 if (To.isNull())
10865 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010866
Douglas Gregor29c42f22012-02-24 07:38:34 +000010867 PackExpansionTypeLoc ToExpansionTL
10868 = TLB.push<PackExpansionTypeLoc>(To);
10869 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10870 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10871 continue;
10872 }
10873
10874 // Expand the pack expansion by substituting for each argument in the
10875 // pack(s).
10876 for (unsigned I = 0; I != *NumExpansions; ++I) {
10877 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10878 TypeLocBuilder TLB;
10879 TLB.reserve(PatternTL.getFullDataSize());
10880 QualType To = getDerived().TransformType(TLB, PatternTL);
10881 if (To.isNull())
10882 return ExprError();
10883
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010884 if (To->containsUnexpandedParameterPack()) {
10885 To = getDerived().RebuildPackExpansionType(To,
10886 PatternTL.getSourceRange(),
10887 ExpansionTL.getEllipsisLoc(),
10888 NumExpansions);
10889 if (To.isNull())
10890 return ExprError();
10891
10892 PackExpansionTypeLoc ToExpansionTL
10893 = TLB.push<PackExpansionTypeLoc>(To);
10894 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10895 }
10896
Douglas Gregor29c42f22012-02-24 07:38:34 +000010897 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10898 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010899
Douglas Gregor29c42f22012-02-24 07:38:34 +000010900 if (!RetainExpansion)
10901 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010902
Douglas Gregor29c42f22012-02-24 07:38:34 +000010903 // If we're supposed to retain a pack expansion, do so by temporarily
10904 // forgetting the partially-substituted parameter pack.
10905 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10906
10907 TypeLocBuilder TLB;
10908 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010909
Douglas Gregor29c42f22012-02-24 07:38:34 +000010910 QualType To = getDerived().TransformType(TLB, PatternTL);
10911 if (To.isNull())
10912 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010913
10914 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010915 PatternTL.getSourceRange(),
10916 ExpansionTL.getEllipsisLoc(),
10917 NumExpansions);
10918 if (To.isNull())
10919 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010920
Douglas Gregor29c42f22012-02-24 07:38:34 +000010921 PackExpansionTypeLoc ToExpansionTL
10922 = TLB.push<PackExpansionTypeLoc>(To);
10923 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10924 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10925 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010926
Douglas Gregor29c42f22012-02-24 07:38:34 +000010927 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010928 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010929
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010930 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010931 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010932}
10933
10934template<typename Derived>
10935ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010936TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10937 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10938 if (!T)
10939 return ExprError();
10940
10941 if (!getDerived().AlwaysRebuild() &&
10942 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010943 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010944
10945 ExprResult SubExpr;
10946 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010947 EnterExpressionEvaluationContext Unevaluated(
10948 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010949 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10950 if (SubExpr.isInvalid())
10951 return ExprError();
10952
10953 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010954 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010955 }
10956
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010957 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010958 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010959}
10960
10961template<typename Derived>
10962ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010963TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10964 ExprResult SubExpr;
10965 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010966 EnterExpressionEvaluationContext Unevaluated(
10967 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010968 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10969 if (SubExpr.isInvalid())
10970 return ExprError();
10971
10972 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010973 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010974 }
10975
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010976 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010977 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010978}
10979
Reid Kleckner32506ed2014-06-12 23:03:48 +000010980template <typename Derived>
10981ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10982 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10983 TypeSourceInfo **RecoveryTSI) {
10984 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10985 DRE, AddrTaken, RecoveryTSI);
10986
10987 // Propagate both errors and recovered types, which return ExprEmpty.
10988 if (!NewDRE.isUsable())
10989 return NewDRE;
10990
10991 // We got an expr, wrap it up in parens.
10992 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10993 return PE;
10994 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10995 PE->getRParen());
10996}
10997
10998template <typename Derived>
10999ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11000 DependentScopeDeclRefExpr *E) {
11001 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
11002 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000011003}
11004
11005template<typename Derived>
11006ExprResult
11007TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11008 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000011009 bool IsAddressOfOperand,
11010 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000011011 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011012 NestedNameSpecifierLoc QualifierLoc
11013 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11014 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011015 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000011016 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000011017
John McCall31f82722010-11-12 08:19:04 +000011018 // TODO: If this is a conversion-function-id, verify that the
11019 // destination type name (if present) resolves the same way after
11020 // instantiation as it did in the local scope.
11021
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011022 DeclarationNameInfo NameInfo
11023 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
11024 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011025 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011026
John McCalle66edc12009-11-24 19:00:30 +000011027 if (!E->hasExplicitTemplateArgs()) {
11028 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011029 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011030 // Note: it is sufficient to compare the Name component of NameInfo:
11031 // if name has not changed, DNLoc has not changed either.
11032 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011033 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011034
Reid Kleckner32506ed2014-06-12 23:03:48 +000011035 return getDerived().RebuildDependentScopeDeclRefExpr(
11036 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
11037 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000011038 }
John McCall6b51f282009-11-23 01:53:49 +000011039
11040 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011041 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11042 E->getNumTemplateArgs(),
11043 TransArgs))
11044 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011045
Reid Kleckner32506ed2014-06-12 23:03:48 +000011046 return getDerived().RebuildDependentScopeDeclRefExpr(
11047 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
11048 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000011049}
11050
11051template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011052ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011053TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000011054 // CXXConstructExprs other than for list-initialization and
11055 // CXXTemporaryObjectExpr are always implicit, so when we have
11056 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000011057 if ((E->getNumArgs() == 1 ||
11058 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000011059 (!getDerived().DropCallArgument(E->getArg(0))) &&
11060 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000011061 return getDerived().TransformExpr(E->getArg(0));
11062
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011063 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000011064
11065 QualType T = getDerived().TransformType(E->getType());
11066 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000011067 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011068
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011069 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11070 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011071 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011073
Douglas Gregora16548e2009-08-11 05:31:07 +000011074 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011075 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000011076 {
11077 EnterExpressionEvaluationContext Context(
11078 getSema(), EnterExpressionEvaluationContext::InitList,
11079 E->isListInitialization());
11080 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11081 &ArgumentChanged))
11082 return ExprError();
11083 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011084
Douglas Gregora16548e2009-08-11 05:31:07 +000011085 if (!getDerived().AlwaysRebuild() &&
11086 T == E->getType() &&
11087 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000011088 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000011089 // Mark the constructor as referenced.
11090 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011091 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011092 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000011093 }
Mike Stump11289f42009-09-09 15:08:12 +000011094
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011095 return getDerived().RebuildCXXConstructExpr(
11096 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
11097 E->hadMultipleCandidates(), E->isListInitialization(),
11098 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
11099 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000011100}
Mike Stump11289f42009-09-09 15:08:12 +000011101
Richard Smith5179eb72016-06-28 19:03:57 +000011102template<typename Derived>
11103ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
11104 CXXInheritedCtorInitExpr *E) {
11105 QualType T = getDerived().TransformType(E->getType());
11106 if (T.isNull())
11107 return ExprError();
11108
11109 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011110 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000011111 if (!Constructor)
11112 return ExprError();
11113
11114 if (!getDerived().AlwaysRebuild() &&
11115 T == E->getType() &&
11116 Constructor == E->getConstructor()) {
11117 // Mark the constructor as referenced.
11118 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011119 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000011120 return E;
11121 }
11122
11123 return getDerived().RebuildCXXInheritedCtorInitExpr(
11124 T, E->getLocation(), Constructor,
11125 E->constructsVBase(), E->inheritedFromVBase());
11126}
11127
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011128/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000011129///
Douglas Gregor363b1512009-12-24 18:51:59 +000011130/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
11131/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011132template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011133ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011134TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011135 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011136}
Mike Stump11289f42009-09-09 15:08:12 +000011137
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011138/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000011139/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000011140///
John McCall5d413782010-12-06 08:20:24 +000011141/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000011142/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011144ExprResult
John McCall5d413782010-12-06 08:20:24 +000011145TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011146 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011147}
Mike Stump11289f42009-09-09 15:08:12 +000011148
Douglas Gregora16548e2009-08-11 05:31:07 +000011149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011150ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011151TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000011152 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011153 TypeSourceInfo *T =
11154 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011155 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011157
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011158 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11159 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011160 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011162
Douglas Gregora16548e2009-08-11 05:31:07 +000011163 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011164 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000011165 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000011166 {
11167 EnterExpressionEvaluationContext Context(
11168 getSema(), EnterExpressionEvaluationContext::InitList,
11169 E->isListInitialization());
11170 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11171 &ArgumentChanged))
11172 return ExprError();
11173 }
Mike Stump11289f42009-09-09 15:08:12 +000011174
Douglas Gregora16548e2009-08-11 05:31:07 +000011175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011176 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011177 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011178 !ArgumentChanged) {
11179 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011180 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000011181 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011182 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011183
Vedant Kumara14a1f92018-01-17 18:53:51 +000011184 // FIXME: We should just pass E->isListInitialization(), but we're not
11185 // prepared to handle list-initialization without a child InitListExpr.
11186 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11187 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011188 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011189 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011190}
Mike Stump11289f42009-09-09 15:08:12 +000011191
Douglas Gregora16548e2009-08-11 05:31:07 +000011192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011193ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011194TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011195 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011196 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011197 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smithb2997f52019-05-21 20:10:50 +000011198 struct TransformedInitCapture {
11199 // The location of the ... if the result is retaining a pack expansion.
11200 SourceLocation EllipsisLoc;
11201 // Zero or more expansions of the init-capture.
11202 SmallVector<InitCaptureInfoTy, 4> Expansions;
11203 };
11204 SmallVector<TransformedInitCapture, 4> InitCaptures;
11205 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011206 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011207 CEnd = E->capture_end();
11208 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011209 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011210 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000011211
Richard Smithb2997f52019-05-21 20:10:50 +000011212 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011213 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011214
11215 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
11216 Optional<unsigned> NumExpansions) {
Richard Smithb2997f52019-05-21 20:10:50 +000011217 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11218 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
11219
11220 if (NewExprInitResult.isInvalid()) {
11221 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
11222 return;
11223 }
11224 Expr *NewExprInit = NewExprInitResult.get();
11225
11226 QualType NewInitCaptureType =
11227 getSema().buildLambdaInitCaptureInitialization(
11228 C->getLocation(), OldVD->getType()->isReferenceType(),
11229 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
11230 C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
11231 NewExprInit);
11232 Result.Expansions.push_back(
11233 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
11234 };
11235
11236 // If this is an init-capture pack, consider expanding the pack now.
11237 if (OldVD->isParameterPack()) {
11238 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
11239 ->getTypeLoc()
11240 .castAs<PackExpansionTypeLoc>();
11241 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11242 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
11243
11244 // Determine whether the set of unexpanded parameter packs can and should
11245 // be expanded.
11246 bool Expand = true;
11247 bool RetainExpansion = false;
11248 Optional<unsigned> OrigNumExpansions =
11249 ExpansionTL.getTypePtr()->getNumExpansions();
11250 Optional<unsigned> NumExpansions = OrigNumExpansions;
11251 if (getDerived().TryExpandParameterPacks(
11252 ExpansionTL.getEllipsisLoc(),
11253 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
11254 RetainExpansion, NumExpansions))
11255 return ExprError();
11256 if (Expand) {
11257 for (unsigned I = 0; I != *NumExpansions; ++I) {
11258 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11259 SubstInitCapture(SourceLocation(), None);
11260 }
11261 }
11262 if (!Expand || RetainExpansion) {
11263 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11264 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
11265 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
11266 }
11267 } else {
11268 SubstInitCapture(SourceLocation(), None);
11269 }
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011270 }
11271
Faisal Vali2cba1332013-10-23 06:44:28 +000011272 // Transform the template parameters, and add them to the current
11273 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011274 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011275 E->getTemplateParameterList());
11276
Richard Smith01014ce2014-11-20 23:53:14 +000011277 // Transform the type of the original lambda's call operator.
11278 // The transformation MUST be done in the CurrentInstantiationScope since
11279 // it introduces a mapping of the original to the newly created
11280 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011281 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011282 {
11283 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011284 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011285 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011286
11287 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011288 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011289 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011290 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011291 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011292 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11293 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11294 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011295 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011296 if (NewCallOpType.isNull())
11297 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011298 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11299 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011300 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011301
Richard Smithc38498f2015-04-27 21:27:54 +000011302 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11303 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11304 LSI->GLTemplateParameterList = TPL;
11305
Eli Friedmand564afb2012-09-19 01:18:11 +000011306 // Create the local class that will describe the lambda.
Richard Smith87346a12019-06-02 18:53:44 +000011307 CXXRecordDecl *OldClass = E->getLambdaClass();
Eli Friedmand564afb2012-09-19 01:18:11 +000011308 CXXRecordDecl *Class
11309 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011310 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011311 /*KnownDependent=*/false,
11312 E->getCaptureDefault());
Richard Smith87346a12019-06-02 18:53:44 +000011313 getDerived().transformedLocalDecl(OldClass, {Class});
11314
11315 Optional<std::pair<unsigned, Decl*>> Mangling;
11316 if (getDerived().ReplacingOriginal())
11317 Mangling = std::make_pair(OldClass->getLambdaManglingNumber(),
11318 OldClass->getLambdaContextDecl());
Eli Friedmand564afb2012-09-19 01:18:11 +000011319
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011320 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011321 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11322 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011323 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011324 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
Richard Smith87346a12019-06-02 18:53:44 +000011325 E->getCallOperator()->isConstexpr(), Mangling);
Faisal Valia734ab92016-03-26 16:11:37 +000011326
Faisal Vali2cba1332013-10-23 06:44:28 +000011327 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011328
Akira Hatanaka402818462016-12-16 21:16:57 +000011329 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11330 I != NumParams; ++I) {
11331 auto *P = NewCallOperator->getParamDecl(I);
11332 if (P->hasUninstantiatedDefaultArg()) {
11333 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011334 getSema(),
11335 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011336 ExprResult R = getDerived().TransformExpr(
11337 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11338 P->setDefaultArg(R.get());
11339 }
11340 }
11341
Faisal Vali2cba1332013-10-23 06:44:28 +000011342 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithb2997f52019-05-21 20:10:50 +000011343 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
Richard Smithba71c082013-05-16 06:20:58 +000011344
Douglas Gregorb4328232012-02-14 00:00:48 +000011345 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011346 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011347 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011348
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011349 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011350 getSema().buildLambdaScope(LSI, NewCallOperator,
11351 E->getIntroducerRange(),
11352 E->getCaptureDefault(),
11353 E->getCaptureDefaultLoc(),
11354 E->hasExplicitParameters(),
11355 E->hasExplicitResultType(),
11356 E->isMutable());
11357
11358 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011359
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011360 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011361 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011362 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011363 CEnd = E->capture_end();
11364 C != CEnd; ++C) {
11365 // When we hit the first implicit capture, tell Sema that we've finished
11366 // the list of explicit captures.
11367 if (!FinishedExplicitCaptures && C->isImplicit()) {
11368 getSema().finishLambdaExplicitCaptures(LSI);
11369 FinishedExplicitCaptures = true;
11370 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011371
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011372 // Capturing 'this' is trivial.
11373 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011374 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11375 /*BuildAndDiagnose*/ true, nullptr,
11376 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011377 continue;
11378 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011379 // Captured expression will be recaptured during captured variables
11380 // rebuilding.
11381 if (C->capturesVLAType())
11382 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011383
Richard Smithba71c082013-05-16 06:20:58 +000011384 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011385 if (E->isInitCapture(C)) {
Richard Smithb2997f52019-05-21 20:10:50 +000011386 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
11387
Richard Smithbb13c9a2013-09-28 04:02:39 +000011388 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011389 llvm::SmallVector<Decl*, 4> NewVDs;
11390
11391 for (InitCaptureInfoTy &Info : NewC.Expansions) {
11392 ExprResult Init = Info.first;
11393 QualType InitQualType = Info.second;
11394 if (Init.isInvalid() || InitQualType.isNull()) {
11395 Invalid = true;
11396 break;
11397 }
11398 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11399 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
11400 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
11401 if (!NewVD) {
11402 Invalid = true;
11403 break;
11404 }
11405 NewVDs.push_back(NewVD);
Richard Smith30116532019-05-28 23:09:46 +000011406 getSema().addInitCapture(LSI, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011407 }
Richard Smithb2997f52019-05-21 20:10:50 +000011408
11409 if (Invalid)
11410 break;
11411
11412 getDerived().transformedLocalDecl(OldVD, NewVDs);
Richard Smithba71c082013-05-16 06:20:58 +000011413 continue;
11414 }
11415
11416 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11417
Douglas Gregor3e308b12012-02-14 19:27:52 +000011418 // Determine the capture kind for Sema.
11419 Sema::TryCaptureKind Kind
11420 = C->isImplicit()? Sema::TryCapture_Implicit
11421 : C->getCaptureKind() == LCK_ByCopy
11422 ? Sema::TryCapture_ExplicitByVal
11423 : Sema::TryCapture_ExplicitByRef;
11424 SourceLocation EllipsisLoc;
11425 if (C->isPackExpansion()) {
11426 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11427 bool ShouldExpand = false;
11428 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011429 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011430 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11431 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011432 Unexpanded,
11433 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011434 NumExpansions)) {
11435 Invalid = true;
11436 continue;
11437 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011438
Douglas Gregor3e308b12012-02-14 19:27:52 +000011439 if (ShouldExpand) {
11440 // The transform has determined that we should perform an expansion;
11441 // transform and capture each of the arguments.
11442 // expansion of the pattern. Do so.
11443 VarDecl *Pack = C->getCapturedVar();
11444 for (unsigned I = 0; I != *NumExpansions; ++I) {
11445 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11446 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011447 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011448 Pack));
11449 if (!CapturedVar) {
11450 Invalid = true;
11451 continue;
11452 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011453
Douglas Gregor3e308b12012-02-14 19:27:52 +000011454 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011455 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11456 }
Richard Smith9467be42014-06-06 17:33:35 +000011457
11458 // FIXME: Retain a pack expansion if RetainExpansion is true.
11459
Douglas Gregor3e308b12012-02-14 19:27:52 +000011460 continue;
11461 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011462
Douglas Gregor3e308b12012-02-14 19:27:52 +000011463 EllipsisLoc = C->getEllipsisLoc();
11464 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011465
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011466 // Transform the captured variable.
11467 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011468 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011469 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011470 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011471 Invalid = true;
11472 continue;
11473 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011474
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011475 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011476 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11477 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011478 }
11479 if (!FinishedExplicitCaptures)
11480 getSema().finishLambdaExplicitCaptures(LSI);
11481
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011482 // Enter a new evaluation context to insulate the lambda from any
11483 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011484 getSema().PushExpressionEvaluationContext(
11485 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011486
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011487 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011488 StmtResult Body =
Richard Smith87346a12019-06-02 18:53:44 +000011489 Invalid ? StmtError() : getDerived().TransformLambdaBody(E->getBody());
Richard Smithc38498f2015-04-27 21:27:54 +000011490
11491 // ActOnLambda* will pop the function scope for us.
11492 FuncScopeCleanup.disable();
11493
Douglas Gregorb4328232012-02-14 00:00:48 +000011494 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011495 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011496 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011497 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011498 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011499 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011500
Richard Smithc38498f2015-04-27 21:27:54 +000011501 // Copy the LSI before ActOnFinishFunctionBody removes it.
11502 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11503 // the call operator.
11504 auto LSICopy = *LSI;
11505 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11506 /*IsInstantiation*/ true);
11507 SavedContext.pop();
11508
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011509 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011510 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011511}
11512
11513template<typename Derived>
Richard Smith87346a12019-06-02 18:53:44 +000011514StmtResult
11515TreeTransform<Derived>::TransformLambdaBody(Stmt *S) {
11516 return TransformStmt(S);
11517}
11518
11519template<typename Derived>
Douglas Gregore31e6062012-02-07 10:09:13 +000011520ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011521TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011522 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011523 TypeSourceInfo *T =
11524 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011525 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011527
Douglas Gregora16548e2009-08-11 05:31:07 +000011528 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011529 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011530 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011531 {
11532 EnterExpressionEvaluationContext Context(
11533 getSema(), EnterExpressionEvaluationContext::InitList,
11534 E->isListInitialization());
11535 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11536 &ArgumentChanged))
11537 return ExprError();
11538 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011539
Douglas Gregora16548e2009-08-11 05:31:07 +000011540 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011541 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011542 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011543 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011544
Douglas Gregora16548e2009-08-11 05:31:07 +000011545 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011546 return getDerived().RebuildCXXUnresolvedConstructExpr(
11547 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011548}
Mike Stump11289f42009-09-09 15:08:12 +000011549
Douglas Gregora16548e2009-08-11 05:31:07 +000011550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011551ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011552TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011553 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011554 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011555 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011556 Expr *OldBase;
11557 QualType BaseType;
11558 QualType ObjectType;
11559 if (!E->isImplicitAccess()) {
11560 OldBase = E->getBase();
11561 Base = getDerived().TransformExpr(OldBase);
11562 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011563 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011564
John McCall2d74de92009-12-01 22:10:20 +000011565 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011566 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011567 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011568 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011569 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011570 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011571 ObjectTy,
11572 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011573 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011574 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011575
John McCallba7bf592010-08-24 05:47:05 +000011576 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011577 BaseType = ((Expr*) Base.get())->getType();
11578 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011579 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011580 BaseType = getDerived().TransformType(E->getBaseType());
11581 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11582 }
Mike Stump11289f42009-09-09 15:08:12 +000011583
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011584 // Transform the first part of the nested-name-specifier that qualifies
11585 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011586 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011587 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011588 E->getFirstQualifierFoundInScope(),
11589 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011590
Douglas Gregore16af532011-02-28 18:50:33 +000011591 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011592 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011593 QualifierLoc
11594 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11595 ObjectType,
11596 FirstQualifierInScope);
11597 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011598 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011599 }
Mike Stump11289f42009-09-09 15:08:12 +000011600
Abramo Bagnara7945c982012-01-27 09:46:47 +000011601 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11602
John McCall31f82722010-11-12 08:19:04 +000011603 // TODO: If this is a conversion-function-id, verify that the
11604 // destination type name (if present) resolves the same way after
11605 // instantiation as it did in the local scope.
11606
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011607 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011608 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011609 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011610 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011611
John McCall2d74de92009-12-01 22:10:20 +000011612 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011613 // This is a reference to a member without an explicitly-specified
11614 // template argument list. Optimize for this common case.
11615 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011616 Base.get() == OldBase &&
11617 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011618 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011619 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011620 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011621 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011622
John McCallb268a282010-08-23 23:25:46 +000011623 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011624 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011625 E->isArrow(),
11626 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011627 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011628 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011629 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011630 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011631 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011632 }
11633
John McCall6b51f282009-11-23 01:53:49 +000011634 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011635 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11636 E->getNumTemplateArgs(),
11637 TransArgs))
11638 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011639
John McCallb268a282010-08-23 23:25:46 +000011640 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011641 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011642 E->isArrow(),
11643 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011644 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011645 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011646 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011647 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011648 &TransArgs);
11649}
11650
11651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011653TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011654 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011655 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011656 QualType BaseType;
11657 if (!Old->isImplicitAccess()) {
11658 Base = getDerived().TransformExpr(Old->getBase());
11659 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011660 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011661 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011662 Old->isArrow());
11663 if (Base.isInvalid())
11664 return ExprError();
11665 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011666 } else {
11667 BaseType = getDerived().TransformType(Old->getBaseType());
11668 }
John McCall10eae182009-11-30 22:42:35 +000011669
Douglas Gregor0da1d432011-02-28 20:01:57 +000011670 NestedNameSpecifierLoc QualifierLoc;
11671 if (Old->getQualifierLoc()) {
11672 QualifierLoc
11673 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11674 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011675 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011676 }
11677
Abramo Bagnara7945c982012-01-27 09:46:47 +000011678 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11679
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011680 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011681 Sema::LookupOrdinaryName);
11682
Richard Smith151c4562016-12-20 21:35:28 +000011683 // Transform the declaration set.
11684 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11685 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011686
Douglas Gregor9262f472010-04-27 18:19:34 +000011687 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011688 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011689 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011690 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011691 Old->getMemberLoc(),
11692 Old->getNamingClass()));
11693 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011694 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011695
Douglas Gregorda7be082010-04-27 16:10:10 +000011696 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011697 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011698
John McCall10eae182009-11-30 22:42:35 +000011699 TemplateArgumentListInfo TransArgs;
11700 if (Old->hasExplicitTemplateArgs()) {
11701 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11702 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011703 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11704 Old->getNumTemplateArgs(),
11705 TransArgs))
11706 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011707 }
John McCall38836f02010-01-15 08:34:02 +000011708
11709 // FIXME: to do this check properly, we will need to preserve the
11710 // first-qualifier-in-scope here, just in case we had a dependent
11711 // base (and therefore couldn't do the check) and a
11712 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011713 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011714
John McCallb268a282010-08-23 23:25:46 +000011715 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011716 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011717 Old->getOperatorLoc(),
11718 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011719 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011720 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011721 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011722 R,
11723 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011724 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011725}
11726
11727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011728ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011729TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011730 EnterExpressionEvaluationContext Unevaluated(
11731 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011732 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11733 if (SubExpr.isInvalid())
11734 return ExprError();
11735
11736 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011737 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011738
11739 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11740}
11741
11742template<typename Derived>
11743ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011744TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011745 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11746 if (Pattern.isInvalid())
11747 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011748
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011749 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011750 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011751
Douglas Gregorb8840002011-01-14 21:20:45 +000011752 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11753 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011754}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011755
11756template<typename Derived>
11757ExprResult
11758TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11759 // If E is not value-dependent, then nothing will change when we transform it.
11760 // Note: This is an instantiation-centric view.
11761 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011762 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011763
Faisal Valid143a0c2017-04-01 21:30:49 +000011764 EnterExpressionEvaluationContext Unevaluated(
11765 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011766
Richard Smithd784e682015-09-23 21:41:42 +000011767 ArrayRef<TemplateArgument> PackArgs;
11768 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011769
Richard Smithd784e682015-09-23 21:41:42 +000011770 // Find the argument list to transform.
11771 if (E->isPartiallySubstituted()) {
11772 PackArgs = E->getPartialArguments();
11773 } else if (E->isValueDependent()) {
11774 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11775 bool ShouldExpand = false;
11776 bool RetainExpansion = false;
11777 Optional<unsigned> NumExpansions;
11778 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11779 Unexpanded,
11780 ShouldExpand, RetainExpansion,
11781 NumExpansions))
11782 return ExprError();
11783
11784 // If we need to expand the pack, build a template argument from it and
11785 // expand that.
11786 if (ShouldExpand) {
11787 auto *Pack = E->getPack();
11788 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11789 ArgStorage = getSema().Context.getPackExpansionType(
11790 getSema().Context.getTypeDeclType(TTPD), None);
11791 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11792 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11793 } else {
11794 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011795 ExprResult DRE = getSema().BuildDeclRefExpr(
11796 VD, VD->getType().getNonLValueExprType(getSema().Context),
11797 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11798 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011799 if (DRE.isInvalid())
11800 return ExprError();
11801 ArgStorage = new (getSema().Context) PackExpansionExpr(
11802 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11803 }
11804 PackArgs = ArgStorage;
11805 }
11806 }
11807
11808 // If we're not expanding the pack, just transform the decl.
11809 if (!PackArgs.size()) {
11810 auto *Pack = cast_or_null<NamedDecl>(
11811 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011812 if (!Pack)
11813 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011814 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11815 E->getPackLoc(),
11816 E->getRParenLoc(), None, None);
11817 }
11818
Richard Smithc5452ed2016-10-19 22:18:42 +000011819 // Try to compute the result without performing a partial substitution.
11820 Optional<unsigned> Result = 0;
11821 for (const TemplateArgument &Arg : PackArgs) {
11822 if (!Arg.isPackExpansion()) {
11823 Result = *Result + 1;
11824 continue;
11825 }
11826
11827 TemplateArgumentLoc ArgLoc;
11828 InventTemplateArgumentLoc(Arg, ArgLoc);
11829
11830 // Find the pattern of the pack expansion.
11831 SourceLocation Ellipsis;
11832 Optional<unsigned> OrigNumExpansions;
11833 TemplateArgumentLoc Pattern =
11834 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11835 OrigNumExpansions);
11836
11837 // Substitute under the pack expansion. Do not expand the pack (yet).
11838 TemplateArgumentLoc OutPattern;
11839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11840 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11841 /*Uneval*/ true))
11842 return true;
11843
11844 // See if we can determine the number of arguments from the result.
11845 Optional<unsigned> NumExpansions =
11846 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11847 if (!NumExpansions) {
11848 // No: we must be in an alias template expansion, and we're going to need
11849 // to actually expand the packs.
11850 Result = None;
11851 break;
11852 }
11853
11854 Result = *Result + *NumExpansions;
11855 }
11856
11857 // Common case: we could determine the number of expansions without
11858 // substituting.
11859 if (Result)
11860 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11861 E->getPackLoc(),
11862 E->getRParenLoc(), *Result, None);
11863
Richard Smithd784e682015-09-23 21:41:42 +000011864 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11865 E->getPackLoc());
11866 {
11867 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11868 typedef TemplateArgumentLocInventIterator<
11869 Derived, const TemplateArgument*> PackLocIterator;
11870 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11871 PackLocIterator(*this, PackArgs.end()),
11872 TransformedPackArgs, /*Uneval*/true))
11873 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011874 }
11875
Richard Smithc5452ed2016-10-19 22:18:42 +000011876 // Check whether we managed to fully-expand the pack.
11877 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011878 SmallVector<TemplateArgument, 8> Args;
11879 bool PartialSubstitution = false;
11880 for (auto &Loc : TransformedPackArgs.arguments()) {
11881 Args.push_back(Loc.getArgument());
11882 if (Loc.getArgument().isPackExpansion())
11883 PartialSubstitution = true;
11884 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011885
Richard Smithd784e682015-09-23 21:41:42 +000011886 if (PartialSubstitution)
11887 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11888 E->getPackLoc(),
11889 E->getRParenLoc(), None, Args);
11890
11891 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011892 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011893 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011894}
11895
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011896template<typename Derived>
11897ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011898TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11899 SubstNonTypeTemplateParmPackExpr *E) {
11900 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011901 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011902}
11903
11904template<typename Derived>
11905ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011906TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11907 SubstNonTypeTemplateParmExpr *E) {
11908 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011909 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011910}
11911
11912template<typename Derived>
11913ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011914TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11915 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011916 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011917}
11918
11919template<typename Derived>
11920ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011921TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11922 MaterializeTemporaryExpr *E) {
11923 return getDerived().TransformExpr(E->GetTemporaryExpr());
11924}
Chad Rosier1dcde962012-08-08 18:46:20 +000011925
Douglas Gregorfe314812011-06-21 17:03:29 +000011926template<typename Derived>
11927ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011928TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11929 Expr *Pattern = E->getPattern();
11930
11931 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11932 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11933 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11934
11935 // Determine whether the set of unexpanded parameter packs can and should
11936 // be expanded.
11937 bool Expand = true;
11938 bool RetainExpansion = false;
Richard Smithc7214f62019-05-13 08:31:14 +000011939 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
11940 NumExpansions = OrigNumExpansions;
Richard Smith0f0af192014-11-08 05:07:16 +000011941 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11942 Pattern->getSourceRange(),
11943 Unexpanded,
11944 Expand, RetainExpansion,
11945 NumExpansions))
11946 return true;
11947
11948 if (!Expand) {
11949 // Do not expand any packs here, just transform and rebuild a fold
11950 // expression.
11951 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11952
11953 ExprResult LHS =
11954 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11955 if (LHS.isInvalid())
11956 return true;
11957
11958 ExprResult RHS =
11959 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11960 if (RHS.isInvalid())
11961 return true;
11962
11963 if (!getDerived().AlwaysRebuild() &&
11964 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11965 return E;
11966
11967 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011968 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000011969 RHS.get(), E->getEndLoc(), NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000011970 }
11971
11972 // The transform has determined that we should perform an elementwise
11973 // expansion of the pattern. Do so.
11974 ExprResult Result = getDerived().TransformExpr(E->getInit());
11975 if (Result.isInvalid())
11976 return true;
11977 bool LeftFold = E->isLeftFold();
11978
11979 // If we're retaining an expansion for a right fold, it is the innermost
11980 // component and takes the init (if any).
11981 if (!LeftFold && RetainExpansion) {
11982 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11983
11984 ExprResult Out = getDerived().TransformExpr(Pattern);
11985 if (Out.isInvalid())
11986 return true;
11987
11988 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011989 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000011990 Result.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000011991 if (Result.isInvalid())
11992 return true;
11993 }
11994
11995 for (unsigned I = 0; I != *NumExpansions; ++I) {
11996 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11997 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11998 ExprResult Out = getDerived().TransformExpr(Pattern);
11999 if (Out.isInvalid())
12000 return true;
12001
12002 if (Out.get()->containsUnexpandedParameterPack()) {
12003 // We still have a pack; retain a pack expansion for this slice.
12004 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012005 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000012006 E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012007 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
12008 OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012009 } else if (Result.isUsable()) {
12010 // We've got down to a single element; build a binary operator.
12011 Result = getDerived().RebuildBinaryOperator(
12012 E->getEllipsisLoc(), E->getOperator(),
12013 LeftFold ? Result.get() : Out.get(),
12014 LeftFold ? Out.get() : Result.get());
12015 } else
12016 Result = Out;
12017
12018 if (Result.isInvalid())
12019 return true;
12020 }
12021
12022 // If we're retaining an expansion for a left fold, it is the outermost
12023 // component and takes the complete expansion so far as its init (if any).
12024 if (LeftFold && RetainExpansion) {
12025 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12026
12027 ExprResult Out = getDerived().TransformExpr(Pattern);
12028 if (Out.isInvalid())
12029 return true;
12030
12031 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012032 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012033 Out.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012034 if (Result.isInvalid())
12035 return true;
12036 }
12037
12038 // If we had no init and an empty pack, and we're not retaining an expansion,
12039 // then produce a fallback value or error.
12040 if (Result.isUnset())
12041 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
12042 E->getOperator());
12043
12044 return Result;
12045}
12046
12047template<typename Derived>
12048ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000012049TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
12050 CXXStdInitializerListExpr *E) {
12051 return getDerived().TransformExpr(E->getSubExpr());
12052}
12053
12054template<typename Derived>
12055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012056TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012057 return SemaRef.MaybeBindToTemporary(E);
12058}
12059
12060template<typename Derived>
12061ExprResult
12062TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012063 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012064}
12065
12066template<typename Derived>
12067ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000012068TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
12069 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12070 if (SubExpr.isInvalid())
12071 return ExprError();
12072
12073 if (!getDerived().AlwaysRebuild() &&
12074 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012075 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000012076
12077 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000012078}
12079
12080template<typename Derived>
12081ExprResult
12082TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
12083 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012084 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012085 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000012086 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012087 /*IsCall=*/false, Elements, &ArgChanged))
12088 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012089
Ted Kremeneke65b0862012-03-06 20:05:56 +000012090 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12091 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012092
Ted Kremeneke65b0862012-03-06 20:05:56 +000012093 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
12094 Elements.data(),
12095 Elements.size());
12096}
12097
12098template<typename Derived>
12099ExprResult
12100TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000012101 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012102 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012103 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012104 bool ArgChanged = false;
12105 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
12106 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000012107
Ted Kremeneke65b0862012-03-06 20:05:56 +000012108 if (OrigElement.isPackExpansion()) {
12109 // This key/value element is a pack expansion.
12110 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12111 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
12112 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
12113 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12114
12115 // Determine whether the set of unexpanded parameter packs can
12116 // and should be expanded.
12117 bool Expand = true;
12118 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000012119 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
12120 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012121 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000012122 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012123 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
12124 PatternRange, Unexpanded, Expand,
12125 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000012126 return ExprError();
12127
12128 if (!Expand) {
12129 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000012130 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000012131 // expansion.
12132 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12133 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12134 if (Key.isInvalid())
12135 return ExprError();
12136
12137 if (Key.get() != OrigElement.Key)
12138 ArgChanged = true;
12139
12140 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12141 if (Value.isInvalid())
12142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012143
Ted Kremeneke65b0862012-03-06 20:05:56 +000012144 if (Value.get() != OrigElement.Value)
12145 ArgChanged = true;
12146
Chad Rosier1dcde962012-08-08 18:46:20 +000012147 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012148 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
12149 };
12150 Elements.push_back(Expansion);
12151 continue;
12152 }
12153
12154 // Record right away that the argument was changed. This needs
12155 // to happen even if the array expands to nothing.
12156 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012157
Ted Kremeneke65b0862012-03-06 20:05:56 +000012158 // The transform has determined that we should perform an elementwise
12159 // expansion of the pattern. Do so.
12160 for (unsigned I = 0; I != *NumExpansions; ++I) {
12161 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
12162 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12163 if (Key.isInvalid())
12164 return ExprError();
12165
12166 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12167 if (Value.isInvalid())
12168 return ExprError();
12169
Chad Rosier1dcde962012-08-08 18:46:20 +000012170 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012171 Key.get(), Value.get(), SourceLocation(), NumExpansions
12172 };
12173
12174 // If any unexpanded parameter packs remain, we still have a
12175 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000012176 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000012177 if (Key.get()->containsUnexpandedParameterPack() ||
12178 Value.get()->containsUnexpandedParameterPack())
12179 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000012180
Ted Kremeneke65b0862012-03-06 20:05:56 +000012181 Elements.push_back(Element);
12182 }
12183
Richard Smith9467be42014-06-06 17:33:35 +000012184 // FIXME: Retain a pack expansion if RetainExpansion is true.
12185
Ted Kremeneke65b0862012-03-06 20:05:56 +000012186 // We've finished with this pack expansion.
12187 continue;
12188 }
12189
12190 // Transform and check key.
12191 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12192 if (Key.isInvalid())
12193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012194
Ted Kremeneke65b0862012-03-06 20:05:56 +000012195 if (Key.get() != OrigElement.Key)
12196 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012197
Ted Kremeneke65b0862012-03-06 20:05:56 +000012198 // Transform and check value.
12199 ExprResult Value
12200 = getDerived().TransformExpr(OrigElement.Value);
12201 if (Value.isInvalid())
12202 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012203
Ted Kremeneke65b0862012-03-06 20:05:56 +000012204 if (Value.get() != OrigElement.Value)
12205 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012206
12207 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000012208 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000012209 };
12210 Elements.push_back(Element);
12211 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012212
Ted Kremeneke65b0862012-03-06 20:05:56 +000012213 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12214 return SemaRef.MaybeBindToTemporary(E);
12215
12216 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000012217 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000012218}
12219
Mike Stump11289f42009-09-09 15:08:12 +000012220template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012221ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012222TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000012223 TypeSourceInfo *EncodedTypeInfo
12224 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
12225 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012226 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012227
Douglas Gregora16548e2009-08-11 05:31:07 +000012228 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000012229 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012230 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012231
12232 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000012233 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000012234 E->getRParenLoc());
12235}
Mike Stump11289f42009-09-09 15:08:12 +000012236
Douglas Gregora16548e2009-08-11 05:31:07 +000012237template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000012238ExprResult TreeTransform<Derived>::
12239TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000012240 // This is a kind of implicit conversion, and it needs to get dropped
12241 // and recomputed for the same general reasons that ImplicitCastExprs
12242 // do, as well a more specific one: this expression is only valid when
12243 // it appears *immediately* as an argument expression.
12244 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000012245}
12246
12247template<typename Derived>
12248ExprResult TreeTransform<Derived>::
12249TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000012250 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000012251 = getDerived().TransformType(E->getTypeInfoAsWritten());
12252 if (!TSInfo)
12253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012254
John McCall31168b02011-06-15 23:02:42 +000012255 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012256 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012257 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012258
John McCall31168b02011-06-15 23:02:42 +000012259 if (!getDerived().AlwaysRebuild() &&
12260 TSInfo == E->getTypeInfoAsWritten() &&
12261 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012262 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012263
John McCall31168b02011-06-15 23:02:42 +000012264 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012265 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012266 Result.get());
12267}
12268
Erik Pilkington29099de2016-07-16 00:35:23 +000012269template <typename Derived>
12270ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12271 ObjCAvailabilityCheckExpr *E) {
12272 return E;
12273}
12274
John McCall31168b02011-06-15 23:02:42 +000012275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012276ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012277TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012278 // Transform arguments.
12279 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012280 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012281 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012282 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012283 &ArgChanged))
12284 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012285
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012286 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12287 // Class message: transform the receiver type.
12288 TypeSourceInfo *ReceiverTypeInfo
12289 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12290 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012291 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012292
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012293 // If nothing changed, just retain the existing message send.
12294 if (!getDerived().AlwaysRebuild() &&
12295 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012296 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012297
12298 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012299 SmallVector<SourceLocation, 16> SelLocs;
12300 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012301 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12302 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012303 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012304 E->getMethodDecl(),
12305 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012306 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012307 E->getRightLoc());
12308 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012309 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12310 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012311 if (!E->getMethodDecl())
12312 return ExprError();
12313
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012314 // Build a new class message send to 'super'.
12315 SmallVector<SourceLocation, 16> SelLocs;
12316 E->getSelectorLocs(SelLocs);
12317 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12318 E->getSelector(),
12319 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012320 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012321 E->getMethodDecl(),
12322 E->getLeftLoc(),
12323 Args,
12324 E->getRightLoc());
12325 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012326
12327 // Instance message: transform the receiver
12328 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12329 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012330 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012331 = getDerived().TransformExpr(E->getInstanceReceiver());
12332 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012333 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012334
12335 // If nothing changed, just retain the existing message send.
12336 if (!getDerived().AlwaysRebuild() &&
12337 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012338 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012339
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012340 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012341 SmallVector<SourceLocation, 16> SelLocs;
12342 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012343 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012344 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012345 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012346 E->getMethodDecl(),
12347 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012348 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012349 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012350}
12351
Mike Stump11289f42009-09-09 15:08:12 +000012352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012354TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012355 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012356}
12357
Mike Stump11289f42009-09-09 15:08:12 +000012358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012360TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012361 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012362}
12363
Mike Stump11289f42009-09-09 15:08:12 +000012364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012366TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012367 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012368 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012369 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012370 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012371
12372 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012373
Douglas Gregord51d90d2010-04-26 20:11:03 +000012374 // If nothing changed, just retain the existing expression.
12375 if (!getDerived().AlwaysRebuild() &&
12376 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012377 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012378
John McCallb268a282010-08-23 23:25:46 +000012379 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012380 E->getLocation(),
12381 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012382}
12383
Mike Stump11289f42009-09-09 15:08:12 +000012384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012385ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012386TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012387 // 'super' and types never change. Property never changes. Just
12388 // retain the existing expression.
12389 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012390 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012391
Douglas Gregor9faee212010-04-26 20:47:02 +000012392 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012393 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012394 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012395 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012396
Douglas Gregor9faee212010-04-26 20:47:02 +000012397 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012398
Douglas Gregor9faee212010-04-26 20:47:02 +000012399 // If nothing changed, just retain the existing expression.
12400 if (!getDerived().AlwaysRebuild() &&
12401 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012402 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012403
John McCallb7bd14f2010-12-02 01:19:52 +000012404 if (E->isExplicitProperty())
12405 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12406 E->getExplicitProperty(),
12407 E->getLocation());
12408
12409 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012410 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012411 E->getImplicitPropertyGetter(),
12412 E->getImplicitPropertySetter(),
12413 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012414}
12415
Mike Stump11289f42009-09-09 15:08:12 +000012416template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012417ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012418TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12419 // Transform the base expression.
12420 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12421 if (Base.isInvalid())
12422 return ExprError();
12423
12424 // Transform the key expression.
12425 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12426 if (Key.isInvalid())
12427 return ExprError();
12428
12429 // If nothing changed, just retain the existing expression.
12430 if (!getDerived().AlwaysRebuild() &&
12431 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012432 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012433
Chad Rosier1dcde962012-08-08 18:46:20 +000012434 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012435 Base.get(), Key.get(),
12436 E->getAtIndexMethodDecl(),
12437 E->setAtIndexMethodDecl());
12438}
12439
12440template<typename Derived>
12441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012442TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012443 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012444 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012445 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012446 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012447
Douglas Gregord51d90d2010-04-26 20:11:03 +000012448 // If nothing changed, just retain the existing expression.
12449 if (!getDerived().AlwaysRebuild() &&
12450 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012451 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012452
John McCallb268a282010-08-23 23:25:46 +000012453 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012454 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012455 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012456}
12457
Mike Stump11289f42009-09-09 15:08:12 +000012458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012460TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012461 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012462 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012463 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012464 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012465 SubExprs, &ArgumentChanged))
12466 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012467
Douglas Gregora16548e2009-08-11 05:31:07 +000012468 if (!getDerived().AlwaysRebuild() &&
12469 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012470 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012471
Douglas Gregora16548e2009-08-11 05:31:07 +000012472 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012473 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012474 E->getRParenLoc());
12475}
12476
Mike Stump11289f42009-09-09 15:08:12 +000012477template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012478ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012479TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12480 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12481 if (SrcExpr.isInvalid())
12482 return ExprError();
12483
12484 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12485 if (!Type)
12486 return ExprError();
12487
12488 if (!getDerived().AlwaysRebuild() &&
12489 Type == E->getTypeSourceInfo() &&
12490 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012491 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012492
12493 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12494 SrcExpr.get(), Type,
12495 E->getRParenLoc());
12496}
12497
12498template<typename Derived>
12499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012500TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012501 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012502
Craig Topperc3ec1492014-05-26 06:22:03 +000012503 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012504 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12505
12506 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012507 blockScope->TheDecl->setBlockMissingReturnType(
12508 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012509
Chris Lattner01cf8db2011-07-20 06:58:45 +000012510 SmallVector<ParmVarDecl*, 4> params;
12511 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012512
John McCallc8e321d2016-03-01 02:09:25 +000012513 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12514
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012515 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012516 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012517 if (getDerived().TransformFunctionTypeParams(
12518 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12519 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12520 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012521 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012522 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012523 }
John McCall490112f2011-02-04 18:33:18 +000012524
Eli Friedman34b49062012-01-26 03:00:14 +000012525 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012526 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012527
John McCallc8e321d2016-03-01 02:09:25 +000012528 auto epi = exprFunctionType->getExtProtoInfo();
12529 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12530
Jordan Rose5c382722013-03-08 21:51:21 +000012531 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012532 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012533 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012534
12535 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012536 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012537 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012538
12539 if (!oldBlock->blockMissingReturnType()) {
12540 blockScope->HasImplicitReturnType = false;
12541 blockScope->ReturnType = exprResultType;
12542 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012543
John McCall3882ace2011-01-05 12:14:39 +000012544 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012545 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012546 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012547 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012548 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012549 }
John McCall3882ace2011-01-05 12:14:39 +000012550
John McCall490112f2011-02-04 18:33:18 +000012551#ifndef NDEBUG
12552 // In builds with assertions, make sure that we captured everything we
12553 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012554 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012555 for (const auto &I : oldBlock->captures()) {
12556 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012557
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012558 // Ignore parameter packs.
Richard Smithb2997f52019-05-21 20:10:50 +000012559 if (oldCapture->isParameterPack())
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012560 continue;
John McCall490112f2011-02-04 18:33:18 +000012561
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012562 VarDecl *newCapture =
12563 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12564 oldCapture));
12565 assert(blockScope->CaptureMap.count(newCapture));
12566 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012567 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012568 }
12569#endif
12570
12571 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012572 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012573}
12574
Mike Stump11289f42009-09-09 15:08:12 +000012575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012576ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012577TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012578 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012579}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012580
12581template<typename Derived>
12582ExprResult
12583TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012584 QualType RetTy = getDerived().TransformType(E->getType());
12585 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012586 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012587 SubExprs.reserve(E->getNumSubExprs());
12588 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12589 SubExprs, &ArgumentChanged))
12590 return ExprError();
12591
12592 if (!getDerived().AlwaysRebuild() &&
12593 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012594 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012595
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012596 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012597 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012598}
Chad Rosier1dcde962012-08-08 18:46:20 +000012599
Douglas Gregora16548e2009-08-11 05:31:07 +000012600//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012601// Type reconstruction
12602//===----------------------------------------------------------------------===//
12603
Mike Stump11289f42009-09-09 15:08:12 +000012604template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012605QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12606 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012607 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012608 getDerived().getBaseEntity());
12609}
12610
Mike Stump11289f42009-09-09 15:08:12 +000012611template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012612QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12613 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012614 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012615 getDerived().getBaseEntity());
12616}
12617
Mike Stump11289f42009-09-09 15:08:12 +000012618template<typename Derived>
12619QualType
John McCall70dd5f62009-10-30 00:06:24 +000012620TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12621 bool WrittenAsLValue,
12622 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012623 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012624 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012625}
12626
12627template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012628QualType
John McCall70dd5f62009-10-30 00:06:24 +000012629TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12630 QualType ClassType,
12631 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012632 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12633 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012634}
12635
12636template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012637QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12638 const ObjCTypeParamDecl *Decl,
12639 SourceLocation ProtocolLAngleLoc,
12640 ArrayRef<ObjCProtocolDecl *> Protocols,
12641 ArrayRef<SourceLocation> ProtocolLocs,
12642 SourceLocation ProtocolRAngleLoc) {
12643 return SemaRef.BuildObjCTypeParamType(Decl,
12644 ProtocolLAngleLoc, Protocols,
12645 ProtocolLocs, ProtocolRAngleLoc,
12646 /*FailOnError=*/true);
12647}
12648
12649template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012650QualType TreeTransform<Derived>::RebuildObjCObjectType(
12651 QualType BaseType,
12652 SourceLocation Loc,
12653 SourceLocation TypeArgsLAngleLoc,
12654 ArrayRef<TypeSourceInfo *> TypeArgs,
12655 SourceLocation TypeArgsRAngleLoc,
12656 SourceLocation ProtocolLAngleLoc,
12657 ArrayRef<ObjCProtocolDecl *> Protocols,
12658 ArrayRef<SourceLocation> ProtocolLocs,
12659 SourceLocation ProtocolRAngleLoc) {
12660 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12661 TypeArgs, TypeArgsRAngleLoc,
12662 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12663 ProtocolRAngleLoc,
12664 /*FailOnError=*/true);
12665}
12666
12667template<typename Derived>
12668QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12669 QualType PointeeType,
12670 SourceLocation Star) {
12671 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12672}
12673
12674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012675QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012676TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12677 ArrayType::ArraySizeModifier SizeMod,
12678 const llvm::APInt *Size,
12679 Expr *SizeExpr,
12680 unsigned IndexTypeQuals,
12681 SourceRange BracketsRange) {
12682 if (SizeExpr || !Size)
12683 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12684 IndexTypeQuals, BracketsRange,
12685 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012686
12687 QualType Types[] = {
12688 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12689 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12690 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012691 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012692 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012693 QualType SizeType;
12694 for (unsigned I = 0; I != NumTypes; ++I)
12695 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12696 SizeType = Types[I];
12697 break;
12698 }
Mike Stump11289f42009-09-09 15:08:12 +000012699
Eli Friedman9562f392012-01-25 23:20:27 +000012700 // Note that we can return a VariableArrayType here in the case where
12701 // the element type was a dependent VariableArrayType.
12702 IntegerLiteral *ArraySize
12703 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12704 /*FIXME*/BracketsRange.getBegin());
12705 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012706 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012707 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012708}
Mike Stump11289f42009-09-09 15:08:12 +000012709
Douglas Gregord6ff3322009-08-04 16:50:30 +000012710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012711QualType
12712TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012713 ArrayType::ArraySizeModifier SizeMod,
12714 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012715 unsigned IndexTypeQuals,
12716 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012717 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012718 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012719}
12720
12721template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012722QualType
Mike Stump11289f42009-09-09 15:08:12 +000012723TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012724 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012725 unsigned IndexTypeQuals,
12726 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012727 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012728 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012729}
Mike Stump11289f42009-09-09 15:08:12 +000012730
Douglas Gregord6ff3322009-08-04 16:50:30 +000012731template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012732QualType
12733TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012734 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012735 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012736 unsigned IndexTypeQuals,
12737 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012738 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012739 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012740 IndexTypeQuals, BracketsRange);
12741}
12742
12743template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012744QualType
12745TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012746 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012747 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012748 unsigned IndexTypeQuals,
12749 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012750 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012751 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012752 IndexTypeQuals, BracketsRange);
12753}
12754
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012755template <typename Derived>
12756QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12757 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12758 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12759 AttributeLoc);
12760}
12761
12762template <typename Derived>
12763QualType
12764TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12765 unsigned NumElements,
12766 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012767 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012768 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012769}
Mike Stump11289f42009-09-09 15:08:12 +000012770
Erich Keanef702b022018-07-13 19:46:04 +000012771template <typename Derived>
12772QualType TreeTransform<Derived>::RebuildDependentVectorType(
12773 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12774 VectorType::VectorKind VecKind) {
12775 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12776}
12777
Douglas Gregord6ff3322009-08-04 16:50:30 +000012778template<typename Derived>
12779QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12780 unsigned NumElements,
12781 SourceLocation AttributeLoc) {
12782 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12783 NumElements, true);
12784 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012785 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12786 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012787 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012788}
Mike Stump11289f42009-09-09 15:08:12 +000012789
Douglas Gregord6ff3322009-08-04 16:50:30 +000012790template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012791QualType
12792TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012794 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012795 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012796}
Mike Stump11289f42009-09-09 15:08:12 +000012797
Douglas Gregord6ff3322009-08-04 16:50:30 +000012798template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012799QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12800 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012802 const FunctionProtoType::ExtProtoInfo &EPI) {
12803 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012804 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012805 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012806 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012807}
Mike Stump11289f42009-09-09 15:08:12 +000012808
Douglas Gregord6ff3322009-08-04 16:50:30 +000012809template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012810QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12811 return SemaRef.Context.getFunctionNoProtoType(T);
12812}
12813
12814template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012815QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12816 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012817 assert(D && "no decl found");
12818 if (D->isInvalidDecl()) return QualType();
12819
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012820 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012821 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012822 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12823 // A valid resolved using typename pack expansion decl can have multiple
12824 // UsingDecls, but they must each have exactly one type, and it must be
12825 // the same type in every case. But we must have at least one expansion!
12826 if (UPD->expansions().empty()) {
12827 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12828 << UPD->isCXXClassMember() << UPD;
12829 return QualType();
12830 }
12831
12832 // We might still have some unresolved types. Try to pick a resolved type
12833 // if we can. The final instantiation will check that the remaining
12834 // unresolved types instantiate to the type we pick.
12835 QualType FallbackT;
12836 QualType T;
12837 for (auto *E : UPD->expansions()) {
12838 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12839 if (ThisT.isNull())
12840 continue;
12841 else if (ThisT->getAs<UnresolvedUsingType>())
12842 FallbackT = ThisT;
12843 else if (T.isNull())
12844 T = ThisT;
12845 else
12846 assert(getSema().Context.hasSameType(ThisT, T) &&
12847 "mismatched resolved types in using pack expansion");
12848 }
12849 return T.isNull() ? FallbackT : T;
12850 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012851 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012852 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12853
12854 // A valid resolved using typename decl points to exactly one type decl.
12855 assert(++Using->shadow_begin() == Using->shadow_end());
12856 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012857 } else {
12858 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12859 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12860 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12861 }
12862
12863 return SemaRef.Context.getTypeDeclType(Ty);
12864}
12865
12866template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012867QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12868 SourceLocation Loc) {
12869 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012870}
12871
12872template<typename Derived>
12873QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12874 return SemaRef.Context.getTypeOfType(Underlying);
12875}
12876
12877template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012878QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12879 SourceLocation Loc) {
12880 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012881}
12882
12883template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012884QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12885 UnaryTransformType::UTTKind UKind,
12886 SourceLocation Loc) {
12887 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12888}
12889
12890template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012891QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012892 TemplateName Template,
12893 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012894 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012895 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012896}
Mike Stump11289f42009-09-09 15:08:12 +000012897
Douglas Gregor1135c352009-08-06 05:28:30 +000012898template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012899QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12900 SourceLocation KWLoc) {
12901 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12902}
12903
12904template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012905QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012906 SourceLocation KWLoc,
12907 bool isReadPipe) {
12908 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12909 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012910}
12911
12912template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012913TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012914TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012915 bool TemplateKW,
12916 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012917 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012918 Template);
12919}
12920
12921template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012922TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012923TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012924 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012925 const IdentifierInfo &Name,
12926 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012927 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012928 NamedDecl *FirstQualifierInScope,
12929 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012930 UnqualifiedId TemplateName;
12931 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012932 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012933 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012934 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012935 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012936 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012937 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012938 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012939}
Mike Stump11289f42009-09-09 15:08:12 +000012940
Douglas Gregora16548e2009-08-11 05:31:07 +000012941template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012942TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012943TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012944 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012945 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012946 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012947 QualType ObjectType,
12948 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012949 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012950 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012951 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012952 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012953 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012954 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012955 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012956 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012957 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012958 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012959 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012960}
Chad Rosier1dcde962012-08-08 18:46:20 +000012961
Douglas Gregor71395fa2009-11-04 00:56:37 +000012962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012963ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012964TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12965 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012966 Expr *OrigCallee,
12967 Expr *First,
12968 Expr *Second) {
12969 Expr *Callee = OrigCallee->IgnoreParenCasts();
12970 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012971
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012972 if (First->getObjectKind() == OK_ObjCProperty) {
12973 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12974 if (BinaryOperator::isAssignmentOp(Opc))
12975 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12976 First, Second);
12977 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12978 if (Result.isInvalid())
12979 return ExprError();
12980 First = Result.get();
12981 }
12982
12983 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12984 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12985 if (Result.isInvalid())
12986 return ExprError();
12987 Second = Result.get();
12988 }
12989
Douglas Gregora16548e2009-08-11 05:31:07 +000012990 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012991 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012992 if (!First->getType()->isOverloadableType() &&
12993 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012994 return getSema().CreateBuiltinArraySubscriptExpr(
12995 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012996 } else if (Op == OO_Arrow) {
12997 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012998 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12999 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000013000 if (!First->getType()->isOverloadableType() ||
13001 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
13002 // The argument is not of overloadable type, or this is an expression
13003 // of the form &Class::member, so try to create a built-in unary
13004 // operation.
John McCalle3027922010-08-25 11:45:40 +000013005 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013006 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000013007
John McCallb268a282010-08-23 23:25:46 +000013008 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000013009 }
13010 } else {
John McCallb268a282010-08-23 23:25:46 +000013011 if (!First->getType()->isOverloadableType() &&
13012 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000013013 // Neither of the arguments is an overloadable type, so try to
13014 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000013015 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000013016 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000013017 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000013018 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013020
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013021 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013022 }
13023 }
Mike Stump11289f42009-09-09 15:08:12 +000013024
13025 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000013026 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000013027 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000013028 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000013029
John McCallb268a282010-08-23 23:25:46 +000013030 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000013031 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000013032 // If the overload could not be resolved in the template definition
13033 // (because we had a dependent argument), ADL is performed as part of
13034 // template instantiation.
13035 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000013036 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000013037 // If we've resolved this to a particular non-member function, just call
13038 // that function. If we resolved it to a member function,
13039 // CreateOverloaded* will find that function for us.
13040 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
13041 if (!isa<CXXMethodDecl>(ND))
13042 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000013043 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000013044 }
Mike Stump11289f42009-09-09 15:08:12 +000013045
Douglas Gregora16548e2009-08-11 05:31:07 +000013046 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000013047 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000013048 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000013049
Douglas Gregora16548e2009-08-11 05:31:07 +000013050 // Create the overloaded operator invocation for unary operators.
13051 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000013052 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013053 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000013054 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
13055 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013056 }
Mike Stump11289f42009-09-09 15:08:12 +000013057
Douglas Gregore9d62932011-07-15 16:25:15 +000013058 if (Op == OO_Subscript) {
13059 SourceLocation LBrace;
13060 SourceLocation RBrace;
13061
13062 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000013063 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000013064 LBrace = SourceLocation::getFromRawEncoding(
13065 NameLoc.CXXOperatorName.BeginOpNameLoc);
13066 RBrace = SourceLocation::getFromRawEncoding(
13067 NameLoc.CXXOperatorName.EndOpNameLoc);
13068 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013069 LBrace = Callee->getBeginLoc();
13070 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000013071 }
13072
13073 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
13074 First, Second);
13075 }
Sebastian Redladba46e2009-10-29 20:17:01 +000013076
Douglas Gregora16548e2009-08-11 05:31:07 +000013077 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000013078 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000013079 ExprResult Result = SemaRef.CreateOverloadedBinOp(
13080 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013081 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013083
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013084 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013085}
Mike Stump11289f42009-09-09 15:08:12 +000013086
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013087template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000013088ExprResult
John McCallb268a282010-08-23 23:25:46 +000013089TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013090 SourceLocation OperatorLoc,
13091 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000013092 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013093 TypeSourceInfo *ScopeType,
13094 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000013095 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000013096 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000013097 QualType BaseType = Base->getType();
13098 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013099 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000013100 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000013101 !BaseType->getAs<PointerType>()->getPointeeType()
13102 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013103 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000013104 return SemaRef.BuildPseudoDestructorExpr(
13105 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
13106 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013107 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013108
Douglas Gregor678f90d2010-02-25 01:56:36 +000013109 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013110 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
13111 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
13112 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
13113 NameInfo.setNamedTypeInfo(DestroyedType);
13114
Richard Smith8e4a3862012-05-15 06:15:11 +000013115 // The scope type is now known to be a valid nested name specifier
13116 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000013117 if (ScopeType) {
13118 if (!ScopeType->getType()->getAs<TagType>()) {
13119 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
13120 diag::err_expected_class_or_namespace)
13121 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
13122 return ExprError();
13123 }
13124 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
13125 CCLoc);
13126 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013127
Abramo Bagnara7945c982012-01-27 09:46:47 +000013128 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000013129 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013130 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013131 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000013132 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013133 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000013134 /*TemplateArgs*/ nullptr,
13135 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013136}
13137
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013138template<typename Derived>
13139StmtResult
13140TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013141 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000013142 CapturedDecl *CD = S->getCapturedDecl();
13143 unsigned NumParams = CD->getNumParams();
13144 unsigned ContextParamPos = CD->getContextParamPosition();
13145 SmallVector<Sema::CapturedParamNameType, 4> Params;
13146 for (unsigned I = 0; I < NumParams; ++I) {
13147 if (I != ContextParamPos) {
13148 Params.push_back(
13149 std::make_pair(
13150 CD->getParam(I)->getName(),
13151 getDerived().TransformType(CD->getParam(I)->getType())));
13152 } else {
13153 Params.push_back(std::make_pair(StringRef(), QualType()));
13154 }
13155 }
Craig Topperc3ec1492014-05-26 06:22:03 +000013156 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000013157 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000013158 StmtResult Body;
13159 {
13160 Sema::CompoundScopeRAII CompoundScope(getSema());
13161 Body = getDerived().TransformStmt(S->getCapturedStmt());
13162 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000013163
13164 if (Body.isInvalid()) {
13165 getSema().ActOnCapturedRegionError();
13166 return StmtError();
13167 }
13168
Nikola Smiljanic01a75982014-05-29 10:55:11 +000013169 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013170}
13171
Douglas Gregord6ff3322009-08-04 16:50:30 +000013172} // end namespace clang
13173
Hans Wennborg59dbe862015-09-29 20:56:43 +000013174#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H