blob: 65f8678d943e4b86a0afe2b2fce72d9b32689454 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattnercab02a62011-02-17 20:34:02 +00006//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
Chris Lattnercab02a62011-02-17 20:34:02 +000011//===----------------------------------------------------------------------===//
12
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000013#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000015
Eric Fiselierbee782b2017-04-03 19:21:00 +000016#include "CoroutineStmtBuilder.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000043/// A semantic tree transformation that allows one to transform one
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +000059/// overriding function should not be virtual.
Douglas Gregord6ff3322009-08-04 16:50:30 +000060///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000096 /// Private RAII object that helps us forget and then re-remember
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000116 /// The set of local declarations that have been transformed, for
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000122 /// Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000125 /// Retrieves a reference to the derived class.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000128 /// Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000136 /// Retrieves a reference to the semantic analysis object used for
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000140 /// Whether the transformation should always rebuild AST nodes, even
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Richard Smith87346a12019-06-02 18:53:44 +0000151 /// Whether the transformation is forming an expression or statement that
152 /// replaces the original. In this case, we'll reuse mangling numbers from
153 /// existing lambdas.
154 bool ReplacingOriginal() { return false; }
155
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000156 /// Returns the location of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000157 /// information was not available elsewhere in the AST.
158 ///
Mike Stump11289f42009-09-09 15:08:12 +0000159 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// provide an alternative implementation that provides better location
161 /// information.
162 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000164 /// Returns the name of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// information was not available elsewhere in the AST.
166 ///
167 /// By default, returns an empty name. Subclasses can provide an alternative
168 /// implementation with a more precise name.
169 DeclarationName getBaseEntity() { return DeclarationName(); }
170
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000171 /// Sets the "base" location and entity when that
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// information is known based on another transformation.
173 ///
174 /// By default, the source location and entity are ignored. Subclasses can
175 /// override this function to provide a customized implementation.
176 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000178 /// RAII object that temporarily sets the base location and entity
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 /// used for reporting diagnostics in types.
180 class TemporaryBase {
181 TreeTransform &Self;
182 SourceLocation OldLocation;
183 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000184
Douglas Gregora16548e2009-08-11 05:31:07 +0000185 public:
186 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000187 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 OldLocation = Self.getDerived().getBaseLocation();
189 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000190
Douglas Gregora518d5b2011-01-25 17:51:48 +0000191 if (Location.isValid())
192 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000193 }
Mike Stump11289f42009-09-09 15:08:12 +0000194
Douglas Gregora16548e2009-08-11 05:31:07 +0000195 ~TemporaryBase() {
196 Self.getDerived().setBase(OldLocation, OldEntity);
197 }
198 };
Mike Stump11289f42009-09-09 15:08:12 +0000199
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000200 /// Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// transformed.
202 ///
203 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000204 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000205 /// not change. For example, template instantiation need not traverse
206 /// non-dependent types.
207 bool AlreadyTransformed(QualType T) {
208 return T.isNull();
209 }
210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000211 /// Determine whether the given call argument should be dropped, e.g.,
Douglas Gregord196a582009-12-14 19:27:10 +0000212 /// because it is a default argument.
213 ///
214 /// Subclasses can provide an alternative implementation of this routine to
215 /// determine which kinds of call arguments get dropped. By default,
216 /// CXXDefaultArgument nodes are dropped (prior to transformation).
217 bool DropCallArgument(Expr *E) {
218 return E->isDefaultArgument();
219 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000220
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000221 /// Determine whether we should expand a pack expansion with the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// given set of parameter packs into separate arguments by repeatedly
223 /// transforming the pattern.
224 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000225 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000226 /// Subclasses can override this routine to provide different behavior.
227 ///
228 /// \param EllipsisLoc The location of the ellipsis that identifies the
229 /// pack expansion.
230 ///
231 /// \param PatternRange The source range that covers the entire pattern of
232 /// the pack expansion.
233 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000234 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000235 /// pattern.
236 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000237 /// \param ShouldExpand Will be set to \c true if the transformer should
238 /// expand the corresponding pack expansions into separate arguments. When
239 /// set, \c NumExpansions must also be set.
240 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000241 /// \param RetainExpansion Whether the caller should add an unexpanded
242 /// pack expansion after all of the expanded arguments. This is used
243 /// when extending explicitly-specified template argument packs per
244 /// C++0x [temp.arg.explicit]p9.
245 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000246 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000247 /// the expanded form of the corresponding pack expansion. This is both an
248 /// input and an output parameter, which can be set by the caller if the
249 /// number of expansions is known a priori (e.g., due to a prior substitution)
250 /// and will be set by the callee when the number of expansions is known.
251 /// The callee must set this value when \c ShouldExpand is \c true; it may
252 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000254 /// \returns true if an error occurred (e.g., because the parameter packs
255 /// are to be instantiated with arguments of different lengths), false
256 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 /// must be set.
258 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
259 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000260 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000261 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000263 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000264 ShouldExpand = false;
265 return false;
266 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000267
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000268 /// "Forget" about the partially-substituted pack template argument,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000269 /// when performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 TemplateArgument ForgetPartiallySubstitutedPack() {
274 return TemplateArgument();
275 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000277 /// "Remember" the partially-substituted pack template argument
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000278 /// after performing an instantiation that must preserve the parameter pack
279 /// use.
280 ///
281 /// This routine is meant to be overridden by the template instantiator.
282 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000284 /// Note to the derived class when a function parameter pack is
Douglas Gregorf3010112011-01-07 16:43:16 +0000285 /// being expanded.
286 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000288 /// Transforms the given type into another type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000291 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000292 /// function. This is expensive, but we don't mind, because
293 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000294 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
296 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000297 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000298
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000299 /// Transforms the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000300 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000301 ///
John McCall550e0c22009-10-21 00:40:46 +0000302 /// By default, this routine transforms a type by delegating to the
303 /// appropriate TransformXXXType to build a new type. Subclasses
304 /// may override this function (to take over all type
305 /// transformations) or some set of the TransformXXXType functions
306 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000307 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000309 /// Transform the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000310 /// type, collecting location information in the given builder
311 /// as necessary.
312 ///
John McCall31f82722010-11-12 08:19:04 +0000313 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000315 /// Transform a type that is permitted to produce a
Richard Smithee579842017-01-30 20:39:26 +0000316 /// DeducedTemplateSpecializationType.
317 ///
318 /// This is used in the (relatively rare) contexts where it is acceptable
319 /// for transformation to produce a class template type with deduced
320 /// template arguments.
321 /// @{
322 QualType TransformTypeWithDeducedTST(QualType T);
323 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
324 /// @}
325
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000326 /// The reason why the value of a statement is not discarded, if any.
327 enum StmtDiscardKind {
328 SDK_Discarded,
329 SDK_NotDiscarded,
330 SDK_StmtExprResult,
331 };
332
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000333 /// Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000334 ///
Mike Stump11289f42009-09-09 15:08:12 +0000335 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000336 /// appropriate TransformXXXStmt function to transform a specific kind of
337 /// statement or the TransformExpr() function to transform an expression.
338 /// Subclasses may override this function to transform statements using some
339 /// other mechanism.
340 ///
341 /// \returns the transformed statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000342 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
Mike Stump11289f42009-09-09 15:08:12 +0000343
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000344 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000345 ///
346 /// By default, this routine transforms a statement by delegating to the
347 /// appropriate TransformOMPXXXClause function to transform a specific kind
348 /// of clause. Subclasses may override this function to transform statements
349 /// using some other mechanism.
350 ///
351 /// \returns the transformed OpenMP clause.
352 OMPClause *TransformOMPClause(OMPClause *S);
353
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000354 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000355 ///
356 /// By default, this routine transforms a statement by delegating to the
357 /// appropriate TransformXXXAttr function to transform a specific kind
358 /// of attribute. Subclasses may override this function to transform
359 /// attributed statements using some other mechanism.
360 ///
361 /// \returns the transformed attribute
362 const Attr *TransformAttr(const Attr *S);
363
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000364/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000365///
366/// Subclasses should override the transformation of attributes with a pragma
367/// spelling to transform expressions stored within the attribute.
368///
369/// \returns the transformed attribute.
370#define ATTR(X)
371#define PRAGMA_SPELLING_ATTR(X) \
372 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
373#include "clang/Basic/AttrList.inc"
374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000375 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000377 /// By default, this routine transforms an expression by delegating to the
378 /// appropriate TransformXXXExpr function to build a new expression.
379 /// Subclasses may override this function to transform expressions using some
380 /// other mechanism.
381 ///
382 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000383 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000385 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000386 ///
387 /// By default, this routine transforms an initializer by stripping off the
388 /// semantic nodes added by initialization, then passing the result to
389 /// TransformExpr or TransformExprs.
390 ///
391 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000392 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000393
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000394 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000395 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// This routine transforms a list of expressions by invoking
397 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000398 /// support for variadic templates by expanding any pack expansions (if the
399 /// derived class permits such expansion) along the way. When pack expansions
400 /// are present, the number of outputs may not equal the number of inputs.
401 ///
402 /// \param Inputs The set of expressions to be transformed.
403 ///
404 /// \param NumInputs The number of expressions in \c Inputs.
405 ///
406 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000407 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000408 /// be.
409 ///
410 /// \param Outputs The transformed input expressions will be added to this
411 /// vector.
412 ///
413 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
414 /// due to transformation.
415 ///
416 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000417 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000418 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000419 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000420
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000421 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 /// or expression.
423 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// By default, acts as the identity function on declarations, unless the
425 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000426 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 llvm::DenseMap<Decl *, Decl *>::iterator Known
429 = TransformedLocalDecls.find(D);
430 if (Known != TransformedLocalDecls.end())
431 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000432
433 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000435
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000436 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000437 ///
438 /// By default, this transforms the variable and expression and rebuilds
439 /// the condition.
440 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
441 Expr *Expr,
442 Sema::ConditionKind Kind);
443
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000444 /// Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000445 /// place them on the new declaration.
446 ///
447 /// By default, this operation does nothing. Subclasses may override this
448 /// behavior to transform attributes.
449 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000451 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000452 /// transformer.
453 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000454 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000455 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
456 /// the transformer itself has to transform the declarations. This routine
457 /// can be overridden by a subclass that keeps track of such mappings.
Richard Smithb2997f52019-05-21 20:10:50 +0000458 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) {
459 assert(New.size() == 1 &&
460 "must override transformedLocalDecl if performing pack expansion");
461 TransformedLocalDecls[Old] = New.front();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000462 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000463
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000464 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000465 ///
Mike Stump11289f42009-09-09 15:08:12 +0000466 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
469 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000470 }
Mike Stump11289f42009-09-09 15:08:12 +0000471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000472 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000473 /// nested-name-specifier in a member access expression.
474 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000475 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000476 /// identifier in a nested-name-specifier of a member access expression, e.g.,
477 /// the \c T in \c x->T::member
478 ///
479 /// By default, invokes TransformDecl() to transform the declaration.
480 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
482 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000483 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000484
Richard Smith151c4562016-12-20 21:35:28 +0000485 /// Transform the set of declarations in an OverloadExpr.
486 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
487 LookupResult &R);
488
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000489 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000490 /// information.
491 ///
492 /// By default, transforms all of the types and declarations within the
493 /// nested-name-specifier. Subclasses may override this function to provide
494 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000495 NestedNameSpecifierLoc
496 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
497 QualType ObjectType = QualType(),
498 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000499
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000500 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000501 ///
502 /// By default, transforms the types of conversion function, constructor,
503 /// and destructor names and then (if needed) rebuilds the declaration name.
504 /// Identifiers and selectors are returned unmodified. Sublcasses may
505 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000506 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000507 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000509 /// Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000510 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000511 /// \param SS The nested-name-specifier that qualifies the template
512 /// name. This nested-name-specifier must already have been transformed.
513 ///
514 /// \param Name The template name to transform.
515 ///
516 /// \param NameLoc The source location of the template name.
517 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000518 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000519 /// access expression, this is the type of the object whose member template
520 /// is being referenced.
521 ///
522 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
523 /// also refers to a name within the current (lexical) scope, this is the
524 /// declaration it refers to.
525 ///
526 /// By default, transforms the template name by transforming the declarations
527 /// and nested-name-specifiers that occur within the template name.
528 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000529 TemplateName
530 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
531 SourceLocation NameLoc,
532 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000533 NamedDecl *FirstQualifierInScope = nullptr,
534 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000535
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000536 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537 ///
Mike Stump11289f42009-09-09 15:08:12 +0000538 /// By default, this operation transforms the type, expression, or
539 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000540 /// new template argument from the transformed result. Subclasses may
541 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000542 ///
543 /// Returns true if there was an error.
544 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000545 TemplateArgumentLoc &Output,
546 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000547
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000548 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000549 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000550 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000551 /// in the input set using \c TransformTemplateArgument(), and appends
552 /// the transformed arguments to the output list.
553 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000554 /// Note that this overload of \c TransformTemplateArguments() is merely
555 /// a convenience function. Subclasses that wish to override this behavior
556 /// should override the iterator-based member template version.
557 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000558 /// \param Inputs The set of template arguments to be transformed.
559 ///
560 /// \param NumInputs The number of template arguments in \p Inputs.
561 ///
562 /// \param Outputs The set of transformed template arguments output by this
563 /// routine.
564 ///
565 /// Returns true if an error occurred.
566 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
567 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000568 TemplateArgumentListInfo &Outputs,
569 bool Uneval = false) {
570 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
571 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000572 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000573
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000574 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000575 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000576 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000577 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000578 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000579 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000580 /// \param First An iterator to the first template argument.
581 ///
582 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000583 ///
584 /// \param Outputs The set of transformed template arguments output by this
585 /// routine.
586 ///
587 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000588 template<typename InputIterator>
589 bool TransformTemplateArguments(InputIterator First,
590 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000591 TemplateArgumentListInfo &Outputs,
592 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000593
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000594 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000595 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
596 TemplateArgumentLoc &ArgLoc);
597
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000598 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000599 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
600 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000601 getDerived().getBaseLocation());
602 }
Mike Stump11289f42009-09-09 15:08:12 +0000603
John McCall550e0c22009-10-21 00:40:46 +0000604#define ABSTRACT_TYPELOC(CLASS, PARENT)
605#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000606 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000607#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000608
Richard Smith2e321552014-11-12 02:00:47 +0000609 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000610 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
611 FunctionProtoTypeLoc TL,
612 CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +0000613 Qualifiers ThisTypeQuals,
Richard Smith2e321552014-11-12 02:00:47 +0000614 Fn TransformExceptionSpec);
615
616 bool TransformExceptionSpec(SourceLocation Loc,
617 FunctionProtoType::ExceptionSpecInfo &ESI,
618 SmallVectorImpl<QualType> &Exceptions,
619 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000620
David Majnemerfad8f482013-10-15 09:33:02 +0000621 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000622
Chad Rosier1dcde962012-08-08 18:46:20 +0000623 QualType
John McCall31f82722010-11-12 08:19:04 +0000624 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
625 TemplateSpecializationTypeLoc TL,
626 TemplateName Template);
627
Chad Rosier1dcde962012-08-08 18:46:20 +0000628 QualType
John McCall31f82722010-11-12 08:19:04 +0000629 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
630 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000631 TemplateName Template,
632 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000633
Nico Weberc153d242014-07-28 00:02:09 +0000634 QualType TransformDependentTemplateSpecializationType(
635 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
636 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000638 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000639 /// given vectors.
640 ///
641 /// The result vectors should be kept in sync; null entries in the
642 /// variables vector are acceptable.
643 ///
644 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000645 bool TransformFunctionTypeParams(
646 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
647 const QualType *ParamTypes,
648 const FunctionProtoType::ExtParameterInfo *ParamInfos,
649 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
650 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000652 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000653 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000654 ///
655 /// \param indexAdjustment - A number to add to the parameter's
656 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000657 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000658 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000659 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000660 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000661
Richard Smith87346a12019-06-02 18:53:44 +0000662 /// Transform the body of a lambda-expression.
Richard Smith7bf8f6f2019-06-04 17:17:20 +0000663 StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
664 /// Alternative implementation of TransformLambdaBody that skips transforming
665 /// the body.
666 StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
Richard Smith87346a12019-06-02 18:53:44 +0000667
John McCall31f82722010-11-12 08:19:04 +0000668 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000669
John McCalldadc5752010-08-24 06:29:42 +0000670 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
671 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000672
Faisal Vali2cba1332013-10-23 06:44:28 +0000673 TemplateParameterList *TransformTemplateParameterList(
674 TemplateParameterList *TPL) {
675 return TPL;
676 }
677
Richard Smithdb2630f2012-10-21 03:28:35 +0000678 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000679
Richard Smithdb2630f2012-10-21 03:28:35 +0000680 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000681 bool IsAddressOfOperand,
682 TypeSourceInfo **RecoveryTSI);
683
684 ExprResult TransformParenDependentScopeDeclRefExpr(
685 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
686 TypeSourceInfo **RecoveryTSI);
687
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000688 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000689
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000690// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
691// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000692#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000693 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000694 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000695#define VALUESTMT(Node, Parent) \
696 LLVM_ATTRIBUTE_NOINLINE \
697 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000698#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000699 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000700 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000701#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000702#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000703
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000704#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000705 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000706 OMPClause *Transform ## Class(Class *S);
707#include "clang/Basic/OpenMPKinds.def"
708
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000709 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000710 ///
711 /// By default, this routine adds type qualifiers only to types that can
712 /// have qualifiers, and silently suppresses those qualifiers that are not
713 /// permitted. Subclasses may override this routine to provide different
714 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000715 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000716
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000717 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ///
719 /// By default, performs semantic analysis when building the pointer type.
720 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000721 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000723 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 ///
Mike Stump11289f42009-09-09 15:08:12 +0000725 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000726 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000727 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000729 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 ///
John McCall70dd5f62009-10-30 00:06:24 +0000731 /// By default, performs semantic analysis when building the
732 /// reference type. Subclasses may override this routine to provide
733 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ///
John McCall70dd5f62009-10-30 00:06:24 +0000735 /// \param LValue whether the type was written with an lvalue sigil
736 /// or an rvalue sigil.
737 QualType RebuildReferenceType(QualType ReferentType,
738 bool LValue,
739 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000741 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// class type it refers into.
743 ///
744 /// By default, performs semantic analysis when building the member pointer
745 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000746 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
747 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000748
Manman Rene6be26c2016-09-13 17:25:08 +0000749 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
750 SourceLocation ProtocolLAngleLoc,
751 ArrayRef<ObjCProtocolDecl *> Protocols,
752 ArrayRef<SourceLocation> ProtocolLocs,
753 SourceLocation ProtocolRAngleLoc);
754
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000755 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000756 ///
757 /// By default, performs semantic analysis when building the object type.
758 /// Subclasses may override this routine to provide different behavior.
759 QualType RebuildObjCObjectType(QualType BaseType,
760 SourceLocation Loc,
761 SourceLocation TypeArgsLAngleLoc,
762 ArrayRef<TypeSourceInfo *> TypeArgs,
763 SourceLocation TypeArgsRAngleLoc,
764 SourceLocation ProtocolLAngleLoc,
765 ArrayRef<ObjCProtocolDecl *> Protocols,
766 ArrayRef<SourceLocation> ProtocolLocs,
767 SourceLocation ProtocolRAngleLoc);
768
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000769 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000770 ///
771 /// By default, directly builds the pointer type, with no additional semantic
772 /// analysis.
773 QualType RebuildObjCObjectPointerType(QualType PointeeType,
774 SourceLocation Star);
775
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000776 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 /// modifier, size of the array (if known), size expression, and index type
778 /// qualifiers.
779 ///
780 /// By default, performs semantic analysis when building the array type.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 QualType RebuildArrayType(QualType ElementType,
784 ArrayType::ArraySizeModifier SizeMod,
785 const llvm::APInt *Size,
786 Expr *SizeExpr,
787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000789
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000790 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// modifier, (known) size of the array, and index type qualifiers.
792 ///
793 /// By default, performs semantic analysis when building the array type.
794 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000795 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 ArrayType::ArraySizeModifier SizeMod,
797 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000798 unsigned IndexTypeQuals,
799 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000801 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000802 /// modifier, and index type qualifiers.
803 ///
804 /// By default, performs semantic analysis when building the array type.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000806 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000808 unsigned IndexTypeQuals,
809 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000811 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000812 /// size modifier, size expression, and index type qualifiers.
813 ///
814 /// By default, performs semantic analysis when building the array type.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000818 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000819 unsigned IndexTypeQuals,
820 SourceRange BracketsRange);
821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000822 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000823 /// size modifier, size expression, and index type qualifiers.
824 ///
825 /// By default, performs semantic analysis when building the array type.
826 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000827 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000829 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 unsigned IndexTypeQuals,
831 SourceRange BracketsRange);
832
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000833 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834 /// number of elements.
835 ///
836 /// By default, performs semantic analysis when building the vector type.
837 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000838 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000839 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000840
Erich Keanef702b022018-07-13 19:46:04 +0000841 /// Build a new potentially dependently-sized extended vector type
842 /// given the element type and number of elements.
843 ///
844 /// By default, performs semantic analysis when building the vector type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
847 SourceLocation AttributeLoc,
848 VectorType::VectorKind);
849
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000850 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000851 /// number of elements.
852 ///
853 /// By default, performs semantic analysis when building the vector type.
854 /// Subclasses may override this routine to provide different behavior.
855 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
856 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000857
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000858 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// given the element type and number of elements.
860 ///
861 /// By default, performs semantic analysis when building the vector type.
862 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000863 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000864 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000865 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000867 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000868 /// type variable with the correct address space (retrieved from
869 /// AddrSpaceExpr) applied to it. The former will be returned in cases
870 /// where the address space remains dependent.
871 ///
872 /// By default, performs semantic analysis when building the type with address
873 /// space applied. Subclasses may override this routine to provide different
874 /// behavior.
875 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
876 Expr *AddrSpaceExpr,
877 SourceLocation AttributeLoc);
878
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000879 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000880 ///
881 /// By default, performs semantic analysis when building the function type.
882 /// Subclasses may override this routine to provide different behavior.
883 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000884 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000885 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000888 QualType RebuildFunctionNoProtoType(QualType ResultType);
889
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000890 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000891 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000892 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000893
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000894 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000895 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000896 return SemaRef.Context.getTypeDeclType(Typedef);
897 }
898
Leonard Chanc72aaf62019-05-07 03:20:17 +0000899 /// Build a new MacroDefined type.
900 QualType RebuildMacroQualifiedType(QualType T,
901 const IdentifierInfo *MacroII) {
902 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
903 }
904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000905 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000906 QualType RebuildRecordType(RecordDecl *Record) {
907 return SemaRef.Context.getTypeDeclType(Record);
908 }
909
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000910 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 QualType RebuildEnumType(EnumDecl *Enum) {
912 return SemaRef.Context.getTypeDeclType(Enum);
913 }
John McCallfcc33b02009-09-05 00:15:47 +0000914
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000915 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000916 ///
917 /// By default, performs semantic analysis when building the typeof type.
918 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000919 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000920
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000921 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000922 ///
923 /// By default, builds a new TypeOfType with the given underlying type.
924 QualType RebuildTypeOfType(QualType Underlying);
925
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000926 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000927 QualType RebuildUnaryTransformType(QualType BaseType,
928 UnaryTransformType::UTTKind UKind,
929 SourceLocation Loc);
930
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000931 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000932 ///
933 /// By default, performs semantic analysis when building the decltype type.
934 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000935 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000937 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000938 ///
939 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000940 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000941 // Note, IsDependent is always false here: we implicitly convert an 'auto'
942 // which has been deduced to a dependent type into an undeduced 'auto', so
943 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000944 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000945 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000946 }
947
Richard Smith600b5262017-01-26 20:40:47 +0000948 /// By default, builds a new DeducedTemplateSpecializationType with the given
949 /// deduced type.
950 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
951 QualType Deduced) {
952 return SemaRef.Context.getDeducedTemplateSpecializationType(
953 Template, Deduced, /*IsDependent*/ false);
954 }
955
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000956 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000957 ///
958 /// By default, performs semantic analysis when building the template
959 /// specialization type. Subclasses may override this routine to provide
960 /// different behavior.
961 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000962 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000963 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000964
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000965 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000966 ///
967 /// By default, builds a new ParenType type from the inner type.
968 /// Subclasses may override this routine to provide different behavior.
969 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000970 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000971 }
972
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000973 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000974 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000975 /// By default, builds a new ElaboratedType type from the keyword,
976 /// the nested-name-specifier and the named type.
977 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000978 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
979 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000980 NestedNameSpecifierLoc QualifierLoc,
981 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000982 return SemaRef.Context.getElaboratedType(Keyword,
983 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000984 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000985 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000986
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000987 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000988 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000989 /// By default, builds a new DependentNameType type from the
990 /// nested-name-specifier and the given type. Subclasses may override
991 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000992 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 ElaboratedTypeKeyword Keyword,
994 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000995 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000996 const IdentifierInfo *Name,
997 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000998 TemplateArgumentListInfo &Args,
999 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00001000 // Rebuild the template name.
1001 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +00001002 CXXScopeSpec SS;
1003 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +00001004 TemplateName InstName = getDerived().RebuildTemplateName(
1005 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1006 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +00001007
Douglas Gregora7a795b2011-03-01 20:11:18 +00001008 if (InstName.isNull())
1009 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001010
Douglas Gregora7a795b2011-03-01 20:11:18 +00001011 // If it's still dependent, make a dependent specialization.
1012 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +00001013 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1014 QualifierLoc.getNestedNameSpecifier(),
1015 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +00001016 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +00001017
Douglas Gregora7a795b2011-03-01 20:11:18 +00001018 // Otherwise, make an elaborated type wrapping a non-dependent
1019 // specialization.
1020 QualType T =
1021 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1022 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001023
Craig Topperc3ec1492014-05-26 06:22:03 +00001024 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001025 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001026
1027 return SemaRef.Context.getElaboratedType(Keyword,
1028 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001029 T);
1030 }
1031
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001032 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001033 ///
1034 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001035 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001036 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001037 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001038 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001039 NestedNameSpecifierLoc QualifierLoc,
1040 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001041 SourceLocation IdLoc,
1042 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001043 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001044 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001045
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001046 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001047 // If the name is still dependent, just build a new dependent name type.
1048 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001049 return SemaRef.Context.getDependentNameType(Keyword,
1050 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001051 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001052 }
1053
Richard Smithee579842017-01-30 20:39:26 +00001054 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1055 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1056 *Id, IdLoc);
1057 // If a dependent name resolves to a deduced template specialization type,
1058 // check that we're in one of the syntactic contexts permitting it.
1059 if (!DeducedTSTContext) {
1060 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1061 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1062 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1063 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1064 Deduced->getTemplateName())
1065 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1066 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1067 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1068 return QualType();
1069 }
1070 }
1071 return T;
1072 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001073
1074 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1075
Abramo Bagnarad7548482010-05-19 21:37:53 +00001076 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001077 // into a non-dependent elaborated-type-specifier. Find the tag we're
1078 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001079 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001080 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1081 if (!DC)
1082 return QualType();
1083
John McCallbf8c5192010-05-27 06:40:31 +00001084 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1085 return QualType();
1086
Craig Topperc3ec1492014-05-26 06:22:03 +00001087 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001088 SemaRef.LookupQualifiedName(Result, DC);
1089 switch (Result.getResultKind()) {
1090 case LookupResult::NotFound:
1091 case LookupResult::NotFoundInCurrentInstantiation:
1092 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001093
Douglas Gregore677daf2010-03-31 22:19:08 +00001094 case LookupResult::Found:
1095 Tag = Result.getAsSingle<TagDecl>();
1096 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001097
Douglas Gregore677daf2010-03-31 22:19:08 +00001098 case LookupResult::FoundOverloaded:
1099 case LookupResult::FoundUnresolvedValue:
1100 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001101
Douglas Gregore677daf2010-03-31 22:19:08 +00001102 case LookupResult::Ambiguous:
1103 // Let the LookupResult structure handle ambiguities.
1104 return QualType();
1105 }
1106
1107 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001108 // Check where the name exists but isn't a tag type and use that to emit
1109 // better diagnostics.
1110 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1111 SemaRef.LookupQualifiedName(Result, DC);
1112 switch (Result.getResultKind()) {
1113 case LookupResult::Found:
1114 case LookupResult::FoundOverloaded:
1115 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001116 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001117 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1118 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1119 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001120 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1121 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001122 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001123 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001124 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001125 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001126 break;
1127 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001128 return QualType();
1129 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001130
Richard Trieucaa33d32011-06-10 03:11:26 +00001131 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001132 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001133 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001134 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1135 return QualType();
1136 }
1137
1138 // Build the elaborated-type-specifier type.
1139 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001140 return SemaRef.Context.getElaboratedType(Keyword,
1141 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001142 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001145 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001146 ///
1147 /// By default, builds a new PackExpansionType type from the given pattern.
1148 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001149 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001150 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001151 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001152 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001153 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1154 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001155 }
1156
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001157 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001158 ///
1159 /// By default, performs semantic analysis when building the atomic type.
1160 /// Subclasses may override this routine to provide different behavior.
1161 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1162
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001163 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001164 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1165 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001166
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001167 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001168 /// indicating whether the "template" keyword was provided, and the template
1169 /// that the template name refers to.
1170 ///
1171 /// By default, builds the new template name directly. Subclasses may override
1172 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001173 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001174 bool TemplateKW,
1175 TemplateDecl *Template);
1176
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001177 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001178 /// name that is referred to as a template.
1179 ///
1180 /// By default, performs semantic analysis to determine whether the name can
1181 /// be resolved to a specific template, then builds the appropriate kind of
1182 /// template name. Subclasses may override this routine to provide different
1183 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001184 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001185 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001186 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001187 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001188 NamedDecl *FirstQualifierInScope,
1189 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001190
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001191 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001192 /// overloaded operator name that is referred to as a template.
1193 ///
1194 /// By default, performs semantic analysis to determine whether the name can
1195 /// be resolved to a specific template, then builds the appropriate kind of
1196 /// template name. Subclasses may override this routine to provide different
1197 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001198 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001199 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001200 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001201 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001202 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001203
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001204 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001205 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001206 ///
1207 /// By default, performs semantic analysis to determine whether the name can
1208 /// be resolved to a specific template, then builds the appropriate kind of
1209 /// template name. Subclasses may override this routine to provide different
1210 /// behavior.
1211 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1212 const TemplateArgument &ArgPack) {
1213 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1214 }
1215
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001216 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001220 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 MultiStmtArg Statements,
1222 SourceLocation RBraceLoc,
1223 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001224 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 IsStmtExpr);
1226 }
1227
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001228 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001232 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001233 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001234 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001235 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 ColonLoc);
1239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001241 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001246 getSema().ActOnCaseStmtBody(S, Body);
1247 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001250 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001254 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001256 Stmt *SubStmt) {
1257 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001258 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001261 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001265 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1266 SourceLocation ColonLoc, Stmt *SubStmt) {
1267 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001270 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001274 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1275 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001276 Stmt *SubStmt) {
1277 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1278 }
1279
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001280 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001284 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001285 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001286 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001287 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001288 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001291 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001292 ///
1293 /// By default, performs semantic analysis to build the new statement.
1294 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001295 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001296 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001297 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001300 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001305 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001306 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001307 }
1308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001309 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001313 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1314 Sema::ConditionResult Cond, Stmt *Body) {
1315 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001316 }
Mike Stump11289f42009-09-09 15:08:12 +00001317
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001318 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001322 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001323 SourceLocation WhileLoc, SourceLocation LParenLoc,
1324 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001325 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1326 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001327 }
1328
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001329 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 ///
1331 /// By default, performs semantic analysis to build the new statement.
1332 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001333 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001334 Stmt *Init, Sema::ConditionResult Cond,
1335 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1336 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001337 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001338 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001341 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001345 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1346 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001347 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001348 }
1349
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001350 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001355 SourceLocation StarLoc,
1356 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001357 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001358 }
Mike Stump11289f42009-09-09 15:08:12 +00001359
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001360 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001364 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001365 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001368 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001372 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001373 SourceLocation StartLoc, SourceLocation EndLoc) {
1374 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001375 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001376 }
Mike Stump11289f42009-09-09 15:08:12 +00001377
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001378 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001379 ///
1380 /// By default, performs semantic analysis to build the new statement.
1381 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001382 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1383 bool IsVolatile, unsigned NumOutputs,
1384 unsigned NumInputs, IdentifierInfo **Names,
1385 MultiExprArg Constraints, MultiExprArg Exprs,
1386 Expr *AsmString, MultiExprArg Clobbers,
Jennifer Yub8fee672019-06-03 15:57:25 +00001387 unsigned NumLabels,
Chad Rosierde70e0e2012-08-25 00:11:56 +00001388 SourceLocation RParenLoc) {
1389 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1390 NumInputs, Names, Constraints, Exprs,
Jennifer Yub8fee672019-06-03 15:57:25 +00001391 AsmString, Clobbers, NumLabels, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001392 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001393
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001394 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001395 ///
1396 /// By default, performs semantic analysis to build the new statement.
1397 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001398 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001399 ArrayRef<Token> AsmToks,
1400 StringRef AsmString,
1401 unsigned NumOutputs, unsigned NumInputs,
1402 ArrayRef<StringRef> Constraints,
1403 ArrayRef<StringRef> Clobbers,
1404 ArrayRef<Expr*> Exprs,
1405 SourceLocation EndLoc) {
1406 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1407 NumOutputs, NumInputs,
1408 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001409 }
1410
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001411 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001415 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1416 bool IsImplicit) {
1417 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001418 }
1419
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001420 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001424 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1425 bool IsImplicit) {
1426 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1427 }
1428
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001429 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1434 Expr *Result,
1435 UnresolvedLookupExpr *Lookup) {
1436 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001437 }
1438
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001439 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001440 ///
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
1443 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1444 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1445 }
1446
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001447 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1448 return getSema().BuildCoroutineBodyStmt(Args);
1449 }
1450
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001451 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001452 ///
1453 /// By default, performs semantic analysis to build the new statement.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001456 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001457 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001458 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001459 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001460 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001461 }
1462
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001463 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001464 ///
1465 /// By default, performs semantic analysis to build the new declaration.
1466 /// Subclasses may override this routine to provide different behavior.
1467 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1468 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001469 return getSema().BuildObjCExceptionDecl(TInfo, T,
1470 ExceptionDecl->getInnerLocStart(),
1471 ExceptionDecl->getLocation(),
1472 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001474
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001475 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001476 ///
1477 /// By default, performs semantic analysis to build the new statement.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001480 SourceLocation RParenLoc,
1481 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001482 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001483 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001484 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001485 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001486
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001487 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001488 ///
1489 /// By default, performs semantic analysis to build the new statement.
1490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001492 Stmt *Body) {
1493 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001495
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001496 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001501 Expr *Operand) {
1502 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001504
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001505 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001506 ///
1507 /// By default, performs semantic analysis to build the new statement.
1508 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001509 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001510 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001511 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001512 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001513 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001514 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001515 return getSema().ActOnOpenMPExecutableDirective(
1516 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001517 }
1518
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001519 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001520 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001521 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001522 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001523 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1524 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001525 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001526 SourceLocation NameModifierLoc,
1527 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001528 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001529 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1530 LParenLoc, NameModifierLoc, ColonLoc,
1531 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001532 }
1533
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001534 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001535 ///
1536 /// By default, performs semantic analysis to build the new OpenMP clause.
1537 /// Subclasses may override this routine to provide different behavior.
1538 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1539 SourceLocation LParenLoc,
1540 SourceLocation EndLoc) {
1541 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1542 EndLoc);
1543 }
1544
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001545 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001546 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001547 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001548 /// Subclasses may override this routine to provide different behavior.
1549 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1550 SourceLocation StartLoc,
1551 SourceLocation LParenLoc,
1552 SourceLocation EndLoc) {
1553 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1554 LParenLoc, EndLoc);
1555 }
1556
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001557 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001558 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001559 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001560 /// Subclasses may override this routine to provide different behavior.
1561 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1562 SourceLocation LParenLoc,
1563 SourceLocation EndLoc) {
1564 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1565 }
1566
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001567 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001568 ///
1569 /// By default, performs semantic analysis to build the new OpenMP clause.
1570 /// Subclasses may override this routine to provide different behavior.
1571 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
1573 SourceLocation EndLoc) {
1574 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1575 }
1576
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001577 /// Build a new OpenMP 'allocator' clause.
1578 ///
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
1582 SourceLocation LParenLoc,
1583 SourceLocation EndLoc) {
1584 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1585 }
1586
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001587 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001588 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001589 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001590 /// Subclasses may override this routine to provide different behavior.
1591 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1592 SourceLocation LParenLoc,
1593 SourceLocation EndLoc) {
1594 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1595 EndLoc);
1596 }
1597
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001598 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001599 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001600 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001601 /// Subclasses may override this routine to provide different behavior.
1602 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1603 SourceLocation KindKwLoc,
1604 SourceLocation StartLoc,
1605 SourceLocation LParenLoc,
1606 SourceLocation EndLoc) {
1607 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1608 StartLoc, LParenLoc, EndLoc);
1609 }
1610
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001611 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001612 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001613 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001614 /// Subclasses may override this routine to provide different behavior.
1615 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1616 SourceLocation KindKwLoc,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation EndLoc) {
1620 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1621 StartLoc, LParenLoc, EndLoc);
1622 }
1623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001624 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001625 ///
1626 /// By default, performs semantic analysis to build the new OpenMP clause.
1627 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001628 OMPClause *RebuildOMPScheduleClause(
1629 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1630 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1631 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1632 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001633 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001634 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1635 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001636 }
1637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001638 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001639 ///
1640 /// By default, performs semantic analysis to build the new OpenMP clause.
1641 /// Subclasses may override this routine to provide different behavior.
1642 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1643 SourceLocation EndLoc,
1644 SourceLocation LParenLoc, Expr *Num) {
1645 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1646 }
1647
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001648 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001649 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001650 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001651 /// Subclasses may override this routine to provide different behavior.
1652 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1653 SourceLocation StartLoc,
1654 SourceLocation LParenLoc,
1655 SourceLocation EndLoc) {
1656 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1657 EndLoc);
1658 }
1659
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001660 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001661 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001662 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001663 /// Subclasses may override this routine to provide different behavior.
1664 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1665 SourceLocation StartLoc,
1666 SourceLocation LParenLoc,
1667 SourceLocation EndLoc) {
1668 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1669 EndLoc);
1670 }
1671
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001672 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001673 ///
1674 /// By default, performs semantic analysis to build the new OpenMP clause.
1675 /// Subclasses may override this routine to provide different behavior.
1676 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1677 SourceLocation StartLoc,
1678 SourceLocation LParenLoc,
1679 SourceLocation EndLoc) {
1680 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1681 EndLoc);
1682 }
1683
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001684 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001685 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001686 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001687 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001688 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1689 SourceLocation StartLoc,
1690 SourceLocation LParenLoc,
1691 SourceLocation EndLoc) {
1692 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1693 EndLoc);
1694 }
1695
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001696 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001697 ///
1698 /// By default, performs semantic analysis to build the new statement.
1699 /// Subclasses may override this routine to provide different behavior.
1700 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1701 SourceLocation StartLoc,
1702 SourceLocation LParenLoc,
1703 SourceLocation ColonLoc,
1704 SourceLocation EndLoc,
1705 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001706 const DeclarationNameInfo &ReductionId,
1707 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001708 return getSema().ActOnOpenMPReductionClause(
1709 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001710 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001711 }
1712
Alexey Bataev169d96a2017-07-18 20:17:46 +00001713 /// Build a new OpenMP 'task_reduction' clause.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPTaskReductionClause(
1718 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1719 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1720 CXXScopeSpec &ReductionIdScopeSpec,
1721 const DeclarationNameInfo &ReductionId,
1722 ArrayRef<Expr *> UnresolvedReductions) {
1723 return getSema().ActOnOpenMPTaskReductionClause(
1724 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1725 ReductionId, UnresolvedReductions);
1726 }
1727
Alexey Bataevfa312f32017-07-21 18:48:21 +00001728 /// Build a new OpenMP 'in_reduction' clause.
1729 ///
1730 /// By default, performs semantic analysis to build the new statement.
1731 /// Subclasses may override this routine to provide different behavior.
1732 OMPClause *
1733 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1734 SourceLocation LParenLoc, SourceLocation ColonLoc,
1735 SourceLocation EndLoc,
1736 CXXScopeSpec &ReductionIdScopeSpec,
1737 const DeclarationNameInfo &ReductionId,
1738 ArrayRef<Expr *> UnresolvedReductions) {
1739 return getSema().ActOnOpenMPInReductionClause(
1740 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1741 ReductionId, UnresolvedReductions);
1742 }
1743
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001744 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001745 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001746 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001747 /// Subclasses may override this routine to provide different behavior.
1748 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1749 SourceLocation StartLoc,
1750 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001751 OpenMPLinearClauseKind Modifier,
1752 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001753 SourceLocation ColonLoc,
1754 SourceLocation EndLoc) {
1755 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001756 Modifier, ModifierLoc, ColonLoc,
1757 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001758 }
1759
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001760 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001761 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001762 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation ColonLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1770 LParenLoc, ColonLoc, EndLoc);
1771 }
1772
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001773 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001774 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001775 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001776 /// Subclasses may override this routine to provide different behavior.
1777 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1778 SourceLocation StartLoc,
1779 SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1782 EndLoc);
1783 }
1784
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001785 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001786 ///
1787 /// By default, performs semantic analysis to build the new OpenMP clause.
1788 /// Subclasses may override this routine to provide different behavior.
1789 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1790 SourceLocation StartLoc,
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001797 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1801 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1802 SourceLocation StartLoc,
1803 SourceLocation LParenLoc,
1804 SourceLocation EndLoc) {
1805 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1806 EndLoc);
1807 }
1808
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001809 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001810 ///
1811 /// By default, performs semantic analysis to build the new OpenMP clause.
1812 /// Subclasses may override this routine to provide different behavior.
1813 OMPClause *
1814 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1815 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1816 SourceLocation StartLoc, SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
1818 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1819 StartLoc, LParenLoc, EndLoc);
1820 }
1821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001822 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001823 ///
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1826 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1827 SourceLocation LParenLoc,
1828 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001829 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001830 EndLoc);
1831 }
1832
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001833 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001834 ///
1835 /// By default, performs semantic analysis to build the new OpenMP clause.
1836 /// Subclasses may override this routine to provide different behavior.
Michael Kruse4304e9d2019-02-19 16:38:20 +00001837 OMPClause *RebuildOMPMapClause(
1838 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1839 ArrayRef<SourceLocation> MapTypeModifiersLoc,
1840 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1841 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1842 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1843 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
Kelvin Lief579432018-12-18 22:18:41 +00001844 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001845 MapperIdScopeSpec, MapperId, MapType,
1846 IsMapTypeImplicit, MapLoc, ColonLoc,
1847 VarList, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001848 }
1849
Alexey Bataeve04483e2019-03-27 14:14:31 +00001850 /// Build a new OpenMP 'allocate' clause.
1851 ///
1852 /// By default, performs semantic analysis to build the new OpenMP clause.
1853 /// Subclasses may override this routine to provide different behavior.
1854 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
1855 SourceLocation StartLoc,
1856 SourceLocation LParenLoc,
1857 SourceLocation ColonLoc,
1858 SourceLocation EndLoc) {
1859 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1860 LParenLoc, ColonLoc, EndLoc);
1861 }
1862
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001863 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001864 ///
1865 /// By default, performs semantic analysis to build the new statement.
1866 /// Subclasses may override this routine to provide different behavior.
1867 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1868 SourceLocation LParenLoc,
1869 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001870 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001871 EndLoc);
1872 }
1873
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001874 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001875 ///
1876 /// By default, performs semantic analysis to build the new statement.
1877 /// Subclasses may override this routine to provide different behavior.
1878 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1879 SourceLocation StartLoc,
1880 SourceLocation LParenLoc,
1881 SourceLocation EndLoc) {
1882 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1883 LParenLoc, EndLoc);
1884 }
1885
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001886 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001887 ///
1888 /// By default, performs semantic analysis to build the new statement.
1889 /// Subclasses may override this routine to provide different behavior.
1890 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1893 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1894 EndLoc);
1895 }
1896
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001897 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001898 ///
1899 /// By default, performs semantic analysis to build the new statement.
1900 /// Subclasses may override this routine to provide different behavior.
1901 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1902 SourceLocation LParenLoc,
1903 SourceLocation EndLoc) {
1904 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1905 EndLoc);
1906 }
1907
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001908 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001909 ///
1910 /// By default, performs semantic analysis to build the new statement.
1911 /// Subclasses may override this routine to provide different behavior.
1912 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1913 SourceLocation LParenLoc,
1914 SourceLocation EndLoc) {
1915 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1916 EndLoc);
1917 }
1918
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001919 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001920 ///
1921 /// By default, performs semantic analysis to build the new statement.
1922 /// Subclasses may override this routine to provide different behavior.
1923 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1924 SourceLocation LParenLoc,
1925 SourceLocation EndLoc) {
1926 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1927 }
1928
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001929 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001930 ///
1931 /// By default, performs semantic analysis to build the new OpenMP clause.
1932 /// Subclasses may override this routine to provide different behavior.
1933 OMPClause *
1934 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1935 Expr *ChunkSize, SourceLocation StartLoc,
1936 SourceLocation LParenLoc, SourceLocation KindLoc,
1937 SourceLocation CommaLoc, SourceLocation EndLoc) {
1938 return getSema().ActOnOpenMPDistScheduleClause(
1939 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1940 }
1941
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001942 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001943 ///
1944 /// By default, performs semantic analysis to build the new statement.
1945 /// Subclasses may override this routine to provide different behavior.
1946 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
Michael Kruse01f670d2019-02-22 22:29:42 +00001947 CXXScopeSpec &MapperIdScopeSpec,
1948 DeclarationNameInfo &MapperId,
1949 const OMPVarListLocTy &Locs,
1950 ArrayRef<Expr *> UnresolvedMappers) {
1951 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1952 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00001953 }
1954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001955 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001956 ///
1957 /// By default, performs semantic analysis to build the new statement.
1958 /// Subclasses may override this routine to provide different behavior.
1959 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
Michael Kruse0336c752019-02-25 20:34:15 +00001960 CXXScopeSpec &MapperIdScopeSpec,
1961 DeclarationNameInfo &MapperId,
1962 const OMPVarListLocTy &Locs,
1963 ArrayRef<Expr *> UnresolvedMappers) {
1964 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1965 Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00001966 }
1967
Carlo Bertolli2404b172016-07-13 15:37:16 +00001968 /// Build a new OpenMP 'use_device_ptr' clause.
1969 ///
1970 /// By default, performs semantic analysis to build the new OpenMP clause.
1971 /// Subclasses may override this routine to provide different behavior.
1972 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001973 const OMPVarListLocTy &Locs) {
1974 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001975 }
1976
Carlo Bertolli70594e92016-07-13 17:16:49 +00001977 /// Build a new OpenMP 'is_device_ptr' clause.
1978 ///
1979 /// By default, performs semantic analysis to build the new OpenMP clause.
1980 /// Subclasses may override this routine to provide different behavior.
1981 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001982 const OMPVarListLocTy &Locs) {
1983 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001984 }
1985
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001986 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001987 ///
1988 /// By default, performs semantic analysis to build the new statement.
1989 /// Subclasses may override this routine to provide different behavior.
1990 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1991 Expr *object) {
1992 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1993 }
1994
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001995 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001996 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001997 /// By default, performs semantic analysis to build the new statement.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00002000 Expr *Object, Stmt *Body) {
2001 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00002002 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00002003
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002004 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00002005 ///
2006 /// By default, performs semantic analysis to build the new statement.
2007 /// Subclasses may override this routine to provide different behavior.
2008 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
2009 Stmt *Body) {
2010 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2011 }
John McCall53848232011-07-27 01:07:15 +00002012
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002013 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00002014 ///
2015 /// By default, performs semantic analysis to build the new statement.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002018 Stmt *Element,
2019 Expr *Collection,
2020 SourceLocation RParenLoc,
2021 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00002022 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002023 Element,
John McCallb268a282010-08-23 23:25:46 +00002024 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002025 RParenLoc);
2026 if (ForEachStmt.isInvalid())
2027 return StmtError();
2028
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002029 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00002030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002031
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002032 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00002033 ///
2034 /// By default, performs semantic analysis to build the new decaration.
2035 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00002036 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00002037 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00002038 SourceLocation StartLoc,
2039 SourceLocation IdLoc,
2040 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002041 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002042 StartLoc, IdLoc, Id);
2043 if (Var)
2044 getSema().CurContext->addDecl(Var);
2045 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002046 }
2047
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002048 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002049 ///
2050 /// By default, performs semantic analysis to build the new statement.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002053 VarDecl *ExceptionDecl,
2054 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002055 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2056 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002059 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002060 ///
2061 /// By default, performs semantic analysis to build the new statement.
2062 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002063 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2064 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002065 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002068 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002069 ///
2070 /// By default, performs semantic analysis to build the new statement.
2071 /// Subclasses may override this routine to provide different behavior.
2072 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002073 SourceLocation CoawaitLoc, Stmt *Init,
2074 SourceLocation ColonLoc, Stmt *Range,
2075 Stmt *Begin, Stmt *End, Expr *Cond,
2076 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002077 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002078 // If we've just learned that the range is actually an Objective-C
2079 // collection, treat this as an Objective-C fast enumeration loop.
2080 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2081 if (RangeStmt->isSingleDecl()) {
2082 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002083 if (RangeVar->isInvalidDecl())
2084 return StmtError();
2085
Douglas Gregorf7106af2013-04-08 18:40:13 +00002086 Expr *RangeExpr = RangeVar->getInit();
2087 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002088 RangeExpr->getType()->isObjCObjectPointerType()) {
2089 // FIXME: Support init-statements in Objective-C++20 ranged for
2090 // statement.
2091 if (Init) {
2092 return SemaRef.Diag(Init->getBeginLoc(),
2093 diag::err_objc_for_range_init_stmt)
2094 << Init->getSourceRange();
2095 }
2096 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2097 RangeExpr, RParenLoc);
2098 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002099 }
2100 }
2101 }
2102
Richard Smith8baa5002018-09-28 18:44:09 +00002103 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2104 Range, Begin, End, Cond, Inc, LoopVar,
2105 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002106 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002107
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002108 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002109 ///
2110 /// By default, performs semantic analysis to build the new statement.
2111 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002112 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002113 bool IsIfExists,
2114 NestedNameSpecifierLoc QualifierLoc,
2115 DeclarationNameInfo NameInfo,
2116 Stmt *Nested) {
2117 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2118 QualifierLoc, NameInfo, Nested);
2119 }
2120
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002121 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002122 ///
2123 /// By default, performs semantic analysis to finish the new statement.
2124 /// Subclasses may override this routine to provide different behavior.
2125 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2126 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002128
David Majnemerfad8f482013-10-15 09:33:02 +00002129 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002130 Stmt *TryBlock, Stmt *Handler) {
2131 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002132 }
2133
David Majnemerfad8f482013-10-15 09:33:02 +00002134 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002135 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002136 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002137 }
2138
David Majnemerfad8f482013-10-15 09:33:02 +00002139 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002140 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002141 }
2142
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002143 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002148 PredefinedExpr::IdentKind IK) {
2149 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002150 }
2151
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002152 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002157 LookupResult &R,
2158 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002159 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2160 }
2161
2162
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002163 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002167 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002168 ValueDecl *VD,
2169 const DeclarationNameInfo &NameInfo,
2170 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002171 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002172 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002173
2174 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002175
2176 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002179 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002180 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002185 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
2187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002188 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002189 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002193 SourceLocation OperatorLoc,
2194 bool isArrow,
2195 CXXScopeSpec &SS,
2196 TypeSourceInfo *ScopeType,
2197 SourceLocation CCLoc,
2198 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002199 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002201 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002202 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002206 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002207 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002208 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002211 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002216 TypeSourceInfo *Type,
2217 ArrayRef<Sema::OffsetOfComponent> Components,
2218 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002219 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002220 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002222
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002223 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002224 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002225 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002228 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2229 SourceLocation OpLoc,
2230 UnaryExprOrTypeTrait ExprKind,
2231 SourceRange R) {
2232 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002235 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002236 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002240 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2241 UnaryExprOrTypeTrait ExprKind,
2242 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002244 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002247
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 }
Mike Stump11289f42009-09-09 15:08:12 +00002250
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002251 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002252 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002255 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002259 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002260 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 RBracketLoc);
2262 }
2263
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002264 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2269 Expr *LowerBound,
2270 SourceLocation ColonLoc, Expr *Length,
2271 SourceLocation RBracketLoc) {
2272 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2273 ColonLoc, Length, RBracketLoc);
2274 }
2275
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002276 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002277 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// By default, performs semantic analysis to build the new expression.
2279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002280 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002282 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002283 Expr *ExecConfig = nullptr) {
Richard Smith255b85f2019-05-08 01:36:36 +00002284 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args,
2285 RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 }
2287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002288 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 /// By default, performs semantic analysis to build the new expression.
2291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002293 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002294 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002295 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002296 const DeclarationNameInfo &MemberNameInfo,
2297 ValueDecl *Member,
2298 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002299 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002300 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002301 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2302 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002303 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002304 // We have a reference to an unnamed field. This is always the
2305 // base of an anonymous struct/union member access, i.e. the
2306 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002307 assert(Member->getType()->isRecordType() &&
2308 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002309
Richard Smithcab9a7d2011-10-26 19:06:56 +00002310 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002311 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002312 QualifierLoc.getNestedNameSpecifier(),
2313 FoundDecl, Member);
2314 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002315 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002316 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002317
2318 CXXScopeSpec EmptySS;
2319 return getSema().BuildFieldReferenceExpr(
2320 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2321 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002324 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002325 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002326
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002327 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002328 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002329
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002330 if (isArrow && !BaseType->isPointerType())
2331 return ExprError();
2332
John McCall16df1e52010-03-30 21:47:33 +00002333 // FIXME: this involves duplicating earlier analysis in a lot of
2334 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002335 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002336 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002337 R.resolveKind();
2338
John McCallb268a282010-08-23 23:25:46 +00002339 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002340 SS, TemplateKWLoc,
2341 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002342 R, ExplicitTemplateArgs,
2343 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002346 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002347 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002351 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002353 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 }
2355
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002356 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002361 SourceLocation QuestionLoc,
2362 Expr *LHS,
2363 SourceLocation ColonLoc,
2364 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002365 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2366 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 }
2368
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002369 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002370 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002373 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002374 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002376 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002377 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002378 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 }
Mike Stump11289f42009-09-09 15:08:12 +00002380
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002381 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002382 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002385 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002386 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002388 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002389 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002390 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 }
Mike Stump11289f42009-09-09 15:08:12 +00002392
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002393 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002394 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 /// By default, performs semantic analysis to build the new expression.
2396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 SourceLocation OpLoc,
2399 SourceLocation AccessorLoc,
2400 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002401
John McCall10eae182009-11-30 22:42:35 +00002402 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002403 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002404 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002405 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002406 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002407 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002408 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002409 /* TemplateArgs */ nullptr,
2410 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 }
Mike Stump11289f42009-09-09 15:08:12 +00002412
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002413 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002414 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 /// By default, performs semantic analysis to build the new expression.
2416 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002417 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002418 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002419 SourceLocation RBraceLoc) {
2420 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
Mike Stump11289f42009-09-09 15:08:12 +00002422
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002423 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002424 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 MultiExprArg ArrayExprs,
2429 SourceLocation EqualOrColonLoc,
2430 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002431 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002434 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002437
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002438 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002441 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002442 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 /// By default, builds the implicit value initialization without performing
2444 /// any semantic analysis. Subclasses may override this routine to provide
2445 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002446 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002447 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002448 }
Mike Stump11289f42009-09-09 15:08:12 +00002449
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002450 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002451 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002454 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002455 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002456 SourceLocation RParenLoc) {
2457 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002458 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002459 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002462 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002463 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002466 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002467 MultiExprArg SubExprs,
2468 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002469 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 }
Mike Stump11289f42009-09-09 15:08:12 +00002471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002472 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002473 ///
2474 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 /// rather than attempting to map the label statement itself.
2476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002478 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002479 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 }
Mike Stump11289f42009-09-09 15:08:12 +00002481
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002482 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002483 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 /// By default, performs semantic analysis to build the new expression.
2485 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002486 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002487 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002489 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 }
Mike Stump11289f42009-09-09 15:08:12 +00002491
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002492 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002493 ///
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002496 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002497 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 SourceLocation RParenLoc) {
2499 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 RParenLoc);
2502 }
Mike Stump11289f42009-09-09 15:08:12 +00002503
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002504 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
2508 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2509 SourceLocation DefaultLoc,
2510 SourceLocation RParenLoc,
2511 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002512 ArrayRef<TypeSourceInfo *> Types,
2513 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002514 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002515 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002516 }
2517
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002518 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// The semantic analysis provides the behavior of template instantiation,
2522 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002523 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 /// argument-dependent lookup, etc. Subclasses may override this routine to
2525 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002527 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002528 Expr *Callee,
2529 Expr *First,
2530 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002531
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002532 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 /// reinterpret_cast.
2534 ///
2535 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002536 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002538 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 Stmt::StmtClass Class,
2540 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002541 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 SourceLocation RAngleLoc,
2543 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002544 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 SourceLocation RParenLoc) {
2546 switch (Class) {
2547 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002548 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002549 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002550 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002551
2552 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002553 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002554 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002555 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002556
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002558 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002559 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002560 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002562
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002564 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002565 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002566 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002569 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 }
Mike Stump11289f42009-09-09 15:08:12 +00002572
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002573 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 ///
2575 /// By default, performs semantic analysis to build the new expression.
2576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002577 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002578 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002579 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 SourceLocation RAngleLoc,
2581 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002582 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002584 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002585 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002586 SourceRange(LAngleLoc, RAngleLoc),
2587 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 }
2589
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002590 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 ///
2592 /// By default, performs semantic analysis to build the new expression.
2593 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002594 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002596 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002597 SourceLocation RAngleLoc,
2598 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002599 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002601 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002602 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002603 SourceRange(LAngleLoc, RAngleLoc),
2604 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 }
2606
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002607 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 ///
2609 /// By default, performs semantic analysis to build the new expression.
2610 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002611 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002613 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 SourceLocation RAngleLoc,
2615 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002616 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002618 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002619 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002620 SourceRange(LAngleLoc, RAngleLoc),
2621 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 }
2623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002624 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 ///
2626 /// By default, performs semantic analysis to build the new expression.
2627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002628 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002629 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002630 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002631 SourceLocation RAngleLoc,
2632 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002633 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002634 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002635 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002636 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002637 SourceRange(LAngleLoc, RAngleLoc),
2638 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 }
Mike Stump11289f42009-09-09 15:08:12 +00002640
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002641 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002645 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2646 SourceLocation LParenLoc,
2647 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002648 SourceLocation RParenLoc,
2649 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002650 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002651 MultiExprArg(&Sub, 1), RParenLoc,
2652 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 }
Mike Stump11289f42009-09-09 15:08:12 +00002654
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002655 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002656 ///
2657 /// By default, performs semantic analysis to build the new expression.
2658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002659 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002660 SourceLocation TypeidLoc,
2661 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002663 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002664 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 }
Mike Stump11289f42009-09-09 15:08:12 +00002666
Francois Pichet9f4f2072010-09-08 12:20:18 +00002667
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002668 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 ///
2670 /// By default, performs semantic analysis to build the new expression.
2671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002672 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002673 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002674 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002676 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002677 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002678 }
2679
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002680 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002681 ///
2682 /// By default, performs semantic analysis to build the new expression.
2683 /// Subclasses may override this routine to provide different behavior.
2684 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2685 SourceLocation TypeidLoc,
2686 TypeSourceInfo *Operand,
2687 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002688 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002689 RParenLoc);
2690 }
2691
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002692 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002693 ///
2694 /// By default, performs semantic analysis to build the new expression.
2695 /// Subclasses may override this routine to provide different behavior.
2696 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2697 SourceLocation TypeidLoc,
2698 Expr *Operand,
2699 SourceLocation RParenLoc) {
2700 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2701 RParenLoc);
2702 }
2703
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002704 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 ///
2706 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002707 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002708 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002709 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002710 QualType ThisType,
2711 bool isImplicit) {
Richard Smith8458c9e2019-05-24 01:35:07 +00002712 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002713 }
2714
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002715 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002716 ///
2717 /// By default, performs semantic analysis to build the new expression.
2718 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002719 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2720 bool IsThrownVariableInScope) {
2721 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002722 }
2723
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002724 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002725 ///
2726 /// By default, builds a new default-argument expression, which does not
2727 /// require any semantic analysis. Subclasses may override this routine to
2728 /// provide different behavior.
Eric Fiselier708afb52019-05-16 21:04:15 +00002729 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
2730 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2731 getSema().CurContext);
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 }
2733
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002734 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002735 ///
2736 /// By default, builds a new default field initialization expression, which
2737 /// does not require any semantic analysis. Subclasses may override this
2738 /// routine to provide different behavior.
2739 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2740 FieldDecl *Field) {
Eric Fiselier708afb52019-05-16 21:04:15 +00002741 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2742 getSema().CurContext);
Richard Smith852c9db2013-04-20 22:23:05 +00002743 }
2744
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002745 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002749 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2750 SourceLocation LParenLoc,
2751 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002752 return getSema().BuildCXXTypeConstructExpr(
2753 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002756 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002760 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002761 bool UseGlobal,
2762 SourceLocation PlacementLParen,
2763 MultiExprArg PlacementArgs,
2764 SourceLocation PlacementRParen,
2765 SourceRange TypeIdParens,
2766 QualType AllocatedType,
2767 TypeSourceInfo *AllocatedTypeInfo,
Richard Smithb9fb1212019-05-06 03:47:15 +00002768 Optional<Expr *> ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002769 SourceRange DirectInitRange,
2770 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002771 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002772 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002773 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002774 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002775 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002776 AllocatedType,
2777 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002778 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002779 DirectInitRange,
2780 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002781 }
Mike Stump11289f42009-09-09 15:08:12 +00002782
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002783 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002784 ///
2785 /// By default, performs semantic analysis to build the new expression.
2786 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002787 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002788 bool IsGlobalDelete,
2789 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002790 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002791 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002792 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002793 }
Mike Stump11289f42009-09-09 15:08:12 +00002794
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002795 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002796 ///
2797 /// By default, performs semantic analysis to build the new expression.
2798 /// Subclasses may override this routine to provide different behavior.
2799 ExprResult RebuildTypeTrait(TypeTrait Trait,
2800 SourceLocation StartLoc,
2801 ArrayRef<TypeSourceInfo *> Args,
2802 SourceLocation RParenLoc) {
2803 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2804 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002805
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002806 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002807 ///
2808 /// By default, performs semantic analysis to build the new expression.
2809 /// Subclasses may override this routine to provide different behavior.
2810 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2811 SourceLocation StartLoc,
2812 TypeSourceInfo *TSInfo,
2813 Expr *DimExpr,
2814 SourceLocation RParenLoc) {
2815 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2816 }
2817
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002818 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002819 ///
2820 /// By default, performs semantic analysis to build the new expression.
2821 /// Subclasses may override this routine to provide different behavior.
2822 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2823 SourceLocation StartLoc,
2824 Expr *Queried,
2825 SourceLocation RParenLoc) {
2826 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2827 }
2828
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002829 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002830 /// expression.
2831 ///
2832 /// By default, performs semantic analysis to build the new expression.
2833 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002834 ExprResult RebuildDependentScopeDeclRefExpr(
2835 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002836 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002837 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002838 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002839 bool IsAddressOfOperand,
2840 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002841 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002842 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002843
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002844 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002845 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2846 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002847
Reid Kleckner32506ed2014-06-12 23:03:48 +00002848 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002849 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002850 }
2851
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002852 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002853 ///
2854 /// By default, performs semantic analysis to build the new expression.
2855 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002856 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002857 SourceLocation TemplateKWLoc,
2858 LookupResult &R,
2859 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002860 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002861 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2862 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002863 }
2864
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002865 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002866 ///
2867 /// By default, performs semantic analysis to build the new expression.
2868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002869 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002870 SourceLocation Loc,
2871 CXXConstructorDecl *Constructor,
2872 bool IsElidable,
2873 MultiExprArg Args,
2874 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002875 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002876 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002877 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002878 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002879 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002880 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002881 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002882 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002883 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002884
Richard Smithc83bf822016-06-10 00:58:19 +00002885 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002886 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002887 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002888 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002889 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002890 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002891 RequiresZeroInit, ConstructKind,
2892 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002893 }
2894
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002895 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002896 /// expression.
2897 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2898 CXXConstructorDecl *Constructor,
2899 bool ConstructsVBase,
2900 bool InheritedFromVBase) {
2901 return new (getSema().Context) CXXInheritedCtorInitExpr(
2902 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2903 }
2904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002905 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002906 ///
2907 /// By default, performs semantic analysis to build the new expression.
2908 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002909 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002910 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002911 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002912 SourceLocation RParenOrBraceLoc,
2913 bool ListInitialization) {
2914 return getSema().BuildCXXTypeConstructExpr(
2915 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002916 }
2917
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002918 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002919 ///
2920 /// By default, performs semantic analysis to build the new expression.
2921 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002922 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2923 SourceLocation LParenLoc,
2924 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002925 SourceLocation RParenLoc,
2926 bool ListInitialization) {
2927 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2928 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002929 }
Mike Stump11289f42009-09-09 15:08:12 +00002930
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002931 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002932 ///
2933 /// By default, performs semantic analysis to build the new expression.
2934 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002935 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002936 QualType BaseType,
2937 bool IsArrow,
2938 SourceLocation OperatorLoc,
2939 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002940 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002941 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002942 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002943 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002944 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002945 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002946
John McCallb268a282010-08-23 23:25:46 +00002947 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002948 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002949 SS, TemplateKWLoc,
2950 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002951 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002952 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002953 }
2954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002955 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002956 ///
2957 /// By default, performs semantic analysis to build the new expression.
2958 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002959 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2960 SourceLocation OperatorLoc,
2961 bool IsArrow,
2962 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002963 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002964 NamedDecl *FirstQualifierInScope,
2965 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002966 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002967 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002968 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002969
John McCallb268a282010-08-23 23:25:46 +00002970 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002971 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002972 SS, TemplateKWLoc,
2973 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002974 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002975 }
Mike Stump11289f42009-09-09 15:08:12 +00002976
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002977 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002978 ///
2979 /// By default, performs semantic analysis to build the new expression.
2980 /// Subclasses may override this routine to provide different behavior.
2981 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2982 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2983 }
2984
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002985 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002986 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2987 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002988 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002989 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002990 Optional<unsigned> Length,
2991 ArrayRef<TemplateArgument> PartialArgs) {
2992 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2993 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002994 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002995
Eric Fiselier708afb52019-05-16 21:04:15 +00002996 /// Build a new expression representing a call to a source location
2997 /// builtin.
2998 ///
2999 /// By default, performs semantic analysis to build the new expression.
3000 /// Subclasses may override this routine to provide different behavior.
3001 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
3002 SourceLocation BuiltinLoc,
3003 SourceLocation RPLoc,
3004 DeclContext *ParentContext) {
3005 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3006 }
3007
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003008 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00003009 ///
3010 /// By default, performs semantic analysis to build the new expression.
3011 /// Subclasses may override this routine to provide different behavior.
3012 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
3013 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3014 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003015
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003016 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003017 ///
3018 /// By default, performs semantic analysis to build the new expression.
3019 /// Subclasses may override this routine to provide different behavior.
3020 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
3021 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003022 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003023 MultiExprArg(Elements, NumElements));
3024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003025
3026 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003027 Expr *Base, Expr *Key,
3028 ObjCMethodDecl *getterMethod,
3029 ObjCMethodDecl *setterMethod) {
3030 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3031 getterMethod, setterMethod);
3032 }
3033
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003034 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003035 ///
3036 /// By default, performs semantic analysis to build the new expression.
3037 /// Subclasses may override this routine to provide different behavior.
3038 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00003039 MutableArrayRef<ObjCDictionaryElement> Elements) {
3040 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00003041 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003042
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003043 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003044 ///
3045 /// By default, performs semantic analysis to build the new expression.
3046 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003047 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00003048 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00003049 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003050 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003051 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003052
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003053 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003054 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003055 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003056 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003057 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003058 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003059 MultiExprArg Args,
3060 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003061 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3062 ReceiverTypeInfo->getType(),
3063 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003064 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003065 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003066 }
3067
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003068 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003069 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003070 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003071 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003072 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003073 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003074 MultiExprArg Args,
3075 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003076 return SemaRef.BuildInstanceMessage(Receiver,
3077 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003078 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003079 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003080 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003081 }
3082
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003083 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003084 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3085 Selector Sel,
3086 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003087 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003088 ObjCMethodDecl *Method,
3089 SourceLocation LBracLoc,
3090 MultiExprArg Args,
3091 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003092 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003093 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003094 SuperLoc,
3095 Sel, Method, LBracLoc, SelectorLocs,
3096 RBracLoc, Args)
3097 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003098 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003099 SuperLoc,
3100 Sel, Method, LBracLoc, SelectorLocs,
3101 RBracLoc, Args);
3102
Fangrui Song6907ce22018-07-30 19:24:48 +00003103
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003104 }
3105
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003106 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003107 ///
3108 /// By default, performs semantic analysis to build the new expression.
3109 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003110 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003111 SourceLocation IvarLoc,
3112 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003113 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003114 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003115 ExprResult Result = getSema().BuildMemberReferenceExpr(
3116 BaseArg, BaseArg->getType(),
3117 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3118 /*FirstQualifierInScope=*/nullptr, NameInfo,
3119 /*TemplateArgs=*/nullptr,
3120 /*S=*/nullptr);
3121 if (IsFreeIvar && Result.isUsable())
3122 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3123 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003124 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003125
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003126 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003127 ///
3128 /// By default, performs semantic analysis to build the new expression.
3129 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003130 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003131 ObjCPropertyDecl *Property,
3132 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003133 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003134 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3135 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3136 /*FIXME:*/PropertyLoc,
3137 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003138 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003139 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003140 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003141 /*TemplateArgs=*/nullptr,
3142 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003143 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003144
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003145 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003146 ///
3147 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003148 /// Subclasses may override this routine to provide different behavior.
3149 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3150 ObjCMethodDecl *Getter,
3151 ObjCMethodDecl *Setter,
3152 SourceLocation PropertyLoc) {
3153 // Since these expressions can only be value-dependent, we do not
3154 // need to perform semantic analysis again.
3155 return Owned(
3156 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3157 VK_LValue, OK_ObjCProperty,
3158 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003159 }
3160
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003161 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003162 ///
3163 /// By default, performs semantic analysis to build the new expression.
3164 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003165 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003166 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003167 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003168 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3169 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003170 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003171 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003172 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003173 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003174 /*TemplateArgs=*/nullptr,
3175 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003178 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003179 ///
3180 /// By default, performs semantic analysis to build the new expression.
3181 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003182 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003183 MultiExprArg SubExprs,
3184 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003185 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003186 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003187 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3188 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3189 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003190 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003191
Douglas Gregora16548e2009-08-11 05:31:07 +00003192 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003193 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003194 Expr *Callee = new (SemaRef.Context)
3195 DeclRefExpr(SemaRef.Context, Builtin, false,
3196 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003197 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3198 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003199 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003200
3201 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003202 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003203 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003204 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003205
Douglas Gregora16548e2009-08-11 05:31:07 +00003206 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003207 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003208 }
John McCall31f82722010-11-12 08:19:04 +00003209
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003210 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003211 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3212 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3213 SourceLocation RParenLoc) {
3214 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3215 BuiltinLoc, RParenLoc);
3216 }
3217
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003218 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003219 ///
3220 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003221 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003222 /// different behavior.
3223 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003224 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003225 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003226 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003227 case TemplateArgument::Expression: {
3228 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003229 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3230 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003231 if (Result.isInvalid())
3232 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003233
Douglas Gregor98318c22011-01-03 21:37:45 +00003234 return TemplateArgumentLoc(Result.get(), Result.get());
3235 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003236
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003237 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003238 return TemplateArgumentLoc(TemplateArgument(
3239 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003240 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003241 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003242 Pattern.getTemplateNameLoc(),
3243 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003244
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003245 case TemplateArgument::Null:
3246 case TemplateArgument::Integral:
3247 case TemplateArgument::Declaration:
3248 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003249 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003250 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003251 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003253 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003254 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003255 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003256 EllipsisLoc,
3257 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003258 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3259 Expansion);
3260 break;
3261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003263 return TemplateArgumentLoc();
3264 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003266 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003267 ///
3268 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003269 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003270 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003271 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003272 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003273 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003274 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003275
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003276 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003277 ///
3278 /// By default, performs semantic analysis in order to build a new fold
3279 /// expression.
3280 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3281 BinaryOperatorKind Operator,
3282 SourceLocation EllipsisLoc, Expr *RHS,
Richard Smithc7214f62019-05-13 08:31:14 +00003283 SourceLocation RParenLoc,
3284 Optional<unsigned> NumExpansions) {
Richard Smith0f0af192014-11-08 05:07:16 +00003285 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
Richard Smithc7214f62019-05-13 08:31:14 +00003286 RHS, RParenLoc, NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +00003287 }
3288
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003289 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003290 ///
3291 /// By default, produces the fallback value for the fold-expression, or
3292 /// produce an error if there is no fallback value.
3293 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3294 BinaryOperatorKind Operator) {
3295 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3296 }
3297
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003298 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003299 ///
3300 /// By default, performs semantic analysis to build the new expression.
3301 /// Subclasses may override this routine to provide different behavior.
3302 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3303 MultiExprArg SubExprs,
3304 QualType RetTy,
3305 AtomicExpr::AtomicOp Op,
3306 SourceLocation RParenLoc) {
3307 // Just create the expression; there is not any interesting semantic
3308 // analysis here because we can't actually build an AtomicExpr until
3309 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003310 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003311 RParenLoc);
3312 }
3313
John McCall31f82722010-11-12 08:19:04 +00003314private:
Douglas Gregor14454802011-02-25 02:25:35 +00003315 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3316 QualType ObjectType,
3317 NamedDecl *FirstQualifierInScope,
3318 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003319
3320 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3321 QualType ObjectType,
3322 NamedDecl *FirstQualifierInScope,
3323 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003324
3325 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3326 NamedDecl *FirstQualifierInScope,
3327 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003328
3329 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3330 DependentNameTypeLoc TL,
3331 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003332};
Douglas Gregora16548e2009-08-11 05:31:07 +00003333
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003334template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003335StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003336 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003337 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003338
Douglas Gregorebe10102009-08-20 07:17:43 +00003339 switch (S->getStmtClass()) {
3340 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003343 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003344#define STMT(Node, Parent) \
3345 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003346#define VALUESTMT(Node, Parent) \
3347 case Stmt::Node##Class: \
3348 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003349#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003350#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003351#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregorebe10102009-08-20 07:17:43 +00003353 // Transform expressions by calling TransformExpr.
3354#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003355#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003356#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003357#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003358 {
John McCalldadc5752010-08-24 06:29:42 +00003359 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003360
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003361 if (SDK == SDK_StmtExprResult)
3362 E = getSema().ActOnStmtExprResult(E);
3363 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003364 }
Mike Stump11289f42009-09-09 15:08:12 +00003365 }
3366
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003367 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003368}
Mike Stump11289f42009-09-09 15:08:12 +00003369
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003370template<typename Derived>
3371OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3372 if (!S)
3373 return S;
3374
3375 switch (S->getClauseKind()) {
3376 default: break;
3377 // Transform individual clause nodes
3378#define OPENMP_CLAUSE(Name, Class) \
3379 case OMPC_ ## Name : \
3380 return getDerived().Transform ## Class(cast<Class>(S));
3381#include "clang/Basic/OpenMPKinds.def"
3382 }
3383
3384 return S;
3385}
3386
Mike Stump11289f42009-09-09 15:08:12 +00003387
Douglas Gregore922c772009-08-04 22:27:00 +00003388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003389ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003390 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003391 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003392
3393 switch (E->getStmtClass()) {
3394 case Stmt::NoStmtClass: break;
3395#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003396#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003397#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003398 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003399#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003400 }
3401
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003402 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003403}
3404
3405template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003406ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003407 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003408 // Initializers are instantiated like expressions, except that various outer
3409 // layers are stripped.
3410 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003411 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003412
Bill Wendling7c44da22018-10-31 03:48:47 +00003413 if (auto *FE = dyn_cast<FullExpr>(Init))
3414 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003415
Richard Smith410306b2016-12-12 02:53:20 +00003416 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3417 Init = AIL->getCommonExpr();
3418
Richard Smithe6ca4752013-05-30 22:40:16 +00003419 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3420 Init = MTE->GetTemporaryExpr();
3421
Richard Smithd59b8322012-12-19 01:39:02 +00003422 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3423 Init = Binder->getSubExpr();
3424
3425 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3426 Init = ICE->getSubExprAsWritten();
3427
Richard Smithcc1b96d2013-06-12 22:31:48 +00003428 if (CXXStdInitializerListExpr *ILE =
3429 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003430 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003431
Richard Smithc6abd962014-07-25 01:12:44 +00003432 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003433 // InitListExprs. Other forms of copy-initialization will be a no-op if
3434 // the initializer is already the right type.
3435 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003436 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003437 return getDerived().TransformExpr(Init);
3438
3439 // Revert value-initialization back to empty parens.
3440 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3441 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003442 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003443 Parens.getEnd());
3444 }
3445
3446 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3447 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003448 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003449 SourceLocation());
3450
3451 // Revert initialization by constructor back to a parenthesized or braced list
3452 // of expressions. Any other form of initializer can just be reused directly.
3453 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003454 return getDerived().TransformExpr(Init);
3455
Richard Smithf8adcdc2014-07-17 05:12:35 +00003456 // If the initialization implicitly converted an initializer list to a
3457 // std::initializer_list object, unwrap the std::initializer_list too.
3458 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003459 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003460
Richard Smith12938cf2018-09-26 04:36:55 +00003461 // Enter a list-init context if this was list initialization.
3462 EnterExpressionEvaluationContext Context(
3463 getSema(), EnterExpressionEvaluationContext::InitList,
3464 Construct->isListInitialization());
3465
Richard Smithd59b8322012-12-19 01:39:02 +00003466 SmallVector<Expr*, 8> NewArgs;
3467 bool ArgChanged = false;
3468 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003469 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003470 return ExprError();
3471
Richard Smithd1036122018-01-12 22:21:33 +00003472 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003473 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003474 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003475 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003476
Richard Smithd59b8322012-12-19 01:39:02 +00003477 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003478 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003479 if (Parens.isInvalid()) {
3480 // This was a variable declaration's initialization for which no initializer
3481 // was specified.
3482 assert(NewArgs.empty() &&
3483 "no parens or braces but have direct init with arguments?");
3484 return ExprEmpty();
3485 }
Richard Smithd59b8322012-12-19 01:39:02 +00003486 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3487 Parens.getEnd());
3488}
3489
3490template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003491bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003492 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003493 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003494 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003495 bool *ArgChanged) {
3496 for (unsigned I = 0; I != NumInputs; ++I) {
3497 // If requested, drop call arguments that need to be dropped.
3498 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3499 if (ArgChanged)
3500 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003501
Douglas Gregora3efea12011-01-03 19:04:46 +00003502 break;
3503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003504
Douglas Gregor968f23a2011-01-03 19:31:53 +00003505 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3506 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Chris Lattner01cf8db2011-07-20 06:58:45 +00003508 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003509 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3510 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregor968f23a2011-01-03 19:31:53 +00003512 // Determine whether the set of unexpanded parameter packs can and should
3513 // be expanded.
3514 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003515 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003516 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3517 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003518 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3519 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003520 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003521 Expand, RetainExpansion,
3522 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003523 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003524
Douglas Gregor968f23a2011-01-03 19:31:53 +00003525 if (!Expand) {
3526 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003527 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003528 // expansion.
3529 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3530 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3531 if (OutPattern.isInvalid())
3532 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003533
3534 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003535 Expansion->getEllipsisLoc(),
3536 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003537 if (Out.isInvalid())
3538 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003539
Douglas Gregor968f23a2011-01-03 19:31:53 +00003540 if (ArgChanged)
3541 *ArgChanged = true;
3542 Outputs.push_back(Out.get());
3543 continue;
3544 }
John McCall542e7c62011-07-06 07:30:07 +00003545
3546 // Record right away that the argument was changed. This needs
3547 // to happen even if the array expands to nothing.
3548 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor968f23a2011-01-03 19:31:53 +00003550 // The transform has determined that we should perform an elementwise
3551 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003552 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003553 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3554 ExprResult Out = getDerived().TransformExpr(Pattern);
3555 if (Out.isInvalid())
3556 return true;
3557
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003558 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003559 Out = getDerived().RebuildPackExpansion(
3560 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003561 if (Out.isInvalid())
3562 return true;
3563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Douglas Gregor968f23a2011-01-03 19:31:53 +00003565 Outputs.push_back(Out.get());
3566 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Richard Smith9467be42014-06-06 17:33:35 +00003568 // If we're supposed to retain a pack expansion, do so by temporarily
3569 // forgetting the partially-substituted parameter pack.
3570 if (RetainExpansion) {
3571 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3572
3573 ExprResult Out = getDerived().TransformExpr(Pattern);
3574 if (Out.isInvalid())
3575 return true;
3576
3577 Out = getDerived().RebuildPackExpansion(
3578 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3579 if (Out.isInvalid())
3580 return true;
3581
3582 Outputs.push_back(Out.get());
3583 }
3584
Douglas Gregor968f23a2011-01-03 19:31:53 +00003585 continue;
3586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Richard Smithd59b8322012-12-19 01:39:02 +00003588 ExprResult Result =
3589 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3590 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003591 if (Result.isInvalid())
3592 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregora3efea12011-01-03 19:04:46 +00003594 if (Result.get() != Inputs[I] && ArgChanged)
3595 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
3597 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003598 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregora3efea12011-01-03 19:04:46 +00003600 return false;
3601}
3602
Richard Smith03a4aa32016-06-23 19:02:52 +00003603template <typename Derived>
3604Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3605 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3606 if (Var) {
3607 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3608 getDerived().TransformDefinition(Var->getLocation(), Var));
3609
3610 if (!ConditionVar)
3611 return Sema::ConditionError();
3612
3613 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3614 }
3615
3616 if (Expr) {
3617 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3618
3619 if (CondExpr.isInvalid())
3620 return Sema::ConditionError();
3621
3622 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3623 }
3624
3625 return Sema::ConditionResult();
3626}
3627
Douglas Gregora3efea12011-01-03 19:04:46 +00003628template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003629NestedNameSpecifierLoc
3630TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3631 NestedNameSpecifierLoc NNS,
3632 QualType ObjectType,
3633 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003634 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003635 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003636 Qualifier = Qualifier.getPrefix())
3637 Qualifiers.push_back(Qualifier);
3638
3639 CXXScopeSpec SS;
3640 while (!Qualifiers.empty()) {
3641 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3642 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003643
Douglas Gregor14454802011-02-25 02:25:35 +00003644 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003645 case NestedNameSpecifier::Identifier: {
3646 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3647 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3648 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3649 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003650 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003651 }
Douglas Gregor14454802011-02-25 02:25:35 +00003652 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor14454802011-02-25 02:25:35 +00003654 case NestedNameSpecifier::Namespace: {
3655 NamespaceDecl *NS
3656 = cast_or_null<NamespaceDecl>(
3657 getDerived().TransformDecl(
3658 Q.getLocalBeginLoc(),
3659 QNNS->getAsNamespace()));
3660 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3661 break;
3662 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor14454802011-02-25 02:25:35 +00003664 case NestedNameSpecifier::NamespaceAlias: {
3665 NamespaceAliasDecl *Alias
3666 = cast_or_null<NamespaceAliasDecl>(
3667 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3668 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003669 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003670 Q.getLocalEndLoc());
3671 break;
3672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
Douglas Gregor14454802011-02-25 02:25:35 +00003674 case NestedNameSpecifier::Global:
3675 // There is no meaningful transformation that one could perform on the
3676 // global scope.
3677 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3678 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Nikola Smiljanic67860242014-09-26 00:28:20 +00003680 case NestedNameSpecifier::Super: {
3681 CXXRecordDecl *RD =
3682 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3683 SourceLocation(), QNNS->getAsRecordDecl()));
3684 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3685 break;
3686 }
3687
Douglas Gregor14454802011-02-25 02:25:35 +00003688 case NestedNameSpecifier::TypeSpecWithTemplate:
3689 case NestedNameSpecifier::TypeSpec: {
3690 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3691 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregor14454802011-02-25 02:25:35 +00003693 if (!TL)
3694 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003695
Douglas Gregor14454802011-02-25 02:25:35 +00003696 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003697 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003698 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003699 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003700 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003701 if (TL.getType()->isEnumeralType())
3702 SemaRef.Diag(TL.getBeginLoc(),
3703 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003704 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3705 Q.getLocalEndLoc());
3706 break;
3707 }
Richard Trieude756fb2011-05-07 01:36:37 +00003708 // If the nested-name-specifier is an invalid type def, don't emit an
3709 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003710 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3711 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003712 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003713 << TL.getType() << SS.getRange();
3714 }
Douglas Gregor14454802011-02-25 02:25:35 +00003715 return NestedNameSpecifierLoc();
3716 }
Douglas Gregore16af532011-02-28 18:50:33 +00003717 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Douglas Gregore16af532011-02-28 18:50:33 +00003719 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003720 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003721 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003722 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
Douglas Gregor14454802011-02-25 02:25:35 +00003724 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003725 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003726 !getDerived().AlwaysRebuild())
3727 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
3729 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003730 // nested-name-specifier, do so.
3731 if (SS.location_size() == NNS.getDataLength() &&
3732 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3733 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3734
3735 // Allocate new nested-name-specifier location information.
3736 return SS.getWithLocInContext(SemaRef.Context);
3737}
3738
3739template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003740DeclarationNameInfo
3741TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003742::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003743 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003744 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003745 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003746
3747 switch (Name.getNameKind()) {
3748 case DeclarationName::Identifier:
3749 case DeclarationName::ObjCZeroArgSelector:
3750 case DeclarationName::ObjCOneArgSelector:
3751 case DeclarationName::ObjCMultiArgSelector:
3752 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003753 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003754 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003755 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003756
Richard Smith35845152017-02-07 01:37:30 +00003757 case DeclarationName::CXXDeductionGuideName: {
3758 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3759 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3760 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3761 if (!NewTemplate)
3762 return DeclarationNameInfo();
3763
3764 DeclarationNameInfo NewNameInfo(NameInfo);
3765 NewNameInfo.setName(
3766 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3767 return NewNameInfo;
3768 }
3769
Douglas Gregorf816bd72009-09-03 22:13:48 +00003770 case DeclarationName::CXXConstructorName:
3771 case DeclarationName::CXXDestructorName:
3772 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003773 TypeSourceInfo *NewTInfo;
3774 CanQualType NewCanTy;
3775 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003776 NewTInfo = getDerived().TransformType(OldTInfo);
3777 if (!NewTInfo)
3778 return DeclarationNameInfo();
3779 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003780 }
3781 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003782 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003783 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003784 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003785 if (NewT.isNull())
3786 return DeclarationNameInfo();
3787 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3788 }
Mike Stump11289f42009-09-09 15:08:12 +00003789
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003790 DeclarationName NewName
3791 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3792 NewCanTy);
3793 DeclarationNameInfo NewNameInfo(NameInfo);
3794 NewNameInfo.setName(NewName);
3795 NewNameInfo.setNamedTypeInfo(NewTInfo);
3796 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003797 }
Mike Stump11289f42009-09-09 15:08:12 +00003798 }
3799
David Blaikie83d382b2011-09-23 05:06:16 +00003800 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003801}
3802
3803template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003804TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003805TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3806 TemplateName Name,
3807 SourceLocation NameLoc,
3808 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003809 NamedDecl *FirstQualifierInScope,
3810 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003811 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3812 TemplateDecl *Template = QTN->getTemplateDecl();
3813 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003814
Douglas Gregor9db53502011-03-02 18:07:45 +00003815 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003816 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003817 Template));
3818 if (!TransTemplate)
3819 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregor9db53502011-03-02 18:07:45 +00003821 if (!getDerived().AlwaysRebuild() &&
3822 SS.getScopeRep() == QTN->getQualifier() &&
3823 TransTemplate == Template)
3824 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003825
Douglas Gregor9db53502011-03-02 18:07:45 +00003826 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3827 TransTemplate);
3828 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003829
Douglas Gregor9db53502011-03-02 18:07:45 +00003830 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3831 if (SS.getScopeRep()) {
3832 // These apply to the scope specifier, not the template.
3833 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003834 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003835 }
3836
Douglas Gregor9db53502011-03-02 18:07:45 +00003837 if (!getDerived().AlwaysRebuild() &&
3838 SS.getScopeRep() == DTN->getQualifier() &&
3839 ObjectType.isNull())
3840 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003841
Richard Smith79810042018-05-11 02:43:08 +00003842 // FIXME: Preserve the location of the "template" keyword.
3843 SourceLocation TemplateKWLoc = NameLoc;
3844
Douglas Gregor9db53502011-03-02 18:07:45 +00003845 if (DTN->isIdentifier()) {
3846 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003847 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003848 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003849 NameLoc,
3850 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003851 FirstQualifierInScope,
3852 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003854
Richard Smith79810042018-05-11 02:43:08 +00003855 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3856 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003857 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor9db53502011-03-02 18:07:45 +00003860 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3861 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003862 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003863 Template));
3864 if (!TransTemplate)
3865 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003866
Douglas Gregor9db53502011-03-02 18:07:45 +00003867 if (!getDerived().AlwaysRebuild() &&
3868 TransTemplate == Template)
3869 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
Douglas Gregor9db53502011-03-02 18:07:45 +00003871 return TemplateName(TransTemplate);
3872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003873
Douglas Gregor9db53502011-03-02 18:07:45 +00003874 if (SubstTemplateTemplateParmPackStorage *SubstPack
3875 = Name.getAsSubstTemplateTemplateParmPack()) {
3876 TemplateTemplateParmDecl *TransParam
3877 = cast_or_null<TemplateTemplateParmDecl>(
3878 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3879 if (!TransParam)
3880 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003881
Douglas Gregor9db53502011-03-02 18:07:45 +00003882 if (!getDerived().AlwaysRebuild() &&
3883 TransParam == SubstPack->getParameterPack())
3884 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003885
3886 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003887 SubstPack->getArgumentPack());
3888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003889
Douglas Gregor9db53502011-03-02 18:07:45 +00003890 // These should be getting filtered out before they reach the AST.
3891 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003892}
3893
3894template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003895void TreeTransform<Derived>::InventTemplateArgumentLoc(
3896 const TemplateArgument &Arg,
3897 TemplateArgumentLoc &Output) {
3898 SourceLocation Loc = getDerived().getBaseLocation();
3899 switch (Arg.getKind()) {
3900 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003901 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003902 break;
3903
3904 case TemplateArgument::Type:
3905 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003906 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003907
John McCall0ad16662009-10-29 08:12:44 +00003908 break;
3909
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003910 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003911 case TemplateArgument::TemplateExpansion: {
3912 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003913 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003914 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3915 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3916 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3917 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003918
Douglas Gregor9d802122011-03-02 17:09:35 +00003919 if (Arg.getKind() == TemplateArgument::Template)
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);
3923 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003924 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003925 Builder.getWithLocInContext(SemaRef.Context),
3926 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003928 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003929 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003930
John McCall0ad16662009-10-29 08:12:44 +00003931 case TemplateArgument::Expression:
3932 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3933 break;
3934
3935 case TemplateArgument::Declaration:
3936 case TemplateArgument::Integral:
3937 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003938 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003939 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003940 break;
3941 }
3942}
3943
3944template<typename Derived>
3945bool TreeTransform<Derived>::TransformTemplateArgument(
3946 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003947 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003948 EnterExpressionEvaluationContext EEEC(
3949 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3950 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3951 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003952 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003953 switch (Arg.getKind()) {
3954 case TemplateArgument::Null:
3955 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003956 case TemplateArgument::Pack:
3957 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003958 case TemplateArgument::NullPtr:
3959 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregore922c772009-08-04 22:27:00 +00003961 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003962 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003963 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003964 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003965
3966 DI = getDerived().TransformType(DI);
3967 if (!DI) return true;
3968
3969 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3970 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003971 }
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003973 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003974 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3975 if (QualifierLoc) {
3976 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3977 if (!QualifierLoc)
3978 return true;
3979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003980
Douglas Gregordf846d12011-03-02 18:46:51 +00003981 CXXScopeSpec SS;
3982 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003983 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003984 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3985 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003986 if (Template.isNull())
3987 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003988
Douglas Gregor9d802122011-03-02 17:09:35 +00003989 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003990 Input.getTemplateNameLoc());
3991 return false;
3992 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003993
3994 case TemplateArgument::TemplateExpansion:
3995 llvm_unreachable("Caller should expand pack expansions");
3996
Douglas Gregore922c772009-08-04 22:27:00 +00003997 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003998 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003999 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00004000 getSema(), Uneval
4001 ? Sema::ExpressionEvaluationContext::Unevaluated
4002 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004003
John McCall0ad16662009-10-29 08:12:44 +00004004 Expr *InputExpr = Input.getSourceExpression();
4005 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4006
Chris Lattnercdb591a2011-04-25 20:37:58 +00004007 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004008 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00004009 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004010 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00004011 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004012 }
Douglas Gregore922c772009-08-04 22:27:00 +00004013 }
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregore922c772009-08-04 22:27:00 +00004015 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00004016 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00004017}
4018
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004019/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00004020/// for each of the template arguments in its underlying iterator.
4021template<typename Derived, typename InputIterator>
4022class TemplateArgumentLocInventIterator {
4023 TreeTransform<Derived> &Self;
4024 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00004025
Douglas Gregorfe921a72010-12-20 23:36:19 +00004026public:
4027 typedef TemplateArgumentLoc value_type;
4028 typedef TemplateArgumentLoc reference;
4029 typedef typename std::iterator_traits<InputIterator>::difference_type
4030 difference_type;
4031 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004032
Douglas Gregorfe921a72010-12-20 23:36:19 +00004033 class pointer {
4034 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregorfe921a72010-12-20 23:36:19 +00004036 public:
4037 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Douglas Gregorfe921a72010-12-20 23:36:19 +00004039 const TemplateArgumentLoc *operator->() const { return &Arg; }
4040 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004041
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00004042 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004043
Douglas Gregorfe921a72010-12-20 23:36:19 +00004044 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4045 InputIterator Iter)
4046 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004047
Douglas Gregorfe921a72010-12-20 23:36:19 +00004048 TemplateArgumentLocInventIterator &operator++() {
4049 ++Iter;
4050 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004051 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004052
Douglas Gregorfe921a72010-12-20 23:36:19 +00004053 TemplateArgumentLocInventIterator operator++(int) {
4054 TemplateArgumentLocInventIterator Old(*this);
4055 ++(*this);
4056 return Old;
4057 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004058
Douglas Gregorfe921a72010-12-20 23:36:19 +00004059 reference operator*() const {
4060 TemplateArgumentLoc Result;
4061 Self.InventTemplateArgumentLoc(*Iter, Result);
4062 return Result;
4063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
Douglas Gregorfe921a72010-12-20 23:36:19 +00004065 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004066
Douglas Gregorfe921a72010-12-20 23:36:19 +00004067 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4068 const TemplateArgumentLocInventIterator &Y) {
4069 return X.Iter == Y.Iter;
4070 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004071
Douglas Gregorfe921a72010-12-20 23:36:19 +00004072 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4073 const TemplateArgumentLocInventIterator &Y) {
4074 return X.Iter != Y.Iter;
4075 }
4076};
Chad Rosier1dcde962012-08-08 18:46:20 +00004077
Douglas Gregor42cafa82010-12-20 17:42:22 +00004078template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004079template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004080bool TreeTransform<Derived>::TransformTemplateArguments(
4081 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4082 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004083 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004084 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004085 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004086
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004087 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4088 // Unpack argument packs, which we translate them into separate
4089 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004090 // FIXME: We could do much better if we could guarantee that the
4091 // TemplateArgumentLocInfo for the pack expansion would be usable for
4092 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004093 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004094 TemplateArgument::pack_iterator>
4095 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004096 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004097 In.getArgument().pack_begin()),
4098 PackLocIterator(*this,
4099 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004100 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004101 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004103 continue;
4104 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004105
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004106 if (In.getArgument().isPackExpansion()) {
4107 // We have a pack expansion, for which we will be substituting into
4108 // the pattern.
4109 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004110 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004111 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004112 = getSema().getTemplateArgumentPackExpansionPattern(
4113 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004114
Chris Lattner01cf8db2011-07-20 06:58:45 +00004115 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004116 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4117 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004118
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004119 // Determine whether the set of unexpanded parameter packs can and should
4120 // be expanded.
4121 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004122 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004123 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004124 if (getDerived().TryExpandParameterPacks(Ellipsis,
4125 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004126 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004127 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004128 RetainExpansion,
4129 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004130 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004131
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004132 if (!Expand) {
4133 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004134 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004135 // expansion.
4136 TemplateArgumentLoc OutPattern;
4137 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004138 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004139 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004140
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004141 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4142 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004143 if (Out.getArgument().isNull())
4144 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004145
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004146 Outputs.addArgument(Out);
4147 continue;
4148 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004149
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004150 // The transform has determined that we should perform an elementwise
4151 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004152 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4154
Richard Smithd784e682015-09-23 21:41:42 +00004155 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004156 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004157
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004158 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004159 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4160 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004161 if (Out.getArgument().isNull())
4162 return true;
4163 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004164
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004165 Outputs.addArgument(Out);
4166 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004167
Douglas Gregor48d24112011-01-10 20:53:55 +00004168 // If we're supposed to retain a pack expansion, do so by temporarily
4169 // forgetting the partially-substituted parameter pack.
4170 if (RetainExpansion) {
4171 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
Richard Smithd784e682015-09-23 21:41:42 +00004173 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004174 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004175
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004176 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4177 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004178 if (Out.getArgument().isNull())
4179 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
Douglas Gregor48d24112011-01-10 20:53:55 +00004181 Outputs.addArgument(Out);
4182 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004183
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004184 continue;
4185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004186
4187 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004188 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004189 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004190
Douglas Gregor42cafa82010-12-20 17:42:22 +00004191 Outputs.addArgument(Out);
4192 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004193
Douglas Gregor42cafa82010-12-20 17:42:22 +00004194 return false;
4195
4196}
4197
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198//===----------------------------------------------------------------------===//
4199// Type transformation
4200//===----------------------------------------------------------------------===//
4201
4202template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004203QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004204 if (getDerived().AlreadyTransformed(T))
4205 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004206
John McCall550e0c22009-10-21 00:40:46 +00004207 // Temporary workaround. All of these transformations should
4208 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004209 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4210 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004211
John McCall31f82722010-11-12 08:19:04 +00004212 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004213
John McCall550e0c22009-10-21 00:40:46 +00004214 if (!NewDI)
4215 return QualType();
4216
4217 return NewDI->getType();
4218}
4219
4220template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004221TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004222 // Refine the base location to the type's location.
4223 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4224 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004225 if (getDerived().AlreadyTransformed(DI->getType()))
4226 return DI;
4227
4228 TypeLocBuilder TLB;
4229
4230 TypeLoc TL = DI->getTypeLoc();
4231 TLB.reserve(TL.getFullDataSize());
4232
John McCall31f82722010-11-12 08:19:04 +00004233 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004234 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004235 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004236
John McCallbcd03502009-12-07 02:54:59 +00004237 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004238}
4239
4240template<typename Derived>
4241QualType
John McCall31f82722010-11-12 08:19:04 +00004242TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004243 switch (T.getTypeLocClass()) {
4244#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004245#define TYPELOC(CLASS, PARENT) \
4246 case TypeLoc::CLASS: \
4247 return getDerived().Transform##CLASS##Type(TLB, \
4248 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004249#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004250 }
Mike Stump11289f42009-09-09 15:08:12 +00004251
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004252 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004253}
4254
Richard Smithee579842017-01-30 20:39:26 +00004255template<typename Derived>
4256QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4257 if (!isa<DependentNameType>(T))
4258 return TransformType(T);
4259
4260 if (getDerived().AlreadyTransformed(T))
4261 return T;
4262 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4263 getDerived().getBaseLocation());
4264 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4265 return NewDI ? NewDI->getType() : QualType();
4266}
4267
4268template<typename Derived>
4269TypeSourceInfo *
4270TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4271 if (!isa<DependentNameType>(DI->getType()))
4272 return TransformType(DI);
4273
4274 // Refine the base location to the type's location.
4275 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4276 getDerived().getBaseEntity());
4277 if (getDerived().AlreadyTransformed(DI->getType()))
4278 return DI;
4279
4280 TypeLocBuilder TLB;
4281
4282 TypeLoc TL = DI->getTypeLoc();
4283 TLB.reserve(TL.getFullDataSize());
4284
Richard Smithee579842017-01-30 20:39:26 +00004285 auto QTL = TL.getAs<QualifiedTypeLoc>();
4286 if (QTL)
4287 TL = QTL.getUnqualifiedLoc();
4288
4289 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4290
4291 QualType Result = getDerived().TransformDependentNameType(
4292 TLB, DNTL, /*DeducedTSTContext*/true);
4293 if (Result.isNull())
4294 return nullptr;
4295
4296 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004297 Result = getDerived().RebuildQualifiedType(Result, QTL);
4298 if (Result.isNull())
4299 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004300 TLB.TypeWasModifiedSafely(Result);
4301 }
4302
4303 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4304}
4305
John McCall550e0c22009-10-21 00:40:46 +00004306template<typename Derived>
4307QualType
4308TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004309 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004310 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004311 if (Result.isNull())
4312 return QualType();
4313
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004314 Result = getDerived().RebuildQualifiedType(Result, T);
4315
4316 if (Result.isNull())
4317 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004318
4319 // RebuildQualifiedType might have updated the type, but not in a way
4320 // that invalidates the TypeLoc. (There's no location information for
4321 // qualifiers.)
4322 TLB.TypeWasModifiedSafely(Result);
4323
4324 return Result;
4325}
4326
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004327template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004328QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004329 QualifiedTypeLoc TL) {
4330
4331 SourceLocation Loc = TL.getBeginLoc();
4332 Qualifiers Quals = TL.getType().getLocalQualifiers();
4333
4334 if (((T.getAddressSpace() != LangAS::Default &&
4335 Quals.getAddressSpace() != LangAS::Default)) &&
4336 T.getAddressSpace() != Quals.getAddressSpace()) {
4337 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4338 << TL.getType() << T;
4339 return QualType();
4340 }
4341
Richard Smithee579842017-01-30 20:39:26 +00004342 // C++ [dcl.fct]p7:
4343 // [When] adding cv-qualifications on top of the function type [...] the
4344 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004345 if (T->isFunctionType()) {
4346 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4347 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004348 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004349 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004350
Richard Smithee579842017-01-30 20:39:26 +00004351 // C++ [dcl.ref]p1:
4352 // when the cv-qualifiers are introduced through the use of a typedef-name
4353 // or decltype-specifier [...] the cv-qualifiers are ignored.
4354 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4355 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004356 if (T->isReferenceType()) {
4357 // The only qualifier that applies to a reference type is restrict.
4358 if (!Quals.hasRestrict())
4359 return T;
4360 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4361 }
Mike Stump11289f42009-09-09 15:08:12 +00004362
John McCall31168b02011-06-15 23:02:42 +00004363 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004364 // resulting type.
4365 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004366 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004367 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004368 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004369 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004370 // A lifetime qualifier applied to a substituted template parameter
4371 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004372 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004373 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004374 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004375 QualType Replacement = SubstTypeParam->getReplacementType();
4376 Qualifiers Qs = Replacement.getQualifiers();
4377 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004378 Replacement = SemaRef.Context.getQualifiedType(
4379 Replacement.getUnqualifiedType(), Qs);
4380 T = SemaRef.Context.getSubstTemplateTypeParmType(
4381 SubstTypeParam->getReplacedParameter(), Replacement);
4382 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004383 // 'auto' types behave the same way as template parameters.
4384 QualType Deduced = AutoTy->getDeducedType();
4385 Qualifiers Qs = Deduced.getQualifiers();
4386 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004387 Deduced =
4388 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4389 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4390 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004391 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004392 // Otherwise, complain about the addition of a qualifier to an
4393 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004394 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4395 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004396 Quals.removeObjCLifetime();
4397 }
4398 }
4399 }
John McCall550e0c22009-10-21 00:40:46 +00004400
Richard Smithee579842017-01-30 20:39:26 +00004401 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004402}
4403
Douglas Gregor14454802011-02-25 02:25:35 +00004404template<typename Derived>
4405TypeLoc
4406TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4407 QualType ObjectType,
4408 NamedDecl *UnqualLookup,
4409 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004410 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004411 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004412
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004413 TypeSourceInfo *TSI =
4414 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4415 if (TSI)
4416 return TSI->getTypeLoc();
4417 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004418}
4419
Douglas Gregor579c15f2011-03-02 18:32:08 +00004420template<typename Derived>
4421TypeSourceInfo *
4422TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4423 QualType ObjectType,
4424 NamedDecl *UnqualLookup,
4425 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004426 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004427 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004428
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004429 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4430 UnqualLookup, SS);
4431}
4432
4433template <typename Derived>
4434TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4435 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4436 CXXScopeSpec &SS) {
4437 QualType T = TL.getType();
4438 assert(!getDerived().AlreadyTransformed(T));
4439
Douglas Gregor579c15f2011-03-02 18:32:08 +00004440 TypeLocBuilder TLB;
4441 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004442
Douglas Gregor579c15f2011-03-02 18:32:08 +00004443 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004444 TemplateSpecializationTypeLoc SpecTL =
4445 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004446
Richard Smithfd3dae02017-01-20 00:20:39 +00004447 TemplateName Template = getDerived().TransformTemplateName(
4448 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4449 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004450 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004451 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
4453 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004454 Template);
4455 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004456 DependentTemplateSpecializationTypeLoc SpecTL =
4457 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004458
Douglas Gregor579c15f2011-03-02 18:32:08 +00004459 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004460 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004461 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004462 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004463 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004464 ObjectType, UnqualLookup,
4465 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004466 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004467 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004468
4469 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004470 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004471 Template,
4472 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004473 } else {
4474 // Nothing special needs to be done for these.
4475 Result = getDerived().TransformType(TLB, TL);
4476 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004477
4478 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004479 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004480
Douglas Gregor579c15f2011-03-02 18:32:08 +00004481 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4482}
4483
John McCall550e0c22009-10-21 00:40:46 +00004484template <class TyLoc> static inline
4485QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4486 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4487 NewT.setNameLoc(T.getNameLoc());
4488 return T.getType();
4489}
4490
John McCall550e0c22009-10-21 00:40:46 +00004491template<typename Derived>
4492QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004493 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004494 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4495 NewT.setBuiltinLoc(T.getBuiltinLoc());
4496 if (T.needsExtraLocalData())
4497 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4498 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004499}
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregord6ff3322009-08-04 16:50:30 +00004501template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004502QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004503 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004504 // FIXME: recurse?
4505 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
Reid Kleckner0503a872013-12-05 01:23:43 +00004508template <typename Derived>
4509QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4510 AdjustedTypeLoc TL) {
4511 // Adjustments applied during transformation are handled elsewhere.
4512 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4513}
4514
Douglas Gregord6ff3322009-08-04 16:50:30 +00004515template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004516QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4517 DecayedTypeLoc TL) {
4518 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4519 if (OriginalType.isNull())
4520 return QualType();
4521
4522 QualType Result = TL.getType();
4523 if (getDerived().AlwaysRebuild() ||
4524 OriginalType != TL.getOriginalLoc().getType())
4525 Result = SemaRef.Context.getDecayedType(OriginalType);
4526 TLB.push<DecayedTypeLoc>(Result);
4527 // Nothing to set for DecayedTypeLoc.
4528 return Result;
4529}
4530
4531template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004532QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004534 QualType PointeeType
4535 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004536 if (PointeeType.isNull())
4537 return QualType();
4538
4539 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004540 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004541 // A dependent pointer type 'T *' has is being transformed such
4542 // that an Objective-C class type is being replaced for 'T'. The
4543 // resulting pointer type is an ObjCObjectPointerType, not a
4544 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004545 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004546
John McCall8b07ec22010-05-15 11:32:37 +00004547 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4548 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004549 return Result;
4550 }
John McCall31f82722010-11-12 08:19:04 +00004551
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004552 if (getDerived().AlwaysRebuild() ||
4553 PointeeType != TL.getPointeeLoc().getType()) {
4554 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4555 if (Result.isNull())
4556 return QualType();
4557 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
John McCall31168b02011-06-15 23:02:42 +00004559 // Objective-C ARC can add lifetime qualifiers to the type that we're
4560 // pointing to.
4561 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004562
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004563 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4564 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004565 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004566}
Mike Stump11289f42009-09-09 15:08:12 +00004567
4568template<typename Derived>
4569QualType
John McCall550e0c22009-10-21 00:40:46 +00004570TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004571 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004572 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004573 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4574 if (PointeeType.isNull())
4575 return QualType();
4576
4577 QualType Result = TL.getType();
4578 if (getDerived().AlwaysRebuild() ||
4579 PointeeType != TL.getPointeeLoc().getType()) {
4580 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004581 TL.getSigilLoc());
4582 if (Result.isNull())
4583 return QualType();
4584 }
4585
Douglas Gregor049211a2010-04-22 16:50:51 +00004586 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004587 NewT.setSigilLoc(TL.getSigilLoc());
4588 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004589}
4590
John McCall70dd5f62009-10-30 00:06:24 +00004591/// Transforms a reference type. Note that somewhat paradoxically we
4592/// don't care whether the type itself is an l-value type or an r-value
4593/// type; we only care if the type was *written* as an l-value type
4594/// or an r-value type.
4595template<typename Derived>
4596QualType
4597TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004599 const ReferenceType *T = TL.getTypePtr();
4600
4601 // Note that this works with the pointee-as-written.
4602 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4603 if (PointeeType.isNull())
4604 return QualType();
4605
4606 QualType Result = TL.getType();
4607 if (getDerived().AlwaysRebuild() ||
4608 PointeeType != T->getPointeeTypeAsWritten()) {
4609 Result = getDerived().RebuildReferenceType(PointeeType,
4610 T->isSpelledAsLValue(),
4611 TL.getSigilLoc());
4612 if (Result.isNull())
4613 return QualType();
4614 }
4615
John McCall31168b02011-06-15 23:02:42 +00004616 // Objective-C ARC can add lifetime qualifiers to the type that we're
4617 // referring to.
4618 TLB.TypeWasModifiedSafely(
4619 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4620
John McCall70dd5f62009-10-30 00:06:24 +00004621 // r-value references can be rebuilt as l-value references.
4622 ReferenceTypeLoc NewTL;
4623 if (isa<LValueReferenceType>(Result))
4624 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4625 else
4626 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4627 NewTL.setSigilLoc(TL.getSigilLoc());
4628
4629 return Result;
4630}
4631
Mike Stump11289f42009-09-09 15:08:12 +00004632template<typename Derived>
4633QualType
John McCall550e0c22009-10-21 00:40:46 +00004634TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004635 LValueReferenceTypeLoc TL) {
4636 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004637}
4638
Mike Stump11289f42009-09-09 15:08:12 +00004639template<typename Derived>
4640QualType
John McCall550e0c22009-10-21 00:40:46 +00004641TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004642 RValueReferenceTypeLoc TL) {
4643 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004644}
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregord6ff3322009-08-04 16:50:30 +00004646template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004647QualType
John McCall550e0c22009-10-21 00:40:46 +00004648TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004649 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004650 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004651 if (PointeeType.isNull())
4652 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004653
Abramo Bagnara509357842011-03-05 14:42:21 +00004654 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004655 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004656 if (OldClsTInfo) {
4657 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4658 if (!NewClsTInfo)
4659 return QualType();
4660 }
4661
4662 const MemberPointerType *T = TL.getTypePtr();
4663 QualType OldClsType = QualType(T->getClass(), 0);
4664 QualType NewClsType;
4665 if (NewClsTInfo)
4666 NewClsType = NewClsTInfo->getType();
4667 else {
4668 NewClsType = getDerived().TransformType(OldClsType);
4669 if (NewClsType.isNull())
4670 return QualType();
4671 }
Mike Stump11289f42009-09-09 15:08:12 +00004672
John McCall550e0c22009-10-21 00:40:46 +00004673 QualType Result = TL.getType();
4674 if (getDerived().AlwaysRebuild() ||
4675 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004676 NewClsType != OldClsType) {
4677 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004678 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004679 if (Result.isNull())
4680 return QualType();
4681 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004682
Reid Kleckner0503a872013-12-05 01:23:43 +00004683 // If we had to adjust the pointee type when building a member pointer, make
4684 // sure to push TypeLoc info for it.
4685 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4686 if (MPT && PointeeType != MPT->getPointeeType()) {
4687 assert(isa<AdjustedType>(MPT->getPointeeType()));
4688 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4689 }
4690
John McCall550e0c22009-10-21 00:40:46 +00004691 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4692 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004693 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004694
4695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004696}
4697
Mike Stump11289f42009-09-09 15:08:12 +00004698template<typename Derived>
4699QualType
John McCall550e0c22009-10-21 00:40:46 +00004700TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004701 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004702 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004703 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004704 if (ElementType.isNull())
4705 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004706
John McCall550e0c22009-10-21 00:40:46 +00004707 QualType Result = TL.getType();
4708 if (getDerived().AlwaysRebuild() ||
4709 ElementType != T->getElementType()) {
4710 Result = getDerived().RebuildConstantArrayType(ElementType,
4711 T->getSizeModifier(),
4712 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004713 T->getIndexTypeCVRQualifiers(),
4714 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004715 if (Result.isNull())
4716 return QualType();
4717 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004718
4719 // We might have either a ConstantArrayType or a VariableArrayType now:
4720 // a ConstantArrayType is allowed to have an element type which is a
4721 // VariableArrayType if the type is dependent. Fortunately, all array
4722 // types have the same location layout.
4723 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004724 NewTL.setLBracketLoc(TL.getLBracketLoc());
4725 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004726
John McCall550e0c22009-10-21 00:40:46 +00004727 Expr *Size = TL.getSizeExpr();
4728 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004729 EnterExpressionEvaluationContext Unevaluated(
4730 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004731 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4732 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004733 }
4734 NewTL.setSizeExpr(Size);
4735
4736 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004737}
Mike Stump11289f42009-09-09 15:08:12 +00004738
Douglas Gregord6ff3322009-08-04 16:50:30 +00004739template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004740QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004741 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004742 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004743 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004744 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004745 if (ElementType.isNull())
4746 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004747
John McCall550e0c22009-10-21 00:40:46 +00004748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
4750 ElementType != T->getElementType()) {
4751 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004752 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004753 T->getIndexTypeCVRQualifiers(),
4754 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004755 if (Result.isNull())
4756 return QualType();
4757 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004758
John McCall550e0c22009-10-21 00:40:46 +00004759 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4760 NewTL.setLBracketLoc(TL.getLBracketLoc());
4761 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004762 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004763
4764 return Result;
4765}
4766
4767template<typename Derived>
4768QualType
4769TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004770 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004771 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004772 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4773 if (ElementType.isNull())
4774 return QualType();
4775
Tim Shenb34d0ef2017-02-14 23:46:37 +00004776 ExprResult SizeResult;
4777 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004778 EnterExpressionEvaluationContext Context(
4779 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004780 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4781 }
4782 if (SizeResult.isInvalid())
4783 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004784 SizeResult =
4785 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004786 if (SizeResult.isInvalid())
4787 return QualType();
4788
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004789 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004790
4791 QualType Result = TL.getType();
4792 if (getDerived().AlwaysRebuild() ||
4793 ElementType != T->getElementType() ||
4794 Size != T->getSizeExpr()) {
4795 Result = getDerived().RebuildVariableArrayType(ElementType,
4796 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004797 Size,
John McCall550e0c22009-10-21 00:40:46 +00004798 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004799 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004800 if (Result.isNull())
4801 return QualType();
4802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004803
Serge Pavlov774c6d02014-02-06 03:49:11 +00004804 // We might have constant size array now, but fortunately it has the same
4805 // location layout.
4806 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004807 NewTL.setLBracketLoc(TL.getLBracketLoc());
4808 NewTL.setRBracketLoc(TL.getRBracketLoc());
4809 NewTL.setSizeExpr(Size);
4810
4811 return Result;
4812}
4813
4814template<typename Derived>
4815QualType
4816TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004817 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004818 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004819 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4820 if (ElementType.isNull())
4821 return QualType();
4822
Richard Smith764d2fe2011-12-20 02:08:33 +00004823 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004824 EnterExpressionEvaluationContext Unevaluated(
4825 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004826
John McCall33ddac02011-01-19 10:06:00 +00004827 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4828 Expr *origSize = TL.getSizeExpr();
4829 if (!origSize) origSize = T->getSizeExpr();
4830
4831 ExprResult sizeResult
4832 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004833 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004834 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004835 return QualType();
4836
John McCall33ddac02011-01-19 10:06:00 +00004837 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004838
4839 QualType Result = TL.getType();
4840 if (getDerived().AlwaysRebuild() ||
4841 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004842 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004843 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4844 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004845 size,
John McCall550e0c22009-10-21 00:40:46 +00004846 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004847 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004848 if (Result.isNull())
4849 return QualType();
4850 }
John McCall550e0c22009-10-21 00:40:46 +00004851
4852 // We might have any sort of array type now, but fortunately they
4853 // all have the same location layout.
4854 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4855 NewTL.setLBracketLoc(TL.getLBracketLoc());
4856 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004857 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004858
4859 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Erich Keanef702b022018-07-13 19:46:04 +00004862template <typename Derived>
4863QualType TreeTransform<Derived>::TransformDependentVectorType(
4864 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4865 const DependentVectorType *T = TL.getTypePtr();
4866 QualType ElementType = getDerived().TransformType(T->getElementType());
4867 if (ElementType.isNull())
4868 return QualType();
4869
4870 EnterExpressionEvaluationContext Unevaluated(
4871 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4872
4873 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4874 Size = SemaRef.ActOnConstantExpression(Size);
4875 if (Size.isInvalid())
4876 return QualType();
4877
4878 QualType Result = TL.getType();
4879 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4880 Size.get() != T->getSizeExpr()) {
4881 Result = getDerived().RebuildDependentVectorType(
4882 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4883 if (Result.isNull())
4884 return QualType();
4885 }
4886
4887 // Result might be dependent or not.
4888 if (isa<DependentVectorType>(Result)) {
4889 DependentVectorTypeLoc NewTL =
4890 TLB.push<DependentVectorTypeLoc>(Result);
4891 NewTL.setNameLoc(TL.getNameLoc());
4892 } else {
4893 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4894 NewTL.setNameLoc(TL.getNameLoc());
4895 }
4896
4897 return Result;
4898}
4899
Mike Stump11289f42009-09-09 15:08:12 +00004900template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004901QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004902 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004903 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004904 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004905
4906 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004907 QualType ElementType = getDerived().TransformType(T->getElementType());
4908 if (ElementType.isNull())
4909 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Richard Smith764d2fe2011-12-20 02:08:33 +00004911 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004912 EnterExpressionEvaluationContext Unevaluated(
4913 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004914
John McCalldadc5752010-08-24 06:29:42 +00004915 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004916 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004917 if (Size.isInvalid())
4918 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004919
John McCall550e0c22009-10-21 00:40:46 +00004920 QualType Result = TL.getType();
4921 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004922 ElementType != T->getElementType() ||
4923 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004924 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004925 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004926 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004927 if (Result.isNull())
4928 return QualType();
4929 }
John McCall550e0c22009-10-21 00:40:46 +00004930
4931 // Result might be dependent or not.
4932 if (isa<DependentSizedExtVectorType>(Result)) {
4933 DependentSizedExtVectorTypeLoc NewTL
4934 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4935 NewTL.setNameLoc(TL.getNameLoc());
4936 } else {
4937 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4938 NewTL.setNameLoc(TL.getNameLoc());
4939 }
4940
4941 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004942}
Mike Stump11289f42009-09-09 15:08:12 +00004943
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004944template <typename Derived>
4945QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4946 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4947 const DependentAddressSpaceType *T = TL.getTypePtr();
4948
4949 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4950
4951 if (pointeeType.isNull())
4952 return QualType();
4953
4954 // Address spaces are constant expressions.
4955 EnterExpressionEvaluationContext Unevaluated(
4956 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4957
4958 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4959 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4960 if (AddrSpace.isInvalid())
4961 return QualType();
4962
4963 QualType Result = TL.getType();
4964 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4965 AddrSpace.get() != T->getAddrSpaceExpr()) {
4966 Result = getDerived().RebuildDependentAddressSpaceType(
4967 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4968 if (Result.isNull())
4969 return QualType();
4970 }
4971
4972 // Result might be dependent or not.
4973 if (isa<DependentAddressSpaceType>(Result)) {
4974 DependentAddressSpaceTypeLoc NewTL =
4975 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4976
4977 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4978 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4979 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4980
4981 } else {
4982 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4983 Result, getDerived().getBaseLocation());
4984 TransformType(TLB, DI->getTypeLoc());
4985 }
4986
4987 return Result;
4988}
4989
4990template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004991QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004992 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004993 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004994 QualType ElementType = getDerived().TransformType(T->getElementType());
4995 if (ElementType.isNull())
4996 return QualType();
4997
John McCall550e0c22009-10-21 00:40:46 +00004998 QualType Result = TL.getType();
4999 if (getDerived().AlwaysRebuild() ||
5000 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00005001 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00005002 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00005003 if (Result.isNull())
5004 return QualType();
5005 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005006
John McCall550e0c22009-10-21 00:40:46 +00005007 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5008 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005009
John McCall550e0c22009-10-21 00:40:46 +00005010 return Result;
5011}
5012
5013template<typename Derived>
5014QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005015 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005016 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005017 QualType ElementType = getDerived().TransformType(T->getElementType());
5018 if (ElementType.isNull())
5019 return QualType();
5020
5021 QualType Result = TL.getType();
5022 if (getDerived().AlwaysRebuild() ||
5023 ElementType != T->getElementType()) {
5024 Result = getDerived().RebuildExtVectorType(ElementType,
5025 T->getNumElements(),
5026 /*FIXME*/ SourceLocation());
5027 if (Result.isNull())
5028 return QualType();
5029 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005030
John McCall550e0c22009-10-21 00:40:46 +00005031 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5032 NewTL.setNameLoc(TL.getNameLoc());
5033
5034 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005035}
Mike Stump11289f42009-09-09 15:08:12 +00005036
David Blaikie05785d12013-02-20 22:23:23 +00005037template <typename Derived>
5038ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
5039 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5040 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00005041 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00005042 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005043
Douglas Gregor715e4612011-01-14 22:40:04 +00005044 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005045 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005046 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00005047 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005048 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
Douglas Gregor715e4612011-01-14 22:40:04 +00005050 TypeLocBuilder TLB;
5051 TypeLoc NewTL = OldDI->getTypeLoc();
5052 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005053
5054 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005055 OldExpansionTL.getPatternLoc());
5056 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005057 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005058
5059 Result = RebuildPackExpansionType(Result,
5060 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005061 OldExpansionTL.getEllipsisLoc(),
5062 NumExpansions);
5063 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005064 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005065
Douglas Gregor715e4612011-01-14 22:40:04 +00005066 PackExpansionTypeLoc NewExpansionTL
5067 = TLB.push<PackExpansionTypeLoc>(Result);
5068 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5069 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5070 } else
5071 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005072 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005073 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005074
John McCall8fb0d9d2011-05-01 22:35:37 +00005075 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005076 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005077
5078 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5079 OldParm->getDeclContext(),
5080 OldParm->getInnerLocStart(),
5081 OldParm->getLocation(),
5082 OldParm->getIdentifier(),
5083 NewDI->getType(),
5084 NewDI,
5085 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005086 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005087 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5088 OldParm->getFunctionScopeIndex() + indexAdjustment);
5089 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005090}
5091
David Majnemer59f77922016-06-24 04:05:48 +00005092template <typename Derived>
5093bool TreeTransform<Derived>::TransformFunctionTypeParams(
5094 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5095 const QualType *ParamTypes,
5096 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5097 SmallVectorImpl<QualType> &OutParamTypes,
5098 SmallVectorImpl<ParmVarDecl *> *PVars,
5099 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005100 int indexAdjustment = 0;
5101
David Majnemer59f77922016-06-24 04:05:48 +00005102 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005103 for (unsigned i = 0; i != NumParams; ++i) {
5104 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005105 assert(OldParm->getFunctionScopeIndex() == i);
5106
David Blaikie05785d12013-02-20 22:23:23 +00005107 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005108 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005109 if (OldParm->isParameterPack()) {
5110 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005111 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005112
Douglas Gregor5499af42011-01-05 23:12:31 +00005113 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005114 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005115 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005116 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5117 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005118 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5119
Douglas Gregor5499af42011-01-05 23:12:31 +00005120 // Determine whether we should expand the parameter packs.
5121 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005122 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005123 Optional<unsigned> OrigNumExpansions =
5124 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005125 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005126 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5127 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005128 Unexpanded,
5129 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005130 RetainExpansion,
5131 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005132 return true;
5133 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005134
Douglas Gregor5499af42011-01-05 23:12:31 +00005135 if (ShouldExpand) {
5136 // Expand the function parameter pack into multiple, separate
5137 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005138 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005139 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005140 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005141 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005142 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005143 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005144 OrigNumExpansions,
5145 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005146 if (!NewParm)
5147 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005148
John McCallc8e321d2016-03-01 02:09:25 +00005149 if (ParamInfos)
5150 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005151 OutParamTypes.push_back(NewParm->getType());
5152 if (PVars)
5153 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005154 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005155
5156 // If we're supposed to retain a pack expansion, do so by temporarily
5157 // forgetting the partially-substituted parameter pack.
5158 if (RetainExpansion) {
5159 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005160 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005161 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005162 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005163 OrigNumExpansions,
5164 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005165 if (!NewParm)
5166 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
John McCallc8e321d2016-03-01 02:09:25 +00005168 if (ParamInfos)
5169 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005170 OutParamTypes.push_back(NewParm->getType());
5171 if (PVars)
5172 PVars->push_back(NewParm);
5173 }
5174
John McCall8fb0d9d2011-05-01 22:35:37 +00005175 // The next parameter should have the same adjustment as the
5176 // last thing we pushed, but we post-incremented indexAdjustment
5177 // on every push. Also, if we push nothing, the adjustment should
5178 // go down by one.
5179 indexAdjustment--;
5180
Douglas Gregor5499af42011-01-05 23:12:31 +00005181 // We're done with the pack expansion.
5182 continue;
5183 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005184
5185 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005186 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005187 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5188 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005189 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005190 NumExpansions,
5191 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005192 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005193 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005194 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005195 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005196
John McCall58f10c32010-03-11 09:03:00 +00005197 if (!NewParm)
5198 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005199
John McCallc8e321d2016-03-01 02:09:25 +00005200 if (ParamInfos)
5201 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005202 OutParamTypes.push_back(NewParm->getType());
5203 if (PVars)
5204 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005205 continue;
5206 }
John McCall58f10c32010-03-11 09:03:00 +00005207
5208 // Deal with the possibility that we don't have a parameter
5209 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005210 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005211 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005212 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005213 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005214 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005215 = dyn_cast<PackExpansionType>(OldType)) {
5216 // We have a function parameter pack that may need to be expanded.
5217 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005218 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005219 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005220
Douglas Gregor5499af42011-01-05 23:12:31 +00005221 // Determine whether we should expand the parameter packs.
5222 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005223 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005224 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005225 Unexpanded,
5226 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005227 RetainExpansion,
5228 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005229 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005231
Douglas Gregor5499af42011-01-05 23:12:31 +00005232 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005233 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005234 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005235 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005236 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5237 QualType NewType = getDerived().TransformType(Pattern);
5238 if (NewType.isNull())
5239 return true;
John McCall58f10c32010-03-11 09:03:00 +00005240
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005241 if (NewType->containsUnexpandedParameterPack()) {
5242 NewType =
5243 getSema().getASTContext().getPackExpansionType(NewType, None);
5244
5245 if (NewType.isNull())
5246 return true;
5247 }
5248
John McCallc8e321d2016-03-01 02:09:25 +00005249 if (ParamInfos)
5250 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005251 OutParamTypes.push_back(NewType);
5252 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005253 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005254 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005255
Douglas Gregor5499af42011-01-05 23:12:31 +00005256 // We're done with the pack expansion.
5257 continue;
5258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005259
Douglas Gregor48d24112011-01-10 20:53:55 +00005260 // If we're supposed to retain a pack expansion, do so by temporarily
5261 // forgetting the partially-substituted parameter pack.
5262 if (RetainExpansion) {
5263 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5264 QualType NewType = getDerived().TransformType(Pattern);
5265 if (NewType.isNull())
5266 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005267
John McCallc8e321d2016-03-01 02:09:25 +00005268 if (ParamInfos)
5269 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005270 OutParamTypes.push_back(NewType);
5271 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005272 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005273 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005274
Chad Rosier1dcde962012-08-08 18:46:20 +00005275 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005276 // expansion.
5277 OldType = Expansion->getPattern();
5278 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005279 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5280 NewType = getDerived().TransformType(OldType);
5281 } else {
5282 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005284
Douglas Gregor5499af42011-01-05 23:12:31 +00005285 if (NewType.isNull())
5286 return true;
5287
5288 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005289 NewType = getSema().Context.getPackExpansionType(NewType,
5290 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005291
John McCallc8e321d2016-03-01 02:09:25 +00005292 if (ParamInfos)
5293 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005294 OutParamTypes.push_back(NewType);
5295 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005296 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005297 }
5298
John McCall8fb0d9d2011-05-01 22:35:37 +00005299#ifndef NDEBUG
5300 if (PVars) {
5301 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5302 if (ParmVarDecl *parm = (*PVars)[i])
5303 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005304 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005305#endif
5306
5307 return false;
5308}
John McCall58f10c32010-03-11 09:03:00 +00005309
5310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005311QualType
John McCall550e0c22009-10-21 00:40:46 +00005312TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005313 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005314 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005315 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005316 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005317 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005318 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5319 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5320 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005321 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005322}
5323
Richard Smith2e321552014-11-12 02:00:47 +00005324template<typename Derived> template<typename Fn>
5325QualType TreeTransform<Derived>::TransformFunctionProtoType(
5326 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005327 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005328
Douglas Gregor4afc2362010-08-31 00:26:14 +00005329 // Transform the parameters and return type.
5330 //
Richard Smithf623c962012-04-17 00:58:00 +00005331 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005332 // When the function has a trailing return type, we instantiate the
5333 // parameters before the return type, since the return type can then refer
5334 // to the parameters themselves (via decltype, sizeof, etc.).
5335 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005336 SmallVector<QualType, 4> ParamTypes;
5337 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005338 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005339 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005340
Douglas Gregor7fb25412010-10-01 18:44:50 +00005341 QualType ResultType;
5342
Richard Smith1226c602012-08-14 22:51:13 +00005343 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005344 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005345 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005346 TL.getTypePtr()->param_type_begin(),
5347 T->getExtParameterInfosOrNull(),
5348 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005349 return QualType();
5350
Douglas Gregor3024f072012-04-16 07:05:22 +00005351 {
5352 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005353 // If a declaration declares a member function or member function
5354 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005355 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005356 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005357 // declarator.
5358 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005359
Alp Toker42a16a62014-01-25 23:51:36 +00005360 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005361 if (ResultType.isNull())
5362 return QualType();
5363 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005364 }
5365 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005366 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005367 if (ResultType.isNull())
5368 return QualType();
5369
Anastasia Stulova6a4c3462018-11-29 14:11:15 +00005370 // Return type can not be qualified with an address space.
5371 if (ResultType.getAddressSpace() != LangAS::Default) {
5372 SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5373 diag::err_attribute_address_function_type);
5374 return QualType();
5375 }
5376
Alp Toker9cacbab2014-01-20 20:26:09 +00005377 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005378 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005379 TL.getTypePtr()->param_type_begin(),
5380 T->getExtParameterInfosOrNull(),
5381 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005382 return QualType();
5383 }
5384
Richard Smith2e321552014-11-12 02:00:47 +00005385 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5386
5387 bool EPIChanged = false;
5388 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5389 return QualType();
5390
John McCallc8e321d2016-03-01 02:09:25 +00005391 // Handle extended parameter information.
5392 if (auto NewExtParamInfos =
5393 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5394 if (!EPI.ExtParameterInfos ||
5395 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5396 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5397 EPIChanged = true;
5398 }
5399 EPI.ExtParameterInfos = NewExtParamInfos;
5400 } else if (EPI.ExtParameterInfos) {
5401 EPIChanged = true;
5402 EPI.ExtParameterInfos = nullptr;
5403 }
Richard Smithf623c962012-04-17 00:58:00 +00005404
John McCall550e0c22009-10-21 00:40:46 +00005405 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005406 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005407 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005408 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005409 if (Result.isNull())
5410 return QualType();
5411 }
Mike Stump11289f42009-09-09 15:08:12 +00005412
John McCall550e0c22009-10-21 00:40:46 +00005413 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005414 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005415 NewTL.setLParenLoc(TL.getLParenLoc());
5416 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005417 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005418 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005419 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5420 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005421
5422 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005423}
Mike Stump11289f42009-09-09 15:08:12 +00005424
Douglas Gregord6ff3322009-08-04 16:50:30 +00005425template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005426bool TreeTransform<Derived>::TransformExceptionSpec(
5427 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5428 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5429 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5430
5431 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005432 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005433 EnterExpressionEvaluationContext Unevaluated(
5434 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005435 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5436 if (NoexceptExpr.isInvalid())
5437 return true;
5438
Richard Smitheaf11ad2018-05-03 03:58:32 +00005439 ExceptionSpecificationType EST = ESI.Type;
5440 NoexceptExpr =
5441 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005442 if (NoexceptExpr.isInvalid())
5443 return true;
5444
Richard Smitheaf11ad2018-05-03 03:58:32 +00005445 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005446 Changed = true;
5447 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005448 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005449 }
5450
5451 if (ESI.Type != EST_Dynamic)
5452 return false;
5453
5454 // Instantiate a dynamic exception specification's type.
5455 for (QualType T : ESI.Exceptions) {
5456 if (const PackExpansionType *PackExpansion =
5457 T->getAs<PackExpansionType>()) {
5458 Changed = true;
5459
5460 // We have a pack expansion. Instantiate it.
5461 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5462 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5463 Unexpanded);
5464 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5465
5466 // Determine whether the set of unexpanded parameter packs can and
5467 // should
5468 // be expanded.
5469 bool Expand = false;
5470 bool RetainExpansion = false;
5471 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5472 // FIXME: Track the location of the ellipsis (and track source location
5473 // information for the types in the exception specification in general).
5474 if (getDerived().TryExpandParameterPacks(
5475 Loc, SourceRange(), Unexpanded, Expand,
5476 RetainExpansion, NumExpansions))
5477 return true;
5478
5479 if (!Expand) {
5480 // We can't expand this pack expansion into separate arguments yet;
5481 // just substitute into the pattern and create a new pack expansion
5482 // type.
5483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5484 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5485 if (U.isNull())
5486 return true;
5487
5488 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5489 Exceptions.push_back(U);
5490 continue;
5491 }
5492
5493 // Substitute into the pack expansion pattern for each slice of the
5494 // pack.
5495 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5496 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5497
5498 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5499 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5500 return true;
5501
5502 Exceptions.push_back(U);
5503 }
5504 } else {
5505 QualType U = getDerived().TransformType(T);
5506 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5507 return true;
5508 if (T != U)
5509 Changed = true;
5510
5511 Exceptions.push_back(U);
5512 }
5513 }
5514
5515 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005516 if (ESI.Exceptions.empty())
5517 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005518 return false;
5519}
5520
5521template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005522QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005523 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005524 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005525 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005526 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005527 if (ResultType.isNull())
5528 return QualType();
5529
5530 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005531 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005532 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5533
5534 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005535 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005536 NewTL.setLParenLoc(TL.getLParenLoc());
5537 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005538 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005539
5540 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005541}
Mike Stump11289f42009-09-09 15:08:12 +00005542
John McCallb96ec562009-12-04 22:46:56 +00005543template<typename Derived> QualType
5544TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005545 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005546 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005547 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005548 if (!D)
5549 return QualType();
5550
5551 QualType Result = TL.getType();
5552 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005553 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005554 if (Result.isNull())
5555 return QualType();
5556 }
5557
5558 // We might get an arbitrary type spec type back. We should at
5559 // least always get a type spec type, though.
5560 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5561 NewTL.setNameLoc(TL.getNameLoc());
5562
5563 return Result;
5564}
5565
Douglas Gregord6ff3322009-08-04 16:50:30 +00005566template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005567QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005568 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005569 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005570 TypedefNameDecl *Typedef
5571 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5572 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573 if (!Typedef)
5574 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005575
John McCall550e0c22009-10-21 00:40:46 +00005576 QualType Result = TL.getType();
5577 if (getDerived().AlwaysRebuild() ||
5578 Typedef != T->getDecl()) {
5579 Result = getDerived().RebuildTypedefType(Typedef);
5580 if (Result.isNull())
5581 return QualType();
5582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
John McCall550e0c22009-10-21 00:40:46 +00005584 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5585 NewTL.setNameLoc(TL.getNameLoc());
5586
5587 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005588}
Mike Stump11289f42009-09-09 15:08:12 +00005589
Douglas Gregord6ff3322009-08-04 16:50:30 +00005590template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005591QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005592 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005593 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005594 EnterExpressionEvaluationContext Unevaluated(
5595 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5596 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005597
John McCalldadc5752010-08-24 06:29:42 +00005598 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005599 if (E.isInvalid())
5600 return QualType();
5601
Eli Friedmane4f22df2012-02-29 04:03:55 +00005602 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5603 if (E.isInvalid())
5604 return QualType();
5605
John McCall550e0c22009-10-21 00:40:46 +00005606 QualType Result = TL.getType();
5607 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005608 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005609 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005610 if (Result.isNull())
5611 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005613 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005614
John McCall550e0c22009-10-21 00:40:46 +00005615 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005616 NewTL.setTypeofLoc(TL.getTypeofLoc());
5617 NewTL.setLParenLoc(TL.getLParenLoc());
5618 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005619
5620 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005621}
Mike Stump11289f42009-09-09 15:08:12 +00005622
5623template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005624QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005625 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005626 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5627 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5628 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005629 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005630
John McCall550e0c22009-10-21 00:40:46 +00005631 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005632 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5633 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005634 if (Result.isNull())
5635 return QualType();
5636 }
Mike Stump11289f42009-09-09 15:08:12 +00005637
John McCall550e0c22009-10-21 00:40:46 +00005638 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005639 NewTL.setTypeofLoc(TL.getTypeofLoc());
5640 NewTL.setLParenLoc(TL.getLParenLoc());
5641 NewTL.setRParenLoc(TL.getRParenLoc());
5642 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005643
5644 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005645}
Mike Stump11289f42009-09-09 15:08:12 +00005646
5647template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005648QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005649 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005650 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005651
Douglas Gregore922c772009-08-04 22:27:00 +00005652 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005653 EnterExpressionEvaluationContext Unevaluated(
5654 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005655 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005656
John McCalldadc5752010-08-24 06:29:42 +00005657 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005658 if (E.isInvalid())
5659 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005660
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005661 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005662 if (E.isInvalid())
5663 return QualType();
5664
John McCall550e0c22009-10-21 00:40:46 +00005665 QualType Result = TL.getType();
5666 if (getDerived().AlwaysRebuild() ||
5667 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005668 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005669 if (Result.isNull())
5670 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005671 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005672 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005673
John McCall550e0c22009-10-21 00:40:46 +00005674 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5675 NewTL.setNameLoc(TL.getNameLoc());
5676
5677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005678}
5679
5680template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005681QualType TreeTransform<Derived>::TransformUnaryTransformType(
5682 TypeLocBuilder &TLB,
5683 UnaryTransformTypeLoc TL) {
5684 QualType Result = TL.getType();
5685 if (Result->isDependentType()) {
5686 const UnaryTransformType *T = TL.getTypePtr();
5687 QualType NewBase =
5688 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5689 Result = getDerived().RebuildUnaryTransformType(NewBase,
5690 T->getUTTKind(),
5691 TL.getKWLoc());
5692 if (Result.isNull())
5693 return QualType();
5694 }
5695
5696 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5697 NewTL.setKWLoc(TL.getKWLoc());
5698 NewTL.setParensRange(TL.getParensRange());
5699 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5700 return Result;
5701}
5702
5703template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005704QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5705 AutoTypeLoc TL) {
5706 const AutoType *T = TL.getTypePtr();
5707 QualType OldDeduced = T->getDeducedType();
5708 QualType NewDeduced;
5709 if (!OldDeduced.isNull()) {
5710 NewDeduced = getDerived().TransformType(OldDeduced);
5711 if (NewDeduced.isNull())
5712 return QualType();
5713 }
5714
5715 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005716 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5717 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005718 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005719 if (Result.isNull())
5720 return QualType();
5721 }
5722
5723 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5724 NewTL.setNameLoc(TL.getNameLoc());
5725
5726 return Result;
5727}
5728
5729template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005730QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5731 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5732 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5733
5734 CXXScopeSpec SS;
5735 TemplateName TemplateName = getDerived().TransformTemplateName(
5736 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5737 if (TemplateName.isNull())
5738 return QualType();
5739
5740 QualType OldDeduced = T->getDeducedType();
5741 QualType NewDeduced;
5742 if (!OldDeduced.isNull()) {
5743 NewDeduced = getDerived().TransformType(OldDeduced);
5744 if (NewDeduced.isNull())
5745 return QualType();
5746 }
5747
5748 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5749 TemplateName, NewDeduced);
5750 if (Result.isNull())
5751 return QualType();
5752
5753 DeducedTemplateSpecializationTypeLoc NewTL =
5754 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5755 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5756
5757 return Result;
5758}
5759
5760template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005761QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005762 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005763 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005764 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005765 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5766 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005767 if (!Record)
5768 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005769
John McCall550e0c22009-10-21 00:40:46 +00005770 QualType Result = TL.getType();
5771 if (getDerived().AlwaysRebuild() ||
5772 Record != T->getDecl()) {
5773 Result = getDerived().RebuildRecordType(Record);
5774 if (Result.isNull())
5775 return QualType();
5776 }
Mike Stump11289f42009-09-09 15:08:12 +00005777
John McCall550e0c22009-10-21 00:40:46 +00005778 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5779 NewTL.setNameLoc(TL.getNameLoc());
5780
5781 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005782}
Mike Stump11289f42009-09-09 15:08:12 +00005783
5784template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005785QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005786 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005787 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005788 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005789 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5790 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005791 if (!Enum)
5792 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005793
John McCall550e0c22009-10-21 00:40:46 +00005794 QualType Result = TL.getType();
5795 if (getDerived().AlwaysRebuild() ||
5796 Enum != T->getDecl()) {
5797 Result = getDerived().RebuildEnumType(Enum);
5798 if (Result.isNull())
5799 return QualType();
5800 }
Mike Stump11289f42009-09-09 15:08:12 +00005801
John McCall550e0c22009-10-21 00:40:46 +00005802 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5803 NewTL.setNameLoc(TL.getNameLoc());
5804
5805 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005806}
John McCallfcc33b02009-09-05 00:15:47 +00005807
John McCalle78aac42010-03-10 03:28:59 +00005808template<typename Derived>
5809QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5810 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005811 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005812 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5813 TL.getTypePtr()->getDecl());
5814 if (!D) return QualType();
5815
5816 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5817 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5818 return T;
5819}
5820
Douglas Gregord6ff3322009-08-04 16:50:30 +00005821template<typename Derived>
5822QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005823 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005824 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005825 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005826}
5827
Mike Stump11289f42009-09-09 15:08:12 +00005828template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005829QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005830 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005831 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005832 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005833
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005834 // Substitute into the replacement type, which itself might involve something
5835 // that needs to be transformed. This only tends to occur with default
5836 // template arguments of template template parameters.
5837 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5838 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5839 if (Replacement.isNull())
5840 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005841
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005842 // Always canonicalize the replacement type.
5843 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5844 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005845 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005846 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005847
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005848 // Propagate type-source information.
5849 SubstTemplateTypeParmTypeLoc NewTL
5850 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5851 NewTL.setNameLoc(TL.getNameLoc());
5852 return Result;
5853
John McCallcebee162009-10-18 09:09:24 +00005854}
5855
5856template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005857QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5858 TypeLocBuilder &TLB,
5859 SubstTemplateTypeParmPackTypeLoc TL) {
5860 return TransformTypeSpecType(TLB, TL);
5861}
5862
5863template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005864QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005865 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005866 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005867 const TemplateSpecializationType *T = TL.getTypePtr();
5868
Douglas Gregordf846d12011-03-02 18:46:51 +00005869 // The nested-name-specifier never matters in a TemplateSpecializationType,
5870 // because we can't have a dependent nested-name-specifier anyway.
5871 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005872 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005873 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5874 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005875 if (Template.isNull())
5876 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005877
John McCall31f82722010-11-12 08:19:04 +00005878 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5879}
5880
Eli Friedman0dfb8892011-10-06 23:00:33 +00005881template<typename Derived>
5882QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5883 AtomicTypeLoc TL) {
5884 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5885 if (ValueType.isNull())
5886 return QualType();
5887
5888 QualType Result = TL.getType();
5889 if (getDerived().AlwaysRebuild() ||
5890 ValueType != TL.getValueLoc().getType()) {
5891 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5892 if (Result.isNull())
5893 return QualType();
5894 }
5895
5896 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5897 NewTL.setKWLoc(TL.getKWLoc());
5898 NewTL.setLParenLoc(TL.getLParenLoc());
5899 NewTL.setRParenLoc(TL.getRParenLoc());
5900
5901 return Result;
5902}
5903
Xiuli Pan9c14e282016-01-09 12:53:17 +00005904template <typename Derived>
5905QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5906 PipeTypeLoc TL) {
5907 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5908 if (ValueType.isNull())
5909 return QualType();
5910
5911 QualType Result = TL.getType();
5912 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005913 const PipeType *PT = Result->getAs<PipeType>();
5914 bool isReadPipe = PT->isReadOnly();
5915 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005916 if (Result.isNull())
5917 return QualType();
5918 }
5919
5920 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5921 NewTL.setKWLoc(TL.getKWLoc());
5922
5923 return Result;
5924}
5925
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005926 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005927 /// container that provides a \c getArgLoc() member function.
5928 ///
5929 /// This iterator is intended to be used with the iterator form of
5930 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5931 template<typename ArgLocContainer>
5932 class TemplateArgumentLocContainerIterator {
5933 ArgLocContainer *Container;
5934 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005935
Douglas Gregorfe921a72010-12-20 23:36:19 +00005936 public:
5937 typedef TemplateArgumentLoc value_type;
5938 typedef TemplateArgumentLoc reference;
5939 typedef int difference_type;
5940 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005941
Douglas Gregorfe921a72010-12-20 23:36:19 +00005942 class pointer {
5943 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005944
Douglas Gregorfe921a72010-12-20 23:36:19 +00005945 public:
5946 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005947
Douglas Gregorfe921a72010-12-20 23:36:19 +00005948 const TemplateArgumentLoc *operator->() const {
5949 return &Arg;
5950 }
5951 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005952
5953
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005954 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005955
Douglas Gregorfe921a72010-12-20 23:36:19 +00005956 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5957 unsigned Index)
5958 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregorfe921a72010-12-20 23:36:19 +00005960 TemplateArgumentLocContainerIterator &operator++() {
5961 ++Index;
5962 return *this;
5963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005964
Douglas Gregorfe921a72010-12-20 23:36:19 +00005965 TemplateArgumentLocContainerIterator operator++(int) {
5966 TemplateArgumentLocContainerIterator Old(*this);
5967 ++(*this);
5968 return Old;
5969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
Douglas Gregorfe921a72010-12-20 23:36:19 +00005971 TemplateArgumentLoc operator*() const {
5972 return Container->getArgLoc(Index);
5973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005974
Douglas Gregorfe921a72010-12-20 23:36:19 +00005975 pointer operator->() const {
5976 return pointer(Container->getArgLoc(Index));
5977 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005978
Douglas Gregorfe921a72010-12-20 23:36:19 +00005979 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005980 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005981 return X.Container == Y.Container && X.Index == Y.Index;
5982 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005983
Douglas Gregorfe921a72010-12-20 23:36:19 +00005984 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005985 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005986 return !(X == Y);
5987 }
5988 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005989
5990
John McCall31f82722010-11-12 08:19:04 +00005991template <typename Derived>
5992QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5993 TypeLocBuilder &TLB,
5994 TemplateSpecializationTypeLoc TL,
5995 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005996 TemplateArgumentListInfo NewTemplateArgs;
5997 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5998 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005999 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
6000 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006001 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00006002 ArgIterator(TL, TL.getNumArgs()),
6003 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00006004 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006005
John McCall0ad16662009-10-29 08:12:44 +00006006 // FIXME: maybe don't rebuild if all the template arguments are the same.
6007
6008 QualType Result =
6009 getDerived().RebuildTemplateSpecializationType(Template,
6010 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00006011 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00006012
6013 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00006014 // Specializations of template template parameters are represented as
6015 // TemplateSpecializationTypes, and substitution of type alias templates
6016 // within a dependent context can transform them into
6017 // DependentTemplateSpecializationTypes.
6018 if (isa<DependentTemplateSpecializationType>(Result)) {
6019 DependentTemplateSpecializationTypeLoc NewTL
6020 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006021 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006022 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006023 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006024 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006025 NewTL.setLAngleLoc(TL.getLAngleLoc());
6026 NewTL.setRAngleLoc(TL.getRAngleLoc());
6027 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6028 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6029 return Result;
6030 }
6031
John McCall0ad16662009-10-29 08:12:44 +00006032 TemplateSpecializationTypeLoc NewTL
6033 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006034 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00006035 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6036 NewTL.setLAngleLoc(TL.getLAngleLoc());
6037 NewTL.setRAngleLoc(TL.getRAngleLoc());
6038 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6039 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006040 }
Mike Stump11289f42009-09-09 15:08:12 +00006041
John McCall0ad16662009-10-29 08:12:44 +00006042 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006043}
Mike Stump11289f42009-09-09 15:08:12 +00006044
Douglas Gregor5a064722011-02-28 17:23:35 +00006045template <typename Derived>
6046QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6047 TypeLocBuilder &TLB,
6048 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00006049 TemplateName Template,
6050 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006051 TemplateArgumentListInfo NewTemplateArgs;
6052 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6053 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6054 typedef TemplateArgumentLocContainerIterator<
6055 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006056 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006057 ArgIterator(TL, TL.getNumArgs()),
6058 NewTemplateArgs))
6059 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006060
Douglas Gregor5a064722011-02-28 17:23:35 +00006061 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006062
Douglas Gregor5a064722011-02-28 17:23:35 +00006063 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6064 QualType Result
6065 = getSema().Context.getDependentTemplateSpecializationType(
6066 TL.getTypePtr()->getKeyword(),
6067 DTN->getQualifier(),
6068 DTN->getIdentifier(),
6069 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006070
Douglas Gregor5a064722011-02-28 17:23:35 +00006071 DependentTemplateSpecializationTypeLoc NewTL
6072 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006073 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006074 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006075 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006076 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006077 NewTL.setLAngleLoc(TL.getLAngleLoc());
6078 NewTL.setRAngleLoc(TL.getRAngleLoc());
6079 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6080 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6081 return Result;
6082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006083
6084 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006085 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006086 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006087 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Douglas Gregor5a064722011-02-28 17:23:35 +00006089 if (!Result.isNull()) {
6090 /// FIXME: Wrap this in an elaborated-type-specifier?
6091 TemplateSpecializationTypeLoc NewTL
6092 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006093 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006094 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006095 NewTL.setLAngleLoc(TL.getLAngleLoc());
6096 NewTL.setRAngleLoc(TL.getRAngleLoc());
6097 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6098 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6099 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006100
Douglas Gregor5a064722011-02-28 17:23:35 +00006101 return Result;
6102}
6103
Mike Stump11289f42009-09-09 15:08:12 +00006104template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006105QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006106TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006107 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006108 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006109
Douglas Gregor844cb502011-03-01 18:12:44 +00006110 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006111 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006112 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006113 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006114 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6115 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006116 return QualType();
6117 }
Mike Stump11289f42009-09-09 15:08:12 +00006118
John McCall31f82722010-11-12 08:19:04 +00006119 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6120 if (NamedT.isNull())
6121 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006122
Richard Smith3f1b5d02011-05-05 21:57:07 +00006123 // C++0x [dcl.type.elab]p2:
6124 // If the identifier resolves to a typedef-name or the simple-template-id
6125 // resolves to an alias template specialization, the
6126 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006127 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6128 if (const TemplateSpecializationType *TST =
6129 NamedT->getAs<TemplateSpecializationType>()) {
6130 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006131 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6132 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006133 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006134 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006135 << TAT << Sema::NTK_TypeAliasTemplate
6136 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006137 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6138 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006139 }
6140 }
6141
John McCall550e0c22009-10-21 00:40:46 +00006142 QualType Result = TL.getType();
6143 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006144 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006145 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006146 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006147 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006148 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006149 if (Result.isNull())
6150 return QualType();
6151 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006152
Abramo Bagnara6150c882010-05-11 21:36:43 +00006153 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006154 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006155 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006156 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006157}
Mike Stump11289f42009-09-09 15:08:12 +00006158
6159template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006160QualType TreeTransform<Derived>::TransformAttributedType(
6161 TypeLocBuilder &TLB,
6162 AttributedTypeLoc TL) {
6163 const AttributedType *oldType = TL.getTypePtr();
6164 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6165 if (modifiedType.isNull())
6166 return QualType();
6167
Richard Smithe43e2b32018-08-20 21:47:29 +00006168 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6169 const Attr *oldAttr = TL.getAttr();
6170 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6171 if (oldAttr && !newAttr)
6172 return QualType();
6173
John McCall81904512011-01-06 01:58:22 +00006174 QualType result = TL.getType();
6175
6176 // FIXME: dependent operand expressions?
6177 if (getDerived().AlwaysRebuild() ||
6178 modifiedType != oldType->getModifiedType()) {
6179 // TODO: this is really lame; we should really be rebuilding the
6180 // equivalent type from first principles.
6181 QualType equivalentType
6182 = getDerived().TransformType(oldType->getEquivalentType());
6183 if (equivalentType.isNull())
6184 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006185
6186 // Check whether we can add nullability; it is only represented as
6187 // type sugar, and therefore cannot be diagnosed in any other way.
6188 if (auto nullability = oldType->getImmediateNullability()) {
6189 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006190 SemaRef.Diag(TL.getAttr()->getLocation(),
6191 diag::err_nullability_nonpointer)
6192 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006193 return QualType();
6194 }
6195 }
6196
Richard Smithe43e2b32018-08-20 21:47:29 +00006197 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006198 modifiedType,
6199 equivalentType);
6200 }
6201
6202 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006203 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006204 return result;
6205}
6206
6207template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006208QualType
6209TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6210 ParenTypeLoc TL) {
6211 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6212 if (Inner.isNull())
6213 return QualType();
6214
6215 QualType Result = TL.getType();
6216 if (getDerived().AlwaysRebuild() ||
6217 Inner != TL.getInnerLoc().getType()) {
6218 Result = getDerived().RebuildParenType(Inner);
6219 if (Result.isNull())
6220 return QualType();
6221 }
6222
6223 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6224 NewTL.setLParenLoc(TL.getLParenLoc());
6225 NewTL.setRParenLoc(TL.getRParenLoc());
6226 return Result;
6227}
6228
Leonard Chanc72aaf62019-05-07 03:20:17 +00006229template <typename Derived>
6230QualType
6231TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6232 MacroQualifiedTypeLoc TL) {
6233 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6234 if (Inner.isNull())
6235 return QualType();
6236
6237 QualType Result = TL.getType();
6238 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6239 Result =
6240 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6241 if (Result.isNull())
6242 return QualType();
6243 }
6244
6245 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6246 NewTL.setExpansionLoc(TL.getExpansionLoc());
6247 return Result;
6248}
6249
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006250template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006251QualType TreeTransform<Derived>::TransformDependentNameType(
6252 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6253 return TransformDependentNameType(TLB, TL, false);
6254}
6255
6256template<typename Derived>
6257QualType TreeTransform<Derived>::TransformDependentNameType(
6258 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006259 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006260
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006261 NestedNameSpecifierLoc QualifierLoc
6262 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6263 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006264 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006265
John McCallc392f372010-06-11 00:33:02 +00006266 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006267 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006268 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006269 QualifierLoc,
6270 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006271 TL.getNameLoc(),
6272 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006273 if (Result.isNull())
6274 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006275
Abramo Bagnarad7548482010-05-19 21:37:53 +00006276 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6277 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006278 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6279
Abramo Bagnarad7548482010-05-19 21:37:53 +00006280 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006281 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006282 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006283 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006284 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006285 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006286 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006287 NewTL.setNameLoc(TL.getNameLoc());
6288 }
John McCall550e0c22009-10-21 00:40:46 +00006289 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006290}
Mike Stump11289f42009-09-09 15:08:12 +00006291
Douglas Gregord6ff3322009-08-04 16:50:30 +00006292template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006293QualType TreeTransform<Derived>::
6294 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006295 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006296 NestedNameSpecifierLoc QualifierLoc;
6297 if (TL.getQualifierLoc()) {
6298 QualifierLoc
6299 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6300 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006301 return QualType();
6302 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006303
John McCall31f82722010-11-12 08:19:04 +00006304 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006305 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006306}
6307
6308template<typename Derived>
6309QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006310TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6311 DependentTemplateSpecializationTypeLoc TL,
6312 NestedNameSpecifierLoc QualifierLoc) {
6313 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006314
Douglas Gregora7a795b2011-03-01 20:11:18 +00006315 TemplateArgumentListInfo NewTemplateArgs;
6316 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6317 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006318
Douglas Gregora7a795b2011-03-01 20:11:18 +00006319 typedef TemplateArgumentLocContainerIterator<
6320 DependentTemplateSpecializationTypeLoc> ArgIterator;
6321 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6322 ArgIterator(TL, TL.getNumArgs()),
6323 NewTemplateArgs))
6324 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006325
Richard Smithfd3dae02017-01-20 00:20:39 +00006326 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006327 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6328 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006329 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006330 if (Result.isNull())
6331 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregora7a795b2011-03-01 20:11:18 +00006333 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6334 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006335
Douglas Gregora7a795b2011-03-01 20:11:18 +00006336 // Copy information relevant to the template specialization.
6337 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006338 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006339 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006340 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006341 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6342 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006343 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006344 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006345
Douglas Gregora7a795b2011-03-01 20:11:18 +00006346 // Copy information relevant to the elaborated type.
6347 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006348 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006349 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006350 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6351 DependentTemplateSpecializationTypeLoc SpecTL
6352 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006353 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006354 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006355 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006356 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006357 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6358 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006359 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006360 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006361 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006362 TemplateSpecializationTypeLoc SpecTL
6363 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006364 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006365 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006366 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6367 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006368 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006369 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006370 }
6371 return Result;
6372}
6373
6374template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006375QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6376 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006377 QualType Pattern
6378 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006379 if (Pattern.isNull())
6380 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006381
6382 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006383 if (getDerived().AlwaysRebuild() ||
6384 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006385 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006386 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006387 TL.getEllipsisLoc(),
6388 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006389 if (Result.isNull())
6390 return QualType();
6391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006392
Douglas Gregor822d0302011-01-12 17:07:58 +00006393 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6394 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6395 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006396}
6397
6398template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006399QualType
6400TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006401 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006402 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006403 TLB.pushFullCopy(TL);
6404 return TL.getType();
6405}
6406
6407template<typename Derived>
6408QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006409TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6410 ObjCTypeParamTypeLoc TL) {
6411 const ObjCTypeParamType *T = TL.getTypePtr();
6412 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6413 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6414 if (!OTP)
6415 return QualType();
6416
6417 QualType Result = TL.getType();
6418 if (getDerived().AlwaysRebuild() ||
6419 OTP != T->getDecl()) {
6420 Result = getDerived().RebuildObjCTypeParamType(OTP,
6421 TL.getProtocolLAngleLoc(),
6422 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6423 TL.getNumProtocols()),
6424 TL.getProtocolLocs(),
6425 TL.getProtocolRAngleLoc());
6426 if (Result.isNull())
6427 return QualType();
6428 }
6429
6430 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6431 if (TL.getNumProtocols()) {
6432 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6433 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6434 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6435 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6436 }
6437 return Result;
6438}
6439
6440template<typename Derived>
6441QualType
John McCall8b07ec22010-05-15 11:32:37 +00006442TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006443 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006444 // Transform base type.
6445 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6446 if (BaseType.isNull())
6447 return QualType();
6448
6449 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6450
6451 // Transform type arguments.
6452 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6453 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6454 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6455 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6456 QualType TypeArg = TypeArgInfo->getType();
6457 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6458 AnyChanged = true;
6459
6460 // We have a pack expansion. Instantiate it.
6461 const auto *PackExpansion = PackExpansionLoc.getType()
6462 ->castAs<PackExpansionType>();
6463 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6464 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6465 Unexpanded);
6466 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6467
6468 // Determine whether the set of unexpanded parameter packs can
6469 // and should be expanded.
6470 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6471 bool Expand = false;
6472 bool RetainExpansion = false;
6473 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6474 if (getDerived().TryExpandParameterPacks(
6475 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6476 Unexpanded, Expand, RetainExpansion, NumExpansions))
6477 return QualType();
6478
6479 if (!Expand) {
6480 // We can't expand this pack expansion into separate arguments yet;
6481 // just substitute into the pattern and create a new pack expansion
6482 // type.
6483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6484
6485 TypeLocBuilder TypeArgBuilder;
6486 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006487 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006488 PatternLoc);
6489 if (NewPatternType.isNull())
6490 return QualType();
6491
6492 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6493 NewPatternType, NumExpansions);
6494 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6495 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6496 NewTypeArgInfos.push_back(
6497 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6498 continue;
6499 }
6500
6501 // Substitute into the pack expansion pattern for each slice of the
6502 // pack.
6503 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6504 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6505
6506 TypeLocBuilder TypeArgBuilder;
6507 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6508
6509 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6510 PatternLoc);
6511 if (NewTypeArg.isNull())
6512 return QualType();
6513
6514 NewTypeArgInfos.push_back(
6515 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6516 }
6517
6518 continue;
6519 }
6520
6521 TypeLocBuilder TypeArgBuilder;
6522 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6523 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6524 if (NewTypeArg.isNull())
6525 return QualType();
6526
6527 // If nothing changed, just keep the old TypeSourceInfo.
6528 if (NewTypeArg == TypeArg) {
6529 NewTypeArgInfos.push_back(TypeArgInfo);
6530 continue;
6531 }
6532
6533 NewTypeArgInfos.push_back(
6534 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6535 AnyChanged = true;
6536 }
6537
6538 QualType Result = TL.getType();
6539 if (getDerived().AlwaysRebuild() || AnyChanged) {
6540 // Rebuild the type.
6541 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006542 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6543 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6544 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6545 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006546
6547 if (Result.isNull())
6548 return QualType();
6549 }
6550
6551 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006552 NewT.setHasBaseTypeAsWritten(true);
6553 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6554 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6555 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6556 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6557 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6558 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6559 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6560 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6561 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006562}
Mike Stump11289f42009-09-09 15:08:12 +00006563
6564template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006565QualType
6566TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006567 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006568 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6569 if (PointeeType.isNull())
6570 return QualType();
6571
6572 QualType Result = TL.getType();
6573 if (getDerived().AlwaysRebuild() ||
6574 PointeeType != TL.getPointeeLoc().getType()) {
6575 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6576 TL.getStarLoc());
6577 if (Result.isNull())
6578 return QualType();
6579 }
6580
6581 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6582 NewT.setStarLoc(TL.getStarLoc());
6583 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006584}
6585
Douglas Gregord6ff3322009-08-04 16:50:30 +00006586//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006587// Statement transformation
6588//===----------------------------------------------------------------------===//
6589template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006590StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006591TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006592 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006593}
6594
6595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006596StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006597TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6598 return getDerived().TransformCompoundStmt(S, false);
6599}
6600
6601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006602StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006603TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006604 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006605 Sema::CompoundScopeRAII CompoundScope(getSema());
6606
John McCall1ababa62010-08-27 19:56:05 +00006607 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006608 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006609 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006610 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006611 StmtResult Result = getDerived().TransformStmt(
6612 B,
6613 IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006614
John McCall1ababa62010-08-27 19:56:05 +00006615 if (Result.isInvalid()) {
6616 // Immediately fail if this was a DeclStmt, since it's very
6617 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006618 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006619 return StmtError();
6620
6621 // Otherwise, just keep processing substatements and fail later.
6622 SubStmtInvalid = true;
6623 continue;
6624 }
Mike Stump11289f42009-09-09 15:08:12 +00006625
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006626 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006627 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006628 }
Mike Stump11289f42009-09-09 15:08:12 +00006629
John McCall1ababa62010-08-27 19:56:05 +00006630 if (SubStmtInvalid)
6631 return StmtError();
6632
Douglas Gregorebe10102009-08-20 07:17:43 +00006633 if (!getDerived().AlwaysRebuild() &&
6634 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006635 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006636
6637 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006638 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 S->getRBracLoc(),
6640 IsStmtExpr);
6641}
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregorebe10102009-08-20 07:17:43 +00006643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006644StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006645TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006646 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006647 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006648 EnterExpressionEvaluationContext Unevaluated(
6649 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006650
Eli Friedman06577382009-11-19 03:14:00 +00006651 // Transform the left-hand case value.
6652 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006653 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006654 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006655 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
Eli Friedman06577382009-11-19 03:14:00 +00006657 // Transform the right-hand case value (for the GNU case-range extension).
6658 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006659 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006660 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006661 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006662 }
Mike Stump11289f42009-09-09 15:08:12 +00006663
Douglas Gregorebe10102009-08-20 07:17:43 +00006664 // Build the case statement.
6665 // Case statements are always rebuilt so that they will attached to their
6666 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006667 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006668 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006669 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006670 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006671 S->getColonLoc());
6672 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006674
Douglas Gregorebe10102009-08-20 07:17:43 +00006675 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006676 StmtResult SubStmt =
6677 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006678 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006680
Douglas Gregorebe10102009-08-20 07:17:43 +00006681 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006682 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006683}
6684
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006685template <typename Derived>
6686StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006687 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006688 StmtResult SubStmt =
6689 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006692
Douglas Gregorebe10102009-08-20 07:17:43 +00006693 // Default statements are always rebuilt
6694 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006695 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006696}
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregorebe10102009-08-20 07:17:43 +00006698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006699StmtResult
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006700TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6701 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006702 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006703 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006704
Chris Lattnercab02a62011-02-17 20:34:02 +00006705 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6706 S->getDecl());
6707 if (!LD)
6708 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006709
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006710 // If we're transforming "in-place" (we're not creating new local
6711 // declarations), assume we're replacing the old label statement
6712 // and clear out the reference to it.
6713 if (LD == S->getDecl())
6714 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006715
Douglas Gregorebe10102009-08-20 07:17:43 +00006716 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006717 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006718 cast<LabelDecl>(LD), SourceLocation(),
6719 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006720}
Mike Stump11289f42009-09-09 15:08:12 +00006721
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006722template <typename Derived>
6723const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6724 if (!R)
6725 return R;
6726
6727 switch (R->getKind()) {
6728// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6729#define ATTR(X)
6730#define PRAGMA_SPELLING_ATTR(X) \
6731 case attr::X: \
6732 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6733#include "clang/Basic/AttrList.inc"
6734 default:
6735 return R;
6736 }
6737}
6738
6739template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006740StmtResult
6741TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6742 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006743 bool AttrsChanged = false;
6744 SmallVector<const Attr *, 1> Attrs;
6745
6746 // Visit attributes and keep track if any are transformed.
6747 for (const auto *I : S->getAttrs()) {
6748 const Attr *R = getDerived().TransformAttr(I);
6749 AttrsChanged |= (I != R);
6750 Attrs.push_back(R);
6751 }
6752
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006753 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006754 if (SubStmt.isInvalid())
6755 return StmtError();
6756
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006757 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006758 return S;
6759
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006760 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006761 SubStmt.get());
6762}
6763
6764template<typename Derived>
6765StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006766TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006767 // Transform the initialization statement
6768 StmtResult Init = getDerived().TransformStmt(S->getInit());
6769 if (Init.isInvalid())
6770 return StmtError();
6771
Douglas Gregorebe10102009-08-20 07:17:43 +00006772 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006773 Sema::ConditionResult Cond = getDerived().TransformCondition(
6774 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006775 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6776 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006777 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006778 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006779
Richard Smithb130fe72016-06-23 19:16:49 +00006780 // If this is a constexpr if, determine which arm we should instantiate.
6781 llvm::Optional<bool> ConstexprConditionValue;
6782 if (S->isConstexpr())
6783 ConstexprConditionValue = Cond.getKnownValue();
6784
Douglas Gregorebe10102009-08-20 07:17:43 +00006785 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006786 StmtResult Then;
6787 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6788 Then = getDerived().TransformStmt(S->getThen());
6789 if (Then.isInvalid())
6790 return StmtError();
6791 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006792 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006793 }
Mike Stump11289f42009-09-09 15:08:12 +00006794
Douglas Gregorebe10102009-08-20 07:17:43 +00006795 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006796 StmtResult Else;
6797 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6798 Else = getDerived().TransformStmt(S->getElse());
6799 if (Else.isInvalid())
6800 return StmtError();
6801 }
Mike Stump11289f42009-09-09 15:08:12 +00006802
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006804 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006805 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006806 Then.get() == S->getThen() &&
6807 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006808 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006809
Richard Smithb130fe72016-06-23 19:16:49 +00006810 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006811 Init.get(), Then.get(), S->getElseLoc(),
6812 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006813}
6814
6815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006816StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006817TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006818 // Transform the initialization statement
6819 StmtResult Init = getDerived().TransformStmt(S->getInit());
6820 if (Init.isInvalid())
6821 return StmtError();
6822
Douglas Gregorebe10102009-08-20 07:17:43 +00006823 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006824 Sema::ConditionResult Cond = getDerived().TransformCondition(
6825 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6826 Sema::ConditionKind::Switch);
6827 if (Cond.isInvalid())
6828 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006829
Douglas Gregorebe10102009-08-20 07:17:43 +00006830 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006831 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006832 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006833 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006834 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006837 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006838 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006839 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregorebe10102009-08-20 07:17:43 +00006841 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006842 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6843 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006844}
Mike Stump11289f42009-09-09 15:08:12 +00006845
Douglas Gregorebe10102009-08-20 07:17:43 +00006846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006848TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006849 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006850 Sema::ConditionResult Cond = getDerived().TransformCondition(
6851 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6852 Sema::ConditionKind::Boolean);
6853 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006854 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006855
Douglas Gregorebe10102009-08-20 07:17:43 +00006856 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006857 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006858 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006859 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006860
Douglas Gregorebe10102009-08-20 07:17:43 +00006861 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006862 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006863 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006864 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006865
Richard Smith03a4aa32016-06-23 19:02:52 +00006866 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006867}
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregorebe10102009-08-20 07:17:43 +00006869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006870StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006871TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006872 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006873 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006874 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006875 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006876
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006877 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006878 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006879 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006880 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006881
Douglas Gregorebe10102009-08-20 07:17:43 +00006882 if (!getDerived().AlwaysRebuild() &&
6883 Cond.get() == S->getCond() &&
6884 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006885 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006886
John McCallb268a282010-08-23 23:25:46 +00006887 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6888 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006889 S->getRParenLoc());
6890}
Mike Stump11289f42009-09-09 15:08:12 +00006891
Douglas Gregorebe10102009-08-20 07:17:43 +00006892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006893StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006894TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006895 if (getSema().getLangOpts().OpenMP)
6896 getSema().startOpenMPLoop();
6897
Douglas Gregorebe10102009-08-20 07:17:43 +00006898 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006899 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006900 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006901 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006902
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006903 // In OpenMP loop region loop control variable must be captured and be
6904 // private. Perform analysis of first part (if any).
6905 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6906 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6907
Douglas Gregorebe10102009-08-20 07:17:43 +00006908 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006909 Sema::ConditionResult Cond = getDerived().TransformCondition(
6910 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6911 Sema::ConditionKind::Boolean);
6912 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006913 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006914
Douglas Gregorebe10102009-08-20 07:17:43 +00006915 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006916 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006917 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006918 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006919
Richard Smith945f8d32013-01-14 22:39:08 +00006920 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006921 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006922 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006923
Douglas Gregorebe10102009-08-20 07:17:43 +00006924 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006925 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006926 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006927 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006928
Douglas Gregorebe10102009-08-20 07:17:43 +00006929 if (!getDerived().AlwaysRebuild() &&
6930 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006931 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006932 Inc.get() == S->getInc() &&
6933 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006934 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006935
Douglas Gregorebe10102009-08-20 07:17:43 +00006936 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006937 Init.get(), Cond, FullInc,
6938 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006939}
6940
6941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006942StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006943TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006944 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6945 S->getLabel());
6946 if (!LD)
6947 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006948
Douglas Gregorebe10102009-08-20 07:17:43 +00006949 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006950 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006951 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006952}
6953
6954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006955StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006956TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006957 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006958 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006959 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006960 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregorebe10102009-08-20 07:17:43 +00006962 if (!getDerived().AlwaysRebuild() &&
6963 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006964 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006965
6966 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006967 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006968}
6969
6970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006971StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006972TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006973 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006974}
Mike Stump11289f42009-09-09 15:08:12 +00006975
Douglas Gregorebe10102009-08-20 07:17:43 +00006976template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006977StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006978TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006979 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006980}
Mike Stump11289f42009-09-09 15:08:12 +00006981
Douglas Gregorebe10102009-08-20 07:17:43 +00006982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006983StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006984TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006985 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6986 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006987 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006988 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006989
Mike Stump11289f42009-09-09 15:08:12 +00006990 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006991 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006992 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006993}
Mike Stump11289f42009-09-09 15:08:12 +00006994
Douglas Gregorebe10102009-08-20 07:17:43 +00006995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006996StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006997TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006998 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006999 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007000 for (auto *D : S->decls()) {
7001 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00007002 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00007003 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007004
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007005 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00007006 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00007007
Douglas Gregorebe10102009-08-20 07:17:43 +00007008 Decls.push_back(Transformed);
7009 }
Mike Stump11289f42009-09-09 15:08:12 +00007010
Douglas Gregorebe10102009-08-20 07:17:43 +00007011 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007012 return S;
Mike Stump11289f42009-09-09 15:08:12 +00007013
Stephen Kellya6e43582018-08-09 21:05:56 +00007014 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007015}
Mike Stump11289f42009-09-09 15:08:12 +00007016
Douglas Gregorebe10102009-08-20 07:17:43 +00007017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007018StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00007019TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007020
Benjamin Kramerf0623432012-08-23 22:51:59 +00007021 SmallVector<Expr*, 8> Constraints;
7022 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007023 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00007024
John McCalldadc5752010-08-24 06:29:42 +00007025 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007026 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007027
7028 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007029
Anders Carlssonaaeef072010-01-24 05:50:09 +00007030 // Go through the outputs.
7031 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007032 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007033
Anders Carlssonaaeef072010-01-24 05:50:09 +00007034 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007035 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007036
Anders Carlssonaaeef072010-01-24 05:50:09 +00007037 // Transform the output expr.
7038 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007039 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007040 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007041 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007042
Anders Carlssonaaeef072010-01-24 05:50:09 +00007043 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007044
John McCallb268a282010-08-23 23:25:46 +00007045 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007046 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007047
Anders Carlssonaaeef072010-01-24 05:50:09 +00007048 // Go through the inputs.
7049 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007050 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007051
Anders Carlssonaaeef072010-01-24 05:50:09 +00007052 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007053 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007054
Anders Carlssonaaeef072010-01-24 05:50:09 +00007055 // Transform the input expr.
7056 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007057 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007058 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007060
Anders Carlssonaaeef072010-01-24 05:50:09 +00007061 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007062
John McCallb268a282010-08-23 23:25:46 +00007063 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007064 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007065
Jennifer Yub8fee672019-06-03 15:57:25 +00007066 // Go through the Labels.
7067 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
7068 Names.push_back(S->getLabelIdentifier(I));
7069
7070 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
7071 if (Result.isInvalid())
7072 return StmtError();
7073 ExprsChanged |= Result.get() != S->getLabelExpr(I);
7074 Exprs.push_back(Result.get());
7075 }
Anders Carlssonaaeef072010-01-24 05:50:09 +00007076 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007077 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007078
7079 // Go through the clobbers.
7080 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00007081 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007082
7083 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007084 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007085 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7086 S->isVolatile(), S->getNumOutputs(),
7087 S->getNumInputs(), Names.data(),
7088 Constraints, Exprs, AsmString.get(),
Jennifer Yub8fee672019-06-03 15:57:25 +00007089 Clobbers, S->getNumLabels(),
7090 S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007091}
7092
Chad Rosier32503022012-06-11 20:47:18 +00007093template<typename Derived>
7094StmtResult
7095TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007096 ArrayRef<Token> AsmToks =
7097 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007098
John McCallf413f5e2013-05-03 00:10:13 +00007099 bool HadError = false, HadChange = false;
7100
7101 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7102 SmallVector<Expr*, 8> TransformedExprs;
7103 TransformedExprs.reserve(SrcExprs.size());
7104 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7105 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7106 if (!Result.isUsable()) {
7107 HadError = true;
7108 } else {
7109 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007110 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007111 }
7112 }
7113
7114 if (HadError) return StmtError();
7115 if (!HadChange && !getDerived().AlwaysRebuild())
7116 return Owned(S);
7117
Chad Rosierb6f46c12012-08-15 16:53:30 +00007118 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007119 AsmToks, S->getAsmString(),
7120 S->getNumOutputs(), S->getNumInputs(),
7121 S->getAllConstraints(), S->getClobbers(),
7122 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007123}
Douglas Gregorebe10102009-08-20 07:17:43 +00007124
Richard Smith9f690bd2015-10-27 06:02:45 +00007125// C++ Coroutines TS
7126
7127template<typename Derived>
7128StmtResult
7129TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007130 auto *ScopeInfo = SemaRef.getCurFunction();
7131 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007132 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007133 ScopeInfo->NeedsCoroutineSuspends &&
7134 ScopeInfo->CoroutineSuspends.first == nullptr &&
7135 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007136 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007137
7138 // Set that we have (possibly-invalid) suspend points before we do anything
7139 // that may fail.
7140 ScopeInfo->setNeedsCoroutineSuspends(false);
7141
7142 // The new CoroutinePromise object needs to be built and put into the current
7143 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007144 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7145 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007146 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7147 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007148 return StmtError();
Richard Smithb2997f52019-05-21 20:10:50 +00007149 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
Eric Fiselierbee782b2017-04-03 19:21:00 +00007150 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007151
7152 // Transform the implicit coroutine statements we built during the initial
7153 // parse.
7154 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7155 if (InitSuspend.isInvalid())
7156 return StmtError();
7157 StmtResult FinalSuspend =
7158 getDerived().TransformStmt(S->getFinalSuspendStmt());
7159 if (FinalSuspend.isInvalid())
7160 return StmtError();
7161 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7162 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007163
7164 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7165 if (BodyRes.isInvalid())
7166 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007167
Eric Fiselierbee782b2017-04-03 19:21:00 +00007168 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7169 if (Builder.isInvalid())
7170 return StmtError();
7171
7172 Expr *ReturnObject = S->getReturnValueInit();
7173 assert(ReturnObject && "the return object is expected to be valid");
7174 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7175 /*NoCopyInit*/ false);
7176 if (Res.isInvalid())
7177 return StmtError();
7178 Builder.ReturnValue = Res.get();
7179
7180 if (S->hasDependentPromiseType()) {
Brian Gesiak38f11822019-06-03 00:47:32 +00007181 // PR41909: We may find a generic coroutine lambda definition within a
7182 // template function that is being instantiated. In this case, the lambda
7183 // will have a dependent promise type, until it is used in an expression
7184 // that creates an instantiation with a non-dependent promise type. We
7185 // should not assert or build coroutine dependent statements for such a
7186 // generic lambda.
7187 auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD);
7188 if (!MD || !MD->getParent()->isGenericLambda()) {
7189 assert(!Promise->getType()->isDependentType() &&
7190 "the promise type must no longer be dependent");
7191 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7192 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7193 "these nodes should not have been built yet");
7194 if (!Builder.buildDependentStatements())
7195 return StmtError();
7196 }
Eric Fiselierbee782b2017-04-03 19:21:00 +00007197 } else {
7198 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7199 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7200 if (Res.isInvalid())
7201 return StmtError();
7202 Builder.OnFallthrough = Res.get();
7203 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007204
Eric Fiselierbee782b2017-04-03 19:21:00 +00007205 if (auto *OnException = S->getExceptionHandler()) {
7206 StmtResult Res = getDerived().TransformStmt(OnException);
7207 if (Res.isInvalid())
7208 return StmtError();
7209 Builder.OnException = Res.get();
7210 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007211
Eric Fiselierbee782b2017-04-03 19:21:00 +00007212 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7213 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7214 if (Res.isInvalid())
7215 return StmtError();
7216 Builder.ReturnStmtOnAllocFailure = Res.get();
7217 }
7218
7219 // Transform any additional statements we may have already built
7220 assert(S->getAllocate() && S->getDeallocate() &&
7221 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007222 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7223 if (AllocRes.isInvalid())
7224 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007225 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007226
7227 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7228 if (DeallocRes.isInvalid())
7229 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007230 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007231
7232 assert(S->getResultDecl() && "ResultDecl must already be built");
7233 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7234 if (ResultDecl.isInvalid())
7235 return StmtError();
7236 Builder.ResultDecl = ResultDecl.get();
7237
7238 if (auto *ReturnStmt = S->getReturnStmt()) {
7239 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7240 if (Res.isInvalid())
7241 return StmtError();
7242 Builder.ReturnStmt = Res.get();
7243 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007244 }
7245
Eric Fiselierbee782b2017-04-03 19:21:00 +00007246 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007247}
7248
7249template<typename Derived>
7250StmtResult
7251TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7252 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7253 /*NotCopyInit*/false);
7254 if (Result.isInvalid())
7255 return StmtError();
7256
7257 // Always rebuild; we don't know if this needs to be injected into a new
7258 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007259 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7260 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007261}
7262
7263template<typename Derived>
7264ExprResult
7265TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7266 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7267 /*NotCopyInit*/false);
7268 if (Result.isInvalid())
7269 return ExprError();
7270
7271 // Always rebuild; we don't know if this needs to be injected into a new
7272 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007273 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7274 E->isImplicit());
7275}
7276
7277template <typename Derived>
7278ExprResult
7279TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7280 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7281 /*NotCopyInit*/ false);
7282 if (OperandResult.isInvalid())
7283 return ExprError();
7284
7285 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7286 E->getOperatorCoawaitLookup());
7287
7288 if (LookupResult.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().RebuildDependentCoawaitExpr(
7294 E->getKeywordLoc(), OperandResult.get(),
7295 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007296}
7297
7298template<typename Derived>
7299ExprResult
7300TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7301 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7302 /*NotCopyInit*/false);
7303 if (Result.isInvalid())
7304 return ExprError();
7305
7306 // Always rebuild; we don't know if this needs to be injected into a new
7307 // context or if the promise type has changed.
7308 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7309}
7310
7311// Objective-C Statements.
7312
Douglas Gregorebe10102009-08-20 07:17:43 +00007313template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007314StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007315TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007316 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007317 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007318 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007319 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007320
Douglas Gregor96c79492010-04-23 22:50:49 +00007321 // Transform the @catch statements (if present).
7322 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007323 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007324 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007325 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007326 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007328 if (Catch.get() != S->getCatchStmt(I))
7329 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007330 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007331 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007332
Douglas Gregor306de2f2010-04-22 23:59:56 +00007333 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007334 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007335 if (S->getFinallyStmt()) {
7336 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7337 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007338 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007339 }
7340
7341 // If nothing changed, just retain this statement.
7342 if (!getDerived().AlwaysRebuild() &&
7343 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007344 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007345 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007346 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007347
Douglas Gregor306de2f2010-04-22 23:59:56 +00007348 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007349 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007350 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007351}
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregorebe10102009-08-20 07:17:43 +00007353template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007354StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007355TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007356 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007357 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007358 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007359 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007360 if (FromVar->getTypeSourceInfo()) {
7361 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7362 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007363 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007364 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007365
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007366 QualType T;
7367 if (TSInfo)
7368 T = TSInfo->getType();
7369 else {
7370 T = getDerived().TransformType(FromVar->getType());
7371 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007372 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007373 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007374
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007375 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7376 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007377 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007378 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007379
John McCalldadc5752010-08-24 06:29:42 +00007380 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007381 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007382 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007383
7384 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007385 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007386 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007387}
Mike Stump11289f42009-09-09 15:08:12 +00007388
Douglas Gregorebe10102009-08-20 07:17:43 +00007389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007390StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007391TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007392 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007393 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007394 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007395 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007396
Douglas Gregor306de2f2010-04-22 23:59:56 +00007397 // If nothing changed, just retain this statement.
7398 if (!getDerived().AlwaysRebuild() &&
7399 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007400 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007401
7402 // Build a new statement.
7403 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007404 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007405}
Mike Stump11289f42009-09-09 15:08:12 +00007406
Douglas Gregorebe10102009-08-20 07:17:43 +00007407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007408StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007409TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007410 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007411 if (S->getThrowExpr()) {
7412 Operand = getDerived().TransformExpr(S->getThrowExpr());
7413 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007414 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007416
Douglas Gregor2900c162010-04-22 21:44:01 +00007417 if (!getDerived().AlwaysRebuild() &&
7418 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007419 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007420
John McCallb268a282010-08-23 23:25:46 +00007421 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007422}
Mike Stump11289f42009-09-09 15:08:12 +00007423
Douglas Gregorebe10102009-08-20 07:17:43 +00007424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007425StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007426TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007427 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007428 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007429 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007430 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007431 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007432 Object =
7433 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7434 Object.get());
7435 if (Object.isInvalid())
7436 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007437
Douglas Gregor6148de72010-04-22 22:01:21 +00007438 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007439 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007440 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007441 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007442
Douglas Gregor6148de72010-04-22 22:01:21 +00007443 // If nothing change, just retain the current statement.
7444 if (!getDerived().AlwaysRebuild() &&
7445 Object.get() == S->getSynchExpr() &&
7446 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007447 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007448
7449 // Build a new statement.
7450 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007451 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007452}
7453
7454template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007455StmtResult
John McCall31168b02011-06-15 23:02:42 +00007456TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7457 ObjCAutoreleasePoolStmt *S) {
7458 // Transform the body.
7459 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7460 if (Body.isInvalid())
7461 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007462
John McCall31168b02011-06-15 23:02:42 +00007463 // If nothing changed, just retain this statement.
7464 if (!getDerived().AlwaysRebuild() &&
7465 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007466 return S;
John McCall31168b02011-06-15 23:02:42 +00007467
7468 // Build a new statement.
7469 return getDerived().RebuildObjCAutoreleasePoolStmt(
7470 S->getAtLoc(), Body.get());
7471}
7472
7473template<typename Derived>
7474StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007475TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007476 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007477 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007478 StmtResult Element =
7479 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007480 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007481 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007482
Douglas Gregorf68a5082010-04-22 23:10:45 +00007483 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007484 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007485 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007486 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007487
Douglas Gregorf68a5082010-04-22 23:10:45 +00007488 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007489 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007490 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007491 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007492
Douglas Gregorf68a5082010-04-22 23:10:45 +00007493 // If nothing changed, just retain this statement.
7494 if (!getDerived().AlwaysRebuild() &&
7495 Element.get() == S->getElement() &&
7496 Collection.get() == S->getCollection() &&
7497 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007498 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007499
Douglas Gregorf68a5082010-04-22 23:10:45 +00007500 // Build a new statement.
7501 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007502 Element.get(),
7503 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007504 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007505 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007506}
7507
David Majnemer5f7efef2013-10-15 09:50:08 +00007508template <typename Derived>
7509StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007510 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007511 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007512 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7513 TypeSourceInfo *T =
7514 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007515 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007516 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007517
David Majnemer5f7efef2013-10-15 09:50:08 +00007518 Var = getDerived().RebuildExceptionDecl(
7519 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7520 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007521 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007522 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007523 }
Mike Stump11289f42009-09-09 15:08:12 +00007524
Douglas Gregorebe10102009-08-20 07:17:43 +00007525 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007526 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007527 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007528 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007529
David Majnemer5f7efef2013-10-15 09:50:08 +00007530 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007531 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007532 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007533
David Majnemer5f7efef2013-10-15 09:50:08 +00007534 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007535}
Mike Stump11289f42009-09-09 15:08:12 +00007536
David Majnemer5f7efef2013-10-15 09:50:08 +00007537template <typename Derived>
7538StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007539 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007540 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007541 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007542 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007543
Douglas Gregorebe10102009-08-20 07:17:43 +00007544 // Transform the handlers.
7545 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007546 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007547 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007548 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007549 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007550 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007551
Douglas Gregorebe10102009-08-20 07:17:43 +00007552 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007553 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007554 }
Mike Stump11289f42009-09-09 15:08:12 +00007555
David Majnemer5f7efef2013-10-15 09:50:08 +00007556 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007557 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007558 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007559
John McCallb268a282010-08-23 23:25:46 +00007560 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007561 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007562}
Mike Stump11289f42009-09-09 15:08:12 +00007563
Richard Smith02e85f32011-04-14 22:09:26 +00007564template<typename Derived>
7565StmtResult
7566TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007567 StmtResult Init =
7568 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7569 if (Init.isInvalid())
7570 return StmtError();
7571
Richard Smith02e85f32011-04-14 22:09:26 +00007572 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7573 if (Range.isInvalid())
7574 return StmtError();
7575
Richard Smith01694c32016-03-20 10:33:40 +00007576 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7577 if (Begin.isInvalid())
7578 return StmtError();
7579 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7580 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007581 return StmtError();
7582
7583 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7584 if (Cond.isInvalid())
7585 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007586 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007587 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007588 if (Cond.isInvalid())
7589 return StmtError();
7590 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007591 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007592
7593 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7594 if (Inc.isInvalid())
7595 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007596 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007597 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007598
7599 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7600 if (LoopVar.isInvalid())
7601 return StmtError();
7602
7603 StmtResult NewStmt = S;
7604 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007605 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007606 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007607 Begin.get() != S->getBeginStmt() ||
7608 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007609 Cond.get() != S->getCond() ||
7610 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007611 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007612 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007613 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007614 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007615 Begin.get(), End.get(),
7616 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007617 Inc.get(), LoopVar.get(),
7618 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007619 if (NewStmt.isInvalid())
7620 return StmtError();
7621 }
Richard Smith02e85f32011-04-14 22:09:26 +00007622
7623 StmtResult Body = getDerived().TransformStmt(S->getBody());
7624 if (Body.isInvalid())
7625 return StmtError();
7626
7627 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7628 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007629 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007630 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007631 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007632 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007633 Begin.get(), End.get(),
7634 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007635 Inc.get(), LoopVar.get(),
7636 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007637 if (NewStmt.isInvalid())
7638 return StmtError();
7639 }
Richard Smith02e85f32011-04-14 22:09:26 +00007640
7641 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007642 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007643
7644 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7645}
7646
John Wiegley1c0675e2011-04-28 01:08:34 +00007647template<typename Derived>
7648StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007649TreeTransform<Derived>::TransformMSDependentExistsStmt(
7650 MSDependentExistsStmt *S) {
7651 // Transform the nested-name-specifier, if any.
7652 NestedNameSpecifierLoc QualifierLoc;
7653 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007654 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007655 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7656 if (!QualifierLoc)
7657 return StmtError();
7658 }
7659
7660 // Transform the declaration name.
7661 DeclarationNameInfo NameInfo = S->getNameInfo();
7662 if (NameInfo.getName()) {
7663 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7664 if (!NameInfo.getName())
7665 return StmtError();
7666 }
7667
7668 // Check whether anything changed.
7669 if (!getDerived().AlwaysRebuild() &&
7670 QualifierLoc == S->getQualifierLoc() &&
7671 NameInfo.getName() == S->getNameInfo().getName())
7672 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007673
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007674 // Determine whether this name exists, if we can.
7675 CXXScopeSpec SS;
7676 SS.Adopt(QualifierLoc);
7677 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007678 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007679 case Sema::IER_Exists:
7680 if (S->isIfExists())
7681 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007682
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007683 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7684
7685 case Sema::IER_DoesNotExist:
7686 if (S->isIfNotExists())
7687 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007688
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007689 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007690
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007691 case Sema::IER_Dependent:
7692 Dependent = true;
7693 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007694
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007695 case Sema::IER_Error:
7696 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007697 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007698
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007699 // We need to continue with the instantiation, so do so now.
7700 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7701 if (SubStmt.isInvalid())
7702 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007703
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007704 // If we have resolved the name, just transform to the substatement.
7705 if (!Dependent)
7706 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007707
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007708 // The name is still dependent, so build a dependent expression again.
7709 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7710 S->isIfExists(),
7711 QualifierLoc,
7712 NameInfo,
7713 SubStmt.get());
7714}
7715
7716template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007717ExprResult
7718TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7719 NestedNameSpecifierLoc QualifierLoc;
7720 if (E->getQualifierLoc()) {
7721 QualifierLoc
7722 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7723 if (!QualifierLoc)
7724 return ExprError();
7725 }
7726
7727 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7728 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7729 if (!PD)
7730 return ExprError();
7731
7732 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7733 if (Base.isInvalid())
7734 return ExprError();
7735
7736 return new (SemaRef.getASTContext())
7737 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7738 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7739 QualifierLoc, E->getMemberLoc());
7740}
7741
David Majnemerfad8f482013-10-15 09:33:02 +00007742template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007743ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7744 MSPropertySubscriptExpr *E) {
7745 auto BaseRes = getDerived().TransformExpr(E->getBase());
7746 if (BaseRes.isInvalid())
7747 return ExprError();
7748 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7749 if (IdxRes.isInvalid())
7750 return ExprError();
7751
7752 if (!getDerived().AlwaysRebuild() &&
7753 BaseRes.get() == E->getBase() &&
7754 IdxRes.get() == E->getIdx())
7755 return E;
7756
7757 return getDerived().RebuildArraySubscriptExpr(
7758 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7759}
7760
7761template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007762StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007763 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007764 if (TryBlock.isInvalid())
7765 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007766
7767 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007768 if (Handler.isInvalid())
7769 return StmtError();
7770
David Majnemerfad8f482013-10-15 09:33:02 +00007771 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7772 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007773 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007774
Warren Huntf6be4cb2014-07-25 20:52:51 +00007775 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7776 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007777}
7778
David Majnemerfad8f482013-10-15 09:33:02 +00007779template <typename Derived>
7780StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007781 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007782 if (Block.isInvalid())
7783 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007784
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007785 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007786}
7787
David Majnemerfad8f482013-10-15 09:33:02 +00007788template <typename Derived>
7789StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007790 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007791 if (FilterExpr.isInvalid())
7792 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007793
David Majnemer7e755502013-10-15 09:30:14 +00007794 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007795 if (Block.isInvalid())
7796 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007797
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007798 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7799 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007800}
7801
David Majnemerfad8f482013-10-15 09:33:02 +00007802template <typename Derived>
7803StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7804 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007805 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7806 else
7807 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7808}
7809
Nico Weber9b982072014-07-07 00:12:30 +00007810template<typename Derived>
7811StmtResult
7812TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7813 return S;
7814}
7815
Alexander Musman64d33f12014-06-04 07:53:32 +00007816//===----------------------------------------------------------------------===//
7817// OpenMP directive transformation
7818//===----------------------------------------------------------------------===//
7819template <typename Derived>
7820StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7821 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007822
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007823 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007824 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007825 ArrayRef<OMPClause *> Clauses = D->clauses();
7826 TClauses.reserve(Clauses.size());
7827 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7828 I != E; ++I) {
7829 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007830 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007831 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007832 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007833 if (Clause)
7834 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007835 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007836 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007837 }
7838 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007839 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007840 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007841 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7842 /*CurScope=*/nullptr);
7843 StmtResult Body;
7844 {
7845 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007846 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007847 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007848 }
7849 AssociatedStmt =
7850 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007851 if (AssociatedStmt.isInvalid()) {
7852 return StmtError();
7853 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007854 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007855 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007856 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007857 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007858
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007859 // Transform directive name for 'omp critical' directive.
7860 DeclarationNameInfo DirName;
7861 if (D->getDirectiveKind() == OMPD_critical) {
7862 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7863 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7864 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007865 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7866 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7867 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007868 } else if (D->getDirectiveKind() == OMPD_cancel) {
7869 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007870 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007871
Alexander Musman64d33f12014-06-04 07:53:32 +00007872 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007873 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007874 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007875}
7876
Alexander Musman64d33f12014-06-04 07:53:32 +00007877template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007878StmtResult
7879TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7880 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007881 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007882 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7884 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7885 return Res;
7886}
7887
Alexander Musman64d33f12014-06-04 07:53:32 +00007888template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007889StmtResult
7890TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7891 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007892 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007893 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7895 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007896 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007897}
7898
Alexey Bataevf29276e2014-06-18 04:14:57 +00007899template <typename Derived>
7900StmtResult
7901TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7902 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007903 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007904 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7906 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7907 return Res;
7908}
7909
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007910template <typename Derived>
7911StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007912TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7913 DeclarationNameInfo DirName;
7914 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007915 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7917 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7918 return Res;
7919}
7920
7921template <typename Derived>
7922StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007923TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7924 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007925 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007926 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7928 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7929 return Res;
7930}
7931
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007932template <typename Derived>
7933StmtResult
7934TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7935 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007936 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007937 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007938 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7939 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7940 return Res;
7941}
7942
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007943template <typename Derived>
7944StmtResult
7945TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7946 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007947 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007948 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007949 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7950 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7951 return Res;
7952}
7953
Alexey Bataev4acb8592014-07-07 13:01:15 +00007954template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007955StmtResult
7956TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7957 DeclarationNameInfo DirName;
7958 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007959 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007960 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7961 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7962 return Res;
7963}
7964
7965template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007966StmtResult
7967TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7968 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007969 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007970 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7971 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7972 return Res;
7973}
7974
7975template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007976StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7977 OMPParallelForDirective *D) {
7978 DeclarationNameInfo DirName;
7979 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007980 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007981 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7982 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7983 return Res;
7984}
7985
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007986template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007987StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7988 OMPParallelForSimdDirective *D) {
7989 DeclarationNameInfo DirName;
7990 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007991 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007992 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7993 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7994 return Res;
7995}
7996
7997template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007998StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7999 OMPParallelSectionsDirective *D) {
8000 DeclarationNameInfo DirName;
8001 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008002 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008003 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8004 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8005 return Res;
8006}
8007
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008008template <typename Derived>
8009StmtResult
8010TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
8011 DeclarationNameInfo DirName;
8012 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008013 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008014 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8015 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8016 return Res;
8017}
8018
Alexey Bataev68446b72014-07-18 07:47:19 +00008019template <typename Derived>
8020StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8021 OMPTaskyieldDirective *D) {
8022 DeclarationNameInfo DirName;
8023 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008024 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00008025 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8026 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8027 return Res;
8028}
8029
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008030template <typename Derived>
8031StmtResult
8032TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8033 DeclarationNameInfo DirName;
8034 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008035 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008036 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8037 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8038 return Res;
8039}
8040
Alexey Bataev2df347a2014-07-18 10:17:07 +00008041template <typename Derived>
8042StmtResult
8043TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8044 DeclarationNameInfo DirName;
8045 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008046 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00008047 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8048 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8049 return Res;
8050}
8051
Alexey Bataev6125da92014-07-21 11:26:11 +00008052template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008053StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8054 OMPTaskgroupDirective *D) {
8055 DeclarationNameInfo DirName;
8056 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008057 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008058 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8059 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8060 return Res;
8061}
8062
8063template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00008064StmtResult
8065TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8066 DeclarationNameInfo DirName;
8067 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008068 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008069 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8070 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8071 return Res;
8072}
8073
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008074template <typename Derived>
8075StmtResult
8076TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8077 DeclarationNameInfo DirName;
8078 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008079 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008080 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8081 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8082 return Res;
8083}
8084
Alexey Bataev0162e452014-07-22 10:10:35 +00008085template <typename Derived>
8086StmtResult
8087TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8088 DeclarationNameInfo DirName;
8089 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008090 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00008091 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8092 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8093 return Res;
8094}
8095
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008096template <typename Derived>
8097StmtResult
8098TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8099 DeclarationNameInfo DirName;
8100 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008101 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008102 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8103 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8104 return Res;
8105}
8106
Alexey Bataev13314bf2014-10-09 04:18:56 +00008107template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008108StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8109 OMPTargetDataDirective *D) {
8110 DeclarationNameInfo DirName;
8111 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008112 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008113 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8114 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8115 return Res;
8116}
8117
8118template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008119StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8120 OMPTargetEnterDataDirective *D) {
8121 DeclarationNameInfo DirName;
8122 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008123 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008124 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8125 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8126 return Res;
8127}
8128
8129template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008130StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8131 OMPTargetExitDataDirective *D) {
8132 DeclarationNameInfo DirName;
8133 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008134 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008135 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8136 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8137 return Res;
8138}
8139
8140template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008141StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8142 OMPTargetParallelDirective *D) {
8143 DeclarationNameInfo DirName;
8144 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008145 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008146 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8147 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8148 return Res;
8149}
8150
8151template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008152StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8153 OMPTargetParallelForDirective *D) {
8154 DeclarationNameInfo DirName;
8155 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008156 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008157 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8158 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8159 return Res;
8160}
8161
8162template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008163StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8164 OMPTargetUpdateDirective *D) {
8165 DeclarationNameInfo DirName;
8166 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008167 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008168 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8169 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8170 return Res;
8171}
8172
8173template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008174StmtResult
8175TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8176 DeclarationNameInfo DirName;
8177 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008178 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008179 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8180 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8181 return Res;
8182}
8183
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008184template <typename Derived>
8185StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8186 OMPCancellationPointDirective *D) {
8187 DeclarationNameInfo DirName;
8188 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008189 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008190 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8191 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8192 return Res;
8193}
8194
Alexey Bataev80909872015-07-02 11:25:17 +00008195template <typename Derived>
8196StmtResult
8197TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8198 DeclarationNameInfo DirName;
8199 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008200 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008201 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8202 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8203 return Res;
8204}
8205
Alexey Bataev49f6e782015-12-01 04:18:41 +00008206template <typename Derived>
8207StmtResult
8208TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8209 DeclarationNameInfo DirName;
8210 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008211 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008212 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8213 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8214 return Res;
8215}
8216
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008217template <typename Derived>
8218StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8219 OMPTaskLoopSimdDirective *D) {
8220 DeclarationNameInfo DirName;
8221 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008222 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008223 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8224 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8225 return Res;
8226}
8227
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008228template <typename Derived>
8229StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8230 OMPDistributeDirective *D) {
8231 DeclarationNameInfo DirName;
8232 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008233 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008234 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8235 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8236 return Res;
8237}
8238
Carlo Bertolli9925f152016-06-27 14:55:37 +00008239template <typename Derived>
8240StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8241 OMPDistributeParallelForDirective *D) {
8242 DeclarationNameInfo DirName;
8243 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008244 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008245 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8246 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8247 return Res;
8248}
8249
Kelvin Li4a39add2016-07-05 05:00:15 +00008250template <typename Derived>
8251StmtResult
8252TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8253 OMPDistributeParallelForSimdDirective *D) {
8254 DeclarationNameInfo DirName;
8255 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008256 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008257 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8258 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8259 return Res;
8260}
8261
Kelvin Li787f3fc2016-07-06 04:45:38 +00008262template <typename Derived>
8263StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8264 OMPDistributeSimdDirective *D) {
8265 DeclarationNameInfo DirName;
8266 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008267 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8269 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8270 return Res;
8271}
8272
Kelvin Lia579b912016-07-14 02:54:56 +00008273template <typename Derived>
8274StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8275 OMPTargetParallelForSimdDirective *D) {
8276 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008277 getDerived().getSema().StartOpenMPDSABlock(
8278 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008279 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8280 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8281 return Res;
8282}
8283
Kelvin Li986330c2016-07-20 22:57:10 +00008284template <typename Derived>
8285StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8286 OMPTargetSimdDirective *D) {
8287 DeclarationNameInfo DirName;
8288 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008289 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008290 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8291 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8292 return Res;
8293}
8294
Kelvin Li02532872016-08-05 14:37:37 +00008295template <typename Derived>
8296StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8297 OMPTeamsDistributeDirective *D) {
8298 DeclarationNameInfo DirName;
8299 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008300 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008301 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8302 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8303 return Res;
8304}
8305
Kelvin Li4e325f72016-10-25 12:50:55 +00008306template <typename Derived>
8307StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8308 OMPTeamsDistributeSimdDirective *D) {
8309 DeclarationNameInfo DirName;
8310 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008311 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008312 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8313 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8314 return Res;
8315}
8316
Kelvin Li579e41c2016-11-30 23:51:03 +00008317template <typename Derived>
8318StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8319 OMPTeamsDistributeParallelForSimdDirective *D) {
8320 DeclarationNameInfo DirName;
8321 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008322 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8323 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008324 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8325 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8326 return Res;
8327}
8328
Kelvin Li7ade93f2016-12-09 03:24:30 +00008329template <typename Derived>
8330StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8331 OMPTeamsDistributeParallelForDirective *D) {
8332 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008333 getDerived().getSema().StartOpenMPDSABlock(
8334 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008335 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8336 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8337 return Res;
8338}
8339
Kelvin Libf594a52016-12-17 05:48:59 +00008340template <typename Derived>
8341StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8342 OMPTargetTeamsDirective *D) {
8343 DeclarationNameInfo DirName;
8344 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008345 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008346 auto Res = getDerived().TransformOMPExecutableDirective(D);
8347 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8348 return Res;
8349}
Kelvin Li579e41c2016-11-30 23:51:03 +00008350
Kelvin Li83c451e2016-12-25 04:52:54 +00008351template <typename Derived>
8352StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8353 OMPTargetTeamsDistributeDirective *D) {
8354 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008355 getDerived().getSema().StartOpenMPDSABlock(
8356 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008357 auto Res = getDerived().TransformOMPExecutableDirective(D);
8358 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8359 return Res;
8360}
8361
Kelvin Li80e8f562016-12-29 22:16:30 +00008362template <typename Derived>
8363StmtResult
8364TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8365 OMPTargetTeamsDistributeParallelForDirective *D) {
8366 DeclarationNameInfo DirName;
8367 getDerived().getSema().StartOpenMPDSABlock(
8368 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008369 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008370 auto Res = getDerived().TransformOMPExecutableDirective(D);
8371 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8372 return Res;
8373}
8374
Kelvin Li1851df52017-01-03 05:23:48 +00008375template <typename Derived>
8376StmtResult TreeTransform<Derived>::
8377 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8378 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8379 DeclarationNameInfo DirName;
8380 getDerived().getSema().StartOpenMPDSABlock(
8381 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008382 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008383 auto Res = getDerived().TransformOMPExecutableDirective(D);
8384 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8385 return Res;
8386}
8387
Kelvin Lida681182017-01-10 18:08:18 +00008388template <typename Derived>
8389StmtResult
8390TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8391 OMPTargetTeamsDistributeSimdDirective *D) {
8392 DeclarationNameInfo DirName;
8393 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008394 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008395 auto Res = getDerived().TransformOMPExecutableDirective(D);
8396 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8397 return Res;
8398}
8399
Kelvin Li1851df52017-01-03 05:23:48 +00008400
Alexander Musman64d33f12014-06-04 07:53:32 +00008401//===----------------------------------------------------------------------===//
8402// OpenMP clause transformation
8403//===----------------------------------------------------------------------===//
8404template <typename Derived>
8405OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008406 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8407 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008408 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008409 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008410 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008411 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008412}
8413
Alexander Musman64d33f12014-06-04 07:53:32 +00008414template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008415OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8416 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8417 if (Cond.isInvalid())
8418 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008419 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008420 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008421}
8422
8423template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008424OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008425TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8426 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8427 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008428 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008429 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008430 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008431}
8432
Alexey Bataev62c87d22014-03-21 04:51:18 +00008433template <typename Derived>
8434OMPClause *
8435TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8436 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8437 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008438 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008439 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008440 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008441}
8442
Alexander Musman8bd31e62014-05-27 15:12:19 +00008443template <typename Derived>
8444OMPClause *
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00008445TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
8446 ExprResult E = getDerived().TransformExpr(C->getAllocator());
8447 if (E.isInvalid())
8448 return nullptr;
8449 return getDerived().RebuildOMPAllocatorClause(
8450 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
8451}
8452
8453template <typename Derived>
8454OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008455TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8456 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8457 if (E.isInvalid())
8458 return nullptr;
8459 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008460 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008461}
8462
8463template <typename Derived>
8464OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008465TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8466 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8467 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008468 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008469 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008470 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008471}
8472
Alexander Musman64d33f12014-06-04 07:53:32 +00008473template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008474OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008475TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008476 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008477 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008478 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008479}
8480
Alexander Musman64d33f12014-06-04 07:53:32 +00008481template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008482OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008483TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008484 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008485 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008486 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008487}
8488
Alexander Musman64d33f12014-06-04 07:53:32 +00008489template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008490OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008491TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8492 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8493 if (E.isInvalid())
8494 return nullptr;
8495 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008496 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008497 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008498 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008499 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008500}
8501
8502template <typename Derived>
8503OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008504TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008505 ExprResult E;
8506 if (auto *Num = C->getNumForLoops()) {
8507 E = getDerived().TransformExpr(Num);
8508 if (E.isInvalid())
8509 return nullptr;
8510 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008511 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008512 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008513}
8514
8515template <typename Derived>
8516OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008517TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8518 // No need to rebuild this clause, no template-dependent parameters.
8519 return C;
8520}
8521
8522template <typename Derived>
8523OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008524TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8525 // No need to rebuild this clause, no template-dependent parameters.
8526 return C;
8527}
8528
8529template <typename Derived>
8530OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008531TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8532 // No need to rebuild this clause, no template-dependent parameters.
8533 return C;
8534}
8535
8536template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008537OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8538 // No need to rebuild this clause, no template-dependent parameters.
8539 return C;
8540}
8541
8542template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008543OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8544 // No need to rebuild this clause, no template-dependent parameters.
8545 return C;
8546}
8547
8548template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008549OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008550TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8551 // No need to rebuild this clause, no template-dependent parameters.
8552 return C;
8553}
8554
8555template <typename Derived>
8556OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008557TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8558 // No need to rebuild this clause, no template-dependent parameters.
8559 return C;
8560}
8561
8562template <typename Derived>
8563OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008564TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8565 // No need to rebuild this clause, no template-dependent parameters.
8566 return C;
8567}
8568
8569template <typename Derived>
8570OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008571TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8572 // No need to rebuild this clause, no template-dependent parameters.
8573 return C;
8574}
8575
8576template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008577OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8578 // No need to rebuild this clause, no template-dependent parameters.
8579 return C;
8580}
8581
8582template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008583OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008584TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8585 // No need to rebuild this clause, no template-dependent parameters.
8586 return C;
8587}
8588
8589template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008590OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8591 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008592 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008593}
8594
8595template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008596OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8597 OMPUnifiedSharedMemoryClause *C) {
8598 llvm_unreachable(
8599 "unified_shared_memory clause cannot appear in dependent context");
8600}
8601
8602template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008603OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8604 OMPReverseOffloadClause *C) {
8605 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8606}
8607
8608template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008609OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8610 OMPDynamicAllocatorsClause *C) {
8611 llvm_unreachable(
8612 "dynamic_allocators clause cannot appear in dependent context");
8613}
8614
8615template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008616OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8617 OMPAtomicDefaultMemOrderClause *C) {
8618 llvm_unreachable(
8619 "atomic_default_mem_order clause cannot appear in dependent context");
8620}
8621
8622template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008623OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008624TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008625 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008626 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 Bataev5ec3eb12013-07-19 03:13:43 +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 Bataev5ec3eb12013-07-19 03:13:43 +00008632 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008633 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008634 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008635}
8636
Alexander Musman64d33f12014-06-04 07:53:32 +00008637template <typename Derived>
8638OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8639 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008640 llvm::SmallVector<Expr *, 16> Vars;
8641 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008642 for (auto *VE : C->varlists()) {
8643 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008644 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008645 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008646 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008647 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008648 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008649 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008650}
8651
Alexander Musman64d33f12014-06-04 07:53:32 +00008652template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008653OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008654TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8655 llvm::SmallVector<Expr *, 16> Vars;
8656 Vars.reserve(C->varlist_size());
8657 for (auto *VE : C->varlists()) {
8658 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8659 if (EVar.isInvalid())
8660 return nullptr;
8661 Vars.push_back(EVar.get());
8662 }
8663 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008664 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008665}
8666
8667template <typename Derived>
8668OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008669TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8670 llvm::SmallVector<Expr *, 16> Vars;
8671 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008672 for (auto *VE : C->varlists()) {
8673 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008674 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008675 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008676 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008677 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008678 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008679 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008680}
8681
Alexander Musman64d33f12014-06-04 07:53:32 +00008682template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008683OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008684TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8685 llvm::SmallVector<Expr *, 16> Vars;
8686 Vars.reserve(C->varlist_size());
8687 for (auto *VE : C->varlists()) {
8688 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8689 if (EVar.isInvalid())
8690 return nullptr;
8691 Vars.push_back(EVar.get());
8692 }
8693 CXXScopeSpec ReductionIdScopeSpec;
8694 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8695
8696 DeclarationNameInfo NameInfo = C->getNameInfo();
8697 if (NameInfo.getName()) {
8698 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8699 if (!NameInfo.getName())
8700 return nullptr;
8701 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008702 // Build a list of all UDR decls with the same names ranged by the Scopes.
8703 // The Scope boundary is a duplication of the previous decl.
8704 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8705 for (auto *E : C->reduction_ops()) {
8706 // Transform all the decls.
8707 if (E) {
8708 auto *ULE = cast<UnresolvedLookupExpr>(E);
8709 UnresolvedSet<8> Decls;
8710 for (auto *D : ULE->decls()) {
8711 NamedDecl *InstD =
8712 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8713 Decls.addDecl(InstD, InstD->getAccess());
8714 }
8715 UnresolvedReductions.push_back(
8716 UnresolvedLookupExpr::Create(
8717 SemaRef.Context, /*NamingClass=*/nullptr,
8718 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8719 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8720 Decls.begin(), Decls.end()));
8721 } else
8722 UnresolvedReductions.push_back(nullptr);
8723 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008724 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008725 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008726 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008727}
8728
8729template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008730OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8731 OMPTaskReductionClause *C) {
8732 llvm::SmallVector<Expr *, 16> Vars;
8733 Vars.reserve(C->varlist_size());
8734 for (auto *VE : C->varlists()) {
8735 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8736 if (EVar.isInvalid())
8737 return nullptr;
8738 Vars.push_back(EVar.get());
8739 }
8740 CXXScopeSpec ReductionIdScopeSpec;
8741 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8742
8743 DeclarationNameInfo NameInfo = C->getNameInfo();
8744 if (NameInfo.getName()) {
8745 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8746 if (!NameInfo.getName())
8747 return nullptr;
8748 }
8749 // Build a list of all UDR decls with the same names ranged by the Scopes.
8750 // The Scope boundary is a duplication of the previous decl.
8751 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8752 for (auto *E : C->reduction_ops()) {
8753 // Transform all the decls.
8754 if (E) {
8755 auto *ULE = cast<UnresolvedLookupExpr>(E);
8756 UnresolvedSet<8> Decls;
8757 for (auto *D : ULE->decls()) {
8758 NamedDecl *InstD =
8759 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8760 Decls.addDecl(InstD, InstD->getAccess());
8761 }
8762 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8763 SemaRef.Context, /*NamingClass=*/nullptr,
8764 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8765 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8766 } else
8767 UnresolvedReductions.push_back(nullptr);
8768 }
8769 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008770 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008771 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008772}
8773
8774template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008775OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008776TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8777 llvm::SmallVector<Expr *, 16> Vars;
8778 Vars.reserve(C->varlist_size());
8779 for (auto *VE : C->varlists()) {
8780 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8781 if (EVar.isInvalid())
8782 return nullptr;
8783 Vars.push_back(EVar.get());
8784 }
8785 CXXScopeSpec ReductionIdScopeSpec;
8786 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8787
8788 DeclarationNameInfo NameInfo = C->getNameInfo();
8789 if (NameInfo.getName()) {
8790 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8791 if (!NameInfo.getName())
8792 return nullptr;
8793 }
8794 // Build a list of all UDR decls with the same names ranged by the Scopes.
8795 // The Scope boundary is a duplication of the previous decl.
8796 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8797 for (auto *E : C->reduction_ops()) {
8798 // Transform all the decls.
8799 if (E) {
8800 auto *ULE = cast<UnresolvedLookupExpr>(E);
8801 UnresolvedSet<8> Decls;
8802 for (auto *D : ULE->decls()) {
8803 NamedDecl *InstD =
8804 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8805 Decls.addDecl(InstD, InstD->getAccess());
8806 }
8807 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8808 SemaRef.Context, /*NamingClass=*/nullptr,
8809 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8810 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8811 } else
8812 UnresolvedReductions.push_back(nullptr);
8813 }
8814 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008815 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008816 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008817}
8818
8819template <typename Derived>
8820OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008821TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8822 llvm::SmallVector<Expr *, 16> Vars;
8823 Vars.reserve(C->varlist_size());
8824 for (auto *VE : C->varlists()) {
8825 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8826 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008827 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008828 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008829 }
8830 ExprResult Step = getDerived().TransformExpr(C->getStep());
8831 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008832 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008833 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008834 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008835 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008836}
8837
Alexander Musman64d33f12014-06-04 07:53:32 +00008838template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008839OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008840TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8841 llvm::SmallVector<Expr *, 16> Vars;
8842 Vars.reserve(C->varlist_size());
8843 for (auto *VE : C->varlists()) {
8844 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8845 if (EVar.isInvalid())
8846 return nullptr;
8847 Vars.push_back(EVar.get());
8848 }
8849 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8850 if (Alignment.isInvalid())
8851 return nullptr;
8852 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008853 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008854 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008855}
8856
Alexander Musman64d33f12014-06-04 07:53:32 +00008857template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008858OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008859TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8860 llvm::SmallVector<Expr *, 16> Vars;
8861 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008862 for (auto *VE : C->varlists()) {
8863 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008864 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008865 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008866 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008867 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008868 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008869 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008870}
8871
Alexey Bataevbae9a792014-06-27 10:37:06 +00008872template <typename Derived>
8873OMPClause *
8874TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8875 llvm::SmallVector<Expr *, 16> Vars;
8876 Vars.reserve(C->varlist_size());
8877 for (auto *VE : C->varlists()) {
8878 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8879 if (EVar.isInvalid())
8880 return nullptr;
8881 Vars.push_back(EVar.get());
8882 }
8883 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008884 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008885}
8886
Alexey Bataev6125da92014-07-21 11:26:11 +00008887template <typename Derived>
8888OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *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 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008897 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008898 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008899}
8900
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008901template <typename Derived>
8902OMPClause *
8903TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8904 llvm::SmallVector<Expr *, 16> Vars;
8905 Vars.reserve(C->varlist_size());
8906 for (auto *VE : C->varlists()) {
8907 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8908 if (EVar.isInvalid())
8909 return nullptr;
8910 Vars.push_back(EVar.get());
8911 }
8912 return getDerived().RebuildOMPDependClause(
8913 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008914 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008915}
8916
Michael Wonge710d542015-08-07 16:16:36 +00008917template <typename Derived>
8918OMPClause *
8919TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8920 ExprResult E = getDerived().TransformExpr(C->getDevice());
8921 if (E.isInvalid())
8922 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008923 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008924 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008925}
8926
Michael Kruse01f670d2019-02-22 22:29:42 +00008927template <typename Derived, class T>
8928bool transformOMPMappableExprListClause(
8929 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
8930 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
8931 DeclarationNameInfo &MapperIdInfo,
8932 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
8933 // Transform expressions in the list.
Kelvin Li0bff7af2015-11-23 05:32:03 +00008934 Vars.reserve(C->varlist_size());
8935 for (auto *VE : C->varlists()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008936 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
Kelvin Li0bff7af2015-11-23 05:32:03 +00008937 if (EVar.isInvalid())
Michael Kruse01f670d2019-02-22 22:29:42 +00008938 return true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008939 Vars.push_back(EVar.get());
8940 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008941 // Transform mapper scope specifier and identifier.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008942 NestedNameSpecifierLoc QualifierLoc;
8943 if (C->getMapperQualifierLoc()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008944 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008945 C->getMapperQualifierLoc());
8946 if (!QualifierLoc)
Michael Kruse01f670d2019-02-22 22:29:42 +00008947 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008948 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00008949 MapperIdScopeSpec.Adopt(QualifierLoc);
Michael Kruse01f670d2019-02-22 22:29:42 +00008950 MapperIdInfo = C->getMapperIdInfo();
Michael Kruse4304e9d2019-02-19 16:38:20 +00008951 if (MapperIdInfo.getName()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008952 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
Michael Kruse4304e9d2019-02-19 16:38:20 +00008953 if (!MapperIdInfo.getName())
Michael Kruse01f670d2019-02-22 22:29:42 +00008954 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008955 }
8956 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
8957 // the previous user-defined mapper lookup in dependent environment.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008958 for (auto *E : C->mapperlists()) {
8959 // Transform all the decls.
8960 if (E) {
8961 auto *ULE = cast<UnresolvedLookupExpr>(E);
8962 UnresolvedSet<8> Decls;
8963 for (auto *D : ULE->decls()) {
8964 NamedDecl *InstD =
Michael Kruse01f670d2019-02-22 22:29:42 +00008965 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008966 Decls.addDecl(InstD, InstD->getAccess());
8967 }
8968 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
Michael Kruse01f670d2019-02-22 22:29:42 +00008969 TT.getSema().Context, /*NamingClass=*/nullptr,
8970 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
8971 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
8972 Decls.end()));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008973 } else {
8974 UnresolvedMappers.push_back(nullptr);
8975 }
8976 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008977 return false;
8978}
8979
8980template <typename Derived>
8981OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00008982 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00008983 llvm::SmallVector<Expr *, 16> Vars;
8984 CXXScopeSpec MapperIdScopeSpec;
8985 DeclarationNameInfo MapperIdInfo;
8986 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
8987 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
8988 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
8989 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008990 return getDerived().RebuildOMPMapClause(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008991 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
8992 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
8993 C->getColonLoc(), Vars, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00008994}
8995
Kelvin Li099bb8c2015-11-24 20:50:12 +00008996template <typename Derived>
8997OMPClause *
Alexey Bataeve04483e2019-03-27 14:14:31 +00008998TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
8999 Expr *Allocator = C->getAllocator();
9000 if (Allocator) {
9001 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
9002 if (AllocatorRes.isInvalid())
9003 return nullptr;
9004 Allocator = AllocatorRes.get();
9005 }
9006 llvm::SmallVector<Expr *, 16> Vars;
9007 Vars.reserve(C->varlist_size());
9008 for (auto *VE : C->varlists()) {
9009 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9010 if (EVar.isInvalid())
9011 return nullptr;
9012 Vars.push_back(EVar.get());
9013 }
9014 return getDerived().RebuildOMPAllocateClause(
9015 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
9016 C->getEndLoc());
9017}
9018
9019template <typename Derived>
9020OMPClause *
Kelvin Li099bb8c2015-11-24 20:50:12 +00009021TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
9022 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
9023 if (E.isInvalid())
9024 return nullptr;
9025 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009026 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00009027}
9028
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009029template <typename Derived>
9030OMPClause *
9031TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
9032 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
9033 if (E.isInvalid())
9034 return nullptr;
9035 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009036 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009037}
9038
Alexey Bataeva0569352015-12-01 10:17:31 +00009039template <typename Derived>
9040OMPClause *
9041TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
9042 ExprResult E = getDerived().TransformExpr(C->getPriority());
9043 if (E.isInvalid())
9044 return nullptr;
9045 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009046 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00009047}
9048
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009049template <typename Derived>
9050OMPClause *
9051TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
9052 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
9053 if (E.isInvalid())
9054 return nullptr;
9055 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009056 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009057}
9058
Alexey Bataev382967a2015-12-08 12:06:20 +00009059template <typename Derived>
9060OMPClause *
9061TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
9062 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
9063 if (E.isInvalid())
9064 return nullptr;
9065 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009066 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00009067}
9068
Alexey Bataev28c75412015-12-15 08:19:24 +00009069template <typename Derived>
9070OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
9071 ExprResult E = getDerived().TransformExpr(C->getHint());
9072 if (E.isInvalid())
9073 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009074 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009075 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00009076}
9077
Carlo Bertollib4adf552016-01-15 18:50:31 +00009078template <typename Derived>
9079OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
9080 OMPDistScheduleClause *C) {
9081 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9082 if (E.isInvalid())
9083 return nullptr;
9084 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009085 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009086 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00009087}
9088
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00009089template <typename Derived>
9090OMPClause *
9091TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
9092 return C;
9093}
9094
Samuel Antao661c0902016-05-26 17:39:58 +00009095template <typename Derived>
9096OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009097 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009098 llvm::SmallVector<Expr *, 16> Vars;
9099 CXXScopeSpec MapperIdScopeSpec;
9100 DeclarationNameInfo MapperIdInfo;
9101 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9102 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
9103 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9104 return nullptr;
9105 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo,
9106 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00009107}
9108
Samuel Antaoec172c62016-05-26 17:49:04 +00009109template <typename Derived>
9110OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009111 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse0336c752019-02-25 20:34:15 +00009112 llvm::SmallVector<Expr *, 16> Vars;
9113 CXXScopeSpec MapperIdScopeSpec;
9114 DeclarationNameInfo MapperIdInfo;
9115 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9116 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
9117 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9118 return nullptr;
9119 return getDerived().RebuildOMPFromClause(
9120 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00009121}
9122
Carlo Bertolli2404b172016-07-13 15:37:16 +00009123template <typename Derived>
9124OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
9125 OMPUseDevicePtrClause *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().RebuildOMPUseDevicePtrClause(Vars, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00009136}
9137
Carlo Bertolli70594e92016-07-13 17:16:49 +00009138template <typename Derived>
9139OMPClause *
9140TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
9141 llvm::SmallVector<Expr *, 16> Vars;
9142 Vars.reserve(C->varlist_size());
9143 for (auto *VE : C->varlists()) {
9144 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9145 if (EVar.isInvalid())
9146 return nullptr;
9147 Vars.push_back(EVar.get());
9148 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009149 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9150 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00009151}
9152
Douglas Gregorebe10102009-08-20 07:17:43 +00009153//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00009154// Expression transformation
9155//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00009156template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009157ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00009158TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
9159 return TransformExpr(E->getSubExpr());
9160}
9161
9162template<typename Derived>
9163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009164TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00009165 if (!E->isTypeDependent())
9166 return E;
9167
9168 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00009169 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00009170}
Mike Stump11289f42009-09-09 15:08:12 +00009171
9172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009174TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009175 NestedNameSpecifierLoc QualifierLoc;
9176 if (E->getQualifierLoc()) {
9177 QualifierLoc
9178 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9179 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009180 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009181 }
John McCallce546572009-12-08 09:08:17 +00009182
9183 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009184 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9185 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009186 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009188
John McCall815039a2010-08-17 21:27:17 +00009189 DeclarationNameInfo NameInfo = E->getNameInfo();
9190 if (NameInfo.getName()) {
9191 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9192 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009193 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009194 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009195
9196 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009197 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009198 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009199 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009200 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009201
9202 // Mark it referenced in the new context regardless.
9203 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009204 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009205
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009206 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009207 }
John McCallce546572009-12-08 09:08:17 +00009208
Craig Topperc3ec1492014-05-26 06:22:03 +00009209 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009210 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009211 TemplateArgs = &TransArgs;
9212 TransArgs.setLAngleLoc(E->getLAngleLoc());
9213 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009214 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9215 E->getNumTemplateArgs(),
9216 TransArgs))
9217 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009218 }
9219
Chad Rosier1dcde962012-08-08 18:46:20 +00009220 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009221 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009222}
Mike Stump11289f42009-09-09 15:08:12 +00009223
Douglas Gregora16548e2009-08-11 05:31:07 +00009224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009226TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009227 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009228}
Mike Stump11289f42009-09-09 15:08:12 +00009229
Leonard Chandb01c3a2018-06-20 17:19:40 +00009230template <typename Derived>
9231ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9232 FixedPointLiteral *E) {
9233 return E;
9234}
9235
Douglas Gregora16548e2009-08-11 05:31:07 +00009236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009238TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009239 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009240}
Mike Stump11289f42009-09-09 15:08:12 +00009241
Douglas Gregora16548e2009-08-11 05:31:07 +00009242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009244TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009245 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009246}
Mike Stump11289f42009-09-09 15:08:12 +00009247
Douglas Gregora16548e2009-08-11 05:31:07 +00009248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009249ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009250TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009251 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009252}
Mike Stump11289f42009-09-09 15:08:12 +00009253
Douglas Gregora16548e2009-08-11 05:31:07 +00009254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009257 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009258}
9259
9260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009261ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009262TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009263 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009264 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009265 return SemaRef.MaybeBindToTemporary(E);
9266}
9267
9268template<typename Derived>
9269ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009270TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9271 ExprResult ControllingExpr =
9272 getDerived().TransformExpr(E->getControllingExpr());
9273 if (ControllingExpr.isInvalid())
9274 return ExprError();
9275
Chris Lattner01cf8db2011-07-20 06:58:45 +00009276 SmallVector<Expr *, 4> AssocExprs;
9277 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009278 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9279 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9280 if (TSI) {
9281 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009282 if (!AssocType)
9283 return ExprError();
9284 AssocTypes.push_back(AssocType);
9285 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009286 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009287 }
9288
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009289 ExprResult AssocExpr =
9290 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009291 if (AssocExpr.isInvalid())
9292 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009293 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009294 }
9295
9296 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9297 E->getDefaultLoc(),
9298 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009299 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009300 AssocTypes,
9301 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009302}
9303
9304template<typename Derived>
9305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009306TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009307 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009308 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009310
Douglas Gregora16548e2009-08-11 05:31:07 +00009311 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009312 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009313
John McCallb268a282010-08-23 23:25:46 +00009314 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009315 E->getRParen());
9316}
9317
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009318/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009319/// allowed to refer to a non-static member of a class even if there's no 'this'
9320/// object available.
9321template<typename Derived>
9322ExprResult
9323TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9324 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009325 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009326 else
9327 return getDerived().TransformExpr(E);
9328}
9329
Mike Stump11289f42009-09-09 15:08:12 +00009330template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009331ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009332TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009333 ExprResult SubExpr;
9334 if (E->getOpcode() == UO_AddrOf)
9335 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9336 else
9337 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009338 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009339 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009342 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009343
Douglas Gregora16548e2009-08-11 05:31:07 +00009344 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9345 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009346 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009347}
Mike Stump11289f42009-09-09 15:08:12 +00009348
Douglas Gregora16548e2009-08-11 05:31:07 +00009349template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009350ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009351TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9352 // Transform the type.
9353 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9354 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009355 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009356
Douglas Gregor882211c2010-04-28 22:16:22 +00009357 // Transform all of the components into components similar to what the
9358 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009359 // FIXME: It would be slightly more efficient in the non-dependent case to
9360 // just map FieldDecls, rather than requiring the rebuilder to look for
9361 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009362 // template code that we don't care.
9363 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009364 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009365 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009366 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009367 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009368 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009369 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009370 Comp.LocStart = ON.getSourceRange().getBegin();
9371 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009372 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009373 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009374 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009375 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009376 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009377 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009378
Douglas Gregor882211c2010-04-28 22:16:22 +00009379 ExprChanged = ExprChanged || Index.get() != FromIndex;
9380 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009381 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009382 break;
9383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009384
James Y Knight7281c352015-12-29 22:31:18 +00009385 case OffsetOfNode::Field:
9386 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009387 Comp.isBrackets = false;
9388 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009389 if (!Comp.U.IdentInfo)
9390 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Douglas Gregor882211c2010-04-28 22:16:22 +00009392 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009393
James Y Knight7281c352015-12-29 22:31:18 +00009394 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009395 // Will be recomputed during the rebuild.
9396 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009398
Douglas Gregor882211c2010-04-28 22:16:22 +00009399 Components.push_back(Comp);
9400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009401
Douglas Gregor882211c2010-04-28 22:16:22 +00009402 // If nothing changed, retain the existing expression.
9403 if (!getDerived().AlwaysRebuild() &&
9404 Type == E->getTypeSourceInfo() &&
9405 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009406 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009407
Douglas Gregor882211c2010-04-28 22:16:22 +00009408 // Build a new offsetof expression.
9409 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009410 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009411}
9412
9413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009414ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009415TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009416 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009417 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009418 return E;
John McCall8d69a212010-11-15 23:31:06 +00009419}
9420
9421template<typename Derived>
9422ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009423TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9424 return E;
9425}
9426
9427template<typename Derived>
9428ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009429TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009430 // Rebuild the syntactic form. The original syntactic form has
9431 // opaque-value expressions in it, so strip those away and rebuild
9432 // the result. This is a really awful way of doing this, but the
9433 // better solution (rebuilding the semantic expressions and
9434 // rebinding OVEs as necessary) doesn't work; we'd need
9435 // TreeTransform to not strip away implicit conversions.
9436 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9437 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009438 if (result.isInvalid()) return ExprError();
9439
9440 // If that gives us a pseudo-object result back, the pseudo-object
9441 // expression must have been an lvalue-to-rvalue conversion which we
9442 // should reapply.
9443 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009444 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009445
9446 return result;
9447}
9448
9449template<typename Derived>
9450ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009451TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9452 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009453 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009454 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009455
John McCallbcd03502009-12-07 02:54:59 +00009456 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009457 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009458 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009459
John McCall4c98fd82009-11-04 07:28:41 +00009460 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009461 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009462
Peter Collingbournee190dee2011-03-11 19:24:49 +00009463 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9464 E->getKind(),
9465 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009466 }
Mike Stump11289f42009-09-09 15:08:12 +00009467
Eli Friedmane4f22df2012-02-29 04:03:55 +00009468 // C++0x [expr.sizeof]p1:
9469 // The operand is either an expression, which is an unevaluated operand
9470 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009471 EnterExpressionEvaluationContext Unevaluated(
9472 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9473 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009474
Reid Kleckner32506ed2014-06-12 23:03:48 +00009475 // Try to recover if we have something like sizeof(T::X) where X is a type.
9476 // Notably, there must be *exactly* one set of parens if X is a type.
9477 TypeSourceInfo *RecoveryTSI = nullptr;
9478 ExprResult SubExpr;
9479 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9480 if (auto *DRE =
9481 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9482 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9483 PE, DRE, false, &RecoveryTSI);
9484 else
9485 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9486
9487 if (RecoveryTSI) {
9488 return getDerived().RebuildUnaryExprOrTypeTrait(
9489 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9490 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009491 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009492
Eli Friedmane4f22df2012-02-29 04:03:55 +00009493 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009494 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009495
Peter Collingbournee190dee2011-03-11 19:24:49 +00009496 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9497 E->getOperatorLoc(),
9498 E->getKind(),
9499 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009500}
Mike Stump11289f42009-09-09 15:08:12 +00009501
Douglas Gregora16548e2009-08-11 05:31:07 +00009502template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009503ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009504TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009505 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009506 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009507 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009508
John McCalldadc5752010-08-24 06:29:42 +00009509 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009510 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009511 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009512
9513
Douglas Gregora16548e2009-08-11 05:31:07 +00009514 if (!getDerived().AlwaysRebuild() &&
9515 LHS.get() == E->getLHS() &&
9516 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009517 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009518
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009519 return getDerived().RebuildArraySubscriptExpr(
9520 LHS.get(),
9521 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009522}
Mike Stump11289f42009-09-09 15:08:12 +00009523
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009524template <typename Derived>
9525ExprResult
9526TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9527 ExprResult Base = getDerived().TransformExpr(E->getBase());
9528 if (Base.isInvalid())
9529 return ExprError();
9530
9531 ExprResult LowerBound;
9532 if (E->getLowerBound()) {
9533 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9534 if (LowerBound.isInvalid())
9535 return ExprError();
9536 }
9537
9538 ExprResult Length;
9539 if (E->getLength()) {
9540 Length = getDerived().TransformExpr(E->getLength());
9541 if (Length.isInvalid())
9542 return ExprError();
9543 }
9544
9545 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9546 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9547 return E;
9548
9549 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009550 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009551 Length.get(), E->getRBracketLoc());
9552}
9553
Mike Stump11289f42009-09-09 15:08:12 +00009554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009556TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009557 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009558 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009559 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009560 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009561
9562 // Transform arguments.
9563 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009564 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009565 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009566 &ArgChanged))
9567 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009568
Douglas Gregora16548e2009-08-11 05:31:07 +00009569 if (!getDerived().AlwaysRebuild() &&
9570 Callee.get() == E->getCallee() &&
9571 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009572 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009573
Douglas Gregora16548e2009-08-11 05:31:07 +00009574 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009575 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009576 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009577 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009578 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009579 E->getRParenLoc());
9580}
Mike Stump11289f42009-09-09 15:08:12 +00009581
9582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009583ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009584TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009585 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009586 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009587 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009588
Douglas Gregorea972d32011-02-28 21:54:11 +00009589 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009590 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009591 QualifierLoc
9592 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009593
Douglas Gregorea972d32011-02-28 21:54:11 +00009594 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009595 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009596 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009597 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009598
Eli Friedman2cfcef62009-12-04 06:40:45 +00009599 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009600 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9601 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009602 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009603 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009604
John McCall16df1e52010-03-30 21:47:33 +00009605 NamedDecl *FoundDecl = E->getFoundDecl();
9606 if (FoundDecl == E->getMemberDecl()) {
9607 FoundDecl = Member;
9608 } else {
9609 FoundDecl = cast_or_null<NamedDecl>(
9610 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9611 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009612 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009613 }
9614
Douglas Gregora16548e2009-08-11 05:31:07 +00009615 if (!getDerived().AlwaysRebuild() &&
9616 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009617 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009618 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009619 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009620 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009621
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009622 // Mark it referenced in the new context regardless.
9623 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009624 SemaRef.MarkMemberReferenced(E);
9625
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009626 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009627 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009628
John McCall6b51f282009-11-23 01:53:49 +00009629 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009630 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009631 TransArgs.setLAngleLoc(E->getLAngleLoc());
9632 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009633 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9634 E->getNumTemplateArgs(),
9635 TransArgs))
9636 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009638
Douglas Gregora16548e2009-08-11 05:31:07 +00009639 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009640 SourceLocation FakeOperatorLoc =
9641 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009642
John McCall38836f02010-01-15 08:34:02 +00009643 // FIXME: to do this check properly, we will need to preserve the
9644 // first-qualifier-in-scope here, just in case we had a dependent
9645 // base (and therefore couldn't do the check) and a
9646 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009647 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009648 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9649 if (MemberNameInfo.getName()) {
9650 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9651 if (!MemberNameInfo.getName())
9652 return ExprError();
9653 }
John McCall38836f02010-01-15 08:34:02 +00009654
John McCallb268a282010-08-23 23:25:46 +00009655 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009656 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009657 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009658 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009659 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009660 Member,
John McCall16df1e52010-03-30 21:47:33 +00009661 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009662 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009663 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009664 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009665}
Mike Stump11289f42009-09-09 15:08:12 +00009666
Douglas Gregora16548e2009-08-11 05:31:07 +00009667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009669TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009670 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009671 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009672 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009673
John McCalldadc5752010-08-24 06:29:42 +00009674 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009677
Douglas Gregora16548e2009-08-11 05:31:07 +00009678 if (!getDerived().AlwaysRebuild() &&
9679 LHS.get() == E->getLHS() &&
9680 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009681 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009682
Lang Hames5de91cc2012-10-02 04:45:10 +00009683 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009684 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009685
Douglas Gregora16548e2009-08-11 05:31:07 +00009686 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009687 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009688}
9689
Mike Stump11289f42009-09-09 15:08:12 +00009690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009691ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009692TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009693 CompoundAssignOperator *E) {
9694 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009695}
Mike Stump11289f42009-09-09 15:08:12 +00009696
Douglas Gregora16548e2009-08-11 05:31:07 +00009697template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009698ExprResult TreeTransform<Derived>::
9699TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9700 // Just rebuild the common and RHS expressions and see whether we
9701 // get any changes.
9702
9703 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9704 if (commonExpr.isInvalid())
9705 return ExprError();
9706
9707 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9708 if (rhs.isInvalid())
9709 return ExprError();
9710
9711 if (!getDerived().AlwaysRebuild() &&
9712 commonExpr.get() == e->getCommon() &&
9713 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009714 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009715
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009716 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009717 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009718 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009719 e->getColonLoc(),
9720 rhs.get());
9721}
9722
9723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009725TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009726 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009727 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009729
John McCalldadc5752010-08-24 06:29:42 +00009730 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009731 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009733
John McCalldadc5752010-08-24 06:29:42 +00009734 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009736 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009737
Douglas Gregora16548e2009-08-11 05:31:07 +00009738 if (!getDerived().AlwaysRebuild() &&
9739 Cond.get() == E->getCond() &&
9740 LHS.get() == E->getLHS() &&
9741 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009742 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009743
John McCallb268a282010-08-23 23:25:46 +00009744 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009745 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009746 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009747 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009748 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009749}
Mike Stump11289f42009-09-09 15:08:12 +00009750
9751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009753TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009754 // Implicit casts are eliminated during transformation, since they
9755 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009756 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009757}
Mike Stump11289f42009-09-09 15:08:12 +00009758
Douglas Gregora16548e2009-08-11 05:31:07 +00009759template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009760ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009761TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009762 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9763 if (!Type)
9764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009765
John McCalldadc5752010-08-24 06:29:42 +00009766 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009767 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009768 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009770
Douglas Gregora16548e2009-08-11 05:31:07 +00009771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009772 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009773 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009774 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009775
John McCall97513962010-01-15 18:39:57 +00009776 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009777 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009778 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009779 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009780}
Mike Stump11289f42009-09-09 15:08:12 +00009781
Douglas Gregora16548e2009-08-11 05:31:07 +00009782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009783ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009784TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009785 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9786 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9787 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009789
John McCalldadc5752010-08-24 06:29:42 +00009790 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora16548e2009-08-11 05:31:07 +00009794 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009795 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009796 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009797 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009798
John McCall5d7aa7f2010-01-19 22:33:45 +00009799 // Note: the expression type doesn't necessarily match the
9800 // type-as-written, but that's okay, because it should always be
9801 // derivable from the initializer.
9802
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009803 return getDerived().RebuildCompoundLiteralExpr(
9804 E->getLParenLoc(), NewT,
9805 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009806}
Mike Stump11289f42009-09-09 15:08:12 +00009807
Douglas Gregora16548e2009-08-11 05:31:07 +00009808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009810TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009811 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009812 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009814
Douglas Gregora16548e2009-08-11 05:31:07 +00009815 if (!getDerived().AlwaysRebuild() &&
9816 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009817 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009818
Douglas Gregora16548e2009-08-11 05:31:07 +00009819 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009820 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009821 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009822 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009823 E->getAccessorLoc(),
9824 E->getAccessor());
9825}
Mike Stump11289f42009-09-09 15:08:12 +00009826
Douglas Gregora16548e2009-08-11 05:31:07 +00009827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009829TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009830 if (InitListExpr *Syntactic = E->getSyntacticForm())
9831 E = Syntactic;
9832
Douglas Gregora16548e2009-08-11 05:31:07 +00009833 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009834
Richard Smith12938cf2018-09-26 04:36:55 +00009835 EnterExpressionEvaluationContext Context(
9836 getSema(), EnterExpressionEvaluationContext::InitList);
9837
Benjamin Kramerf0623432012-08-23 22:51:59 +00009838 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009839 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009840 Inits, &InitChanged))
9841 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009842
Richard Smith520449d2015-02-05 06:15:50 +00009843 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9844 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9845 // in some cases. We can't reuse it in general, because the syntactic and
9846 // semantic forms are linked, and we can't know that semantic form will
9847 // match even if the syntactic form does.
9848 }
Mike Stump11289f42009-09-09 15:08:12 +00009849
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009850 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009851 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009852}
Mike Stump11289f42009-09-09 15:08:12 +00009853
Douglas Gregora16548e2009-08-11 05:31:07 +00009854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009856TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009857 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009858
Douglas Gregorebe10102009-08-20 07:17:43 +00009859 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009860 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009861 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009863
Douglas Gregorebe10102009-08-20 07:17:43 +00009864 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009865 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009866 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009867 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9868 if (D.isFieldDesignator()) {
9869 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9870 D.getDotLoc(),
9871 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009872 if (D.getField()) {
9873 FieldDecl *Field = cast_or_null<FieldDecl>(
9874 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9875 if (Field != D.getField())
9876 // Rebuild the expression when the transformed FieldDecl is
9877 // different to the already assigned FieldDecl.
9878 ExprChanged = true;
9879 } else {
9880 // Ensure that the designator expression is rebuilt when there isn't
9881 // a resolved FieldDecl in the designator as we don't want to assign
9882 // a FieldDecl to a pattern designator that will be instantiated again.
9883 ExprChanged = true;
9884 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009885 continue;
9886 }
Mike Stump11289f42009-09-09 15:08:12 +00009887
David Majnemerf7e36092016-06-23 00:15:04 +00009888 if (D.isArrayDesignator()) {
9889 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009890 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009891 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009892
David Majnemerf7e36092016-06-23 00:15:04 +00009893 Desig.AddDesignator(
9894 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009895
David Majnemerf7e36092016-06-23 00:15:04 +00009896 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009897 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009898 continue;
9899 }
Mike Stump11289f42009-09-09 15:08:12 +00009900
David Majnemerf7e36092016-06-23 00:15:04 +00009901 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009902 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009903 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009904 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009905 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009906
David Majnemerf7e36092016-06-23 00:15:04 +00009907 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009908 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009910
9911 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009912 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009913 D.getLBracketLoc(),
9914 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009915
David Majnemerf7e36092016-06-23 00:15:04 +00009916 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9917 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009918
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009919 ArrayExprs.push_back(Start.get());
9920 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009921 }
Mike Stump11289f42009-09-09 15:08:12 +00009922
Douglas Gregora16548e2009-08-11 05:31:07 +00009923 if (!getDerived().AlwaysRebuild() &&
9924 Init.get() == E->getInit() &&
9925 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009926 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009927
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009928 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009929 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009930 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009931}
Mike Stump11289f42009-09-09 15:08:12 +00009932
Yunzhong Gaocb779302015-06-10 00:27:52 +00009933// Seems that if TransformInitListExpr() only works on the syntactic form of an
9934// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9935template<typename Derived>
9936ExprResult
9937TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9938 DesignatedInitUpdateExpr *E) {
9939 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9940 "initializer");
9941 return ExprError();
9942}
9943
9944template<typename Derived>
9945ExprResult
9946TreeTransform<Derived>::TransformNoInitExpr(
9947 NoInitExpr *E) {
9948 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9949 return ExprError();
9950}
9951
Douglas Gregora16548e2009-08-11 05:31:07 +00009952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009953ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009954TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9955 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9956 return ExprError();
9957}
9958
9959template<typename Derived>
9960ExprResult
9961TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9962 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9963 return ExprError();
9964}
9965
9966template<typename Derived>
9967ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009968TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009969 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009970 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009971
Douglas Gregor3da3c062009-10-28 00:29:27 +00009972 // FIXME: Will we ever have proper type location here? Will we actually
9973 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009974 QualType T = getDerived().TransformType(E->getType());
9975 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009977
Douglas Gregora16548e2009-08-11 05:31:07 +00009978 if (!getDerived().AlwaysRebuild() &&
9979 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009980 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009981
Douglas Gregora16548e2009-08-11 05:31:07 +00009982 return getDerived().RebuildImplicitValueInitExpr(T);
9983}
Mike Stump11289f42009-09-09 15:08:12 +00009984
Douglas Gregora16548e2009-08-11 05:31:07 +00009985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009987TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009988 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9989 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009991
John McCalldadc5752010-08-24 06:29:42 +00009992 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009993 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009995
Douglas Gregora16548e2009-08-11 05:31:07 +00009996 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009997 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009998 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009999 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010000
John McCallb268a282010-08-23 23:25:46 +000010001 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +000010002 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010003}
10004
10005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010006ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010007TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010008 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010009 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +000010010 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
10011 &ArgumentChanged))
10012 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010013
Douglas Gregora16548e2009-08-11 05:31:07 +000010014 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010015 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +000010016 E->getRParenLoc());
10017}
Mike Stump11289f42009-09-09 15:08:12 +000010018
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010019/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010020///
10021/// By default, the transformation of an address-of-label expression always
10022/// rebuilds the expression, so that the label identifier can be resolved to
10023/// the corresponding label statement by semantic analysis.
10024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010025ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010026TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +000010027 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
10028 E->getLabel());
10029 if (!LD)
10030 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +000010033 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +000010034}
Mike Stump11289f42009-09-09 15:08:12 +000010035
10036template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010038TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +000010039 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +000010040 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +000010041 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +000010042 if (SubStmt.isInvalid()) {
10043 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +000010044 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +000010045 }
Mike Stump11289f42009-09-09 15:08:12 +000010046
Douglas Gregora16548e2009-08-11 05:31:07 +000010047 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +000010048 SubStmt.get() == E->getSubStmt()) {
10049 // Calling this an 'error' is unintuitive, but it does the right thing.
10050 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010051 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +000010052 }
Mike Stump11289f42009-09-09 15:08:12 +000010053
10054 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010055 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010056 E->getRParenLoc());
10057}
Mike Stump11289f42009-09-09 15:08:12 +000010058
Douglas Gregora16548e2009-08-11 05:31:07 +000010059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010061TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010062 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +000010063 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010065
John McCalldadc5752010-08-24 06:29:42 +000010066 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010067 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010069
John McCalldadc5752010-08-24 06:29:42 +000010070 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010071 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010073
Douglas Gregora16548e2009-08-11 05:31:07 +000010074 if (!getDerived().AlwaysRebuild() &&
10075 Cond.get() == E->getCond() &&
10076 LHS.get() == E->getLHS() &&
10077 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010078 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010079
Douglas Gregora16548e2009-08-11 05:31:07 +000010080 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +000010081 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010082 E->getRParenLoc());
10083}
Mike Stump11289f42009-09-09 15:08:12 +000010084
Douglas Gregora16548e2009-08-11 05:31:07 +000010085template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010086ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010087TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010088 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010089}
10090
10091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010092ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010093TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010094 switch (E->getOperator()) {
10095 case OO_New:
10096 case OO_Delete:
10097 case OO_Array_New:
10098 case OO_Array_Delete:
10099 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +000010100
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010101 case OO_Call: {
10102 // This is a call to an object's operator().
10103 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
10104
10105 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +000010106 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010107 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010108 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010109
10110 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +000010111 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010112 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010113
10114 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010115 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010116 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +000010117 Args))
10118 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010119
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010120 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
10121 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010122 }
10123
10124#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
10125 case OO_##Name:
10126#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
10127#include "clang/Basic/OperatorKinds.def"
10128 case OO_Subscript:
10129 // Handled below.
10130 break;
10131
10132 case OO_Conditional:
10133 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010134
10135 case OO_None:
10136 case NUM_OVERLOADED_OPERATORS:
10137 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010138 }
10139
John McCalldadc5752010-08-24 06:29:42 +000010140 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +000010141 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010143
Richard Smithdb2630f2012-10-21 03:28:35 +000010144 ExprResult First;
10145 if (E->getOperator() == OO_Amp)
10146 First = getDerived().TransformAddressOfOperand(E->getArg(0));
10147 else
10148 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +000010149 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010150 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010151
John McCalldadc5752010-08-24 06:29:42 +000010152 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +000010153 if (E->getNumArgs() == 2) {
10154 Second = getDerived().TransformExpr(E->getArg(1));
10155 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010156 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010157 }
Mike Stump11289f42009-09-09 15:08:12 +000010158
Douglas Gregora16548e2009-08-11 05:31:07 +000010159 if (!getDerived().AlwaysRebuild() &&
10160 Callee.get() == E->getCallee() &&
10161 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +000010162 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010163 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +000010164
Lang Hames5de91cc2012-10-02 04:45:10 +000010165 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +000010166 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +000010167
Douglas Gregora16548e2009-08-11 05:31:07 +000010168 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
10169 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +000010170 Callee.get(),
10171 First.get(),
10172 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010173}
Mike Stump11289f42009-09-09 15:08:12 +000010174
Douglas Gregora16548e2009-08-11 05:31:07 +000010175template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010176ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010177TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10178 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010179}
Mike Stump11289f42009-09-09 15:08:12 +000010180
Eric Fiselier708afb52019-05-16 21:04:15 +000010181template <typename Derived>
10182ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
10183 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
10184 getSema().CurContext != E->getParentContext();
10185
10186 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
10187 return E;
10188
10189 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
10190 E->getEndLoc(),
10191 getSema().CurContext);
10192}
10193
Douglas Gregora16548e2009-08-11 05:31:07 +000010194template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010195ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +000010196TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10197 // Transform the callee.
10198 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10199 if (Callee.isInvalid())
10200 return ExprError();
10201
10202 // Transform exec config.
10203 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10204 if (EC.isInvalid())
10205 return ExprError();
10206
10207 // Transform arguments.
10208 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010209 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010210 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010211 &ArgChanged))
10212 return ExprError();
10213
10214 if (!getDerived().AlwaysRebuild() &&
10215 Callee.get() == E->getCallee() &&
10216 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010217 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010218
10219 // FIXME: Wrong source location information for the '('.
10220 SourceLocation FakeLParenLoc
10221 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10222 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010223 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010224 E->getRParenLoc(), EC.get());
10225}
10226
10227template<typename Derived>
10228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010229TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010230 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10231 if (!Type)
10232 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010233
John McCalldadc5752010-08-24 06:29:42 +000010234 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010235 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010236 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010237 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010238
Douglas Gregora16548e2009-08-11 05:31:07 +000010239 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010240 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010241 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010242 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010243 return getDerived().RebuildCXXNamedCastExpr(
10244 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10245 Type, E->getAngleBrackets().getEnd(),
10246 // FIXME. this should be '(' location
10247 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010248}
Mike Stump11289f42009-09-09 15:08:12 +000010249
Douglas Gregora16548e2009-08-11 05:31:07 +000010250template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010251ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010252TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10253 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010254}
Mike Stump11289f42009-09-09 15:08:12 +000010255
10256template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010257ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010258TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10259 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010260}
10261
Douglas Gregora16548e2009-08-11 05:31:07 +000010262template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010263ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010264TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010265 CXXReinterpretCastExpr *E) {
10266 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010267}
Mike Stump11289f42009-09-09 15:08:12 +000010268
Douglas Gregora16548e2009-08-11 05:31:07 +000010269template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010270ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010271TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10272 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010273}
Mike Stump11289f42009-09-09 15:08:12 +000010274
Douglas Gregora16548e2009-08-11 05:31:07 +000010275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010276ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010277TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010278 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010279 TypeSourceInfo *Type =
10280 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010281 if (!Type)
10282 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010283
John McCalldadc5752010-08-24 06:29:42 +000010284 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010285 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010286 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010288
Douglas Gregora16548e2009-08-11 05:31:07 +000010289 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010290 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010291 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010292 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010293
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010294 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010295 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010296 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010297 E->getRParenLoc(),
10298 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010299}
Mike Stump11289f42009-09-09 15:08:12 +000010300
Douglas Gregora16548e2009-08-11 05:31:07 +000010301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010303TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010304 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010305 TypeSourceInfo *TInfo
10306 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10307 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010308 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010309
Douglas Gregora16548e2009-08-11 05:31:07 +000010310 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010311 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010312 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010313
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010314 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010315 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010316 }
Mike Stump11289f42009-09-09 15:08:12 +000010317
Eli Friedman456f0182012-01-20 01:26:23 +000010318 // We don't know whether the subexpression is potentially evaluated until
10319 // after we perform semantic analysis. We speculatively assume it is
10320 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010321 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010322 EnterExpressionEvaluationContext Unevaluated(
10323 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10324 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010325
John McCalldadc5752010-08-24 06:29:42 +000010326 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010327 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010329
Douglas Gregora16548e2009-08-11 05:31:07 +000010330 if (!getDerived().AlwaysRebuild() &&
10331 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010332 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010333
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010334 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010335 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010336}
10337
10338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010339ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010340TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10341 if (E->isTypeOperand()) {
10342 TypeSourceInfo *TInfo
10343 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10344 if (!TInfo)
10345 return ExprError();
10346
10347 if (!getDerived().AlwaysRebuild() &&
10348 TInfo == E->getTypeOperandSourceInfo())
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 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010353 }
10354
Faisal Valid143a0c2017-04-01 21:30:49 +000010355 EnterExpressionEvaluationContext Unevaluated(
10356 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010357
10358 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10359 if (SubExpr.isInvalid())
10360 return ExprError();
10361
10362 if (!getDerived().AlwaysRebuild() &&
10363 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010364 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010365
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010366 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010367 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010368}
10369
10370template<typename Derived>
10371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010372TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010373 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010374}
Mike Stump11289f42009-09-09 15:08:12 +000010375
Douglas Gregora16548e2009-08-11 05:31:07 +000010376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010377ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010378TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010379 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010380 return E;
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>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010386 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010387
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010388 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
Richard Smith8458c9e2019-05-24 01:35:07 +000010389 // Mark it referenced in the new context regardless.
10390 // FIXME: this is a bit instantiation-specific.
10391 getSema().MarkThisReferenced(E);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010392 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010393 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010394
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010395 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
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>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010401 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010402 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010404
Douglas Gregora16548e2009-08-11 05:31:07 +000010405 if (!getDerived().AlwaysRebuild() &&
10406 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010407 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010408
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010409 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10410 E->isThrownVariableInScope());
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
John McCall47f29ea2009-12-08 09:21:05 +000010415TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010416 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10417 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010418 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010420
Eric Fiselier708afb52019-05-16 21:04:15 +000010421 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
10422 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010423 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010424
Douglas Gregor033f6752009-12-23 23:03:06 +000010425 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010426}
Mike Stump11289f42009-09-09 15:08:12 +000010427
Douglas Gregora16548e2009-08-11 05:31:07 +000010428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010429ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010430TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010431 FieldDecl *Field = cast_or_null<FieldDecl>(
10432 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010433 if (!Field)
10434 return ExprError();
10435
Eric Fiselier708afb52019-05-16 21:04:15 +000010436 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
10437 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010438 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010439
10440 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10441}
10442
10443template<typename Derived>
10444ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010445TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10446 CXXScalarValueInitExpr *E) {
10447 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10448 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010449 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010450
Douglas Gregora16548e2009-08-11 05:31:07 +000010451 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010452 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010453 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010454
Chad Rosier1dcde962012-08-08 18:46:20 +000010455 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010456 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010457 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010458}
Mike Stump11289f42009-09-09 15:08:12 +000010459
Douglas Gregora16548e2009-08-11 05:31:07 +000010460template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010461ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010462TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010463 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010464 TypeSourceInfo *AllocTypeInfo =
10465 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010466 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010468
Douglas Gregora16548e2009-08-11 05:31:07 +000010469 // Transform the size of the array we're allocating (if any).
Richard Smithb9fb1212019-05-06 03:47:15 +000010470 Optional<Expr *> ArraySize;
10471 if (Optional<Expr *> OldArraySize = E->getArraySize()) {
10472 ExprResult NewArraySize;
10473 if (*OldArraySize) {
10474 NewArraySize = getDerived().TransformExpr(*OldArraySize);
10475 if (NewArraySize.isInvalid())
10476 return ExprError();
10477 }
10478 ArraySize = NewArraySize.get();
10479 }
Mike Stump11289f42009-09-09 15:08:12 +000010480
Douglas Gregora16548e2009-08-11 05:31:07 +000010481 // Transform the placement arguments (if any).
10482 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010483 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010484 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010485 E->getNumPlacementArgs(), true,
10486 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010487 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010488
Sebastian Redl6047f072012-02-16 12:22:20 +000010489 // Transform the initializer (if any).
10490 Expr *OldInit = E->getInitializer();
10491 ExprResult NewInit;
10492 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010493 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010494 if (NewInit.isInvalid())
10495 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010496
Sebastian Redl6047f072012-02-16 12:22:20 +000010497 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010498 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010499 if (E->getOperatorNew()) {
10500 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010501 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010502 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010503 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010504 }
10505
Craig Topperc3ec1492014-05-26 06:22:03 +000010506 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010507 if (E->getOperatorDelete()) {
10508 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010509 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010510 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010511 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010512 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010513
Douglas Gregora16548e2009-08-11 05:31:07 +000010514 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010515 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Richard Smithb9fb1212019-05-06 03:47:15 +000010516 ArraySize == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010517 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010518 OperatorNew == E->getOperatorNew() &&
10519 OperatorDelete == E->getOperatorDelete() &&
10520 !ArgumentChanged) {
10521 // Mark any declarations we need as referenced.
10522 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010523 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010524 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010525 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010526 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010527
Sebastian Redl6047f072012-02-16 12:22:20 +000010528 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010529 QualType ElementType
10530 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10531 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10532 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10533 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010534 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010535 }
10536 }
10537 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010538
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010539 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010540 }
Mike Stump11289f42009-09-09 15:08:12 +000010541
Douglas Gregor0744ef62010-09-07 21:49:58 +000010542 QualType AllocType = AllocTypeInfo->getType();
Richard Smithb9fb1212019-05-06 03:47:15 +000010543 if (!ArraySize) {
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010544 // If no array size was specified, but the new expression was
10545 // instantiated with an array type (e.g., "new T" where T is
10546 // instantiated with "int[4]"), extract the outer bound from the
10547 // array type as our array size. We do this with constant and
10548 // dependently-sized array types.
10549 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10550 if (!ArrayT) {
10551 // Do nothing
10552 } else if (const ConstantArrayType *ConsArrayT
10553 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010554 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10555 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010556 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010557 AllocType = ConsArrayT->getElementType();
10558 } else if (const DependentSizedArrayType *DepArrayT
10559 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10560 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010561 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010562 AllocType = DepArrayT->getElementType();
10563 }
10564 }
10565 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010566
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010567 return getDerived().RebuildCXXNewExpr(
10568 E->getBeginLoc(), E->isGlobalNew(),
10569 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10570 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
Richard Smithb9fb1212019-05-06 03:47:15 +000010571 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010572}
Mike Stump11289f42009-09-09 15:08:12 +000010573
Douglas Gregora16548e2009-08-11 05:31:07 +000010574template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010575ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010576TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010577 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010578 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010580
Douglas Gregord2d9da02010-02-26 00:38:10 +000010581 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010582 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010583 if (E->getOperatorDelete()) {
10584 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010585 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010586 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010587 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010588 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010589
Douglas Gregora16548e2009-08-11 05:31:07 +000010590 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010591 Operand.get() == E->getArgument() &&
10592 OperatorDelete == E->getOperatorDelete()) {
10593 // Mark any declarations we need as referenced.
10594 // FIXME: instantiation-specific.
10595 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010596 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010597
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010598 if (!E->getArgument()->isTypeDependent()) {
10599 QualType Destroyed = SemaRef.Context.getBaseElementType(
10600 E->getDestroyedType());
10601 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10602 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010603 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010604 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010605 }
10606 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010607
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010608 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010609 }
Mike Stump11289f42009-09-09 15:08:12 +000010610
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010611 return getDerived().RebuildCXXDeleteExpr(
10612 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010613}
Mike Stump11289f42009-09-09 15:08:12 +000010614
Douglas Gregora16548e2009-08-11 05:31:07 +000010615template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010616ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010617TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010618 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010619 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010620 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010622
John McCallba7bf592010-08-24 05:47:05 +000010623 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010624 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010625 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010626 E->getOperatorLoc(),
10627 E->isArrow()? tok::arrow : tok::period,
10628 ObjectTypePtr,
10629 MayBePseudoDestructor);
10630 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010631 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010632
John McCallba7bf592010-08-24 05:47:05 +000010633 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010634 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10635 if (QualifierLoc) {
10636 QualifierLoc
10637 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10638 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010639 return ExprError();
10640 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010641 CXXScopeSpec SS;
10642 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010643
Douglas Gregor678f90d2010-02-25 01:56:36 +000010644 PseudoDestructorTypeStorage Destroyed;
10645 if (E->getDestroyedTypeInfo()) {
10646 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010647 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010648 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010649 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010650 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010651 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010652 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010653 // We aren't likely to be able to resolve the identifier down to a type
10654 // now anyway, so just retain the identifier.
10655 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10656 E->getDestroyedTypeLoc());
10657 } else {
10658 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010659 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010660 *E->getDestroyedTypeIdentifier(),
10661 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010662 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010663 SS, ObjectTypePtr,
10664 false);
10665 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010666 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010667
Douglas Gregor678f90d2010-02-25 01:56:36 +000010668 Destroyed
10669 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10670 E->getDestroyedTypeLoc());
10671 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010672
Craig Topperc3ec1492014-05-26 06:22:03 +000010673 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010674 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010675 CXXScopeSpec EmptySS;
10676 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010677 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010678 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010679 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010680 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010681
John McCallb268a282010-08-23 23:25:46 +000010682 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010683 E->getOperatorLoc(),
10684 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010685 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010686 ScopeTypeInfo,
10687 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010688 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010689 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010690}
Mike Stump11289f42009-09-09 15:08:12 +000010691
Richard Smith151c4562016-12-20 21:35:28 +000010692template <typename Derived>
10693bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10694 bool RequiresADL,
10695 LookupResult &R) {
10696 // Transform all the decls.
10697 bool AllEmptyPacks = true;
10698 for (auto *OldD : Old->decls()) {
10699 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10700 if (!InstD) {
10701 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10702 // This can happen because of dependent hiding.
10703 if (isa<UsingShadowDecl>(OldD))
10704 continue;
10705 else {
10706 R.clear();
10707 return true;
10708 }
10709 }
10710
10711 // Expand using pack declarations.
10712 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10713 ArrayRef<NamedDecl*> Decls = SingleDecl;
10714 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10715 Decls = UPD->expansions();
10716
10717 // Expand using declarations.
10718 for (auto *D : Decls) {
10719 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10720 for (auto *SD : UD->shadows())
10721 R.addDecl(SD);
10722 } else {
10723 R.addDecl(D);
10724 }
10725 }
10726
10727 AllEmptyPacks &= Decls.empty();
10728 };
10729
10730 // C++ [temp.res]/8.4.2:
10731 // The program is ill-formed, no diagnostic required, if [...] lookup for
10732 // a name in the template definition found a using-declaration, but the
10733 // lookup in the corresponding scope in the instantiation odoes not find
10734 // any declarations because the using-declaration was a pack expansion and
10735 // the corresponding pack is empty
10736 if (AllEmptyPacks && !RequiresADL) {
10737 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010738 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010739 return true;
10740 }
10741
10742 // Resolve a kind, but don't do any further analysis. If it's
10743 // ambiguous, the callee needs to deal with it.
10744 R.resolveKind();
10745 return false;
10746}
10747
Douglas Gregorad8a3362009-09-04 17:36:40 +000010748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010749ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010750TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010751 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010752 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10753 Sema::LookupOrdinaryName);
10754
Richard Smith151c4562016-12-20 21:35:28 +000010755 // Transform the declaration set.
10756 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10757 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010758
10759 // Rebuild the nested-name qualifier, if present.
10760 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010761 if (Old->getQualifierLoc()) {
10762 NestedNameSpecifierLoc QualifierLoc
10763 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10764 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010765 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010766
Douglas Gregor0da1d432011-02-28 20:01:57 +000010767 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010768 }
10769
Douglas Gregor9262f472010-04-27 18:19:34 +000010770 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010771 CXXRecordDecl *NamingClass
10772 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10773 Old->getNameLoc(),
10774 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010775 if (!NamingClass) {
10776 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010777 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010778 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010779
Douglas Gregorda7be082010-04-27 16:10:10 +000010780 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010781 }
10782
Abramo Bagnara7945c982012-01-27 09:46:47 +000010783 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10784
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010785 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010786 // it's a normal declaration name or member reference.
10787 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10788 NamedDecl *D = R.getAsSingle<NamedDecl>();
10789 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10790 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10791 // give a good diagnostic.
10792 if (D && D->isCXXInstanceMember()) {
10793 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10794 /*TemplateArgs=*/nullptr,
10795 /*Scope=*/nullptr);
10796 }
10797
John McCalle66edc12009-11-24 19:00:30 +000010798 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010799 }
John McCalle66edc12009-11-24 19:00:30 +000010800
10801 // If we have template arguments, rebuild them, then rebuild the
10802 // templateid expression.
10803 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010804 if (Old->hasExplicitTemplateArgs() &&
10805 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010806 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010807 TransArgs)) {
10808 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010809 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010810 }
John McCalle66edc12009-11-24 19:00:30 +000010811
Abramo Bagnara7945c982012-01-27 09:46:47 +000010812 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010813 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010814}
Mike Stump11289f42009-09-09 15:08:12 +000010815
Douglas Gregora16548e2009-08-11 05:31:07 +000010816template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010817ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010818TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10819 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010820 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010821 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10822 TypeSourceInfo *From = E->getArg(I);
10823 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010824 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010825 TypeLocBuilder TLB;
10826 TLB.reserve(FromTL.getFullDataSize());
10827 QualType To = getDerived().TransformType(TLB, FromTL);
10828 if (To.isNull())
10829 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010830
Douglas Gregor29c42f22012-02-24 07:38:34 +000010831 if (To == From->getType())
10832 Args.push_back(From);
10833 else {
10834 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10835 ArgChanged = true;
10836 }
10837 continue;
10838 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010839
Douglas Gregor29c42f22012-02-24 07:38:34 +000010840 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010841
Douglas Gregor29c42f22012-02-24 07:38:34 +000010842 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010843 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010844 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10845 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10846 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010847
Douglas Gregor29c42f22012-02-24 07:38:34 +000010848 // Determine whether the set of unexpanded parameter packs can and should
10849 // be expanded.
10850 bool Expand = true;
10851 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010852 Optional<unsigned> OrigNumExpansions =
10853 ExpansionTL.getTypePtr()->getNumExpansions();
10854 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010855 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10856 PatternTL.getSourceRange(),
10857 Unexpanded,
10858 Expand, RetainExpansion,
10859 NumExpansions))
10860 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010861
Douglas Gregor29c42f22012-02-24 07:38:34 +000010862 if (!Expand) {
10863 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010864 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010865 // expansion.
10866 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010867
Douglas Gregor29c42f22012-02-24 07:38:34 +000010868 TypeLocBuilder TLB;
10869 TLB.reserve(From->getTypeLoc().getFullDataSize());
10870
10871 QualType To = getDerived().TransformType(TLB, PatternTL);
10872 if (To.isNull())
10873 return ExprError();
10874
Chad Rosier1dcde962012-08-08 18:46:20 +000010875 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010876 PatternTL.getSourceRange(),
10877 ExpansionTL.getEllipsisLoc(),
10878 NumExpansions);
10879 if (To.isNull())
10880 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010881
Douglas Gregor29c42f22012-02-24 07:38:34 +000010882 PackExpansionTypeLoc ToExpansionTL
10883 = TLB.push<PackExpansionTypeLoc>(To);
10884 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10885 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10886 continue;
10887 }
10888
10889 // Expand the pack expansion by substituting for each argument in the
10890 // pack(s).
10891 for (unsigned I = 0; I != *NumExpansions; ++I) {
10892 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10893 TypeLocBuilder TLB;
10894 TLB.reserve(PatternTL.getFullDataSize());
10895 QualType To = getDerived().TransformType(TLB, PatternTL);
10896 if (To.isNull())
10897 return ExprError();
10898
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010899 if (To->containsUnexpandedParameterPack()) {
10900 To = getDerived().RebuildPackExpansionType(To,
10901 PatternTL.getSourceRange(),
10902 ExpansionTL.getEllipsisLoc(),
10903 NumExpansions);
10904 if (To.isNull())
10905 return ExprError();
10906
10907 PackExpansionTypeLoc ToExpansionTL
10908 = TLB.push<PackExpansionTypeLoc>(To);
10909 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10910 }
10911
Douglas Gregor29c42f22012-02-24 07:38:34 +000010912 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10913 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010914
Douglas Gregor29c42f22012-02-24 07:38:34 +000010915 if (!RetainExpansion)
10916 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010917
Douglas Gregor29c42f22012-02-24 07:38:34 +000010918 // If we're supposed to retain a pack expansion, do so by temporarily
10919 // forgetting the partially-substituted parameter pack.
10920 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10921
10922 TypeLocBuilder TLB;
10923 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010924
Douglas Gregor29c42f22012-02-24 07:38:34 +000010925 QualType To = getDerived().TransformType(TLB, PatternTL);
10926 if (To.isNull())
10927 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010928
10929 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010930 PatternTL.getSourceRange(),
10931 ExpansionTL.getEllipsisLoc(),
10932 NumExpansions);
10933 if (To.isNull())
10934 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010935
Douglas Gregor29c42f22012-02-24 07:38:34 +000010936 PackExpansionTypeLoc ToExpansionTL
10937 = TLB.push<PackExpansionTypeLoc>(To);
10938 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10939 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10940 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010941
Douglas Gregor29c42f22012-02-24 07:38:34 +000010942 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010943 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010944
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010945 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010946 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010947}
10948
10949template<typename Derived>
10950ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010951TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10952 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10953 if (!T)
10954 return ExprError();
10955
10956 if (!getDerived().AlwaysRebuild() &&
10957 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010958 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010959
10960 ExprResult SubExpr;
10961 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010962 EnterExpressionEvaluationContext Unevaluated(
10963 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010964 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10965 if (SubExpr.isInvalid())
10966 return ExprError();
10967
10968 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010969 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010970 }
10971
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010972 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010973 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010974}
10975
10976template<typename Derived>
10977ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010978TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10979 ExprResult SubExpr;
10980 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010981 EnterExpressionEvaluationContext Unevaluated(
10982 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010983 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10984 if (SubExpr.isInvalid())
10985 return ExprError();
10986
10987 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010988 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010989 }
10990
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010991 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010992 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010993}
10994
Reid Kleckner32506ed2014-06-12 23:03:48 +000010995template <typename Derived>
10996ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10997 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10998 TypeSourceInfo **RecoveryTSI) {
10999 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
11000 DRE, AddrTaken, RecoveryTSI);
11001
11002 // Propagate both errors and recovered types, which return ExprEmpty.
11003 if (!NewDRE.isUsable())
11004 return NewDRE;
11005
11006 // We got an expr, wrap it up in parens.
11007 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
11008 return PE;
11009 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
11010 PE->getRParen());
11011}
11012
11013template <typename Derived>
11014ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11015 DependentScopeDeclRefExpr *E) {
11016 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
11017 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000011018}
11019
11020template<typename Derived>
11021ExprResult
11022TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11023 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000011024 bool IsAddressOfOperand,
11025 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000011026 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011027 NestedNameSpecifierLoc QualifierLoc
11028 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11029 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011030 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000011031 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000011032
John McCall31f82722010-11-12 08:19:04 +000011033 // TODO: If this is a conversion-function-id, verify that the
11034 // destination type name (if present) resolves the same way after
11035 // instantiation as it did in the local scope.
11036
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011037 DeclarationNameInfo NameInfo
11038 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
11039 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011040 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011041
John McCalle66edc12009-11-24 19:00:30 +000011042 if (!E->hasExplicitTemplateArgs()) {
11043 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011044 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011045 // Note: it is sufficient to compare the Name component of NameInfo:
11046 // if name has not changed, DNLoc has not changed either.
11047 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011048 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011049
Reid Kleckner32506ed2014-06-12 23:03:48 +000011050 return getDerived().RebuildDependentScopeDeclRefExpr(
11051 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
11052 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000011053 }
John McCall6b51f282009-11-23 01:53:49 +000011054
11055 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011056 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11057 E->getNumTemplateArgs(),
11058 TransArgs))
11059 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011060
Reid Kleckner32506ed2014-06-12 23:03:48 +000011061 return getDerived().RebuildDependentScopeDeclRefExpr(
11062 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
11063 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000011064}
11065
11066template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011068TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000011069 // CXXConstructExprs other than for list-initialization and
11070 // CXXTemporaryObjectExpr are always implicit, so when we have
11071 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000011072 if ((E->getNumArgs() == 1 ||
11073 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000011074 (!getDerived().DropCallArgument(E->getArg(0))) &&
11075 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000011076 return getDerived().TransformExpr(E->getArg(0));
11077
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011078 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000011079
11080 QualType T = getDerived().TransformType(E->getType());
11081 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000011082 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011083
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011084 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11085 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011086 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011087 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011088
Douglas Gregora16548e2009-08-11 05:31:07 +000011089 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011090 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000011091 {
11092 EnterExpressionEvaluationContext Context(
11093 getSema(), EnterExpressionEvaluationContext::InitList,
11094 E->isListInitialization());
11095 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11096 &ArgumentChanged))
11097 return ExprError();
11098 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011099
Douglas Gregora16548e2009-08-11 05:31:07 +000011100 if (!getDerived().AlwaysRebuild() &&
11101 T == E->getType() &&
11102 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000011103 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000011104 // Mark the constructor as referenced.
11105 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011106 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011107 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000011108 }
Mike Stump11289f42009-09-09 15:08:12 +000011109
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011110 return getDerived().RebuildCXXConstructExpr(
11111 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
11112 E->hadMultipleCandidates(), E->isListInitialization(),
11113 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
11114 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000011115}
Mike Stump11289f42009-09-09 15:08:12 +000011116
Richard Smith5179eb72016-06-28 19:03:57 +000011117template<typename Derived>
11118ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
11119 CXXInheritedCtorInitExpr *E) {
11120 QualType T = getDerived().TransformType(E->getType());
11121 if (T.isNull())
11122 return ExprError();
11123
11124 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011125 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000011126 if (!Constructor)
11127 return ExprError();
11128
11129 if (!getDerived().AlwaysRebuild() &&
11130 T == E->getType() &&
11131 Constructor == E->getConstructor()) {
11132 // Mark the constructor as referenced.
11133 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011134 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000011135 return E;
11136 }
11137
11138 return getDerived().RebuildCXXInheritedCtorInitExpr(
11139 T, E->getLocation(), Constructor,
11140 E->constructsVBase(), E->inheritedFromVBase());
11141}
11142
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011143/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000011144///
Douglas Gregor363b1512009-12-24 18:51:59 +000011145/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
11146/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011148ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011149TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011150 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011151}
Mike Stump11289f42009-09-09 15:08:12 +000011152
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011153/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000011154/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000011155///
John McCall5d413782010-12-06 08:20:24 +000011156/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000011157/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011159ExprResult
John McCall5d413782010-12-06 08:20:24 +000011160TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011161 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011162}
Mike Stump11289f42009-09-09 15:08:12 +000011163
Douglas Gregora16548e2009-08-11 05:31:07 +000011164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011165ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011166TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000011167 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011168 TypeSourceInfo *T =
11169 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011170 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011172
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011173 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11174 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011175 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011176 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011177
Douglas Gregora16548e2009-08-11 05:31:07 +000011178 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011179 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000011180 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000011181 {
11182 EnterExpressionEvaluationContext Context(
11183 getSema(), EnterExpressionEvaluationContext::InitList,
11184 E->isListInitialization());
11185 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11186 &ArgumentChanged))
11187 return ExprError();
11188 }
Mike Stump11289f42009-09-09 15:08:12 +000011189
Douglas Gregora16548e2009-08-11 05:31:07 +000011190 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011191 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011192 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011193 !ArgumentChanged) {
11194 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011195 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000011196 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011197 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011198
Vedant Kumara14a1f92018-01-17 18:53:51 +000011199 // FIXME: We should just pass E->isListInitialization(), but we're not
11200 // prepared to handle list-initialization without a child InitListExpr.
11201 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11202 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011203 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011204 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011205}
Mike Stump11289f42009-09-09 15:08:12 +000011206
Douglas Gregora16548e2009-08-11 05:31:07 +000011207template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011208ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011209TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011210 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011211 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011212 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smithb2997f52019-05-21 20:10:50 +000011213 struct TransformedInitCapture {
11214 // The location of the ... if the result is retaining a pack expansion.
11215 SourceLocation EllipsisLoc;
11216 // Zero or more expansions of the init-capture.
11217 SmallVector<InitCaptureInfoTy, 4> Expansions;
11218 };
11219 SmallVector<TransformedInitCapture, 4> InitCaptures;
11220 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011221 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011222 CEnd = E->capture_end();
11223 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011224 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011225 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000011226
Richard Smithb2997f52019-05-21 20:10:50 +000011227 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011228 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011229
11230 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
11231 Optional<unsigned> NumExpansions) {
Richard Smithb2997f52019-05-21 20:10:50 +000011232 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11233 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
11234
11235 if (NewExprInitResult.isInvalid()) {
11236 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
11237 return;
11238 }
11239 Expr *NewExprInit = NewExprInitResult.get();
11240
11241 QualType NewInitCaptureType =
11242 getSema().buildLambdaInitCaptureInitialization(
11243 C->getLocation(), OldVD->getType()->isReferenceType(),
11244 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
11245 C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
11246 NewExprInit);
11247 Result.Expansions.push_back(
11248 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
11249 };
11250
11251 // If this is an init-capture pack, consider expanding the pack now.
11252 if (OldVD->isParameterPack()) {
11253 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
11254 ->getTypeLoc()
11255 .castAs<PackExpansionTypeLoc>();
11256 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11257 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
11258
11259 // Determine whether the set of unexpanded parameter packs can and should
11260 // be expanded.
11261 bool Expand = true;
11262 bool RetainExpansion = false;
11263 Optional<unsigned> OrigNumExpansions =
11264 ExpansionTL.getTypePtr()->getNumExpansions();
11265 Optional<unsigned> NumExpansions = OrigNumExpansions;
11266 if (getDerived().TryExpandParameterPacks(
11267 ExpansionTL.getEllipsisLoc(),
11268 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
11269 RetainExpansion, NumExpansions))
11270 return ExprError();
11271 if (Expand) {
11272 for (unsigned I = 0; I != *NumExpansions; ++I) {
11273 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11274 SubstInitCapture(SourceLocation(), None);
11275 }
11276 }
11277 if (!Expand || RetainExpansion) {
11278 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11279 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
11280 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
11281 }
11282 } else {
11283 SubstInitCapture(SourceLocation(), None);
11284 }
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011285 }
11286
Faisal Vali2cba1332013-10-23 06:44:28 +000011287 // Transform the template parameters, and add them to the current
11288 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011289 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011290 E->getTemplateParameterList());
11291
Richard Smith01014ce2014-11-20 23:53:14 +000011292 // Transform the type of the original lambda's call operator.
11293 // The transformation MUST be done in the CurrentInstantiationScope since
11294 // it introduces a mapping of the original to the newly created
11295 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011296 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011297 {
11298 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011299 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011300 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011301
11302 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011303 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011304 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011305 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011306 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011307 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11308 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11309 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011310 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011311 if (NewCallOpType.isNull())
11312 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011313 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11314 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011315 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011316
Richard Smithc38498f2015-04-27 21:27:54 +000011317 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11318 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11319 LSI->GLTemplateParameterList = TPL;
11320
Eli Friedmand564afb2012-09-19 01:18:11 +000011321 // Create the local class that will describe the lambda.
Richard Smith87346a12019-06-02 18:53:44 +000011322 CXXRecordDecl *OldClass = E->getLambdaClass();
Eli Friedmand564afb2012-09-19 01:18:11 +000011323 CXXRecordDecl *Class
11324 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011325 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011326 /*KnownDependent=*/false,
11327 E->getCaptureDefault());
Richard Smith87346a12019-06-02 18:53:44 +000011328 getDerived().transformedLocalDecl(OldClass, {Class});
11329
11330 Optional<std::pair<unsigned, Decl*>> Mangling;
11331 if (getDerived().ReplacingOriginal())
11332 Mangling = std::make_pair(OldClass->getLambdaManglingNumber(),
11333 OldClass->getLambdaContextDecl());
Eli Friedmand564afb2012-09-19 01:18:11 +000011334
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011335 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011336 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11337 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011338 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011339 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
Gauthier Harnisch796ed032019-06-14 08:56:20 +000011340 E->getCallOperator()->getConstexprKind(), Mangling);
Faisal Valia734ab92016-03-26 16:11:37 +000011341
Faisal Vali2cba1332013-10-23 06:44:28 +000011342 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011343
Akira Hatanaka402818462016-12-16 21:16:57 +000011344 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11345 I != NumParams; ++I) {
11346 auto *P = NewCallOperator->getParamDecl(I);
11347 if (P->hasUninstantiatedDefaultArg()) {
11348 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011349 getSema(),
11350 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011351 ExprResult R = getDerived().TransformExpr(
11352 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11353 P->setDefaultArg(R.get());
11354 }
11355 }
11356
Faisal Vali2cba1332013-10-23 06:44:28 +000011357 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithb2997f52019-05-21 20:10:50 +000011358 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
Richard Smithba71c082013-05-16 06:20:58 +000011359
Douglas Gregorb4328232012-02-14 00:00:48 +000011360 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011361 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011362 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011363
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011364 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011365 getSema().buildLambdaScope(LSI, NewCallOperator,
11366 E->getIntroducerRange(),
11367 E->getCaptureDefault(),
11368 E->getCaptureDefaultLoc(),
11369 E->hasExplicitParameters(),
11370 E->hasExplicitResultType(),
11371 E->isMutable());
11372
11373 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011374
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011375 // Transform captures.
Chad Rosier1dcde962012-08-08 18:46:20 +000011376 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011377 CEnd = E->capture_end();
11378 C != CEnd; ++C) {
11379 // When we hit the first implicit capture, tell Sema that we've finished
11380 // the list of explicit captures.
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011381 if (C->isImplicit())
11382 break;
Chad Rosier1dcde962012-08-08 18:46:20 +000011383
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011384 // Capturing 'this' is trivial.
11385 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011386 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11387 /*BuildAndDiagnose*/ true, nullptr,
11388 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011389 continue;
11390 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011391 // Captured expression will be recaptured during captured variables
11392 // rebuilding.
11393 if (C->capturesVLAType())
11394 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011395
Richard Smithba71c082013-05-16 06:20:58 +000011396 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011397 if (E->isInitCapture(C)) {
Richard Smithb2997f52019-05-21 20:10:50 +000011398 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
11399
Richard Smithbb13c9a2013-09-28 04:02:39 +000011400 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011401 llvm::SmallVector<Decl*, 4> NewVDs;
11402
11403 for (InitCaptureInfoTy &Info : NewC.Expansions) {
11404 ExprResult Init = Info.first;
11405 QualType InitQualType = Info.second;
11406 if (Init.isInvalid() || InitQualType.isNull()) {
11407 Invalid = true;
11408 break;
11409 }
11410 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11411 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
11412 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
11413 if (!NewVD) {
11414 Invalid = true;
11415 break;
11416 }
11417 NewVDs.push_back(NewVD);
Richard Smith30116532019-05-28 23:09:46 +000011418 getSema().addInitCapture(LSI, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011419 }
Richard Smithb2997f52019-05-21 20:10:50 +000011420
11421 if (Invalid)
11422 break;
11423
11424 getDerived().transformedLocalDecl(OldVD, NewVDs);
Richard Smithba71c082013-05-16 06:20:58 +000011425 continue;
11426 }
11427
11428 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11429
Douglas Gregor3e308b12012-02-14 19:27:52 +000011430 // Determine the capture kind for Sema.
11431 Sema::TryCaptureKind Kind
11432 = C->isImplicit()? Sema::TryCapture_Implicit
11433 : C->getCaptureKind() == LCK_ByCopy
11434 ? Sema::TryCapture_ExplicitByVal
11435 : Sema::TryCapture_ExplicitByRef;
11436 SourceLocation EllipsisLoc;
11437 if (C->isPackExpansion()) {
11438 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11439 bool ShouldExpand = false;
11440 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011441 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011442 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11443 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011444 Unexpanded,
11445 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011446 NumExpansions)) {
11447 Invalid = true;
11448 continue;
11449 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011450
Douglas Gregor3e308b12012-02-14 19:27:52 +000011451 if (ShouldExpand) {
11452 // The transform has determined that we should perform an expansion;
11453 // transform and capture each of the arguments.
11454 // expansion of the pattern. Do so.
11455 VarDecl *Pack = C->getCapturedVar();
11456 for (unsigned I = 0; I != *NumExpansions; ++I) {
11457 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11458 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011459 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011460 Pack));
11461 if (!CapturedVar) {
11462 Invalid = true;
11463 continue;
11464 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011465
Douglas Gregor3e308b12012-02-14 19:27:52 +000011466 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011467 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11468 }
Richard Smith9467be42014-06-06 17:33:35 +000011469
11470 // FIXME: Retain a pack expansion if RetainExpansion is true.
11471
Douglas Gregor3e308b12012-02-14 19:27:52 +000011472 continue;
11473 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011474
Douglas Gregor3e308b12012-02-14 19:27:52 +000011475 EllipsisLoc = C->getEllipsisLoc();
11476 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011477
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011478 // Transform the captured variable.
11479 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011480 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011481 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011482 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011483 Invalid = true;
11484 continue;
11485 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011486
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011487 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011488 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11489 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011490 }
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011491 getSema().finishLambdaExplicitCaptures(LSI);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011492
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011493 // FIXME: Sema's lambda-building mechanism expects us to push an expression
11494 // evaluation context even if we're not transforming the function body.
Faisal Valid143a0c2017-04-01 21:30:49 +000011495 getSema().PushExpressionEvaluationContext(
11496 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011497
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011498 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011499 StmtResult Body =
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011500 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
Richard Smithc38498f2015-04-27 21:27:54 +000011501
11502 // ActOnLambda* will pop the function scope for us.
11503 FuncScopeCleanup.disable();
11504
Douglas Gregorb4328232012-02-14 00:00:48 +000011505 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011506 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011507 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011508 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011509 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011510 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011511
Richard Smithc38498f2015-04-27 21:27:54 +000011512 // Copy the LSI before ActOnFinishFunctionBody removes it.
11513 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11514 // the call operator.
11515 auto LSICopy = *LSI;
11516 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11517 /*IsInstantiation*/ true);
11518 SavedContext.pop();
11519
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011520 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011521 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011522}
11523
11524template<typename Derived>
Richard Smith87346a12019-06-02 18:53:44 +000011525StmtResult
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011526TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
Richard Smith87346a12019-06-02 18:53:44 +000011527 return TransformStmt(S);
11528}
11529
11530template<typename Derived>
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011531StmtResult
11532TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) {
11533 // Transform captures.
11534 for (LambdaExpr::capture_iterator C = E->capture_begin(),
11535 CEnd = E->capture_end();
11536 C != CEnd; ++C) {
11537 // When we hit the first implicit capture, tell Sema that we've finished
11538 // the list of explicit captures.
11539 if (!C->isImplicit())
11540 continue;
11541
11542 // Capturing 'this' is trivial.
11543 if (C->capturesThis()) {
11544 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11545 /*BuildAndDiagnose*/ true, nullptr,
11546 C->getCaptureKind() == LCK_StarThis);
11547 continue;
11548 }
11549 // Captured expression will be recaptured during captured variables
11550 // rebuilding.
11551 if (C->capturesVLAType())
11552 continue;
11553
11554 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11555 assert(!E->isInitCapture(C) && "implicit init-capture?");
11556
11557 // Transform the captured variable.
11558 VarDecl *CapturedVar = cast_or_null<VarDecl>(
11559 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
11560 if (!CapturedVar || CapturedVar->isInvalidDecl())
11561 return StmtError();
11562
11563 // Capture the transformed variable.
11564 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
11565 }
11566
11567 return S;
11568}
11569
11570template<typename Derived>
Douglas Gregore31e6062012-02-07 10:09:13 +000011571ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011572TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011573 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011574 TypeSourceInfo *T =
11575 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011576 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011577 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011578
Douglas Gregora16548e2009-08-11 05:31:07 +000011579 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011580 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011581 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011582 {
11583 EnterExpressionEvaluationContext Context(
11584 getSema(), EnterExpressionEvaluationContext::InitList,
11585 E->isListInitialization());
11586 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11587 &ArgumentChanged))
11588 return ExprError();
11589 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011590
Douglas Gregora16548e2009-08-11 05:31:07 +000011591 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011592 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011593 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011594 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011595
Douglas Gregora16548e2009-08-11 05:31:07 +000011596 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011597 return getDerived().RebuildCXXUnresolvedConstructExpr(
11598 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011599}
Mike Stump11289f42009-09-09 15:08:12 +000011600
Douglas Gregora16548e2009-08-11 05:31:07 +000011601template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011602ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011603TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011604 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011605 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011606 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011607 Expr *OldBase;
11608 QualType BaseType;
11609 QualType ObjectType;
11610 if (!E->isImplicitAccess()) {
11611 OldBase = E->getBase();
11612 Base = getDerived().TransformExpr(OldBase);
11613 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011615
John McCall2d74de92009-12-01 22:10:20 +000011616 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011617 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011618 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011619 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011620 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011621 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011622 ObjectTy,
11623 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011624 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011625 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011626
John McCallba7bf592010-08-24 05:47:05 +000011627 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011628 BaseType = ((Expr*) Base.get())->getType();
11629 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011630 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011631 BaseType = getDerived().TransformType(E->getBaseType());
11632 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11633 }
Mike Stump11289f42009-09-09 15:08:12 +000011634
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011635 // Transform the first part of the nested-name-specifier that qualifies
11636 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011637 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011638 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011639 E->getFirstQualifierFoundInScope(),
11640 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011641
Douglas Gregore16af532011-02-28 18:50:33 +000011642 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011643 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011644 QualifierLoc
11645 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11646 ObjectType,
11647 FirstQualifierInScope);
11648 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011649 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011650 }
Mike Stump11289f42009-09-09 15:08:12 +000011651
Abramo Bagnara7945c982012-01-27 09:46:47 +000011652 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11653
John McCall31f82722010-11-12 08:19:04 +000011654 // TODO: If this is a conversion-function-id, verify that the
11655 // destination type name (if present) resolves the same way after
11656 // instantiation as it did in the local scope.
11657
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011658 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011659 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011660 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011661 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011662
John McCall2d74de92009-12-01 22:10:20 +000011663 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011664 // This is a reference to a member without an explicitly-specified
11665 // template argument list. Optimize for this common case.
11666 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011667 Base.get() == OldBase &&
11668 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011669 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011670 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011671 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011672 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011673
John McCallb268a282010-08-23 23:25:46 +000011674 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011675 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011676 E->isArrow(),
11677 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011678 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011679 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011680 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011681 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011682 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011683 }
11684
John McCall6b51f282009-11-23 01:53:49 +000011685 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011686 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11687 E->getNumTemplateArgs(),
11688 TransArgs))
11689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011690
John McCallb268a282010-08-23 23:25:46 +000011691 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011692 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011693 E->isArrow(),
11694 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011695 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011696 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011697 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011698 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011699 &TransArgs);
11700}
11701
11702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011703ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011704TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011705 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011706 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011707 QualType BaseType;
11708 if (!Old->isImplicitAccess()) {
11709 Base = getDerived().TransformExpr(Old->getBase());
11710 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011711 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011712 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011713 Old->isArrow());
11714 if (Base.isInvalid())
11715 return ExprError();
11716 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011717 } else {
11718 BaseType = getDerived().TransformType(Old->getBaseType());
11719 }
John McCall10eae182009-11-30 22:42:35 +000011720
Douglas Gregor0da1d432011-02-28 20:01:57 +000011721 NestedNameSpecifierLoc QualifierLoc;
11722 if (Old->getQualifierLoc()) {
11723 QualifierLoc
11724 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11725 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011726 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011727 }
11728
Abramo Bagnara7945c982012-01-27 09:46:47 +000011729 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11730
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011731 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011732 Sema::LookupOrdinaryName);
11733
Richard Smith151c4562016-12-20 21:35:28 +000011734 // Transform the declaration set.
11735 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11736 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011737
Douglas Gregor9262f472010-04-27 18:19:34 +000011738 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011739 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011740 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011741 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011742 Old->getMemberLoc(),
11743 Old->getNamingClass()));
11744 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011745 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011746
Douglas Gregorda7be082010-04-27 16:10:10 +000011747 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011748 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011749
John McCall10eae182009-11-30 22:42:35 +000011750 TemplateArgumentListInfo TransArgs;
11751 if (Old->hasExplicitTemplateArgs()) {
11752 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11753 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011754 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11755 Old->getNumTemplateArgs(),
11756 TransArgs))
11757 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011758 }
John McCall38836f02010-01-15 08:34:02 +000011759
11760 // FIXME: to do this check properly, we will need to preserve the
11761 // first-qualifier-in-scope here, just in case we had a dependent
11762 // base (and therefore couldn't do the check) and a
11763 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011764 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011765
John McCallb268a282010-08-23 23:25:46 +000011766 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011767 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011768 Old->getOperatorLoc(),
11769 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011770 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011771 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011772 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011773 R,
11774 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011775 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011776}
11777
11778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011779ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011780TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011781 EnterExpressionEvaluationContext Unevaluated(
11782 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011783 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11784 if (SubExpr.isInvalid())
11785 return ExprError();
11786
11787 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011788 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011789
11790 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11791}
11792
11793template<typename Derived>
11794ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011795TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011796 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11797 if (Pattern.isInvalid())
11798 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011799
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011800 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011801 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011802
Douglas Gregorb8840002011-01-14 21:20:45 +000011803 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11804 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011805}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011806
11807template<typename Derived>
11808ExprResult
11809TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11810 // If E is not value-dependent, then nothing will change when we transform it.
11811 // Note: This is an instantiation-centric view.
11812 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011813 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011814
Faisal Valid143a0c2017-04-01 21:30:49 +000011815 EnterExpressionEvaluationContext Unevaluated(
11816 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011817
Richard Smithd784e682015-09-23 21:41:42 +000011818 ArrayRef<TemplateArgument> PackArgs;
11819 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011820
Richard Smithd784e682015-09-23 21:41:42 +000011821 // Find the argument list to transform.
11822 if (E->isPartiallySubstituted()) {
11823 PackArgs = E->getPartialArguments();
11824 } else if (E->isValueDependent()) {
11825 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11826 bool ShouldExpand = false;
11827 bool RetainExpansion = false;
11828 Optional<unsigned> NumExpansions;
11829 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11830 Unexpanded,
11831 ShouldExpand, RetainExpansion,
11832 NumExpansions))
11833 return ExprError();
11834
11835 // If we need to expand the pack, build a template argument from it and
11836 // expand that.
11837 if (ShouldExpand) {
11838 auto *Pack = E->getPack();
11839 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11840 ArgStorage = getSema().Context.getPackExpansionType(
11841 getSema().Context.getTypeDeclType(TTPD), None);
11842 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11843 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11844 } else {
11845 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011846 ExprResult DRE = getSema().BuildDeclRefExpr(
11847 VD, VD->getType().getNonLValueExprType(getSema().Context),
11848 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11849 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011850 if (DRE.isInvalid())
11851 return ExprError();
11852 ArgStorage = new (getSema().Context) PackExpansionExpr(
11853 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11854 }
11855 PackArgs = ArgStorage;
11856 }
11857 }
11858
11859 // If we're not expanding the pack, just transform the decl.
11860 if (!PackArgs.size()) {
11861 auto *Pack = cast_or_null<NamedDecl>(
11862 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011863 if (!Pack)
11864 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011865 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11866 E->getPackLoc(),
11867 E->getRParenLoc(), None, None);
11868 }
11869
Richard Smithc5452ed2016-10-19 22:18:42 +000011870 // Try to compute the result without performing a partial substitution.
11871 Optional<unsigned> Result = 0;
11872 for (const TemplateArgument &Arg : PackArgs) {
11873 if (!Arg.isPackExpansion()) {
11874 Result = *Result + 1;
11875 continue;
11876 }
11877
11878 TemplateArgumentLoc ArgLoc;
11879 InventTemplateArgumentLoc(Arg, ArgLoc);
11880
11881 // Find the pattern of the pack expansion.
11882 SourceLocation Ellipsis;
11883 Optional<unsigned> OrigNumExpansions;
11884 TemplateArgumentLoc Pattern =
11885 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11886 OrigNumExpansions);
11887
11888 // Substitute under the pack expansion. Do not expand the pack (yet).
11889 TemplateArgumentLoc OutPattern;
11890 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11891 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11892 /*Uneval*/ true))
11893 return true;
11894
11895 // See if we can determine the number of arguments from the result.
11896 Optional<unsigned> NumExpansions =
11897 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11898 if (!NumExpansions) {
11899 // No: we must be in an alias template expansion, and we're going to need
11900 // to actually expand the packs.
11901 Result = None;
11902 break;
11903 }
11904
11905 Result = *Result + *NumExpansions;
11906 }
11907
11908 // Common case: we could determine the number of expansions without
11909 // substituting.
11910 if (Result)
11911 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11912 E->getPackLoc(),
11913 E->getRParenLoc(), *Result, None);
11914
Richard Smithd784e682015-09-23 21:41:42 +000011915 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11916 E->getPackLoc());
11917 {
11918 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11919 typedef TemplateArgumentLocInventIterator<
11920 Derived, const TemplateArgument*> PackLocIterator;
11921 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11922 PackLocIterator(*this, PackArgs.end()),
11923 TransformedPackArgs, /*Uneval*/true))
11924 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011925 }
11926
Richard Smithc5452ed2016-10-19 22:18:42 +000011927 // Check whether we managed to fully-expand the pack.
11928 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011929 SmallVector<TemplateArgument, 8> Args;
11930 bool PartialSubstitution = false;
11931 for (auto &Loc : TransformedPackArgs.arguments()) {
11932 Args.push_back(Loc.getArgument());
11933 if (Loc.getArgument().isPackExpansion())
11934 PartialSubstitution = true;
11935 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011936
Richard Smithd784e682015-09-23 21:41:42 +000011937 if (PartialSubstitution)
11938 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11939 E->getPackLoc(),
11940 E->getRParenLoc(), None, Args);
11941
11942 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011943 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011944 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011945}
11946
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011947template<typename Derived>
11948ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011949TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11950 SubstNonTypeTemplateParmPackExpr *E) {
11951 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011952 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011953}
11954
11955template<typename Derived>
11956ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011957TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11958 SubstNonTypeTemplateParmExpr *E) {
11959 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011960 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011961}
11962
11963template<typename Derived>
11964ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011965TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11966 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011967 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011968}
11969
11970template<typename Derived>
11971ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011972TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11973 MaterializeTemporaryExpr *E) {
11974 return getDerived().TransformExpr(E->GetTemporaryExpr());
11975}
Chad Rosier1dcde962012-08-08 18:46:20 +000011976
Douglas Gregorfe314812011-06-21 17:03:29 +000011977template<typename Derived>
11978ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011979TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11980 Expr *Pattern = E->getPattern();
11981
11982 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11983 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11984 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11985
11986 // Determine whether the set of unexpanded parameter packs can and should
11987 // be expanded.
11988 bool Expand = true;
11989 bool RetainExpansion = false;
Richard Smithc7214f62019-05-13 08:31:14 +000011990 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
11991 NumExpansions = OrigNumExpansions;
Richard Smith0f0af192014-11-08 05:07:16 +000011992 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11993 Pattern->getSourceRange(),
11994 Unexpanded,
11995 Expand, RetainExpansion,
11996 NumExpansions))
11997 return true;
11998
11999 if (!Expand) {
12000 // Do not expand any packs here, just transform and rebuild a fold
12001 // expression.
12002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12003
12004 ExprResult LHS =
12005 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
12006 if (LHS.isInvalid())
12007 return true;
12008
12009 ExprResult RHS =
12010 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
12011 if (RHS.isInvalid())
12012 return true;
12013
12014 if (!getDerived().AlwaysRebuild() &&
12015 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
12016 return E;
12017
12018 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012019 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012020 RHS.get(), E->getEndLoc(), NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012021 }
12022
12023 // The transform has determined that we should perform an elementwise
12024 // expansion of the pattern. Do so.
12025 ExprResult Result = getDerived().TransformExpr(E->getInit());
12026 if (Result.isInvalid())
12027 return true;
12028 bool LeftFold = E->isLeftFold();
12029
12030 // If we're retaining an expansion for a right fold, it is the innermost
12031 // component and takes the init (if any).
12032 if (!LeftFold && RetainExpansion) {
12033 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12034
12035 ExprResult Out = getDerived().TransformExpr(Pattern);
12036 if (Out.isInvalid())
12037 return true;
12038
12039 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012040 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012041 Result.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012042 if (Result.isInvalid())
12043 return true;
12044 }
12045
12046 for (unsigned I = 0; I != *NumExpansions; ++I) {
12047 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
12048 getSema(), LeftFold ? I : *NumExpansions - I - 1);
12049 ExprResult Out = getDerived().TransformExpr(Pattern);
12050 if (Out.isInvalid())
12051 return true;
12052
12053 if (Out.get()->containsUnexpandedParameterPack()) {
12054 // We still have a pack; retain a pack expansion for this slice.
12055 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012056 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000012057 E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012058 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
12059 OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012060 } else if (Result.isUsable()) {
12061 // We've got down to a single element; build a binary operator.
12062 Result = getDerived().RebuildBinaryOperator(
12063 E->getEllipsisLoc(), E->getOperator(),
12064 LeftFold ? Result.get() : Out.get(),
12065 LeftFold ? Out.get() : Result.get());
12066 } else
12067 Result = Out;
12068
12069 if (Result.isInvalid())
12070 return true;
12071 }
12072
12073 // If we're retaining an expansion for a left fold, it is the outermost
12074 // component and takes the complete expansion so far as its init (if any).
12075 if (LeftFold && RetainExpansion) {
12076 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12077
12078 ExprResult Out = getDerived().TransformExpr(Pattern);
12079 if (Out.isInvalid())
12080 return true;
12081
12082 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012083 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012084 Out.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012085 if (Result.isInvalid())
12086 return true;
12087 }
12088
12089 // If we had no init and an empty pack, and we're not retaining an expansion,
12090 // then produce a fallback value or error.
12091 if (Result.isUnset())
12092 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
12093 E->getOperator());
12094
12095 return Result;
12096}
12097
12098template<typename Derived>
12099ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000012100TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
12101 CXXStdInitializerListExpr *E) {
12102 return getDerived().TransformExpr(E->getSubExpr());
12103}
12104
12105template<typename Derived>
12106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012107TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012108 return SemaRef.MaybeBindToTemporary(E);
12109}
12110
12111template<typename Derived>
12112ExprResult
12113TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012114 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012115}
12116
12117template<typename Derived>
12118ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000012119TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
12120 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12121 if (SubExpr.isInvalid())
12122 return ExprError();
12123
12124 if (!getDerived().AlwaysRebuild() &&
12125 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012126 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000012127
12128 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000012129}
12130
12131template<typename Derived>
12132ExprResult
12133TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
12134 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012135 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012136 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000012137 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012138 /*IsCall=*/false, Elements, &ArgChanged))
12139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012140
Ted Kremeneke65b0862012-03-06 20:05:56 +000012141 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12142 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012143
Ted Kremeneke65b0862012-03-06 20:05:56 +000012144 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
12145 Elements.data(),
12146 Elements.size());
12147}
12148
12149template<typename Derived>
12150ExprResult
12151TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000012152 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012153 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012154 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012155 bool ArgChanged = false;
12156 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
12157 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000012158
Ted Kremeneke65b0862012-03-06 20:05:56 +000012159 if (OrigElement.isPackExpansion()) {
12160 // This key/value element is a pack expansion.
12161 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12162 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
12163 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
12164 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12165
12166 // Determine whether the set of unexpanded parameter packs can
12167 // and should be expanded.
12168 bool Expand = true;
12169 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000012170 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
12171 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012172 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000012173 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012174 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
12175 PatternRange, Unexpanded, Expand,
12176 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000012177 return ExprError();
12178
12179 if (!Expand) {
12180 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000012181 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000012182 // expansion.
12183 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12184 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12185 if (Key.isInvalid())
12186 return ExprError();
12187
12188 if (Key.get() != OrigElement.Key)
12189 ArgChanged = true;
12190
12191 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12192 if (Value.isInvalid())
12193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012194
Ted Kremeneke65b0862012-03-06 20:05:56 +000012195 if (Value.get() != OrigElement.Value)
12196 ArgChanged = true;
12197
Chad Rosier1dcde962012-08-08 18:46:20 +000012198 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012199 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
12200 };
12201 Elements.push_back(Expansion);
12202 continue;
12203 }
12204
12205 // Record right away that the argument was changed. This needs
12206 // to happen even if the array expands to nothing.
12207 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012208
Ted Kremeneke65b0862012-03-06 20:05:56 +000012209 // The transform has determined that we should perform an elementwise
12210 // expansion of the pattern. Do so.
12211 for (unsigned I = 0; I != *NumExpansions; ++I) {
12212 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
12213 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12214 if (Key.isInvalid())
12215 return ExprError();
12216
12217 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12218 if (Value.isInvalid())
12219 return ExprError();
12220
Chad Rosier1dcde962012-08-08 18:46:20 +000012221 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012222 Key.get(), Value.get(), SourceLocation(), NumExpansions
12223 };
12224
12225 // If any unexpanded parameter packs remain, we still have a
12226 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000012227 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000012228 if (Key.get()->containsUnexpandedParameterPack() ||
12229 Value.get()->containsUnexpandedParameterPack())
12230 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000012231
Ted Kremeneke65b0862012-03-06 20:05:56 +000012232 Elements.push_back(Element);
12233 }
12234
Richard Smith9467be42014-06-06 17:33:35 +000012235 // FIXME: Retain a pack expansion if RetainExpansion is true.
12236
Ted Kremeneke65b0862012-03-06 20:05:56 +000012237 // We've finished with this pack expansion.
12238 continue;
12239 }
12240
12241 // Transform and check key.
12242 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12243 if (Key.isInvalid())
12244 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012245
Ted Kremeneke65b0862012-03-06 20:05:56 +000012246 if (Key.get() != OrigElement.Key)
12247 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012248
Ted Kremeneke65b0862012-03-06 20:05:56 +000012249 // Transform and check value.
12250 ExprResult Value
12251 = getDerived().TransformExpr(OrigElement.Value);
12252 if (Value.isInvalid())
12253 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012254
Ted Kremeneke65b0862012-03-06 20:05:56 +000012255 if (Value.get() != OrigElement.Value)
12256 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012257
12258 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000012259 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000012260 };
12261 Elements.push_back(Element);
12262 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012263
Ted Kremeneke65b0862012-03-06 20:05:56 +000012264 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12265 return SemaRef.MaybeBindToTemporary(E);
12266
12267 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000012268 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000012269}
12270
Mike Stump11289f42009-09-09 15:08:12 +000012271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012273TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000012274 TypeSourceInfo *EncodedTypeInfo
12275 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
12276 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012278
Douglas Gregora16548e2009-08-11 05:31:07 +000012279 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000012280 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012281 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012282
12283 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000012284 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000012285 E->getRParenLoc());
12286}
Mike Stump11289f42009-09-09 15:08:12 +000012287
Douglas Gregora16548e2009-08-11 05:31:07 +000012288template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000012289ExprResult TreeTransform<Derived>::
12290TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000012291 // This is a kind of implicit conversion, and it needs to get dropped
12292 // and recomputed for the same general reasons that ImplicitCastExprs
12293 // do, as well a more specific one: this expression is only valid when
12294 // it appears *immediately* as an argument expression.
12295 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000012296}
12297
12298template<typename Derived>
12299ExprResult TreeTransform<Derived>::
12300TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000012301 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000012302 = getDerived().TransformType(E->getTypeInfoAsWritten());
12303 if (!TSInfo)
12304 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012305
John McCall31168b02011-06-15 23:02:42 +000012306 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012307 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012308 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012309
John McCall31168b02011-06-15 23:02:42 +000012310 if (!getDerived().AlwaysRebuild() &&
12311 TSInfo == E->getTypeInfoAsWritten() &&
12312 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012313 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012314
John McCall31168b02011-06-15 23:02:42 +000012315 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012316 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012317 Result.get());
12318}
12319
Erik Pilkington29099de2016-07-16 00:35:23 +000012320template <typename Derived>
12321ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12322 ObjCAvailabilityCheckExpr *E) {
12323 return E;
12324}
12325
John McCall31168b02011-06-15 23:02:42 +000012326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012327ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012328TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012329 // Transform arguments.
12330 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012331 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012332 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012333 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012334 &ArgChanged))
12335 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012336
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012337 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12338 // Class message: transform the receiver type.
12339 TypeSourceInfo *ReceiverTypeInfo
12340 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12341 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012342 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012343
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012344 // If nothing changed, just retain the existing message send.
12345 if (!getDerived().AlwaysRebuild() &&
12346 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012347 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012348
12349 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012350 SmallVector<SourceLocation, 16> SelLocs;
12351 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012352 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12353 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012354 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012355 E->getMethodDecl(),
12356 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012357 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012358 E->getRightLoc());
12359 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012360 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12361 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012362 if (!E->getMethodDecl())
12363 return ExprError();
12364
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012365 // Build a new class message send to 'super'.
12366 SmallVector<SourceLocation, 16> SelLocs;
12367 E->getSelectorLocs(SelLocs);
12368 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12369 E->getSelector(),
12370 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012371 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012372 E->getMethodDecl(),
12373 E->getLeftLoc(),
12374 Args,
12375 E->getRightLoc());
12376 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012377
12378 // Instance message: transform the receiver
12379 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12380 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012381 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012382 = getDerived().TransformExpr(E->getInstanceReceiver());
12383 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012384 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012385
12386 // If nothing changed, just retain the existing message send.
12387 if (!getDerived().AlwaysRebuild() &&
12388 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012389 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012390
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012391 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012392 SmallVector<SourceLocation, 16> SelLocs;
12393 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012394 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012395 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012396 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012397 E->getMethodDecl(),
12398 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012399 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012400 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012401}
12402
Mike Stump11289f42009-09-09 15:08:12 +000012403template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012404ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012405TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012406 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012407}
12408
Mike Stump11289f42009-09-09 15:08:12 +000012409template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012410ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012411TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012412 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012413}
12414
Mike Stump11289f42009-09-09 15:08:12 +000012415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012417TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012418 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012419 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012420 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012421 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012422
12423 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012424
Douglas Gregord51d90d2010-04-26 20:11:03 +000012425 // If nothing changed, just retain the existing expression.
12426 if (!getDerived().AlwaysRebuild() &&
12427 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012428 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012429
John McCallb268a282010-08-23 23:25:46 +000012430 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012431 E->getLocation(),
12432 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012433}
12434
Mike Stump11289f42009-09-09 15:08:12 +000012435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012437TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012438 // 'super' and types never change. Property never changes. Just
12439 // retain the existing expression.
12440 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012441 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012442
Douglas Gregor9faee212010-04-26 20:47:02 +000012443 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012444 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012445 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012446 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012447
Douglas Gregor9faee212010-04-26 20:47:02 +000012448 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012449
Douglas Gregor9faee212010-04-26 20:47:02 +000012450 // If nothing changed, just retain the existing expression.
12451 if (!getDerived().AlwaysRebuild() &&
12452 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012453 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012454
John McCallb7bd14f2010-12-02 01:19:52 +000012455 if (E->isExplicitProperty())
12456 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12457 E->getExplicitProperty(),
12458 E->getLocation());
12459
12460 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012461 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012462 E->getImplicitPropertyGetter(),
12463 E->getImplicitPropertySetter(),
12464 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012465}
12466
Mike Stump11289f42009-09-09 15:08:12 +000012467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012468ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012469TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12470 // Transform the base expression.
12471 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12472 if (Base.isInvalid())
12473 return ExprError();
12474
12475 // Transform the key expression.
12476 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12477 if (Key.isInvalid())
12478 return ExprError();
12479
12480 // If nothing changed, just retain the existing expression.
12481 if (!getDerived().AlwaysRebuild() &&
12482 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012483 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012484
Chad Rosier1dcde962012-08-08 18:46:20 +000012485 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012486 Base.get(), Key.get(),
12487 E->getAtIndexMethodDecl(),
12488 E->setAtIndexMethodDecl());
12489}
12490
12491template<typename Derived>
12492ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012493TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012494 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012495 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012496 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012497 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012498
Douglas Gregord51d90d2010-04-26 20:11:03 +000012499 // If nothing changed, just retain the existing expression.
12500 if (!getDerived().AlwaysRebuild() &&
12501 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012502 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012503
John McCallb268a282010-08-23 23:25:46 +000012504 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012505 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012506 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012507}
12508
Mike Stump11289f42009-09-09 15:08:12 +000012509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012510ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012511TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012512 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012513 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012514 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012515 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012516 SubExprs, &ArgumentChanged))
12517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012518
Douglas Gregora16548e2009-08-11 05:31:07 +000012519 if (!getDerived().AlwaysRebuild() &&
12520 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012521 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012522
Douglas Gregora16548e2009-08-11 05:31:07 +000012523 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012524 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012525 E->getRParenLoc());
12526}
12527
Mike Stump11289f42009-09-09 15:08:12 +000012528template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012529ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012530TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12531 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12532 if (SrcExpr.isInvalid())
12533 return ExprError();
12534
12535 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12536 if (!Type)
12537 return ExprError();
12538
12539 if (!getDerived().AlwaysRebuild() &&
12540 Type == E->getTypeSourceInfo() &&
12541 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012542 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012543
12544 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12545 SrcExpr.get(), Type,
12546 E->getRParenLoc());
12547}
12548
12549template<typename Derived>
12550ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012551TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012552 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012553
Craig Topperc3ec1492014-05-26 06:22:03 +000012554 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012555 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12556
12557 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012558 blockScope->TheDecl->setBlockMissingReturnType(
12559 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012560
Chris Lattner01cf8db2011-07-20 06:58:45 +000012561 SmallVector<ParmVarDecl*, 4> params;
12562 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012563
John McCallc8e321d2016-03-01 02:09:25 +000012564 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12565
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012566 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012567 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012568 if (getDerived().TransformFunctionTypeParams(
12569 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12570 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12571 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012572 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012573 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012574 }
John McCall490112f2011-02-04 18:33:18 +000012575
Eli Friedman34b49062012-01-26 03:00:14 +000012576 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012577 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012578
John McCallc8e321d2016-03-01 02:09:25 +000012579 auto epi = exprFunctionType->getExtProtoInfo();
12580 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12581
Jordan Rose5c382722013-03-08 21:51:21 +000012582 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012583 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012584 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012585
12586 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012587 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012588 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012589
12590 if (!oldBlock->blockMissingReturnType()) {
12591 blockScope->HasImplicitReturnType = false;
12592 blockScope->ReturnType = exprResultType;
12593 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012594
John McCall3882ace2011-01-05 12:14:39 +000012595 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012596 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012597 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012598 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012599 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012600 }
John McCall3882ace2011-01-05 12:14:39 +000012601
John McCall490112f2011-02-04 18:33:18 +000012602#ifndef NDEBUG
12603 // In builds with assertions, make sure that we captured everything we
12604 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012605 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012606 for (const auto &I : oldBlock->captures()) {
12607 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012608
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012609 // Ignore parameter packs.
Richard Smithb2997f52019-05-21 20:10:50 +000012610 if (oldCapture->isParameterPack())
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012611 continue;
John McCall490112f2011-02-04 18:33:18 +000012612
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012613 VarDecl *newCapture =
12614 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12615 oldCapture));
12616 assert(blockScope->CaptureMap.count(newCapture));
12617 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012618 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012619 }
12620#endif
12621
12622 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012623 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012624}
12625
Mike Stump11289f42009-09-09 15:08:12 +000012626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012627ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012628TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012629 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012630}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012631
12632template<typename Derived>
12633ExprResult
12634TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012635 QualType RetTy = getDerived().TransformType(E->getType());
12636 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012637 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012638 SubExprs.reserve(E->getNumSubExprs());
12639 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12640 SubExprs, &ArgumentChanged))
12641 return ExprError();
12642
12643 if (!getDerived().AlwaysRebuild() &&
12644 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012645 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012646
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012647 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012648 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012649}
Chad Rosier1dcde962012-08-08 18:46:20 +000012650
Douglas Gregora16548e2009-08-11 05:31:07 +000012651//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012652// Type reconstruction
12653//===----------------------------------------------------------------------===//
12654
Mike Stump11289f42009-09-09 15:08:12 +000012655template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012656QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12657 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012658 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012659 getDerived().getBaseEntity());
12660}
12661
Mike Stump11289f42009-09-09 15:08:12 +000012662template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012663QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12664 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012665 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012666 getDerived().getBaseEntity());
12667}
12668
Mike Stump11289f42009-09-09 15:08:12 +000012669template<typename Derived>
12670QualType
John McCall70dd5f62009-10-30 00:06:24 +000012671TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12672 bool WrittenAsLValue,
12673 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012674 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012675 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012676}
12677
12678template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012679QualType
John McCall70dd5f62009-10-30 00:06:24 +000012680TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12681 QualType ClassType,
12682 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012683 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12684 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012685}
12686
12687template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012688QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12689 const ObjCTypeParamDecl *Decl,
12690 SourceLocation ProtocolLAngleLoc,
12691 ArrayRef<ObjCProtocolDecl *> Protocols,
12692 ArrayRef<SourceLocation> ProtocolLocs,
12693 SourceLocation ProtocolRAngleLoc) {
12694 return SemaRef.BuildObjCTypeParamType(Decl,
12695 ProtocolLAngleLoc, Protocols,
12696 ProtocolLocs, ProtocolRAngleLoc,
12697 /*FailOnError=*/true);
12698}
12699
12700template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012701QualType TreeTransform<Derived>::RebuildObjCObjectType(
12702 QualType BaseType,
12703 SourceLocation Loc,
12704 SourceLocation TypeArgsLAngleLoc,
12705 ArrayRef<TypeSourceInfo *> TypeArgs,
12706 SourceLocation TypeArgsRAngleLoc,
12707 SourceLocation ProtocolLAngleLoc,
12708 ArrayRef<ObjCProtocolDecl *> Protocols,
12709 ArrayRef<SourceLocation> ProtocolLocs,
12710 SourceLocation ProtocolRAngleLoc) {
12711 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12712 TypeArgs, TypeArgsRAngleLoc,
12713 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12714 ProtocolRAngleLoc,
12715 /*FailOnError=*/true);
12716}
12717
12718template<typename Derived>
12719QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12720 QualType PointeeType,
12721 SourceLocation Star) {
12722 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12723}
12724
12725template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012726QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012727TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12728 ArrayType::ArraySizeModifier SizeMod,
12729 const llvm::APInt *Size,
12730 Expr *SizeExpr,
12731 unsigned IndexTypeQuals,
12732 SourceRange BracketsRange) {
12733 if (SizeExpr || !Size)
12734 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12735 IndexTypeQuals, BracketsRange,
12736 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012737
12738 QualType Types[] = {
12739 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12740 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12741 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012742 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012743 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012744 QualType SizeType;
12745 for (unsigned I = 0; I != NumTypes; ++I)
12746 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12747 SizeType = Types[I];
12748 break;
12749 }
Mike Stump11289f42009-09-09 15:08:12 +000012750
Eli Friedman9562f392012-01-25 23:20:27 +000012751 // Note that we can return a VariableArrayType here in the case where
12752 // the element type was a dependent VariableArrayType.
12753 IntegerLiteral *ArraySize
12754 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12755 /*FIXME*/BracketsRange.getBegin());
12756 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012757 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012758 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012759}
Mike Stump11289f42009-09-09 15:08:12 +000012760
Douglas Gregord6ff3322009-08-04 16:50:30 +000012761template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012762QualType
12763TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012764 ArrayType::ArraySizeModifier SizeMod,
12765 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012766 unsigned IndexTypeQuals,
12767 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012768 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012769 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012770}
12771
12772template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012773QualType
Mike Stump11289f42009-09-09 15:08:12 +000012774TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012775 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012776 unsigned IndexTypeQuals,
12777 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012778 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012779 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012780}
Mike Stump11289f42009-09-09 15:08:12 +000012781
Douglas Gregord6ff3322009-08-04 16:50:30 +000012782template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012783QualType
12784TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012785 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012786 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012787 unsigned IndexTypeQuals,
12788 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012789 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012790 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012791 IndexTypeQuals, BracketsRange);
12792}
12793
12794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012795QualType
12796TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012799 unsigned IndexTypeQuals,
12800 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012801 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012802 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012803 IndexTypeQuals, BracketsRange);
12804}
12805
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012806template <typename Derived>
12807QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12808 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12809 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12810 AttributeLoc);
12811}
12812
12813template <typename Derived>
12814QualType
12815TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12816 unsigned NumElements,
12817 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012818 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012819 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012820}
Mike Stump11289f42009-09-09 15:08:12 +000012821
Erich Keanef702b022018-07-13 19:46:04 +000012822template <typename Derived>
12823QualType TreeTransform<Derived>::RebuildDependentVectorType(
12824 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12825 VectorType::VectorKind VecKind) {
12826 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12827}
12828
Douglas Gregord6ff3322009-08-04 16:50:30 +000012829template<typename Derived>
12830QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12831 unsigned NumElements,
12832 SourceLocation AttributeLoc) {
12833 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12834 NumElements, true);
12835 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012836 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12837 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012838 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012839}
Mike Stump11289f42009-09-09 15:08:12 +000012840
Douglas Gregord6ff3322009-08-04 16:50:30 +000012841template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012842QualType
12843TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012844 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012845 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012846 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012847}
Mike Stump11289f42009-09-09 15:08:12 +000012848
Douglas Gregord6ff3322009-08-04 16:50:30 +000012849template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012850QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12851 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012852 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012853 const FunctionProtoType::ExtProtoInfo &EPI) {
12854 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012855 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012856 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012857 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012858}
Mike Stump11289f42009-09-09 15:08:12 +000012859
Douglas Gregord6ff3322009-08-04 16:50:30 +000012860template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012861QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12862 return SemaRef.Context.getFunctionNoProtoType(T);
12863}
12864
12865template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012866QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12867 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012868 assert(D && "no decl found");
12869 if (D->isInvalidDecl()) return QualType();
12870
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012871 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012872 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012873 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12874 // A valid resolved using typename pack expansion decl can have multiple
12875 // UsingDecls, but they must each have exactly one type, and it must be
12876 // the same type in every case. But we must have at least one expansion!
12877 if (UPD->expansions().empty()) {
12878 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12879 << UPD->isCXXClassMember() << UPD;
12880 return QualType();
12881 }
12882
12883 // We might still have some unresolved types. Try to pick a resolved type
12884 // if we can. The final instantiation will check that the remaining
12885 // unresolved types instantiate to the type we pick.
12886 QualType FallbackT;
12887 QualType T;
12888 for (auto *E : UPD->expansions()) {
12889 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12890 if (ThisT.isNull())
12891 continue;
12892 else if (ThisT->getAs<UnresolvedUsingType>())
12893 FallbackT = ThisT;
12894 else if (T.isNull())
12895 T = ThisT;
12896 else
12897 assert(getSema().Context.hasSameType(ThisT, T) &&
12898 "mismatched resolved types in using pack expansion");
12899 }
12900 return T.isNull() ? FallbackT : T;
12901 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012902 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012903 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12904
12905 // A valid resolved using typename decl points to exactly one type decl.
12906 assert(++Using->shadow_begin() == Using->shadow_end());
12907 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012908 } else {
12909 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12910 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12911 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12912 }
12913
12914 return SemaRef.Context.getTypeDeclType(Ty);
12915}
12916
12917template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012918QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12919 SourceLocation Loc) {
12920 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012921}
12922
12923template<typename Derived>
12924QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12925 return SemaRef.Context.getTypeOfType(Underlying);
12926}
12927
12928template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012929QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12930 SourceLocation Loc) {
12931 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012932}
12933
12934template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012935QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12936 UnaryTransformType::UTTKind UKind,
12937 SourceLocation Loc) {
12938 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12939}
12940
12941template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012942QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012943 TemplateName Template,
12944 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012945 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012946 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012947}
Mike Stump11289f42009-09-09 15:08:12 +000012948
Douglas Gregor1135c352009-08-06 05:28:30 +000012949template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012950QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12951 SourceLocation KWLoc) {
12952 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12953}
12954
12955template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012956QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012957 SourceLocation KWLoc,
12958 bool isReadPipe) {
12959 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12960 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012961}
12962
12963template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012964TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012965TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012966 bool TemplateKW,
12967 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012968 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012969 Template);
12970}
12971
12972template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012973TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012974TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012975 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012976 const IdentifierInfo &Name,
12977 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012978 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012979 NamedDecl *FirstQualifierInScope,
12980 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012981 UnqualifiedId TemplateName;
12982 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012983 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012984 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012985 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012986 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012987 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012988 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012989 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012990}
Mike Stump11289f42009-09-09 15:08:12 +000012991
Douglas Gregora16548e2009-08-11 05:31:07 +000012992template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012993TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012994TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012995 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012996 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012997 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012998 QualType ObjectType,
12999 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000013000 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000013001 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000013002 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000013003 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000013004 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000013005 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013006 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000013007 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000013008 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000013009 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000013010 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000013011}
Chad Rosier1dcde962012-08-08 18:46:20 +000013012
Douglas Gregor71395fa2009-11-04 00:56:37 +000013013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000013014ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000013015TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
13016 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000013017 Expr *OrigCallee,
13018 Expr *First,
13019 Expr *Second) {
13020 Expr *Callee = OrigCallee->IgnoreParenCasts();
13021 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000013022
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000013023 if (First->getObjectKind() == OK_ObjCProperty) {
13024 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
13025 if (BinaryOperator::isAssignmentOp(Opc))
13026 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
13027 First, Second);
13028 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
13029 if (Result.isInvalid())
13030 return ExprError();
13031 First = Result.get();
13032 }
13033
13034 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
13035 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
13036 if (Result.isInvalid())
13037 return ExprError();
13038 Second = Result.get();
13039 }
13040
Douglas Gregora16548e2009-08-11 05:31:07 +000013041 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000013042 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000013043 if (!First->getType()->isOverloadableType() &&
13044 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013045 return getSema().CreateBuiltinArraySubscriptExpr(
13046 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000013047 } else if (Op == OO_Arrow) {
13048 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000013049 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
13050 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000013051 if (!First->getType()->isOverloadableType() ||
13052 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
13053 // The argument is not of overloadable type, or this is an expression
13054 // of the form &Class::member, so try to create a built-in unary
13055 // operation.
John McCalle3027922010-08-25 11:45:40 +000013056 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013057 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000013058
John McCallb268a282010-08-23 23:25:46 +000013059 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000013060 }
13061 } else {
John McCallb268a282010-08-23 23:25:46 +000013062 if (!First->getType()->isOverloadableType() &&
13063 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000013064 // Neither of the arguments is an overloadable type, so try to
13065 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000013066 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000013067 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000013068 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000013069 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013071
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013072 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013073 }
13074 }
Mike Stump11289f42009-09-09 15:08:12 +000013075
13076 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000013077 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000013078 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000013079 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000013080
John McCallb268a282010-08-23 23:25:46 +000013081 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000013082 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000013083 // If the overload could not be resolved in the template definition
13084 // (because we had a dependent argument), ADL is performed as part of
13085 // template instantiation.
13086 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000013087 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000013088 // If we've resolved this to a particular non-member function, just call
13089 // that function. If we resolved it to a member function,
13090 // CreateOverloaded* will find that function for us.
13091 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
13092 if (!isa<CXXMethodDecl>(ND))
13093 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000013094 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000013095 }
Mike Stump11289f42009-09-09 15:08:12 +000013096
Douglas Gregora16548e2009-08-11 05:31:07 +000013097 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000013098 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000013099 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000013100
Douglas Gregora16548e2009-08-11 05:31:07 +000013101 // Create the overloaded operator invocation for unary operators.
13102 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000013103 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013104 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000013105 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
13106 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013107 }
Mike Stump11289f42009-09-09 15:08:12 +000013108
Douglas Gregore9d62932011-07-15 16:25:15 +000013109 if (Op == OO_Subscript) {
13110 SourceLocation LBrace;
13111 SourceLocation RBrace;
13112
13113 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000013114 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000013115 LBrace = SourceLocation::getFromRawEncoding(
13116 NameLoc.CXXOperatorName.BeginOpNameLoc);
13117 RBrace = SourceLocation::getFromRawEncoding(
13118 NameLoc.CXXOperatorName.EndOpNameLoc);
13119 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013120 LBrace = Callee->getBeginLoc();
13121 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000013122 }
13123
13124 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
13125 First, Second);
13126 }
Sebastian Redladba46e2009-10-29 20:17:01 +000013127
Douglas Gregora16548e2009-08-11 05:31:07 +000013128 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000013129 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000013130 ExprResult Result = SemaRef.CreateOverloadedBinOp(
13131 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013132 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013133 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013134
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013135 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013136}
Mike Stump11289f42009-09-09 15:08:12 +000013137
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013138template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000013139ExprResult
John McCallb268a282010-08-23 23:25:46 +000013140TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013141 SourceLocation OperatorLoc,
13142 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000013143 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013144 TypeSourceInfo *ScopeType,
13145 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000013146 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000013147 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000013148 QualType BaseType = Base->getType();
13149 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013150 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000013151 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000013152 !BaseType->getAs<PointerType>()->getPointeeType()
13153 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013154 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000013155 return SemaRef.BuildPseudoDestructorExpr(
13156 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
13157 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013158 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013159
Douglas Gregor678f90d2010-02-25 01:56:36 +000013160 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013161 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
13162 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
13163 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
13164 NameInfo.setNamedTypeInfo(DestroyedType);
13165
Richard Smith8e4a3862012-05-15 06:15:11 +000013166 // The scope type is now known to be a valid nested name specifier
13167 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000013168 if (ScopeType) {
13169 if (!ScopeType->getType()->getAs<TagType>()) {
13170 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
13171 diag::err_expected_class_or_namespace)
13172 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
13173 return ExprError();
13174 }
13175 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
13176 CCLoc);
13177 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013178
Abramo Bagnara7945c982012-01-27 09:46:47 +000013179 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000013180 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013181 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013182 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000013183 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013184 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000013185 /*TemplateArgs*/ nullptr,
13186 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013187}
13188
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013189template<typename Derived>
13190StmtResult
13191TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013192 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000013193 CapturedDecl *CD = S->getCapturedDecl();
13194 unsigned NumParams = CD->getNumParams();
13195 unsigned ContextParamPos = CD->getContextParamPosition();
13196 SmallVector<Sema::CapturedParamNameType, 4> Params;
13197 for (unsigned I = 0; I < NumParams; ++I) {
13198 if (I != ContextParamPos) {
13199 Params.push_back(
13200 std::make_pair(
13201 CD->getParam(I)->getName(),
13202 getDerived().TransformType(CD->getParam(I)->getType())));
13203 } else {
13204 Params.push_back(std::make_pair(StringRef(), QualType()));
13205 }
13206 }
Craig Topperc3ec1492014-05-26 06:22:03 +000013207 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000013208 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000013209 StmtResult Body;
13210 {
13211 Sema::CompoundScopeRAII CompoundScope(getSema());
13212 Body = getDerived().TransformStmt(S->getCapturedStmt());
13213 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000013214
13215 if (Body.isInvalid()) {
13216 getSema().ActOnCapturedRegionError();
13217 return StmtError();
13218 }
13219
Nikola Smiljanic01a75982014-05-29 10:55:11 +000013220 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013221}
13222
Douglas Gregord6ff3322009-08-04 16:50:30 +000013223} // end namespace clang
13224
Hans Wennborg59dbe862015-09-29 20:56:43 +000013225#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H