blob: 9f5a5f6caca62abcd53f53beebb416b43c6cf16f [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.
Simon Pilgrimc716e5d2019-06-03 09:56:09 +0000663 StmtResult TransformLambdaBody(Stmt *Body);
Richard Smith87346a12019-06-02 18:53:44 +0000664
John McCall31f82722010-11-12 08:19:04 +0000665 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000666
John McCalldadc5752010-08-24 06:29:42 +0000667 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
668 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000669
Faisal Vali2cba1332013-10-23 06:44:28 +0000670 TemplateParameterList *TransformTemplateParameterList(
671 TemplateParameterList *TPL) {
672 return TPL;
673 }
674
Richard Smithdb2630f2012-10-21 03:28:35 +0000675 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000676
Richard Smithdb2630f2012-10-21 03:28:35 +0000677 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000678 bool IsAddressOfOperand,
679 TypeSourceInfo **RecoveryTSI);
680
681 ExprResult TransformParenDependentScopeDeclRefExpr(
682 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
683 TypeSourceInfo **RecoveryTSI);
684
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000685 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000686
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000687// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
688// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000689#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000690 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000691 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000692#define VALUESTMT(Node, Parent) \
693 LLVM_ATTRIBUTE_NOINLINE \
694 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000695#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000696 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000697 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000698#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000699#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000700
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000701#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000702 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000703 OMPClause *Transform ## Class(Class *S);
704#include "clang/Basic/OpenMPKinds.def"
705
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000706 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000707 ///
708 /// By default, this routine adds type qualifiers only to types that can
709 /// have qualifiers, and silently suppresses those qualifiers that are not
710 /// permitted. Subclasses may override this routine to provide different
711 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000712 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000713
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000714 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000715 ///
716 /// By default, performs semantic analysis when building the pointer type.
717 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000718 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000719
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000720 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 ///
Mike Stump11289f42009-09-09 15:08:12 +0000722 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000724 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000725
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000726 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000727 ///
John McCall70dd5f62009-10-30 00:06:24 +0000728 /// By default, performs semantic analysis when building the
729 /// reference type. Subclasses may override this routine to provide
730 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000731 ///
John McCall70dd5f62009-10-30 00:06:24 +0000732 /// \param LValue whether the type was written with an lvalue sigil
733 /// or an rvalue sigil.
734 QualType RebuildReferenceType(QualType ReferentType,
735 bool LValue,
736 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000737
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000738 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// class type it refers into.
740 ///
741 /// By default, performs semantic analysis when building the member pointer
742 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000743 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
744 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000745
Manman Rene6be26c2016-09-13 17:25:08 +0000746 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
747 SourceLocation ProtocolLAngleLoc,
748 ArrayRef<ObjCProtocolDecl *> Protocols,
749 ArrayRef<SourceLocation> ProtocolLocs,
750 SourceLocation ProtocolRAngleLoc);
751
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000752 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000753 ///
754 /// By default, performs semantic analysis when building the object type.
755 /// Subclasses may override this routine to provide different behavior.
756 QualType RebuildObjCObjectType(QualType BaseType,
757 SourceLocation Loc,
758 SourceLocation TypeArgsLAngleLoc,
759 ArrayRef<TypeSourceInfo *> TypeArgs,
760 SourceLocation TypeArgsRAngleLoc,
761 SourceLocation ProtocolLAngleLoc,
762 ArrayRef<ObjCProtocolDecl *> Protocols,
763 ArrayRef<SourceLocation> ProtocolLocs,
764 SourceLocation ProtocolRAngleLoc);
765
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000766 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000767 ///
768 /// By default, directly builds the pointer type, with no additional semantic
769 /// analysis.
770 QualType RebuildObjCObjectPointerType(QualType PointeeType,
771 SourceLocation Star);
772
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000773 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 /// modifier, size of the array (if known), size expression, and index type
775 /// qualifiers.
776 ///
777 /// By default, performs semantic analysis when building the array type.
778 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000779 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780 QualType RebuildArrayType(QualType ElementType,
781 ArrayType::ArraySizeModifier SizeMod,
782 const llvm::APInt *Size,
783 Expr *SizeExpr,
784 unsigned IndexTypeQuals,
785 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000786
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000787 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// modifier, (known) size of the array, and index type qualifiers.
789 ///
790 /// By default, performs semantic analysis when building the array type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000793 ArrayType::ArraySizeModifier SizeMod,
794 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000795 unsigned IndexTypeQuals,
796 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000798 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 /// modifier, and index type qualifiers.
800 ///
801 /// By default, performs semantic analysis when building the array type.
802 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000803 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000804 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000805 unsigned IndexTypeQuals,
806 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000808 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 /// size modifier, size expression, and index type qualifiers.
810 ///
811 /// By default, performs semantic analysis when building the array type.
812 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000813 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000814 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000815 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000816 unsigned IndexTypeQuals,
817 SourceRange BracketsRange);
818
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000819 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000820 /// size modifier, size expression, and index type qualifiers.
821 ///
822 /// By default, performs semantic analysis when building the array type.
823 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000824 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000825 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000826 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 unsigned IndexTypeQuals,
828 SourceRange BracketsRange);
829
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000830 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831 /// number of elements.
832 ///
833 /// By default, performs semantic analysis when building the vector type.
834 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000835 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000836 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Erich Keanef702b022018-07-13 19:46:04 +0000838 /// Build a new potentially dependently-sized extended vector type
839 /// given the element type and number of elements.
840 ///
841 /// By default, performs semantic analysis when building the vector type.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
844 SourceLocation AttributeLoc,
845 VectorType::VectorKind);
846
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000847 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000848 /// number of elements.
849 ///
850 /// By default, performs semantic analysis when building the vector type.
851 /// Subclasses may override this routine to provide different behavior.
852 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
853 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000854
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000855 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000856 /// given the element type and number of elements.
857 ///
858 /// By default, performs semantic analysis when building the vector type.
859 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000860 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000861 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000862 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000863
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000864 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000865 /// type variable with the correct address space (retrieved from
866 /// AddrSpaceExpr) applied to it. The former will be returned in cases
867 /// where the address space remains dependent.
868 ///
869 /// By default, performs semantic analysis when building the type with address
870 /// space applied. Subclasses may override this routine to provide different
871 /// behavior.
872 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
873 Expr *AddrSpaceExpr,
874 SourceLocation AttributeLoc);
875
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000876 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000877 ///
878 /// By default, performs semantic analysis when building the function type.
879 /// Subclasses may override this routine to provide different behavior.
880 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000881 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000882 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000883
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000884 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000885 QualType RebuildFunctionNoProtoType(QualType ResultType);
886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000888 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000889 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000890
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000891 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000892 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000893 return SemaRef.Context.getTypeDeclType(Typedef);
894 }
895
Leonard Chanc72aaf62019-05-07 03:20:17 +0000896 /// Build a new MacroDefined type.
897 QualType RebuildMacroQualifiedType(QualType T,
898 const IdentifierInfo *MacroII) {
899 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
900 }
901
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000902 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000903 QualType RebuildRecordType(RecordDecl *Record) {
904 return SemaRef.Context.getTypeDeclType(Record);
905 }
906
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000907 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000908 QualType RebuildEnumType(EnumDecl *Enum) {
909 return SemaRef.Context.getTypeDeclType(Enum);
910 }
John McCallfcc33b02009-09-05 00:15:47 +0000911
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000912 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000913 ///
914 /// By default, performs semantic analysis when building the typeof type.
915 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000916 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000917
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000918 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000919 ///
920 /// By default, builds a new TypeOfType with the given underlying type.
921 QualType RebuildTypeOfType(QualType Underlying);
922
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000923 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000924 QualType RebuildUnaryTransformType(QualType BaseType,
925 UnaryTransformType::UTTKind UKind,
926 SourceLocation Loc);
927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000928 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000929 ///
930 /// By default, performs semantic analysis when building the decltype type.
931 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000932 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000933
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000934 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000935 ///
936 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000937 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000938 // Note, IsDependent is always false here: we implicitly convert an 'auto'
939 // which has been deduced to a dependent type into an undeduced 'auto', so
940 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000941 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000942 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000943 }
944
Richard Smith600b5262017-01-26 20:40:47 +0000945 /// By default, builds a new DeducedTemplateSpecializationType with the given
946 /// deduced type.
947 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
948 QualType Deduced) {
949 return SemaRef.Context.getDeducedTemplateSpecializationType(
950 Template, Deduced, /*IsDependent*/ false);
951 }
952
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000953 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000954 ///
955 /// By default, performs semantic analysis when building the template
956 /// specialization type. Subclasses may override this routine to provide
957 /// different behavior.
958 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000959 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000960 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000961
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000962 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000963 ///
964 /// By default, builds a new ParenType type from the inner type.
965 /// Subclasses may override this routine to provide different behavior.
966 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000967 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000968 }
969
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000970 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000971 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000972 /// By default, builds a new ElaboratedType type from the keyword,
973 /// the nested-name-specifier and the named type.
974 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000975 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
976 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000977 NestedNameSpecifierLoc QualifierLoc,
978 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000979 return SemaRef.Context.getElaboratedType(Keyword,
980 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000981 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000982 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000983
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000984 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000985 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000986 /// By default, builds a new DependentNameType type from the
987 /// nested-name-specifier and the given type. Subclasses may override
988 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000989 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000990 ElaboratedTypeKeyword Keyword,
991 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000992 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 const IdentifierInfo *Name,
994 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000995 TemplateArgumentListInfo &Args,
996 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000997 // Rebuild the template name.
998 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000999 CXXScopeSpec SS;
1000 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +00001001 TemplateName InstName = getDerived().RebuildTemplateName(
1002 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1003 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +00001004
Douglas Gregora7a795b2011-03-01 20:11:18 +00001005 if (InstName.isNull())
1006 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001007
Douglas Gregora7a795b2011-03-01 20:11:18 +00001008 // If it's still dependent, make a dependent specialization.
1009 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +00001010 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1011 QualifierLoc.getNestedNameSpecifier(),
1012 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +00001013 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +00001014
Douglas Gregora7a795b2011-03-01 20:11:18 +00001015 // Otherwise, make an elaborated type wrapping a non-dependent
1016 // specialization.
1017 QualType T =
1018 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1019 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001020
Craig Topperc3ec1492014-05-26 06:22:03 +00001021 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001022 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001023
1024 return SemaRef.Context.getElaboratedType(Keyword,
1025 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001026 T);
1027 }
1028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001029 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001030 ///
1031 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001032 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001033 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001034 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001035 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001036 NestedNameSpecifierLoc QualifierLoc,
1037 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001038 SourceLocation IdLoc,
1039 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001040 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001041 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001042
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001043 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001044 // If the name is still dependent, just build a new dependent name type.
1045 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001046 return SemaRef.Context.getDependentNameType(Keyword,
1047 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001048 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001049 }
1050
Richard Smithee579842017-01-30 20:39:26 +00001051 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1052 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1053 *Id, IdLoc);
1054 // If a dependent name resolves to a deduced template specialization type,
1055 // check that we're in one of the syntactic contexts permitting it.
1056 if (!DeducedTSTContext) {
1057 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1058 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1059 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1060 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1061 Deduced->getTemplateName())
1062 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1063 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1064 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1065 return QualType();
1066 }
1067 }
1068 return T;
1069 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001070
1071 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1072
Abramo Bagnarad7548482010-05-19 21:37:53 +00001073 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001074 // into a non-dependent elaborated-type-specifier. Find the tag we're
1075 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001076 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001077 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1078 if (!DC)
1079 return QualType();
1080
John McCallbf8c5192010-05-27 06:40:31 +00001081 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1082 return QualType();
1083
Craig Topperc3ec1492014-05-26 06:22:03 +00001084 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001085 SemaRef.LookupQualifiedName(Result, DC);
1086 switch (Result.getResultKind()) {
1087 case LookupResult::NotFound:
1088 case LookupResult::NotFoundInCurrentInstantiation:
1089 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001090
Douglas Gregore677daf2010-03-31 22:19:08 +00001091 case LookupResult::Found:
1092 Tag = Result.getAsSingle<TagDecl>();
1093 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001094
Douglas Gregore677daf2010-03-31 22:19:08 +00001095 case LookupResult::FoundOverloaded:
1096 case LookupResult::FoundUnresolvedValue:
1097 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001098
Douglas Gregore677daf2010-03-31 22:19:08 +00001099 case LookupResult::Ambiguous:
1100 // Let the LookupResult structure handle ambiguities.
1101 return QualType();
1102 }
1103
1104 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001105 // Check where the name exists but isn't a tag type and use that to emit
1106 // better diagnostics.
1107 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1108 SemaRef.LookupQualifiedName(Result, DC);
1109 switch (Result.getResultKind()) {
1110 case LookupResult::Found:
1111 case LookupResult::FoundOverloaded:
1112 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001113 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001114 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1115 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1116 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001117 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1118 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001119 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001120 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001121 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001122 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001123 break;
1124 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001125 return QualType();
1126 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001127
Richard Trieucaa33d32011-06-10 03:11:26 +00001128 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001129 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001130 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001131 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1132 return QualType();
1133 }
1134
1135 // Build the elaborated-type-specifier type.
1136 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001137 return SemaRef.Context.getElaboratedType(Keyword,
1138 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001139 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001140 }
Mike Stump11289f42009-09-09 15:08:12 +00001141
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001142 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001143 ///
1144 /// By default, builds a new PackExpansionType type from the given pattern.
1145 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001146 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001147 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001148 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001149 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001150 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1151 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001152 }
1153
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001154 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001155 ///
1156 /// By default, performs semantic analysis when building the atomic type.
1157 /// Subclasses may override this routine to provide different behavior.
1158 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1159
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001160 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001161 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1162 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001164 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001165 /// indicating whether the "template" keyword was provided, and the template
1166 /// that the template name refers to.
1167 ///
1168 /// By default, builds the new template name directly. Subclasses may override
1169 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001170 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001171 bool TemplateKW,
1172 TemplateDecl *Template);
1173
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001174 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001175 /// name that is referred to as a template.
1176 ///
1177 /// By default, performs semantic analysis to determine whether the name can
1178 /// be resolved to a specific template, then builds the appropriate kind of
1179 /// template name. Subclasses may override this routine to provide different
1180 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001181 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001182 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001183 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001184 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001185 NamedDecl *FirstQualifierInScope,
1186 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001188 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001189 /// overloaded operator name that is referred to as a template.
1190 ///
1191 /// By default, performs semantic analysis to determine whether the name can
1192 /// be resolved to a specific template, then builds the appropriate kind of
1193 /// template name. Subclasses may override this routine to provide different
1194 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001195 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001196 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001197 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001198 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001199 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001201 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001202 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001203 ///
1204 /// By default, performs semantic analysis to determine whether the name can
1205 /// be resolved to a specific template, then builds the appropriate kind of
1206 /// template name. Subclasses may override this routine to provide different
1207 /// behavior.
1208 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1209 const TemplateArgument &ArgPack) {
1210 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1211 }
1212
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001213 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001217 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 MultiStmtArg Statements,
1219 SourceLocation RBraceLoc,
1220 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001221 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 IsStmtExpr);
1223 }
1224
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001225 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001229 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001230 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001234 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 ColonLoc);
1236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001238 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001242 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001243 getSema().ActOnCaseStmtBody(S, Body);
1244 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001245 }
Mike Stump11289f42009-09-09 15:08:12 +00001246
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001247 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 ///
1249 /// By default, performs semantic analysis to build the new statement.
1250 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001251 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001253 Stmt *SubStmt) {
1254 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001255 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001258 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001262 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1263 SourceLocation ColonLoc, Stmt *SubStmt) {
1264 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001265 }
Mike Stump11289f42009-09-09 15:08:12 +00001266
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001267 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001268 ///
1269 /// By default, performs semantic analysis to build the new statement.
1270 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001271 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1272 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001273 Stmt *SubStmt) {
1274 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1275 }
1276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001277 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001278 ///
1279 /// By default, performs semantic analysis to build the new statement.
1280 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001281 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001282 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001283 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001284 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001285 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001288 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001289 ///
1290 /// By default, performs semantic analysis to build the new statement.
1291 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001292 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001293 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001294 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001295 }
Mike Stump11289f42009-09-09 15:08:12 +00001296
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001297 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001298 ///
1299 /// By default, performs semantic analysis to build the new statement.
1300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001301 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001302 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001303 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001304 }
1305
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001306 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001307 ///
1308 /// By default, performs semantic analysis to build the new statement.
1309 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001310 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1311 Sema::ConditionResult Cond, Stmt *Body) {
1312 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001315 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001316 ///
1317 /// By default, performs semantic analysis to build the new statement.
1318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001319 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001320 SourceLocation WhileLoc, SourceLocation LParenLoc,
1321 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001322 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1323 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001324 }
1325
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001326 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001330 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001331 Stmt *Init, Sema::ConditionResult Cond,
1332 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1333 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001334 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001335 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001336 }
Mike Stump11289f42009-09-09 15:08:12 +00001337
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001338 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001339 ///
1340 /// By default, performs semantic analysis to build the new statement.
1341 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001342 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1343 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001344 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001345 }
1346
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001347 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001351 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001352 SourceLocation StarLoc,
1353 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001354 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001355 }
Mike Stump11289f42009-09-09 15:08:12 +00001356
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001357 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001361 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001362 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001365 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001366 ///
1367 /// By default, performs semantic analysis to build the new statement.
1368 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001369 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001370 SourceLocation StartLoc, SourceLocation EndLoc) {
1371 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001372 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001373 }
Mike Stump11289f42009-09-09 15:08:12 +00001374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001375 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001379 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1380 bool IsVolatile, unsigned NumOutputs,
1381 unsigned NumInputs, IdentifierInfo **Names,
1382 MultiExprArg Constraints, MultiExprArg Exprs,
1383 Expr *AsmString, MultiExprArg Clobbers,
Jennifer Yub8fee672019-06-03 15:57:25 +00001384 unsigned NumLabels,
Chad Rosierde70e0e2012-08-25 00:11:56 +00001385 SourceLocation RParenLoc) {
1386 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1387 NumInputs, Names, Constraints, Exprs,
Jennifer Yub8fee672019-06-03 15:57:25 +00001388 AsmString, Clobbers, NumLabels, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001389 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001390
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001391 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001392 ///
1393 /// By default, performs semantic analysis to build the new statement.
1394 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001395 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001396 ArrayRef<Token> AsmToks,
1397 StringRef AsmString,
1398 unsigned NumOutputs, unsigned NumInputs,
1399 ArrayRef<StringRef> Constraints,
1400 ArrayRef<StringRef> Clobbers,
1401 ArrayRef<Expr*> Exprs,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1404 NumOutputs, NumInputs,
1405 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001406 }
1407
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001408 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001409 ///
1410 /// By default, performs semantic analysis to build the new statement.
1411 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001412 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1413 bool IsImplicit) {
1414 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001415 }
1416
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001417 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001418 ///
1419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001421 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1422 bool IsImplicit) {
1423 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1424 }
1425
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001426 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
1430 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1431 Expr *Result,
1432 UnresolvedLookupExpr *Lookup) {
1433 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001434 }
1435
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001436 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001437 ///
1438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
1440 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1441 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1442 }
1443
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001444 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1445 return getSema().BuildCoroutineBodyStmt(Args);
1446 }
1447
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001448 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001449 ///
1450 /// By default, performs semantic analysis to build the new statement.
1451 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001452 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001453 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001454 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001455 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001456 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001457 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001458 }
1459
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001460 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001461 ///
1462 /// By default, performs semantic analysis to build the new declaration.
1463 /// Subclasses may override this routine to provide different behavior.
1464 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1465 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001466 return getSema().BuildObjCExceptionDecl(TInfo, T,
1467 ExceptionDecl->getInnerLocStart(),
1468 ExceptionDecl->getLocation(),
1469 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001472 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001473 ///
1474 /// By default, performs semantic analysis to build the new statement.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001476 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001477 SourceLocation RParenLoc,
1478 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001479 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001480 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001481 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001483
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001484 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001485 ///
1486 /// By default, performs semantic analysis to build the new statement.
1487 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001488 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001489 Stmt *Body) {
1490 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001491 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001492
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001493 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001494 ///
1495 /// By default, performs semantic analysis to build the new statement.
1496 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001497 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001498 Expr *Operand) {
1499 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001501
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001502 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001503 ///
1504 /// By default, performs semantic analysis to build the new statement.
1505 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001506 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001507 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001508 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001509 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001510 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001511 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001512 return getSema().ActOnOpenMPExecutableDirective(
1513 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001514 }
1515
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001516 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001519 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001520 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1521 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001522 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001523 SourceLocation NameModifierLoc,
1524 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001525 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001526 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1527 LParenLoc, NameModifierLoc, ColonLoc,
1528 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001529 }
1530
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001531 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001532 ///
1533 /// By default, performs semantic analysis to build the new OpenMP clause.
1534 /// Subclasses may override this routine to provide different behavior.
1535 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1536 SourceLocation LParenLoc,
1537 SourceLocation EndLoc) {
1538 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1539 EndLoc);
1540 }
1541
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001542 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001543 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001544 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
1549 SourceLocation EndLoc) {
1550 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1551 LParenLoc, EndLoc);
1552 }
1553
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001554 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001555 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001556 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001557 /// Subclasses may override this routine to provide different behavior.
1558 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1562 }
1563
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001564 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001565 ///
1566 /// By default, performs semantic analysis to build the new OpenMP clause.
1567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1569 SourceLocation LParenLoc,
1570 SourceLocation EndLoc) {
1571 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1572 }
1573
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001574 /// Build a new OpenMP 'allocator' clause.
1575 ///
1576 /// By default, performs semantic analysis to build the new OpenMP clause.
1577 /// Subclasses may override this routine to provide different behavior.
1578 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
1579 SourceLocation LParenLoc,
1580 SourceLocation EndLoc) {
1581 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1582 }
1583
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001584 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001585 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001586 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001587 /// Subclasses may override this routine to provide different behavior.
1588 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1592 EndLoc);
1593 }
1594
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001595 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001596 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001597 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1600 SourceLocation KindKwLoc,
1601 SourceLocation StartLoc,
1602 SourceLocation LParenLoc,
1603 SourceLocation EndLoc) {
1604 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1605 StartLoc, LParenLoc, EndLoc);
1606 }
1607
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001608 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001609 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001610 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001611 /// Subclasses may override this routine to provide different behavior.
1612 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1613 SourceLocation KindKwLoc,
1614 SourceLocation StartLoc,
1615 SourceLocation LParenLoc,
1616 SourceLocation EndLoc) {
1617 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1618 StartLoc, LParenLoc, EndLoc);
1619 }
1620
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001621 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001622 ///
1623 /// By default, performs semantic analysis to build the new OpenMP clause.
1624 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001625 OMPClause *RebuildOMPScheduleClause(
1626 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1627 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1628 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1629 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001630 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001631 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1632 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001633 }
1634
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001635 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001636 ///
1637 /// By default, performs semantic analysis to build the new OpenMP clause.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1640 SourceLocation EndLoc,
1641 SourceLocation LParenLoc, Expr *Num) {
1642 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1643 }
1644
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001645 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001646 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001647 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001648 /// Subclasses may override this routine to provide different behavior.
1649 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc,
1651 SourceLocation LParenLoc,
1652 SourceLocation EndLoc) {
1653 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1654 EndLoc);
1655 }
1656
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001657 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001658 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001659 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001660 /// Subclasses may override this routine to provide different behavior.
1661 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1662 SourceLocation StartLoc,
1663 SourceLocation LParenLoc,
1664 SourceLocation EndLoc) {
1665 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1666 EndLoc);
1667 }
1668
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001669 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001670 ///
1671 /// By default, performs semantic analysis to build the new OpenMP clause.
1672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1674 SourceLocation StartLoc,
1675 SourceLocation LParenLoc,
1676 SourceLocation EndLoc) {
1677 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1678 EndLoc);
1679 }
1680
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001681 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001682 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001683 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001684 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001685 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1686 SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation EndLoc) {
1689 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1690 EndLoc);
1691 }
1692
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001693 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1698 SourceLocation StartLoc,
1699 SourceLocation LParenLoc,
1700 SourceLocation ColonLoc,
1701 SourceLocation EndLoc,
1702 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001703 const DeclarationNameInfo &ReductionId,
1704 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001705 return getSema().ActOnOpenMPReductionClause(
1706 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001707 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001708 }
1709
Alexey Bataev169d96a2017-07-18 20:17:46 +00001710 /// Build a new OpenMP 'task_reduction' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new statement.
1713 /// Subclasses may override this routine to provide different behavior.
1714 OMPClause *RebuildOMPTaskReductionClause(
1715 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1716 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1717 CXXScopeSpec &ReductionIdScopeSpec,
1718 const DeclarationNameInfo &ReductionId,
1719 ArrayRef<Expr *> UnresolvedReductions) {
1720 return getSema().ActOnOpenMPTaskReductionClause(
1721 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1722 ReductionId, UnresolvedReductions);
1723 }
1724
Alexey Bataevfa312f32017-07-21 18:48:21 +00001725 /// Build a new OpenMP 'in_reduction' clause.
1726 ///
1727 /// By default, performs semantic analysis to build the new statement.
1728 /// Subclasses may override this routine to provide different behavior.
1729 OMPClause *
1730 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1731 SourceLocation LParenLoc, SourceLocation ColonLoc,
1732 SourceLocation EndLoc,
1733 CXXScopeSpec &ReductionIdScopeSpec,
1734 const DeclarationNameInfo &ReductionId,
1735 ArrayRef<Expr *> UnresolvedReductions) {
1736 return getSema().ActOnOpenMPInReductionClause(
1737 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1738 ReductionId, UnresolvedReductions);
1739 }
1740
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001741 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001742 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001743 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001744 /// Subclasses may override this routine to provide different behavior.
1745 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1746 SourceLocation StartLoc,
1747 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001748 OpenMPLinearClauseKind Modifier,
1749 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001750 SourceLocation ColonLoc,
1751 SourceLocation EndLoc) {
1752 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001753 Modifier, ModifierLoc, ColonLoc,
1754 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001755 }
1756
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001757 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001758 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001759 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001760 /// Subclasses may override this routine to provide different behavior.
1761 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1762 SourceLocation StartLoc,
1763 SourceLocation LParenLoc,
1764 SourceLocation ColonLoc,
1765 SourceLocation EndLoc) {
1766 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1767 LParenLoc, ColonLoc, EndLoc);
1768 }
1769
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001770 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001771 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001772 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001773 /// Subclasses may override this routine to provide different behavior.
1774 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1775 SourceLocation StartLoc,
1776 SourceLocation LParenLoc,
1777 SourceLocation EndLoc) {
1778 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1779 EndLoc);
1780 }
1781
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001782 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001783 ///
1784 /// By default, performs semantic analysis to build the new OpenMP clause.
1785 /// Subclasses may override this routine to provide different behavior.
1786 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1787 SourceLocation StartLoc,
1788 SourceLocation LParenLoc,
1789 SourceLocation EndLoc) {
1790 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1791 EndLoc);
1792 }
1793
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001794 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001795 ///
1796 /// By default, performs semantic analysis to build the new OpenMP clause.
1797 /// Subclasses may override this routine to provide different behavior.
1798 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1799 SourceLocation StartLoc,
1800 SourceLocation LParenLoc,
1801 SourceLocation EndLoc) {
1802 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1803 EndLoc);
1804 }
1805
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001806 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001807 ///
1808 /// By default, performs semantic analysis to build the new OpenMP clause.
1809 /// Subclasses may override this routine to provide different behavior.
1810 OMPClause *
1811 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1812 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1813 SourceLocation StartLoc, SourceLocation LParenLoc,
1814 SourceLocation EndLoc) {
1815 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1816 StartLoc, LParenLoc, EndLoc);
1817 }
1818
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001819 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001820 ///
1821 /// By default, performs semantic analysis to build the new statement.
1822 /// Subclasses may override this routine to provide different behavior.
1823 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1824 SourceLocation LParenLoc,
1825 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001826 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001827 EndLoc);
1828 }
1829
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001830 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001831 ///
1832 /// By default, performs semantic analysis to build the new OpenMP clause.
1833 /// Subclasses may override this routine to provide different behavior.
Michael Kruse4304e9d2019-02-19 16:38:20 +00001834 OMPClause *RebuildOMPMapClause(
1835 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1836 ArrayRef<SourceLocation> MapTypeModifiersLoc,
1837 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1838 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1839 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1840 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
Kelvin Lief579432018-12-18 22:18:41 +00001841 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001842 MapperIdScopeSpec, MapperId, MapType,
1843 IsMapTypeImplicit, MapLoc, ColonLoc,
1844 VarList, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001845 }
1846
Alexey Bataeve04483e2019-03-27 14:14:31 +00001847 /// Build a new OpenMP 'allocate' clause.
1848 ///
1849 /// By default, performs semantic analysis to build the new OpenMP clause.
1850 /// Subclasses may override this routine to provide different behavior.
1851 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
1852 SourceLocation StartLoc,
1853 SourceLocation LParenLoc,
1854 SourceLocation ColonLoc,
1855 SourceLocation EndLoc) {
1856 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1857 LParenLoc, ColonLoc, EndLoc);
1858 }
1859
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001860 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001861 ///
1862 /// By default, performs semantic analysis to build the new statement.
1863 /// Subclasses may override this routine to provide different behavior.
1864 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1865 SourceLocation LParenLoc,
1866 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001867 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001868 EndLoc);
1869 }
1870
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001871 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001872 ///
1873 /// By default, performs semantic analysis to build the new statement.
1874 /// Subclasses may override this routine to provide different behavior.
1875 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1876 SourceLocation StartLoc,
1877 SourceLocation LParenLoc,
1878 SourceLocation EndLoc) {
1879 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1880 LParenLoc, EndLoc);
1881 }
1882
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001883 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001884 ///
1885 /// By default, performs semantic analysis to build the new statement.
1886 /// Subclasses may override this routine to provide different behavior.
1887 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1888 SourceLocation LParenLoc,
1889 SourceLocation EndLoc) {
1890 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1891 EndLoc);
1892 }
1893
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001894 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001895 ///
1896 /// By default, performs semantic analysis to build the new statement.
1897 /// Subclasses may override this routine to provide different behavior.
1898 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1899 SourceLocation LParenLoc,
1900 SourceLocation EndLoc) {
1901 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1902 EndLoc);
1903 }
1904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001905 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001906 ///
1907 /// By default, performs semantic analysis to build the new statement.
1908 /// Subclasses may override this routine to provide different behavior.
1909 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1910 SourceLocation LParenLoc,
1911 SourceLocation EndLoc) {
1912 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1913 EndLoc);
1914 }
1915
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001916 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001917 ///
1918 /// By default, performs semantic analysis to build the new statement.
1919 /// Subclasses may override this routine to provide different behavior.
1920 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1921 SourceLocation LParenLoc,
1922 SourceLocation EndLoc) {
1923 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1924 }
1925
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001926 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001927 ///
1928 /// By default, performs semantic analysis to build the new OpenMP clause.
1929 /// Subclasses may override this routine to provide different behavior.
1930 OMPClause *
1931 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1932 Expr *ChunkSize, SourceLocation StartLoc,
1933 SourceLocation LParenLoc, SourceLocation KindLoc,
1934 SourceLocation CommaLoc, SourceLocation EndLoc) {
1935 return getSema().ActOnOpenMPDistScheduleClause(
1936 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1937 }
1938
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001939 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001940 ///
1941 /// By default, performs semantic analysis to build the new statement.
1942 /// Subclasses may override this routine to provide different behavior.
1943 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
Michael Kruse01f670d2019-02-22 22:29:42 +00001944 CXXScopeSpec &MapperIdScopeSpec,
1945 DeclarationNameInfo &MapperId,
1946 const OMPVarListLocTy &Locs,
1947 ArrayRef<Expr *> UnresolvedMappers) {
1948 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1949 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00001950 }
1951
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001952 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001953 ///
1954 /// By default, performs semantic analysis to build the new statement.
1955 /// Subclasses may override this routine to provide different behavior.
1956 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
Michael Kruse0336c752019-02-25 20:34:15 +00001957 CXXScopeSpec &MapperIdScopeSpec,
1958 DeclarationNameInfo &MapperId,
1959 const OMPVarListLocTy &Locs,
1960 ArrayRef<Expr *> UnresolvedMappers) {
1961 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1962 Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00001963 }
1964
Carlo Bertolli2404b172016-07-13 15:37:16 +00001965 /// Build a new OpenMP 'use_device_ptr' clause.
1966 ///
1967 /// By default, performs semantic analysis to build the new OpenMP clause.
1968 /// Subclasses may override this routine to provide different behavior.
1969 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001970 const OMPVarListLocTy &Locs) {
1971 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001972 }
1973
Carlo Bertolli70594e92016-07-13 17:16:49 +00001974 /// Build a new OpenMP 'is_device_ptr' clause.
1975 ///
1976 /// By default, performs semantic analysis to build the new OpenMP clause.
1977 /// Subclasses may override this routine to provide different behavior.
1978 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001979 const OMPVarListLocTy &Locs) {
1980 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001981 }
1982
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001983 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001984 ///
1985 /// By default, performs semantic analysis to build the new statement.
1986 /// Subclasses may override this routine to provide different behavior.
1987 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1988 Expr *object) {
1989 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1990 }
1991
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001992 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001993 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001994 /// By default, performs semantic analysis to build the new statement.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001997 Expr *Object, Stmt *Body) {
1998 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001999 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00002000
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002001 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00002002 ///
2003 /// By default, performs semantic analysis to build the new statement.
2004 /// Subclasses may override this routine to provide different behavior.
2005 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
2006 Stmt *Body) {
2007 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2008 }
John McCall53848232011-07-27 01:07:15 +00002009
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002010 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00002011 ///
2012 /// By default, performs semantic analysis to build the new statement.
2013 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002014 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002015 Stmt *Element,
2016 Expr *Collection,
2017 SourceLocation RParenLoc,
2018 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00002019 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002020 Element,
John McCallb268a282010-08-23 23:25:46 +00002021 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002022 RParenLoc);
2023 if (ForEachStmt.isInvalid())
2024 return StmtError();
2025
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002026 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00002027 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002029 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00002030 ///
2031 /// By default, performs semantic analysis to build the new decaration.
2032 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00002033 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00002034 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00002035 SourceLocation StartLoc,
2036 SourceLocation IdLoc,
2037 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002038 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002039 StartLoc, IdLoc, Id);
2040 if (Var)
2041 getSema().CurContext->addDecl(Var);
2042 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002043 }
2044
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002045 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002046 ///
2047 /// By default, performs semantic analysis to build the new statement.
2048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002049 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002050 VarDecl *ExceptionDecl,
2051 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002052 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2053 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002054 }
Mike Stump11289f42009-09-09 15:08:12 +00002055
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002056 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002057 ///
2058 /// By default, performs semantic analysis to build the new statement.
2059 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002060 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2061 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002062 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002063 }
Mike Stump11289f42009-09-09 15:08:12 +00002064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002065 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002066 ///
2067 /// By default, performs semantic analysis to build the new statement.
2068 /// Subclasses may override this routine to provide different behavior.
2069 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002070 SourceLocation CoawaitLoc, Stmt *Init,
2071 SourceLocation ColonLoc, Stmt *Range,
2072 Stmt *Begin, Stmt *End, Expr *Cond,
2073 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002074 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002075 // If we've just learned that the range is actually an Objective-C
2076 // collection, treat this as an Objective-C fast enumeration loop.
2077 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2078 if (RangeStmt->isSingleDecl()) {
2079 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002080 if (RangeVar->isInvalidDecl())
2081 return StmtError();
2082
Douglas Gregorf7106af2013-04-08 18:40:13 +00002083 Expr *RangeExpr = RangeVar->getInit();
2084 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002085 RangeExpr->getType()->isObjCObjectPointerType()) {
2086 // FIXME: Support init-statements in Objective-C++20 ranged for
2087 // statement.
2088 if (Init) {
2089 return SemaRef.Diag(Init->getBeginLoc(),
2090 diag::err_objc_for_range_init_stmt)
2091 << Init->getSourceRange();
2092 }
2093 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2094 RangeExpr, RParenLoc);
2095 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002096 }
2097 }
2098 }
2099
Richard Smith8baa5002018-09-28 18:44:09 +00002100 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2101 Range, Begin, End, Cond, Inc, LoopVar,
2102 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002103 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002104
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002105 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002106 ///
2107 /// By default, performs semantic analysis to build the new statement.
2108 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002109 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002110 bool IsIfExists,
2111 NestedNameSpecifierLoc QualifierLoc,
2112 DeclarationNameInfo NameInfo,
2113 Stmt *Nested) {
2114 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2115 QualifierLoc, NameInfo, Nested);
2116 }
2117
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002118 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002119 ///
2120 /// By default, performs semantic analysis to finish the new statement.
2121 /// Subclasses may override this routine to provide different behavior.
2122 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2123 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2124 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002125
David Majnemerfad8f482013-10-15 09:33:02 +00002126 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002127 Stmt *TryBlock, Stmt *Handler) {
2128 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002129 }
2130
David Majnemerfad8f482013-10-15 09:33:02 +00002131 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002132 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002133 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002134 }
2135
David Majnemerfad8f482013-10-15 09:33:02 +00002136 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002137 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002138 }
2139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002140 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002141 ///
2142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
2144 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002145 PredefinedExpr::IdentKind IK) {
2146 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002147 }
2148
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002149 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002154 LookupResult &R,
2155 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002156 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2157 }
2158
2159
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002160 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002161 ///
2162 /// By default, performs semantic analysis to build the new expression.
2163 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002164 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002165 ValueDecl *VD,
2166 const DeclarationNameInfo &NameInfo,
2167 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002168 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002169 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002170
2171 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002172
2173 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 }
Mike Stump11289f42009-09-09 15:08:12 +00002175
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002176 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002177 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 /// By default, performs semantic analysis to build the new expression.
2179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002180 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002182 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 }
2184
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002185 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002186 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002189 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002190 SourceLocation OperatorLoc,
2191 bool isArrow,
2192 CXXScopeSpec &SS,
2193 TypeSourceInfo *ScopeType,
2194 SourceLocation CCLoc,
2195 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002196 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002197
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002198 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002199 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 /// By default, performs semantic analysis to build the new expression.
2201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002203 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002204 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002205 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 }
Mike Stump11289f42009-09-09 15:08:12 +00002207
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002208 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002209 ///
2210 /// By default, performs semantic analysis to build the new expression.
2211 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002212 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002213 TypeSourceInfo *Type,
2214 ArrayRef<Sema::OffsetOfComponent> Components,
2215 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002216 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002217 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002219
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002220 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002221 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 /// By default, performs semantic analysis to build the new expression.
2224 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002225 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2226 SourceLocation OpLoc,
2227 UnaryExprOrTypeTrait ExprKind,
2228 SourceRange R) {
2229 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002230 }
2231
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002232 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002233 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002234 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002235 /// By default, performs semantic analysis to build the new expression.
2236 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002237 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2238 UnaryExprOrTypeTrait ExprKind,
2239 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002241 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002244
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002245 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 }
Mike Stump11289f42009-09-09 15:08:12 +00002247
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002248 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002249 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002252 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002254 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002255 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002256 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002257 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 RBracketLoc);
2259 }
2260
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002261 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
2265 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2266 Expr *LowerBound,
2267 SourceLocation ColonLoc, Expr *Length,
2268 SourceLocation RBracketLoc) {
2269 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2270 ColonLoc, Length, RBracketLoc);
2271 }
2272
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002273 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 /// By default, performs semantic analysis to build the new expression.
2276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002277 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002279 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002280 Expr *ExecConfig = nullptr) {
Richard Smith255b85f2019-05-08 01:36:36 +00002281 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args,
2282 RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 }
2284
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002285 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002286 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 /// By default, performs semantic analysis to build the new expression.
2288 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002289 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002290 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002291 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002292 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002293 const DeclarationNameInfo &MemberNameInfo,
2294 ValueDecl *Member,
2295 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002296 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002297 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002298 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2299 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002300 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002301 // We have a reference to an unnamed field. This is always the
2302 // base of an anonymous struct/union member access, i.e. the
2303 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002304 assert(Member->getType()->isRecordType() &&
2305 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002306
Richard Smithcab9a7d2011-10-26 19:06:56 +00002307 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002308 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002309 QualifierLoc.getNestedNameSpecifier(),
2310 FoundDecl, Member);
2311 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002312 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002313 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002314
2315 CXXScopeSpec EmptySS;
2316 return getSema().BuildFieldReferenceExpr(
2317 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2318 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002319 }
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002321 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002322 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002323
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002324 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002325 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002326
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002327 if (isArrow && !BaseType->isPointerType())
2328 return ExprError();
2329
John McCall16df1e52010-03-30 21:47:33 +00002330 // FIXME: this involves duplicating earlier analysis in a lot of
2331 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002332 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002333 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002334 R.resolveKind();
2335
John McCallb268a282010-08-23 23:25:46 +00002336 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002337 SS, TemplateKWLoc,
2338 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002339 R, ExplicitTemplateArgs,
2340 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 }
Mike Stump11289f42009-09-09 15:08:12 +00002342
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002343 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002344 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002345 /// By default, performs semantic analysis to build the new expression.
2346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002347 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002348 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002349 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002350 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 }
2352
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002353 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002354 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002355 /// By default, performs semantic analysis to build the new expression.
2356 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002357 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002358 SourceLocation QuestionLoc,
2359 Expr *LHS,
2360 SourceLocation ColonLoc,
2361 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002362 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2363 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 }
2365
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002366 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002367 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 /// By default, performs semantic analysis to build the new expression.
2369 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002370 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002371 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002373 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002374 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002375 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 }
Mike Stump11289f42009-09-09 15:08:12 +00002377
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002378 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002379 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 /// By default, performs semantic analysis to build the new expression.
2381 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002382 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002383 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002385 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002386 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002387 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
Mike Stump11289f42009-09-09 15:08:12 +00002389
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002390 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002391 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002394 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 SourceLocation OpLoc,
2396 SourceLocation AccessorLoc,
2397 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002398
John McCall10eae182009-11-30 22:42:35 +00002399 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002400 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002401 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002402 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002403 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002404 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002405 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002406 /* TemplateArgs */ nullptr,
2407 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 }
Mike Stump11289f42009-09-09 15:08:12 +00002409
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002410 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002411 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002414 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002415 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002416 SourceLocation RBraceLoc) {
2417 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 }
Mike Stump11289f42009-09-09 15:08:12 +00002419
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002420 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002421 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002422 /// By default, performs semantic analysis to build the new expression.
2423 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002424 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 MultiExprArg ArrayExprs,
2426 SourceLocation EqualOrColonLoc,
2427 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002428 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002429 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002430 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002431 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002434
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002435 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 }
Mike Stump11289f42009-09-09 15:08:12 +00002437
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002438 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002439 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002440 /// By default, builds the implicit value initialization without performing
2441 /// any semantic analysis. Subclasses may override this routine to provide
2442 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002443 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002444 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 }
Mike Stump11289f42009-09-09 15:08:12 +00002446
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002447 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002448 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 /// By default, performs semantic analysis to build the new expression.
2450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002451 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002452 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002453 SourceLocation RParenLoc) {
2454 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002455 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002456 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 }
2458
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002459 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002460 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 /// By default, performs semantic analysis to build the new expression.
2462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002463 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002464 MultiExprArg SubExprs,
2465 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002466 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002467 }
Mike Stump11289f42009-09-09 15:08:12 +00002468
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002469 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002470 ///
2471 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002472 /// rather than attempting to map the label statement itself.
2473 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002474 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002475 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002476 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 }
Mike Stump11289f42009-09-09 15:08:12 +00002478
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002479 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002480 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 /// By default, performs semantic analysis to build the new expression.
2482 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002483 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002484 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002486 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002487 }
Mike Stump11289f42009-09-09 15:08:12 +00002488
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002489 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 ///
2491 /// By default, performs semantic analysis to build the new expression.
2492 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002493 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002494 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 SourceLocation RParenLoc) {
2496 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002497 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 RParenLoc);
2499 }
Mike Stump11289f42009-09-09 15:08:12 +00002500
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002501 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
2505 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2506 SourceLocation DefaultLoc,
2507 SourceLocation RParenLoc,
2508 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002509 ArrayRef<TypeSourceInfo *> Types,
2510 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002511 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002512 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002513 }
2514
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002515 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 ///
2517 /// By default, performs semantic analysis to build the new expression.
2518 /// The semantic analysis provides the behavior of template instantiation,
2519 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002520 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 /// argument-dependent lookup, etc. Subclasses may override this routine to
2522 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002523 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002525 Expr *Callee,
2526 Expr *First,
2527 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002528
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002529 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 /// reinterpret_cast.
2531 ///
2532 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002533 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002535 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 Stmt::StmtClass Class,
2537 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002538 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 SourceLocation RAngleLoc,
2540 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002541 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 SourceLocation RParenLoc) {
2543 switch (Class) {
2544 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002545 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002546 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002547 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002548
2549 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002550 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002551 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002552 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002555 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002556 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002557 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002559
Douglas Gregora16548e2009-08-11 05:31:07 +00002560 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002561 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002562 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002563 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002564
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002566 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 }
Mike Stump11289f42009-09-09 15:08:12 +00002569
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002570 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 ///
2572 /// By default, performs semantic analysis to build the new expression.
2573 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002574 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002576 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002577 SourceLocation RAngleLoc,
2578 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002579 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002581 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002582 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002583 SourceRange(LAngleLoc, RAngleLoc),
2584 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 }
2586
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002587 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 ///
2589 /// By default, performs semantic analysis to build the new expression.
2590 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002591 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002593 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002594 SourceLocation RAngleLoc,
2595 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002596 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002597 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002598 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002599 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002600 SourceRange(LAngleLoc, RAngleLoc),
2601 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002602 }
2603
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002604 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002608 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002609 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002610 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002611 SourceLocation RAngleLoc,
2612 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002613 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002615 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002616 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002617 SourceRange(LAngleLoc, RAngleLoc),
2618 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002619 }
2620
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002621 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 ///
2623 /// By default, performs semantic analysis to build the new expression.
2624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002626 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002627 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002628 SourceLocation RAngleLoc,
2629 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002630 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002631 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002632 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002633 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002634 SourceRange(LAngleLoc, RAngleLoc),
2635 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002636 }
Mike Stump11289f42009-09-09 15:08:12 +00002637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002638 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 ///
2640 /// By default, performs semantic analysis to build the new expression.
2641 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002642 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2643 SourceLocation LParenLoc,
2644 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002645 SourceLocation RParenLoc,
2646 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002647 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002648 MultiExprArg(&Sub, 1), RParenLoc,
2649 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 }
Mike Stump11289f42009-09-09 15:08:12 +00002651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002652 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002656 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002657 SourceLocation TypeidLoc,
2658 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002660 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002661 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 }
Mike Stump11289f42009-09-09 15:08:12 +00002663
Francois Pichet9f4f2072010-09-08 12:20:18 +00002664
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002665 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 ///
2667 /// By default, performs semantic analysis to build the new expression.
2668 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002669 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002670 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002671 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002672 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002673 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002674 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002675 }
2676
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002677 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002678 ///
2679 /// By default, performs semantic analysis to build the new expression.
2680 /// Subclasses may override this routine to provide different behavior.
2681 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2682 SourceLocation TypeidLoc,
2683 TypeSourceInfo *Operand,
2684 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002685 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002686 RParenLoc);
2687 }
2688
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002689 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
2693 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2694 SourceLocation TypeidLoc,
2695 Expr *Operand,
2696 SourceLocation RParenLoc) {
2697 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2698 RParenLoc);
2699 }
2700
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002701 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002702 ///
2703 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002704 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002706 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002707 QualType ThisType,
2708 bool isImplicit) {
Richard Smith8458c9e2019-05-24 01:35:07 +00002709 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002710 }
2711
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002712 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002716 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2717 bool IsThrownVariableInScope) {
2718 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 }
2720
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002721 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002722 ///
2723 /// By default, builds a new default-argument expression, which does not
2724 /// require any semantic analysis. Subclasses may override this routine to
2725 /// provide different behavior.
Eric Fiselier708afb52019-05-16 21:04:15 +00002726 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
2727 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2728 getSema().CurContext);
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 }
2730
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002731 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002732 ///
2733 /// By default, builds a new default field initialization expression, which
2734 /// does not require any semantic analysis. Subclasses may override this
2735 /// routine to provide different behavior.
2736 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2737 FieldDecl *Field) {
Eric Fiselier708afb52019-05-16 21:04:15 +00002738 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2739 getSema().CurContext);
Richard Smith852c9db2013-04-20 22:23:05 +00002740 }
2741
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002742 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002746 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2747 SourceLocation LParenLoc,
2748 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002749 return getSema().BuildCXXTypeConstructExpr(
2750 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002751 }
Mike Stump11289f42009-09-09 15:08:12 +00002752
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002753 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 ///
2755 /// By default, performs semantic analysis to build the new expression.
2756 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002757 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002758 bool UseGlobal,
2759 SourceLocation PlacementLParen,
2760 MultiExprArg PlacementArgs,
2761 SourceLocation PlacementRParen,
2762 SourceRange TypeIdParens,
2763 QualType AllocatedType,
2764 TypeSourceInfo *AllocatedTypeInfo,
Richard Smithb9fb1212019-05-06 03:47:15 +00002765 Optional<Expr *> ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002766 SourceRange DirectInitRange,
2767 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002768 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002769 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002770 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002771 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002772 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002773 AllocatedType,
2774 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002775 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002776 DirectInitRange,
2777 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002778 }
Mike Stump11289f42009-09-09 15:08:12 +00002779
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002780 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002784 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002785 bool IsGlobalDelete,
2786 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002787 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002788 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002789 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002790 }
Mike Stump11289f42009-09-09 15:08:12 +00002791
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002792 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002793 ///
2794 /// By default, performs semantic analysis to build the new expression.
2795 /// Subclasses may override this routine to provide different behavior.
2796 ExprResult RebuildTypeTrait(TypeTrait Trait,
2797 SourceLocation StartLoc,
2798 ArrayRef<TypeSourceInfo *> Args,
2799 SourceLocation RParenLoc) {
2800 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2801 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002802
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002803 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002804 ///
2805 /// By default, performs semantic analysis to build the new expression.
2806 /// Subclasses may override this routine to provide different behavior.
2807 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2808 SourceLocation StartLoc,
2809 TypeSourceInfo *TSInfo,
2810 Expr *DimExpr,
2811 SourceLocation RParenLoc) {
2812 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2813 }
2814
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002815 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002816 ///
2817 /// By default, performs semantic analysis to build the new expression.
2818 /// Subclasses may override this routine to provide different behavior.
2819 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2820 SourceLocation StartLoc,
2821 Expr *Queried,
2822 SourceLocation RParenLoc) {
2823 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2824 }
2825
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002826 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 /// expression.
2828 ///
2829 /// By default, performs semantic analysis to build the new expression.
2830 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002831 ExprResult RebuildDependentScopeDeclRefExpr(
2832 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002833 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002834 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002835 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002836 bool IsAddressOfOperand,
2837 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002838 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002839 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002840
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002841 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002842 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2843 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002844
Reid Kleckner32506ed2014-06-12 23:03:48 +00002845 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002846 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002847 }
2848
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002849 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002850 ///
2851 /// By default, performs semantic analysis to build the new expression.
2852 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002853 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002854 SourceLocation TemplateKWLoc,
2855 LookupResult &R,
2856 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002857 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002858 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2859 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002860 }
2861
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002862 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002863 ///
2864 /// By default, performs semantic analysis to build the new expression.
2865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002866 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002867 SourceLocation Loc,
2868 CXXConstructorDecl *Constructor,
2869 bool IsElidable,
2870 MultiExprArg Args,
2871 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002872 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002873 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002874 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002875 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002876 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002877 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002878 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002879 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002880 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
Richard Smithc83bf822016-06-10 00:58:19 +00002882 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002883 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002884 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002885 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002886 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002887 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002888 RequiresZeroInit, ConstructKind,
2889 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002890 }
2891
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002892 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002893 /// expression.
2894 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2895 CXXConstructorDecl *Constructor,
2896 bool ConstructsVBase,
2897 bool InheritedFromVBase) {
2898 return new (getSema().Context) CXXInheritedCtorInitExpr(
2899 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2900 }
2901
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002902 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002903 ///
2904 /// By default, performs semantic analysis to build the new expression.
2905 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002906 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002907 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002908 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002909 SourceLocation RParenOrBraceLoc,
2910 bool ListInitialization) {
2911 return getSema().BuildCXXTypeConstructExpr(
2912 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002913 }
2914
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002915 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002916 ///
2917 /// By default, performs semantic analysis to build the new expression.
2918 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002919 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2920 SourceLocation LParenLoc,
2921 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002922 SourceLocation RParenLoc,
2923 bool ListInitialization) {
2924 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2925 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002926 }
Mike Stump11289f42009-09-09 15:08:12 +00002927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002928 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002929 ///
2930 /// By default, performs semantic analysis to build the new expression.
2931 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002932 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002933 QualType BaseType,
2934 bool IsArrow,
2935 SourceLocation OperatorLoc,
2936 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002937 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002938 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002939 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002940 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002941 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002942 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002943
John McCallb268a282010-08-23 23:25:46 +00002944 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002945 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002946 SS, TemplateKWLoc,
2947 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002948 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002949 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002950 }
2951
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002952 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002953 ///
2954 /// By default, performs semantic analysis to build the new expression.
2955 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002956 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2957 SourceLocation OperatorLoc,
2958 bool IsArrow,
2959 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002960 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002961 NamedDecl *FirstQualifierInScope,
2962 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002963 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002964 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002965 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002966
John McCallb268a282010-08-23 23:25:46 +00002967 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002968 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002969 SS, TemplateKWLoc,
2970 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002971 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002972 }
Mike Stump11289f42009-09-09 15:08:12 +00002973
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002974 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002975 ///
2976 /// By default, performs semantic analysis to build the new expression.
2977 /// Subclasses may override this routine to provide different behavior.
2978 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2979 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2980 }
2981
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002982 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002983 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2984 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002985 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002986 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002987 Optional<unsigned> Length,
2988 ArrayRef<TemplateArgument> PartialArgs) {
2989 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2990 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002991 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002992
Eric Fiselier708afb52019-05-16 21:04:15 +00002993 /// Build a new expression representing a call to a source location
2994 /// builtin.
2995 ///
2996 /// By default, performs semantic analysis to build the new expression.
2997 /// Subclasses may override this routine to provide different behavior.
2998 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
2999 SourceLocation BuiltinLoc,
3000 SourceLocation RPLoc,
3001 DeclContext *ParentContext) {
3002 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3003 }
3004
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003005 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00003006 ///
3007 /// By default, performs semantic analysis to build the new expression.
3008 /// Subclasses may override this routine to provide different behavior.
3009 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
3010 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3011 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003012
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003013 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003014 ///
3015 /// By default, performs semantic analysis to build the new expression.
3016 /// Subclasses may override this routine to provide different behavior.
3017 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
3018 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003019 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003020 MultiExprArg(Elements, NumElements));
3021 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003022
3023 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003024 Expr *Base, Expr *Key,
3025 ObjCMethodDecl *getterMethod,
3026 ObjCMethodDecl *setterMethod) {
3027 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3028 getterMethod, setterMethod);
3029 }
3030
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003031 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003032 ///
3033 /// By default, performs semantic analysis to build the new expression.
3034 /// Subclasses may override this routine to provide different behavior.
3035 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00003036 MutableArrayRef<ObjCDictionaryElement> Elements) {
3037 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00003038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003039
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003040 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003041 ///
3042 /// By default, performs semantic analysis to build the new expression.
3043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003044 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00003045 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00003046 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003047 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003048 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003049
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003050 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003051 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003052 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003053 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003054 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003055 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003056 MultiExprArg Args,
3057 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003058 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3059 ReceiverTypeInfo->getType(),
3060 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003061 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003062 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003063 }
3064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003065 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003066 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003067 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003068 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003069 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003070 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003071 MultiExprArg Args,
3072 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003073 return SemaRef.BuildInstanceMessage(Receiver,
3074 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003075 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003076 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003077 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003078 }
3079
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003080 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003081 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3082 Selector Sel,
3083 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003084 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003085 ObjCMethodDecl *Method,
3086 SourceLocation LBracLoc,
3087 MultiExprArg Args,
3088 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003089 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003090 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003091 SuperLoc,
3092 Sel, Method, LBracLoc, SelectorLocs,
3093 RBracLoc, Args)
3094 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003095 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003096 SuperLoc,
3097 Sel, Method, LBracLoc, SelectorLocs,
3098 RBracLoc, Args);
3099
Fangrui Song6907ce22018-07-30 19:24:48 +00003100
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003101 }
3102
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003103 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003104 ///
3105 /// By default, performs semantic analysis to build the new expression.
3106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003107 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003108 SourceLocation IvarLoc,
3109 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003110 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003111 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003112 ExprResult Result = getSema().BuildMemberReferenceExpr(
3113 BaseArg, BaseArg->getType(),
3114 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3115 /*FirstQualifierInScope=*/nullptr, NameInfo,
3116 /*TemplateArgs=*/nullptr,
3117 /*S=*/nullptr);
3118 if (IsFreeIvar && Result.isUsable())
3119 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3120 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003121 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003122
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003123 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003124 ///
3125 /// By default, performs semantic analysis to build the new expression.
3126 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003127 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003128 ObjCPropertyDecl *Property,
3129 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003130 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003131 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3132 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3133 /*FIXME:*/PropertyLoc,
3134 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003135 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003136 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003137 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003138 /*TemplateArgs=*/nullptr,
3139 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003140 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003141
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003142 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003143 ///
3144 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003145 /// Subclasses may override this routine to provide different behavior.
3146 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3147 ObjCMethodDecl *Getter,
3148 ObjCMethodDecl *Setter,
3149 SourceLocation PropertyLoc) {
3150 // Since these expressions can only be value-dependent, we do not
3151 // need to perform semantic analysis again.
3152 return Owned(
3153 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3154 VK_LValue, OK_ObjCProperty,
3155 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003156 }
3157
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003158 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003159 ///
3160 /// By default, performs semantic analysis to build the new expression.
3161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003162 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003163 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003164 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003165 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3166 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003167 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003168 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003169 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003170 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003171 /*TemplateArgs=*/nullptr,
3172 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003174
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003175 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003176 ///
3177 /// By default, performs semantic analysis to build the new expression.
3178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003179 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003180 MultiExprArg SubExprs,
3181 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003182 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003183 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003184 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3185 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3186 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003187 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregora16548e2009-08-11 05:31:07 +00003189 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003190 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003191 Expr *Callee = new (SemaRef.Context)
3192 DeclRefExpr(SemaRef.Context, Builtin, false,
3193 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003194 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3195 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003196 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003197
3198 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003199 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003200 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003201 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003202
Douglas Gregora16548e2009-08-11 05:31:07 +00003203 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003204 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003205 }
John McCall31f82722010-11-12 08:19:04 +00003206
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003207 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003208 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3209 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3210 SourceLocation RParenLoc) {
3211 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3212 BuiltinLoc, RParenLoc);
3213 }
3214
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003215 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003216 ///
3217 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003218 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003219 /// different behavior.
3220 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003221 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003222 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003223 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003224 case TemplateArgument::Expression: {
3225 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003226 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3227 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003228 if (Result.isInvalid())
3229 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor98318c22011-01-03 21:37:45 +00003231 return TemplateArgumentLoc(Result.get(), Result.get());
3232 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003233
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003234 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003235 return TemplateArgumentLoc(TemplateArgument(
3236 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003237 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003238 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003239 Pattern.getTemplateNameLoc(),
3240 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003241
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003242 case TemplateArgument::Null:
3243 case TemplateArgument::Integral:
3244 case TemplateArgument::Declaration:
3245 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003246 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003247 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003248 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003249
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003250 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003251 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003252 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003253 EllipsisLoc,
3254 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003255 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3256 Expansion);
3257 break;
3258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003260 return TemplateArgumentLoc();
3261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003263 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003264 ///
3265 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003266 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003267 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003268 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003269 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003270 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003271 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003272
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003273 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003274 ///
3275 /// By default, performs semantic analysis in order to build a new fold
3276 /// expression.
3277 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3278 BinaryOperatorKind Operator,
3279 SourceLocation EllipsisLoc, Expr *RHS,
Richard Smithc7214f62019-05-13 08:31:14 +00003280 SourceLocation RParenLoc,
3281 Optional<unsigned> NumExpansions) {
Richard Smith0f0af192014-11-08 05:07:16 +00003282 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
Richard Smithc7214f62019-05-13 08:31:14 +00003283 RHS, RParenLoc, NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +00003284 }
3285
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003286 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003287 ///
3288 /// By default, produces the fallback value for the fold-expression, or
3289 /// produce an error if there is no fallback value.
3290 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3291 BinaryOperatorKind Operator) {
3292 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3293 }
3294
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003295 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003296 ///
3297 /// By default, performs semantic analysis to build the new expression.
3298 /// Subclasses may override this routine to provide different behavior.
3299 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3300 MultiExprArg SubExprs,
3301 QualType RetTy,
3302 AtomicExpr::AtomicOp Op,
3303 SourceLocation RParenLoc) {
3304 // Just create the expression; there is not any interesting semantic
3305 // analysis here because we can't actually build an AtomicExpr until
3306 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003307 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003308 RParenLoc);
3309 }
3310
John McCall31f82722010-11-12 08:19:04 +00003311private:
Douglas Gregor14454802011-02-25 02:25:35 +00003312 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3313 QualType ObjectType,
3314 NamedDecl *FirstQualifierInScope,
3315 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003316
3317 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3318 QualType ObjectType,
3319 NamedDecl *FirstQualifierInScope,
3320 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003321
3322 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3323 NamedDecl *FirstQualifierInScope,
3324 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003325
3326 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3327 DependentNameTypeLoc TL,
3328 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003329};
Douglas Gregora16548e2009-08-11 05:31:07 +00003330
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003331template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003332StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003333 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003334 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003335
Douglas Gregorebe10102009-08-20 07:17:43 +00003336 switch (S->getStmtClass()) {
3337 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003338
Douglas Gregorebe10102009-08-20 07:17:43 +00003339 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003340 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003341#define STMT(Node, Parent) \
3342 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003343#define VALUESTMT(Node, Parent) \
3344 case Stmt::Node##Class: \
3345 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003346#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003347#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003349
Douglas Gregorebe10102009-08-20 07:17:43 +00003350 // Transform expressions by calling TransformExpr.
3351#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003352#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003353#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003354#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003355 {
John McCalldadc5752010-08-24 06:29:42 +00003356 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003357
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003358 if (SDK == SDK_StmtExprResult)
3359 E = getSema().ActOnStmtExprResult(E);
3360 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 }
Mike Stump11289f42009-09-09 15:08:12 +00003362 }
3363
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003364 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003367template<typename Derived>
3368OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3369 if (!S)
3370 return S;
3371
3372 switch (S->getClauseKind()) {
3373 default: break;
3374 // Transform individual clause nodes
3375#define OPENMP_CLAUSE(Name, Class) \
3376 case OMPC_ ## Name : \
3377 return getDerived().Transform ## Class(cast<Class>(S));
3378#include "clang/Basic/OpenMPKinds.def"
3379 }
3380
3381 return S;
3382}
3383
Mike Stump11289f42009-09-09 15:08:12 +00003384
Douglas Gregore922c772009-08-04 22:27:00 +00003385template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003386ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003387 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003388 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003389
3390 switch (E->getStmtClass()) {
3391 case Stmt::NoStmtClass: break;
3392#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003393#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003394#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003395 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003396#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003397 }
3398
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003399 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003400}
3401
3402template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003403ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003404 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003405 // Initializers are instantiated like expressions, except that various outer
3406 // layers are stripped.
3407 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003408 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003409
Bill Wendling7c44da22018-10-31 03:48:47 +00003410 if (auto *FE = dyn_cast<FullExpr>(Init))
3411 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003412
Richard Smith410306b2016-12-12 02:53:20 +00003413 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3414 Init = AIL->getCommonExpr();
3415
Richard Smithe6ca4752013-05-30 22:40:16 +00003416 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3417 Init = MTE->GetTemporaryExpr();
3418
Richard Smithd59b8322012-12-19 01:39:02 +00003419 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3420 Init = Binder->getSubExpr();
3421
3422 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3423 Init = ICE->getSubExprAsWritten();
3424
Richard Smithcc1b96d2013-06-12 22:31:48 +00003425 if (CXXStdInitializerListExpr *ILE =
3426 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003427 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003428
Richard Smithc6abd962014-07-25 01:12:44 +00003429 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003430 // InitListExprs. Other forms of copy-initialization will be a no-op if
3431 // the initializer is already the right type.
3432 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003433 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003434 return getDerived().TransformExpr(Init);
3435
3436 // Revert value-initialization back to empty parens.
3437 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3438 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003439 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003440 Parens.getEnd());
3441 }
3442
3443 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3444 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003445 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003446 SourceLocation());
3447
3448 // Revert initialization by constructor back to a parenthesized or braced list
3449 // of expressions. Any other form of initializer can just be reused directly.
3450 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003451 return getDerived().TransformExpr(Init);
3452
Richard Smithf8adcdc2014-07-17 05:12:35 +00003453 // If the initialization implicitly converted an initializer list to a
3454 // std::initializer_list object, unwrap the std::initializer_list too.
3455 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003456 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003457
Richard Smith12938cf2018-09-26 04:36:55 +00003458 // Enter a list-init context if this was list initialization.
3459 EnterExpressionEvaluationContext Context(
3460 getSema(), EnterExpressionEvaluationContext::InitList,
3461 Construct->isListInitialization());
3462
Richard Smithd59b8322012-12-19 01:39:02 +00003463 SmallVector<Expr*, 8> NewArgs;
3464 bool ArgChanged = false;
3465 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003466 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003467 return ExprError();
3468
Richard Smithd1036122018-01-12 22:21:33 +00003469 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003470 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003471 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003472 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003473
Richard Smithd59b8322012-12-19 01:39:02 +00003474 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003475 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003476 if (Parens.isInvalid()) {
3477 // This was a variable declaration's initialization for which no initializer
3478 // was specified.
3479 assert(NewArgs.empty() &&
3480 "no parens or braces but have direct init with arguments?");
3481 return ExprEmpty();
3482 }
Richard Smithd59b8322012-12-19 01:39:02 +00003483 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3484 Parens.getEnd());
3485}
3486
3487template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003488bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003489 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003490 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003491 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003492 bool *ArgChanged) {
3493 for (unsigned I = 0; I != NumInputs; ++I) {
3494 // If requested, drop call arguments that need to be dropped.
3495 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3496 if (ArgChanged)
3497 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregora3efea12011-01-03 19:04:46 +00003499 break;
3500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003501
Douglas Gregor968f23a2011-01-03 19:31:53 +00003502 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3503 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003504
Chris Lattner01cf8db2011-07-20 06:58:45 +00003505 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003506 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3507 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003508
Douglas Gregor968f23a2011-01-03 19:31:53 +00003509 // Determine whether the set of unexpanded parameter packs can and should
3510 // be expanded.
3511 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003512 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003513 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3514 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003515 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3516 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003517 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003518 Expand, RetainExpansion,
3519 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003520 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor968f23a2011-01-03 19:31:53 +00003522 if (!Expand) {
3523 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003524 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003525 // expansion.
3526 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3527 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3528 if (OutPattern.isInvalid())
3529 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003530
3531 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003532 Expansion->getEllipsisLoc(),
3533 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003534 if (Out.isInvalid())
3535 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Douglas Gregor968f23a2011-01-03 19:31:53 +00003537 if (ArgChanged)
3538 *ArgChanged = true;
3539 Outputs.push_back(Out.get());
3540 continue;
3541 }
John McCall542e7c62011-07-06 07:30:07 +00003542
3543 // Record right away that the argument was changed. This needs
3544 // to happen even if the array expands to nothing.
3545 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003546
Douglas Gregor968f23a2011-01-03 19:31:53 +00003547 // The transform has determined that we should perform an elementwise
3548 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003549 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003550 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3551 ExprResult Out = getDerived().TransformExpr(Pattern);
3552 if (Out.isInvalid())
3553 return true;
3554
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003555 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003556 Out = getDerived().RebuildPackExpansion(
3557 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003558 if (Out.isInvalid())
3559 return true;
3560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor968f23a2011-01-03 19:31:53 +00003562 Outputs.push_back(Out.get());
3563 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003564
Richard Smith9467be42014-06-06 17:33:35 +00003565 // If we're supposed to retain a pack expansion, do so by temporarily
3566 // forgetting the partially-substituted parameter pack.
3567 if (RetainExpansion) {
3568 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3569
3570 ExprResult Out = getDerived().TransformExpr(Pattern);
3571 if (Out.isInvalid())
3572 return true;
3573
3574 Out = getDerived().RebuildPackExpansion(
3575 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3576 if (Out.isInvalid())
3577 return true;
3578
3579 Outputs.push_back(Out.get());
3580 }
3581
Douglas Gregor968f23a2011-01-03 19:31:53 +00003582 continue;
3583 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003584
Richard Smithd59b8322012-12-19 01:39:02 +00003585 ExprResult Result =
3586 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3587 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003588 if (Result.isInvalid())
3589 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Douglas Gregora3efea12011-01-03 19:04:46 +00003591 if (Result.get() != Inputs[I] && ArgChanged)
3592 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
3594 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003595 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregora3efea12011-01-03 19:04:46 +00003597 return false;
3598}
3599
Richard Smith03a4aa32016-06-23 19:02:52 +00003600template <typename Derived>
3601Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3602 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3603 if (Var) {
3604 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3605 getDerived().TransformDefinition(Var->getLocation(), Var));
3606
3607 if (!ConditionVar)
3608 return Sema::ConditionError();
3609
3610 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3611 }
3612
3613 if (Expr) {
3614 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3615
3616 if (CondExpr.isInvalid())
3617 return Sema::ConditionError();
3618
3619 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3620 }
3621
3622 return Sema::ConditionResult();
3623}
3624
Douglas Gregora3efea12011-01-03 19:04:46 +00003625template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003626NestedNameSpecifierLoc
3627TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3628 NestedNameSpecifierLoc NNS,
3629 QualType ObjectType,
3630 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003631 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003632 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003633 Qualifier = Qualifier.getPrefix())
3634 Qualifiers.push_back(Qualifier);
3635
3636 CXXScopeSpec SS;
3637 while (!Qualifiers.empty()) {
3638 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3639 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003640
Douglas Gregor14454802011-02-25 02:25:35 +00003641 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003642 case NestedNameSpecifier::Identifier: {
3643 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3644 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3645 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3646 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003647 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003648 }
Douglas Gregor14454802011-02-25 02:25:35 +00003649 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003650
Douglas Gregor14454802011-02-25 02:25:35 +00003651 case NestedNameSpecifier::Namespace: {
3652 NamespaceDecl *NS
3653 = cast_or_null<NamespaceDecl>(
3654 getDerived().TransformDecl(
3655 Q.getLocalBeginLoc(),
3656 QNNS->getAsNamespace()));
3657 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3658 break;
3659 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003660
Douglas Gregor14454802011-02-25 02:25:35 +00003661 case NestedNameSpecifier::NamespaceAlias: {
3662 NamespaceAliasDecl *Alias
3663 = cast_or_null<NamespaceAliasDecl>(
3664 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3665 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003666 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003667 Q.getLocalEndLoc());
3668 break;
3669 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003670
Douglas Gregor14454802011-02-25 02:25:35 +00003671 case NestedNameSpecifier::Global:
3672 // There is no meaningful transformation that one could perform on the
3673 // global scope.
3674 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3675 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003676
Nikola Smiljanic67860242014-09-26 00:28:20 +00003677 case NestedNameSpecifier::Super: {
3678 CXXRecordDecl *RD =
3679 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3680 SourceLocation(), QNNS->getAsRecordDecl()));
3681 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3682 break;
3683 }
3684
Douglas Gregor14454802011-02-25 02:25:35 +00003685 case NestedNameSpecifier::TypeSpecWithTemplate:
3686 case NestedNameSpecifier::TypeSpec: {
3687 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3688 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
Douglas Gregor14454802011-02-25 02:25:35 +00003690 if (!TL)
3691 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregor14454802011-02-25 02:25:35 +00003693 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003694 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003695 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003696 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003697 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003698 if (TL.getType()->isEnumeralType())
3699 SemaRef.Diag(TL.getBeginLoc(),
3700 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003701 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3702 Q.getLocalEndLoc());
3703 break;
3704 }
Richard Trieude756fb2011-05-07 01:36:37 +00003705 // If the nested-name-specifier is an invalid type def, don't emit an
3706 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003707 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3708 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003709 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003710 << TL.getType() << SS.getRange();
3711 }
Douglas Gregor14454802011-02-25 02:25:35 +00003712 return NestedNameSpecifierLoc();
3713 }
Douglas Gregore16af532011-02-28 18:50:33 +00003714 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003715
Douglas Gregore16af532011-02-28 18:50:33 +00003716 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003717 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003718 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor14454802011-02-25 02:25:35 +00003721 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003722 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003723 !getDerived().AlwaysRebuild())
3724 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003725
3726 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003727 // nested-name-specifier, do so.
3728 if (SS.location_size() == NNS.getDataLength() &&
3729 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3730 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3731
3732 // Allocate new nested-name-specifier location information.
3733 return SS.getWithLocInContext(SemaRef.Context);
3734}
3735
3736template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003737DeclarationNameInfo
3738TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003739::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003740 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003741 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003742 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003743
3744 switch (Name.getNameKind()) {
3745 case DeclarationName::Identifier:
3746 case DeclarationName::ObjCZeroArgSelector:
3747 case DeclarationName::ObjCOneArgSelector:
3748 case DeclarationName::ObjCMultiArgSelector:
3749 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003750 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003751 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003752 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003753
Richard Smith35845152017-02-07 01:37:30 +00003754 case DeclarationName::CXXDeductionGuideName: {
3755 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3756 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3757 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3758 if (!NewTemplate)
3759 return DeclarationNameInfo();
3760
3761 DeclarationNameInfo NewNameInfo(NameInfo);
3762 NewNameInfo.setName(
3763 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3764 return NewNameInfo;
3765 }
3766
Douglas Gregorf816bd72009-09-03 22:13:48 +00003767 case DeclarationName::CXXConstructorName:
3768 case DeclarationName::CXXDestructorName:
3769 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003770 TypeSourceInfo *NewTInfo;
3771 CanQualType NewCanTy;
3772 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003773 NewTInfo = getDerived().TransformType(OldTInfo);
3774 if (!NewTInfo)
3775 return DeclarationNameInfo();
3776 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003777 }
3778 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003779 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003780 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003781 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003782 if (NewT.isNull())
3783 return DeclarationNameInfo();
3784 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3785 }
Mike Stump11289f42009-09-09 15:08:12 +00003786
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003787 DeclarationName NewName
3788 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3789 NewCanTy);
3790 DeclarationNameInfo NewNameInfo(NameInfo);
3791 NewNameInfo.setName(NewName);
3792 NewNameInfo.setNamedTypeInfo(NewTInfo);
3793 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003794 }
Mike Stump11289f42009-09-09 15:08:12 +00003795 }
3796
David Blaikie83d382b2011-09-23 05:06:16 +00003797 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003798}
3799
3800template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003801TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003802TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3803 TemplateName Name,
3804 SourceLocation NameLoc,
3805 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003806 NamedDecl *FirstQualifierInScope,
3807 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003808 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3809 TemplateDecl *Template = QTN->getTemplateDecl();
3810 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Douglas Gregor9db53502011-03-02 18:07:45 +00003812 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003813 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003814 Template));
3815 if (!TransTemplate)
3816 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003817
Douglas Gregor9db53502011-03-02 18:07:45 +00003818 if (!getDerived().AlwaysRebuild() &&
3819 SS.getScopeRep() == QTN->getQualifier() &&
3820 TransTemplate == Template)
3821 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003822
Douglas Gregor9db53502011-03-02 18:07:45 +00003823 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3824 TransTemplate);
3825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003826
Douglas Gregor9db53502011-03-02 18:07:45 +00003827 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3828 if (SS.getScopeRep()) {
3829 // These apply to the scope specifier, not the template.
3830 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003831 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003832 }
3833
Douglas Gregor9db53502011-03-02 18:07:45 +00003834 if (!getDerived().AlwaysRebuild() &&
3835 SS.getScopeRep() == DTN->getQualifier() &&
3836 ObjectType.isNull())
3837 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003838
Richard Smith79810042018-05-11 02:43:08 +00003839 // FIXME: Preserve the location of the "template" keyword.
3840 SourceLocation TemplateKWLoc = NameLoc;
3841
Douglas Gregor9db53502011-03-02 18:07:45 +00003842 if (DTN->isIdentifier()) {
3843 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003844 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003845 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003846 NameLoc,
3847 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003848 FirstQualifierInScope,
3849 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
Richard Smith79810042018-05-11 02:43:08 +00003852 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3853 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003854 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003855 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003856
Douglas Gregor9db53502011-03-02 18:07:45 +00003857 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3858 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003859 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003860 Template));
3861 if (!TransTemplate)
3862 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003863
Douglas Gregor9db53502011-03-02 18:07:45 +00003864 if (!getDerived().AlwaysRebuild() &&
3865 TransTemplate == Template)
3866 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
Douglas Gregor9db53502011-03-02 18:07:45 +00003868 return TemplateName(TransTemplate);
3869 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003870
Douglas Gregor9db53502011-03-02 18:07:45 +00003871 if (SubstTemplateTemplateParmPackStorage *SubstPack
3872 = Name.getAsSubstTemplateTemplateParmPack()) {
3873 TemplateTemplateParmDecl *TransParam
3874 = cast_or_null<TemplateTemplateParmDecl>(
3875 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3876 if (!TransParam)
3877 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003878
Douglas Gregor9db53502011-03-02 18:07:45 +00003879 if (!getDerived().AlwaysRebuild() &&
3880 TransParam == SubstPack->getParameterPack())
3881 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003882
3883 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003884 SubstPack->getArgumentPack());
3885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003886
Douglas Gregor9db53502011-03-02 18:07:45 +00003887 // These should be getting filtered out before they reach the AST.
3888 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003889}
3890
3891template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003892void TreeTransform<Derived>::InventTemplateArgumentLoc(
3893 const TemplateArgument &Arg,
3894 TemplateArgumentLoc &Output) {
3895 SourceLocation Loc = getDerived().getBaseLocation();
3896 switch (Arg.getKind()) {
3897 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003898 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003899 break;
3900
3901 case TemplateArgument::Type:
3902 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003903 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003904
John McCall0ad16662009-10-29 08:12:44 +00003905 break;
3906
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003907 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003908 case TemplateArgument::TemplateExpansion: {
3909 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003910 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003911 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3912 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3913 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3914 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003915
Douglas Gregor9d802122011-03-02 17:09:35 +00003916 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003917 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003918 Builder.getWithLocInContext(SemaRef.Context),
3919 Loc);
3920 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003921 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003922 Builder.getWithLocInContext(SemaRef.Context),
3923 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003924
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003925 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003926 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003927
John McCall0ad16662009-10-29 08:12:44 +00003928 case TemplateArgument::Expression:
3929 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3930 break;
3931
3932 case TemplateArgument::Declaration:
3933 case TemplateArgument::Integral:
3934 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003935 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003936 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003937 break;
3938 }
3939}
3940
3941template<typename Derived>
3942bool TreeTransform<Derived>::TransformTemplateArgument(
3943 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003944 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003945 EnterExpressionEvaluationContext EEEC(
3946 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3947 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3948 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003949 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003950 switch (Arg.getKind()) {
3951 case TemplateArgument::Null:
3952 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003953 case TemplateArgument::Pack:
3954 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003955 case TemplateArgument::NullPtr:
3956 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregore922c772009-08-04 22:27:00 +00003958 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003959 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003960 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003961 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003962
3963 DI = getDerived().TransformType(DI);
3964 if (!DI) return true;
3965
3966 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3967 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003968 }
Mike Stump11289f42009-09-09 15:08:12 +00003969
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003970 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003971 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3972 if (QualifierLoc) {
3973 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3974 if (!QualifierLoc)
3975 return true;
3976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003977
Douglas Gregordf846d12011-03-02 18:46:51 +00003978 CXXScopeSpec SS;
3979 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003980 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003981 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3982 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003983 if (Template.isNull())
3984 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003985
Douglas Gregor9d802122011-03-02 17:09:35 +00003986 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003987 Input.getTemplateNameLoc());
3988 return false;
3989 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003990
3991 case TemplateArgument::TemplateExpansion:
3992 llvm_unreachable("Caller should expand pack expansions");
3993
Douglas Gregore922c772009-08-04 22:27:00 +00003994 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003995 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003996 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003997 getSema(), Uneval
3998 ? Sema::ExpressionEvaluationContext::Unevaluated
3999 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004000
John McCall0ad16662009-10-29 08:12:44 +00004001 Expr *InputExpr = Input.getSourceExpression();
4002 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4003
Chris Lattnercdb591a2011-04-25 20:37:58 +00004004 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004005 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00004006 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004007 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00004008 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004009 }
Douglas Gregore922c772009-08-04 22:27:00 +00004010 }
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregore922c772009-08-04 22:27:00 +00004012 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00004013 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00004014}
4015
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004016/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00004017/// for each of the template arguments in its underlying iterator.
4018template<typename Derived, typename InputIterator>
4019class TemplateArgumentLocInventIterator {
4020 TreeTransform<Derived> &Self;
4021 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00004022
Douglas Gregorfe921a72010-12-20 23:36:19 +00004023public:
4024 typedef TemplateArgumentLoc value_type;
4025 typedef TemplateArgumentLoc reference;
4026 typedef typename std::iterator_traits<InputIterator>::difference_type
4027 difference_type;
4028 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004029
Douglas Gregorfe921a72010-12-20 23:36:19 +00004030 class pointer {
4031 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004032
Douglas Gregorfe921a72010-12-20 23:36:19 +00004033 public:
4034 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregorfe921a72010-12-20 23:36:19 +00004036 const TemplateArgumentLoc *operator->() const { return &Arg; }
4037 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00004039 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004040
Douglas Gregorfe921a72010-12-20 23:36:19 +00004041 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4042 InputIterator Iter)
4043 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004044
Douglas Gregorfe921a72010-12-20 23:36:19 +00004045 TemplateArgumentLocInventIterator &operator++() {
4046 ++Iter;
4047 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004048 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004049
Douglas Gregorfe921a72010-12-20 23:36:19 +00004050 TemplateArgumentLocInventIterator operator++(int) {
4051 TemplateArgumentLocInventIterator Old(*this);
4052 ++(*this);
4053 return Old;
4054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004055
Douglas Gregorfe921a72010-12-20 23:36:19 +00004056 reference operator*() const {
4057 TemplateArgumentLoc Result;
4058 Self.InventTemplateArgumentLoc(*Iter, Result);
4059 return Result;
4060 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004061
Douglas Gregorfe921a72010-12-20 23:36:19 +00004062 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004063
Douglas Gregorfe921a72010-12-20 23:36:19 +00004064 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4065 const TemplateArgumentLocInventIterator &Y) {
4066 return X.Iter == Y.Iter;
4067 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004068
Douglas Gregorfe921a72010-12-20 23:36:19 +00004069 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4070 const TemplateArgumentLocInventIterator &Y) {
4071 return X.Iter != Y.Iter;
4072 }
4073};
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
Douglas Gregor42cafa82010-12-20 17:42:22 +00004075template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004076template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004077bool TreeTransform<Derived>::TransformTemplateArguments(
4078 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4079 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004080 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004081 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004082 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004083
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004084 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4085 // Unpack argument packs, which we translate them into separate
4086 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004087 // FIXME: We could do much better if we could guarantee that the
4088 // TemplateArgumentLocInfo for the pack expansion would be usable for
4089 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004090 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004091 TemplateArgument::pack_iterator>
4092 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004093 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004094 In.getArgument().pack_begin()),
4095 PackLocIterator(*this,
4096 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004097 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004098 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004100 continue;
4101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004103 if (In.getArgument().isPackExpansion()) {
4104 // We have a pack expansion, for which we will be substituting into
4105 // the pattern.
4106 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004107 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004108 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004109 = getSema().getTemplateArgumentPackExpansionPattern(
4110 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004111
Chris Lattner01cf8db2011-07-20 06:58:45 +00004112 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004113 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4114 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004115
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004116 // Determine whether the set of unexpanded parameter packs can and should
4117 // be expanded.
4118 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004119 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004120 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004121 if (getDerived().TryExpandParameterPacks(Ellipsis,
4122 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004123 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004124 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004125 RetainExpansion,
4126 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004127 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004129 if (!Expand) {
4130 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004131 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004132 // expansion.
4133 TemplateArgumentLoc OutPattern;
4134 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004135 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004136 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004137
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004138 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4139 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004140 if (Out.getArgument().isNull())
4141 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004143 Outputs.addArgument(Out);
4144 continue;
4145 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004146
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004147 // The transform has determined that we should perform an elementwise
4148 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004149 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004150 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4151
Richard Smithd784e682015-09-23 21:41:42 +00004152 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004153 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004154
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004155 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004156 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4157 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004158 if (Out.getArgument().isNull())
4159 return true;
4160 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004161
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004162 Outputs.addArgument(Out);
4163 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004164
Douglas Gregor48d24112011-01-10 20:53:55 +00004165 // If we're supposed to retain a pack expansion, do so by temporarily
4166 // forgetting the partially-substituted parameter pack.
4167 if (RetainExpansion) {
4168 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004169
Richard Smithd784e682015-09-23 21:41:42 +00004170 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004171 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004173 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4174 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004175 if (Out.getArgument().isNull())
4176 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004177
Douglas Gregor48d24112011-01-10 20:53:55 +00004178 Outputs.addArgument(Out);
4179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004181 continue;
4182 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004183
4184 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004185 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004186 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004187
Douglas Gregor42cafa82010-12-20 17:42:22 +00004188 Outputs.addArgument(Out);
4189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004190
Douglas Gregor42cafa82010-12-20 17:42:22 +00004191 return false;
4192
4193}
4194
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195//===----------------------------------------------------------------------===//
4196// Type transformation
4197//===----------------------------------------------------------------------===//
4198
4199template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004200QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004201 if (getDerived().AlreadyTransformed(T))
4202 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004203
John McCall550e0c22009-10-21 00:40:46 +00004204 // Temporary workaround. All of these transformations should
4205 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004206 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4207 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004208
John McCall31f82722010-11-12 08:19:04 +00004209 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004210
John McCall550e0c22009-10-21 00:40:46 +00004211 if (!NewDI)
4212 return QualType();
4213
4214 return NewDI->getType();
4215}
4216
4217template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004218TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004219 // Refine the base location to the type's location.
4220 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4221 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004222 if (getDerived().AlreadyTransformed(DI->getType()))
4223 return DI;
4224
4225 TypeLocBuilder TLB;
4226
4227 TypeLoc TL = DI->getTypeLoc();
4228 TLB.reserve(TL.getFullDataSize());
4229
John McCall31f82722010-11-12 08:19:04 +00004230 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004231 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004232 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004233
John McCallbcd03502009-12-07 02:54:59 +00004234 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004235}
4236
4237template<typename Derived>
4238QualType
John McCall31f82722010-11-12 08:19:04 +00004239TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004240 switch (T.getTypeLocClass()) {
4241#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004242#define TYPELOC(CLASS, PARENT) \
4243 case TypeLoc::CLASS: \
4244 return getDerived().Transform##CLASS##Type(TLB, \
4245 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004246#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004247 }
Mike Stump11289f42009-09-09 15:08:12 +00004248
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004249 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004250}
4251
Richard Smithee579842017-01-30 20:39:26 +00004252template<typename Derived>
4253QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4254 if (!isa<DependentNameType>(T))
4255 return TransformType(T);
4256
4257 if (getDerived().AlreadyTransformed(T))
4258 return T;
4259 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4260 getDerived().getBaseLocation());
4261 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4262 return NewDI ? NewDI->getType() : QualType();
4263}
4264
4265template<typename Derived>
4266TypeSourceInfo *
4267TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4268 if (!isa<DependentNameType>(DI->getType()))
4269 return TransformType(DI);
4270
4271 // Refine the base location to the type's location.
4272 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4273 getDerived().getBaseEntity());
4274 if (getDerived().AlreadyTransformed(DI->getType()))
4275 return DI;
4276
4277 TypeLocBuilder TLB;
4278
4279 TypeLoc TL = DI->getTypeLoc();
4280 TLB.reserve(TL.getFullDataSize());
4281
Richard Smithee579842017-01-30 20:39:26 +00004282 auto QTL = TL.getAs<QualifiedTypeLoc>();
4283 if (QTL)
4284 TL = QTL.getUnqualifiedLoc();
4285
4286 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4287
4288 QualType Result = getDerived().TransformDependentNameType(
4289 TLB, DNTL, /*DeducedTSTContext*/true);
4290 if (Result.isNull())
4291 return nullptr;
4292
4293 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004294 Result = getDerived().RebuildQualifiedType(Result, QTL);
4295 if (Result.isNull())
4296 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004297 TLB.TypeWasModifiedSafely(Result);
4298 }
4299
4300 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4301}
4302
John McCall550e0c22009-10-21 00:40:46 +00004303template<typename Derived>
4304QualType
4305TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004306 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004307 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004308 if (Result.isNull())
4309 return QualType();
4310
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004311 Result = getDerived().RebuildQualifiedType(Result, T);
4312
4313 if (Result.isNull())
4314 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004315
4316 // RebuildQualifiedType might have updated the type, but not in a way
4317 // that invalidates the TypeLoc. (There's no location information for
4318 // qualifiers.)
4319 TLB.TypeWasModifiedSafely(Result);
4320
4321 return Result;
4322}
4323
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004324template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004325QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004326 QualifiedTypeLoc TL) {
4327
4328 SourceLocation Loc = TL.getBeginLoc();
4329 Qualifiers Quals = TL.getType().getLocalQualifiers();
4330
4331 if (((T.getAddressSpace() != LangAS::Default &&
4332 Quals.getAddressSpace() != LangAS::Default)) &&
4333 T.getAddressSpace() != Quals.getAddressSpace()) {
4334 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4335 << TL.getType() << T;
4336 return QualType();
4337 }
4338
Richard Smithee579842017-01-30 20:39:26 +00004339 // C++ [dcl.fct]p7:
4340 // [When] adding cv-qualifications on top of the function type [...] the
4341 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004342 if (T->isFunctionType()) {
4343 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4344 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004345 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004346 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004347
Richard Smithee579842017-01-30 20:39:26 +00004348 // C++ [dcl.ref]p1:
4349 // when the cv-qualifiers are introduced through the use of a typedef-name
4350 // or decltype-specifier [...] the cv-qualifiers are ignored.
4351 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4352 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004353 if (T->isReferenceType()) {
4354 // The only qualifier that applies to a reference type is restrict.
4355 if (!Quals.hasRestrict())
4356 return T;
4357 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4358 }
Mike Stump11289f42009-09-09 15:08:12 +00004359
John McCall31168b02011-06-15 23:02:42 +00004360 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004361 // resulting type.
4362 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004363 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004364 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004365 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004366 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004367 // A lifetime qualifier applied to a substituted template parameter
4368 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004369 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004370 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004371 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004372 QualType Replacement = SubstTypeParam->getReplacementType();
4373 Qualifiers Qs = Replacement.getQualifiers();
4374 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004375 Replacement = SemaRef.Context.getQualifiedType(
4376 Replacement.getUnqualifiedType(), Qs);
4377 T = SemaRef.Context.getSubstTemplateTypeParmType(
4378 SubstTypeParam->getReplacedParameter(), Replacement);
4379 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004380 // 'auto' types behave the same way as template parameters.
4381 QualType Deduced = AutoTy->getDeducedType();
4382 Qualifiers Qs = Deduced.getQualifiers();
4383 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004384 Deduced =
4385 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4386 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4387 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004388 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004389 // Otherwise, complain about the addition of a qualifier to an
4390 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004391 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4392 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004393 Quals.removeObjCLifetime();
4394 }
4395 }
4396 }
John McCall550e0c22009-10-21 00:40:46 +00004397
Richard Smithee579842017-01-30 20:39:26 +00004398 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004399}
4400
Douglas Gregor14454802011-02-25 02:25:35 +00004401template<typename Derived>
4402TypeLoc
4403TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4404 QualType ObjectType,
4405 NamedDecl *UnqualLookup,
4406 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004407 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004408 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004409
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004410 TypeSourceInfo *TSI =
4411 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4412 if (TSI)
4413 return TSI->getTypeLoc();
4414 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004415}
4416
Douglas Gregor579c15f2011-03-02 18:32:08 +00004417template<typename Derived>
4418TypeSourceInfo *
4419TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4420 QualType ObjectType,
4421 NamedDecl *UnqualLookup,
4422 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004423 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004424 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004425
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004426 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4427 UnqualLookup, SS);
4428}
4429
4430template <typename Derived>
4431TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4432 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4433 CXXScopeSpec &SS) {
4434 QualType T = TL.getType();
4435 assert(!getDerived().AlreadyTransformed(T));
4436
Douglas Gregor579c15f2011-03-02 18:32:08 +00004437 TypeLocBuilder TLB;
4438 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004439
Douglas Gregor579c15f2011-03-02 18:32:08 +00004440 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004441 TemplateSpecializationTypeLoc SpecTL =
4442 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004443
Richard Smithfd3dae02017-01-20 00:20:39 +00004444 TemplateName Template = getDerived().TransformTemplateName(
4445 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4446 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004447 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004448 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004449
4450 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004451 Template);
4452 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004453 DependentTemplateSpecializationTypeLoc SpecTL =
4454 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004455
Douglas Gregor579c15f2011-03-02 18:32:08 +00004456 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004457 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004458 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004459 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004460 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004461 ObjectType, UnqualLookup,
4462 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004463 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004464 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004465
4466 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004467 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004468 Template,
4469 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004470 } else {
4471 // Nothing special needs to be done for these.
4472 Result = getDerived().TransformType(TLB, TL);
4473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004474
4475 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004476 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004477
Douglas Gregor579c15f2011-03-02 18:32:08 +00004478 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4479}
4480
John McCall550e0c22009-10-21 00:40:46 +00004481template <class TyLoc> static inline
4482QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4483 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4484 NewT.setNameLoc(T.getNameLoc());
4485 return T.getType();
4486}
4487
John McCall550e0c22009-10-21 00:40:46 +00004488template<typename Derived>
4489QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004490 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004491 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4492 NewT.setBuiltinLoc(T.getBuiltinLoc());
4493 if (T.needsExtraLocalData())
4494 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4495 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496}
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregord6ff3322009-08-04 16:50:30 +00004498template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004499QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004500 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004501 // FIXME: recurse?
4502 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004503}
Mike Stump11289f42009-09-09 15:08:12 +00004504
Reid Kleckner0503a872013-12-05 01:23:43 +00004505template <typename Derived>
4506QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4507 AdjustedTypeLoc TL) {
4508 // Adjustments applied during transformation are handled elsewhere.
4509 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4510}
4511
Douglas Gregord6ff3322009-08-04 16:50:30 +00004512template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004513QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4514 DecayedTypeLoc TL) {
4515 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4516 if (OriginalType.isNull())
4517 return QualType();
4518
4519 QualType Result = TL.getType();
4520 if (getDerived().AlwaysRebuild() ||
4521 OriginalType != TL.getOriginalLoc().getType())
4522 Result = SemaRef.Context.getDecayedType(OriginalType);
4523 TLB.push<DecayedTypeLoc>(Result);
4524 // Nothing to set for DecayedTypeLoc.
4525 return Result;
4526}
4527
4528template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004529QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004530 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004531 QualType PointeeType
4532 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004533 if (PointeeType.isNull())
4534 return QualType();
4535
4536 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004537 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004538 // A dependent pointer type 'T *' has is being transformed such
4539 // that an Objective-C class type is being replaced for 'T'. The
4540 // resulting pointer type is an ObjCObjectPointerType, not a
4541 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004542 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004543
John McCall8b07ec22010-05-15 11:32:37 +00004544 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4545 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004546 return Result;
4547 }
John McCall31f82722010-11-12 08:19:04 +00004548
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004549 if (getDerived().AlwaysRebuild() ||
4550 PointeeType != TL.getPointeeLoc().getType()) {
4551 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4552 if (Result.isNull())
4553 return QualType();
4554 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004555
John McCall31168b02011-06-15 23:02:42 +00004556 // Objective-C ARC can add lifetime qualifiers to the type that we're
4557 // pointing to.
4558 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004559
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004560 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4561 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004562 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563}
Mike Stump11289f42009-09-09 15:08:12 +00004564
4565template<typename Derived>
4566QualType
John McCall550e0c22009-10-21 00:40:46 +00004567TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004568 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004569 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004570 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4571 if (PointeeType.isNull())
4572 return QualType();
4573
4574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 PointeeType != TL.getPointeeLoc().getType()) {
4577 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004578 TL.getSigilLoc());
4579 if (Result.isNull())
4580 return QualType();
4581 }
4582
Douglas Gregor049211a2010-04-22 16:50:51 +00004583 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004584 NewT.setSigilLoc(TL.getSigilLoc());
4585 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586}
4587
John McCall70dd5f62009-10-30 00:06:24 +00004588/// Transforms a reference type. Note that somewhat paradoxically we
4589/// don't care whether the type itself is an l-value type or an r-value
4590/// type; we only care if the type was *written* as an l-value type
4591/// or an r-value type.
4592template<typename Derived>
4593QualType
4594TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004595 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004596 const ReferenceType *T = TL.getTypePtr();
4597
4598 // Note that this works with the pointee-as-written.
4599 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4600 if (PointeeType.isNull())
4601 return QualType();
4602
4603 QualType Result = TL.getType();
4604 if (getDerived().AlwaysRebuild() ||
4605 PointeeType != T->getPointeeTypeAsWritten()) {
4606 Result = getDerived().RebuildReferenceType(PointeeType,
4607 T->isSpelledAsLValue(),
4608 TL.getSigilLoc());
4609 if (Result.isNull())
4610 return QualType();
4611 }
4612
John McCall31168b02011-06-15 23:02:42 +00004613 // Objective-C ARC can add lifetime qualifiers to the type that we're
4614 // referring to.
4615 TLB.TypeWasModifiedSafely(
4616 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4617
John McCall70dd5f62009-10-30 00:06:24 +00004618 // r-value references can be rebuilt as l-value references.
4619 ReferenceTypeLoc NewTL;
4620 if (isa<LValueReferenceType>(Result))
4621 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4622 else
4623 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4624 NewTL.setSigilLoc(TL.getSigilLoc());
4625
4626 return Result;
4627}
4628
Mike Stump11289f42009-09-09 15:08:12 +00004629template<typename Derived>
4630QualType
John McCall550e0c22009-10-21 00:40:46 +00004631TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004632 LValueReferenceTypeLoc TL) {
4633 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634}
4635
Mike Stump11289f42009-09-09 15:08:12 +00004636template<typename Derived>
4637QualType
John McCall550e0c22009-10-21 00:40:46 +00004638TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004639 RValueReferenceTypeLoc TL) {
4640 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004641}
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregord6ff3322009-08-04 16:50:30 +00004643template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004644QualType
John McCall550e0c22009-10-21 00:40:46 +00004645TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004646 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004647 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004648 if (PointeeType.isNull())
4649 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004650
Abramo Bagnara509357842011-03-05 14:42:21 +00004651 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004652 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004653 if (OldClsTInfo) {
4654 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4655 if (!NewClsTInfo)
4656 return QualType();
4657 }
4658
4659 const MemberPointerType *T = TL.getTypePtr();
4660 QualType OldClsType = QualType(T->getClass(), 0);
4661 QualType NewClsType;
4662 if (NewClsTInfo)
4663 NewClsType = NewClsTInfo->getType();
4664 else {
4665 NewClsType = getDerived().TransformType(OldClsType);
4666 if (NewClsType.isNull())
4667 return QualType();
4668 }
Mike Stump11289f42009-09-09 15:08:12 +00004669
John McCall550e0c22009-10-21 00:40:46 +00004670 QualType Result = TL.getType();
4671 if (getDerived().AlwaysRebuild() ||
4672 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004673 NewClsType != OldClsType) {
4674 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004675 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004676 if (Result.isNull())
4677 return QualType();
4678 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004679
Reid Kleckner0503a872013-12-05 01:23:43 +00004680 // If we had to adjust the pointee type when building a member pointer, make
4681 // sure to push TypeLoc info for it.
4682 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4683 if (MPT && PointeeType != MPT->getPointeeType()) {
4684 assert(isa<AdjustedType>(MPT->getPointeeType()));
4685 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4686 }
4687
John McCall550e0c22009-10-21 00:40:46 +00004688 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4689 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004690 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004691
4692 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004693}
4694
Mike Stump11289f42009-09-09 15:08:12 +00004695template<typename Derived>
4696QualType
John McCall550e0c22009-10-21 00:40:46 +00004697TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004698 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004699 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004701 if (ElementType.isNull())
4702 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004703
John McCall550e0c22009-10-21 00:40:46 +00004704 QualType Result = TL.getType();
4705 if (getDerived().AlwaysRebuild() ||
4706 ElementType != T->getElementType()) {
4707 Result = getDerived().RebuildConstantArrayType(ElementType,
4708 T->getSizeModifier(),
4709 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004710 T->getIndexTypeCVRQualifiers(),
4711 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004712 if (Result.isNull())
4713 return QualType();
4714 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004715
4716 // We might have either a ConstantArrayType or a VariableArrayType now:
4717 // a ConstantArrayType is allowed to have an element type which is a
4718 // VariableArrayType if the type is dependent. Fortunately, all array
4719 // types have the same location layout.
4720 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004721 NewTL.setLBracketLoc(TL.getLBracketLoc());
4722 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004723
John McCall550e0c22009-10-21 00:40:46 +00004724 Expr *Size = TL.getSizeExpr();
4725 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004726 EnterExpressionEvaluationContext Unevaluated(
4727 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004728 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4729 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004730 }
4731 NewTL.setSizeExpr(Size);
4732
4733 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004734}
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregord6ff3322009-08-04 16:50:30 +00004736template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004737QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004738 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004739 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004740 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004741 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004742 if (ElementType.isNull())
4743 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004744
John McCall550e0c22009-10-21 00:40:46 +00004745 QualType Result = TL.getType();
4746 if (getDerived().AlwaysRebuild() ||
4747 ElementType != T->getElementType()) {
4748 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004749 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004750 T->getIndexTypeCVRQualifiers(),
4751 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004752 if (Result.isNull())
4753 return QualType();
4754 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004755
John McCall550e0c22009-10-21 00:40:46 +00004756 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4757 NewTL.setLBracketLoc(TL.getLBracketLoc());
4758 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004759 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004760
4761 return Result;
4762}
4763
4764template<typename Derived>
4765QualType
4766TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004767 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004768 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004769 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4770 if (ElementType.isNull())
4771 return QualType();
4772
Tim Shenb34d0ef2017-02-14 23:46:37 +00004773 ExprResult SizeResult;
4774 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004775 EnterExpressionEvaluationContext Context(
4776 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004777 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4778 }
4779 if (SizeResult.isInvalid())
4780 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004781 SizeResult =
4782 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004783 if (SizeResult.isInvalid())
4784 return QualType();
4785
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004786 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004787
4788 QualType Result = TL.getType();
4789 if (getDerived().AlwaysRebuild() ||
4790 ElementType != T->getElementType() ||
4791 Size != T->getSizeExpr()) {
4792 Result = getDerived().RebuildVariableArrayType(ElementType,
4793 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004794 Size,
John McCall550e0c22009-10-21 00:40:46 +00004795 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004796 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004797 if (Result.isNull())
4798 return QualType();
4799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004800
Serge Pavlov774c6d02014-02-06 03:49:11 +00004801 // We might have constant size array now, but fortunately it has the same
4802 // location layout.
4803 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004804 NewTL.setLBracketLoc(TL.getLBracketLoc());
4805 NewTL.setRBracketLoc(TL.getRBracketLoc());
4806 NewTL.setSizeExpr(Size);
4807
4808 return Result;
4809}
4810
4811template<typename Derived>
4812QualType
4813TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004814 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004815 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004816 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4817 if (ElementType.isNull())
4818 return QualType();
4819
Richard Smith764d2fe2011-12-20 02:08:33 +00004820 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004821 EnterExpressionEvaluationContext Unevaluated(
4822 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004823
John McCall33ddac02011-01-19 10:06:00 +00004824 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4825 Expr *origSize = TL.getSizeExpr();
4826 if (!origSize) origSize = T->getSizeExpr();
4827
4828 ExprResult sizeResult
4829 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004830 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004831 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004832 return QualType();
4833
John McCall33ddac02011-01-19 10:06:00 +00004834 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004835
4836 QualType Result = TL.getType();
4837 if (getDerived().AlwaysRebuild() ||
4838 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004839 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004840 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4841 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004842 size,
John McCall550e0c22009-10-21 00:40:46 +00004843 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004844 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004845 if (Result.isNull())
4846 return QualType();
4847 }
John McCall550e0c22009-10-21 00:40:46 +00004848
4849 // We might have any sort of array type now, but fortunately they
4850 // all have the same location layout.
4851 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4852 NewTL.setLBracketLoc(TL.getLBracketLoc());
4853 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004854 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004855
4856 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004857}
Mike Stump11289f42009-09-09 15:08:12 +00004858
Erich Keanef702b022018-07-13 19:46:04 +00004859template <typename Derived>
4860QualType TreeTransform<Derived>::TransformDependentVectorType(
4861 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4862 const DependentVectorType *T = TL.getTypePtr();
4863 QualType ElementType = getDerived().TransformType(T->getElementType());
4864 if (ElementType.isNull())
4865 return QualType();
4866
4867 EnterExpressionEvaluationContext Unevaluated(
4868 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4869
4870 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4871 Size = SemaRef.ActOnConstantExpression(Size);
4872 if (Size.isInvalid())
4873 return QualType();
4874
4875 QualType Result = TL.getType();
4876 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4877 Size.get() != T->getSizeExpr()) {
4878 Result = getDerived().RebuildDependentVectorType(
4879 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4880 if (Result.isNull())
4881 return QualType();
4882 }
4883
4884 // Result might be dependent or not.
4885 if (isa<DependentVectorType>(Result)) {
4886 DependentVectorTypeLoc NewTL =
4887 TLB.push<DependentVectorTypeLoc>(Result);
4888 NewTL.setNameLoc(TL.getNameLoc());
4889 } else {
4890 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4891 NewTL.setNameLoc(TL.getNameLoc());
4892 }
4893
4894 return Result;
4895}
4896
Mike Stump11289f42009-09-09 15:08:12 +00004897template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004898QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004899 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004900 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004901 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004902
4903 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004904 QualType ElementType = getDerived().TransformType(T->getElementType());
4905 if (ElementType.isNull())
4906 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004907
Richard Smith764d2fe2011-12-20 02:08:33 +00004908 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004909 EnterExpressionEvaluationContext Unevaluated(
4910 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004911
John McCalldadc5752010-08-24 06:29:42 +00004912 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004913 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004914 if (Size.isInvalid())
4915 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004916
John McCall550e0c22009-10-21 00:40:46 +00004917 QualType Result = TL.getType();
4918 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004919 ElementType != T->getElementType() ||
4920 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004921 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004922 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004923 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004924 if (Result.isNull())
4925 return QualType();
4926 }
John McCall550e0c22009-10-21 00:40:46 +00004927
4928 // Result might be dependent or not.
4929 if (isa<DependentSizedExtVectorType>(Result)) {
4930 DependentSizedExtVectorTypeLoc NewTL
4931 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4932 NewTL.setNameLoc(TL.getNameLoc());
4933 } else {
4934 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4935 NewTL.setNameLoc(TL.getNameLoc());
4936 }
4937
4938 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004939}
Mike Stump11289f42009-09-09 15:08:12 +00004940
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004941template <typename Derived>
4942QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4943 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4944 const DependentAddressSpaceType *T = TL.getTypePtr();
4945
4946 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4947
4948 if (pointeeType.isNull())
4949 return QualType();
4950
4951 // Address spaces are constant expressions.
4952 EnterExpressionEvaluationContext Unevaluated(
4953 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4954
4955 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4956 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4957 if (AddrSpace.isInvalid())
4958 return QualType();
4959
4960 QualType Result = TL.getType();
4961 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4962 AddrSpace.get() != T->getAddrSpaceExpr()) {
4963 Result = getDerived().RebuildDependentAddressSpaceType(
4964 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4965 if (Result.isNull())
4966 return QualType();
4967 }
4968
4969 // Result might be dependent or not.
4970 if (isa<DependentAddressSpaceType>(Result)) {
4971 DependentAddressSpaceTypeLoc NewTL =
4972 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4973
4974 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4975 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4976 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4977
4978 } else {
4979 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4980 Result, getDerived().getBaseLocation());
4981 TransformType(TLB, DI->getTypeLoc());
4982 }
4983
4984 return Result;
4985}
4986
4987template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004988QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004989 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004990 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004991 QualType ElementType = getDerived().TransformType(T->getElementType());
4992 if (ElementType.isNull())
4993 return QualType();
4994
John McCall550e0c22009-10-21 00:40:46 +00004995 QualType Result = TL.getType();
4996 if (getDerived().AlwaysRebuild() ||
4997 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004998 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004999 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00005000 if (Result.isNull())
5001 return QualType();
5002 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005003
John McCall550e0c22009-10-21 00:40:46 +00005004 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5005 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005006
John McCall550e0c22009-10-21 00:40:46 +00005007 return Result;
5008}
5009
5010template<typename Derived>
5011QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005012 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005013 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005014 QualType ElementType = getDerived().TransformType(T->getElementType());
5015 if (ElementType.isNull())
5016 return QualType();
5017
5018 QualType Result = TL.getType();
5019 if (getDerived().AlwaysRebuild() ||
5020 ElementType != T->getElementType()) {
5021 Result = getDerived().RebuildExtVectorType(ElementType,
5022 T->getNumElements(),
5023 /*FIXME*/ SourceLocation());
5024 if (Result.isNull())
5025 return QualType();
5026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005027
John McCall550e0c22009-10-21 00:40:46 +00005028 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5029 NewTL.setNameLoc(TL.getNameLoc());
5030
5031 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005032}
Mike Stump11289f42009-09-09 15:08:12 +00005033
David Blaikie05785d12013-02-20 22:23:23 +00005034template <typename Derived>
5035ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
5036 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5037 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00005038 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00005039 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005040
Douglas Gregor715e4612011-01-14 22:40:04 +00005041 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005042 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005043 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00005044 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005045 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00005046
Douglas Gregor715e4612011-01-14 22:40:04 +00005047 TypeLocBuilder TLB;
5048 TypeLoc NewTL = OldDI->getTypeLoc();
5049 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005050
5051 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005052 OldExpansionTL.getPatternLoc());
5053 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005054 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005055
5056 Result = RebuildPackExpansionType(Result,
5057 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005058 OldExpansionTL.getEllipsisLoc(),
5059 NumExpansions);
5060 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005061 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005062
Douglas Gregor715e4612011-01-14 22:40:04 +00005063 PackExpansionTypeLoc NewExpansionTL
5064 = TLB.push<PackExpansionTypeLoc>(Result);
5065 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5066 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5067 } else
5068 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005069 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005070 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005071
John McCall8fb0d9d2011-05-01 22:35:37 +00005072 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005073 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005074
5075 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5076 OldParm->getDeclContext(),
5077 OldParm->getInnerLocStart(),
5078 OldParm->getLocation(),
5079 OldParm->getIdentifier(),
5080 NewDI->getType(),
5081 NewDI,
5082 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005083 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005084 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5085 OldParm->getFunctionScopeIndex() + indexAdjustment);
5086 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005087}
5088
David Majnemer59f77922016-06-24 04:05:48 +00005089template <typename Derived>
5090bool TreeTransform<Derived>::TransformFunctionTypeParams(
5091 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5092 const QualType *ParamTypes,
5093 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5094 SmallVectorImpl<QualType> &OutParamTypes,
5095 SmallVectorImpl<ParmVarDecl *> *PVars,
5096 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005097 int indexAdjustment = 0;
5098
David Majnemer59f77922016-06-24 04:05:48 +00005099 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005100 for (unsigned i = 0; i != NumParams; ++i) {
5101 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005102 assert(OldParm->getFunctionScopeIndex() == i);
5103
David Blaikie05785d12013-02-20 22:23:23 +00005104 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005105 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005106 if (OldParm->isParameterPack()) {
5107 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005108 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005109
Douglas Gregor5499af42011-01-05 23:12:31 +00005110 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005111 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005112 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005113 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5114 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005115 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5116
Douglas Gregor5499af42011-01-05 23:12:31 +00005117 // Determine whether we should expand the parameter packs.
5118 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005119 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005120 Optional<unsigned> OrigNumExpansions =
5121 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005122 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005123 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5124 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005125 Unexpanded,
5126 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005127 RetainExpansion,
5128 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005129 return true;
5130 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005131
Douglas Gregor5499af42011-01-05 23:12:31 +00005132 if (ShouldExpand) {
5133 // Expand the function parameter pack into multiple, separate
5134 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005135 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005136 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005137 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005138 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005139 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005140 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005141 OrigNumExpansions,
5142 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005143 if (!NewParm)
5144 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005145
John McCallc8e321d2016-03-01 02:09:25 +00005146 if (ParamInfos)
5147 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005148 OutParamTypes.push_back(NewParm->getType());
5149 if (PVars)
5150 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005151 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005152
5153 // If we're supposed to retain a pack expansion, do so by temporarily
5154 // forgetting the partially-substituted parameter pack.
5155 if (RetainExpansion) {
5156 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005157 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005158 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005159 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005160 OrigNumExpansions,
5161 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005162 if (!NewParm)
5163 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005164
John McCallc8e321d2016-03-01 02:09:25 +00005165 if (ParamInfos)
5166 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005167 OutParamTypes.push_back(NewParm->getType());
5168 if (PVars)
5169 PVars->push_back(NewParm);
5170 }
5171
John McCall8fb0d9d2011-05-01 22:35:37 +00005172 // The next parameter should have the same adjustment as the
5173 // last thing we pushed, but we post-incremented indexAdjustment
5174 // on every push. Also, if we push nothing, the adjustment should
5175 // go down by one.
5176 indexAdjustment--;
5177
Douglas Gregor5499af42011-01-05 23:12:31 +00005178 // We're done with the pack expansion.
5179 continue;
5180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005181
5182 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005183 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005184 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5185 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005186 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005187 NumExpansions,
5188 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005189 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005190 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005191 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005192 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005193
John McCall58f10c32010-03-11 09:03:00 +00005194 if (!NewParm)
5195 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005196
John McCallc8e321d2016-03-01 02:09:25 +00005197 if (ParamInfos)
5198 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005199 OutParamTypes.push_back(NewParm->getType());
5200 if (PVars)
5201 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005202 continue;
5203 }
John McCall58f10c32010-03-11 09:03:00 +00005204
5205 // Deal with the possibility that we don't have a parameter
5206 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005207 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005208 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005209 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005210 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005211 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005212 = dyn_cast<PackExpansionType>(OldType)) {
5213 // We have a function parameter pack that may need to be expanded.
5214 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005215 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005216 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005217
Douglas Gregor5499af42011-01-05 23:12:31 +00005218 // Determine whether we should expand the parameter packs.
5219 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005220 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005221 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005222 Unexpanded,
5223 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005224 RetainExpansion,
5225 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005226 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005227 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005228
Douglas Gregor5499af42011-01-05 23:12:31 +00005229 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005230 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005231 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005232 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005233 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5234 QualType NewType = getDerived().TransformType(Pattern);
5235 if (NewType.isNull())
5236 return true;
John McCall58f10c32010-03-11 09:03:00 +00005237
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005238 if (NewType->containsUnexpandedParameterPack()) {
5239 NewType =
5240 getSema().getASTContext().getPackExpansionType(NewType, None);
5241
5242 if (NewType.isNull())
5243 return true;
5244 }
5245
John McCallc8e321d2016-03-01 02:09:25 +00005246 if (ParamInfos)
5247 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005248 OutParamTypes.push_back(NewType);
5249 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005250 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005252
Douglas Gregor5499af42011-01-05 23:12:31 +00005253 // We're done with the pack expansion.
5254 continue;
5255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregor48d24112011-01-10 20:53:55 +00005257 // If we're supposed to retain a pack expansion, do so by temporarily
5258 // forgetting the partially-substituted parameter pack.
5259 if (RetainExpansion) {
5260 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5261 QualType NewType = getDerived().TransformType(Pattern);
5262 if (NewType.isNull())
5263 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
John McCallc8e321d2016-03-01 02:09:25 +00005265 if (ParamInfos)
5266 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005267 OutParamTypes.push_back(NewType);
5268 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005269 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005270 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005271
Chad Rosier1dcde962012-08-08 18:46:20 +00005272 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005273 // expansion.
5274 OldType = Expansion->getPattern();
5275 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005276 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5277 NewType = getDerived().TransformType(OldType);
5278 } else {
5279 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005281
Douglas Gregor5499af42011-01-05 23:12:31 +00005282 if (NewType.isNull())
5283 return true;
5284
5285 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005286 NewType = getSema().Context.getPackExpansionType(NewType,
5287 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005288
John McCallc8e321d2016-03-01 02:09:25 +00005289 if (ParamInfos)
5290 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005291 OutParamTypes.push_back(NewType);
5292 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005293 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005294 }
5295
John McCall8fb0d9d2011-05-01 22:35:37 +00005296#ifndef NDEBUG
5297 if (PVars) {
5298 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5299 if (ParmVarDecl *parm = (*PVars)[i])
5300 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005301 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005302#endif
5303
5304 return false;
5305}
John McCall58f10c32010-03-11 09:03:00 +00005306
5307template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005308QualType
John McCall550e0c22009-10-21 00:40:46 +00005309TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005310 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005311 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005312 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005313 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005314 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005315 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5316 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5317 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005318 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005319}
5320
Richard Smith2e321552014-11-12 02:00:47 +00005321template<typename Derived> template<typename Fn>
5322QualType TreeTransform<Derived>::TransformFunctionProtoType(
5323 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005324 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005325
Douglas Gregor4afc2362010-08-31 00:26:14 +00005326 // Transform the parameters and return type.
5327 //
Richard Smithf623c962012-04-17 00:58:00 +00005328 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005329 // When the function has a trailing return type, we instantiate the
5330 // parameters before the return type, since the return type can then refer
5331 // to the parameters themselves (via decltype, sizeof, etc.).
5332 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005333 SmallVector<QualType, 4> ParamTypes;
5334 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005335 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005336 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005337
Douglas Gregor7fb25412010-10-01 18:44:50 +00005338 QualType ResultType;
5339
Richard Smith1226c602012-08-14 22:51:13 +00005340 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005341 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005342 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005343 TL.getTypePtr()->param_type_begin(),
5344 T->getExtParameterInfosOrNull(),
5345 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005346 return QualType();
5347
Douglas Gregor3024f072012-04-16 07:05:22 +00005348 {
5349 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005350 // If a declaration declares a member function or member function
5351 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005352 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005353 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005354 // declarator.
5355 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005356
Alp Toker42a16a62014-01-25 23:51:36 +00005357 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005358 if (ResultType.isNull())
5359 return QualType();
5360 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005361 }
5362 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005363 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005364 if (ResultType.isNull())
5365 return QualType();
5366
Anastasia Stulova6a4c3462018-11-29 14:11:15 +00005367 // Return type can not be qualified with an address space.
5368 if (ResultType.getAddressSpace() != LangAS::Default) {
5369 SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5370 diag::err_attribute_address_function_type);
5371 return QualType();
5372 }
5373
Alp Toker9cacbab2014-01-20 20:26:09 +00005374 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005375 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005376 TL.getTypePtr()->param_type_begin(),
5377 T->getExtParameterInfosOrNull(),
5378 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005379 return QualType();
5380 }
5381
Richard Smith2e321552014-11-12 02:00:47 +00005382 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5383
5384 bool EPIChanged = false;
5385 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5386 return QualType();
5387
John McCallc8e321d2016-03-01 02:09:25 +00005388 // Handle extended parameter information.
5389 if (auto NewExtParamInfos =
5390 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5391 if (!EPI.ExtParameterInfos ||
5392 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5393 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5394 EPIChanged = true;
5395 }
5396 EPI.ExtParameterInfos = NewExtParamInfos;
5397 } else if (EPI.ExtParameterInfos) {
5398 EPIChanged = true;
5399 EPI.ExtParameterInfos = nullptr;
5400 }
Richard Smithf623c962012-04-17 00:58:00 +00005401
John McCall550e0c22009-10-21 00:40:46 +00005402 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005403 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005404 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005405 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005406 if (Result.isNull())
5407 return QualType();
5408 }
Mike Stump11289f42009-09-09 15:08:12 +00005409
John McCall550e0c22009-10-21 00:40:46 +00005410 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005411 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005412 NewTL.setLParenLoc(TL.getLParenLoc());
5413 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005414 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005415 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005416 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5417 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005418
5419 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005420}
Mike Stump11289f42009-09-09 15:08:12 +00005421
Douglas Gregord6ff3322009-08-04 16:50:30 +00005422template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005423bool TreeTransform<Derived>::TransformExceptionSpec(
5424 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5425 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5426 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5427
5428 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005429 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005430 EnterExpressionEvaluationContext Unevaluated(
5431 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005432 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5433 if (NoexceptExpr.isInvalid())
5434 return true;
5435
Richard Smitheaf11ad2018-05-03 03:58:32 +00005436 ExceptionSpecificationType EST = ESI.Type;
5437 NoexceptExpr =
5438 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005439 if (NoexceptExpr.isInvalid())
5440 return true;
5441
Richard Smitheaf11ad2018-05-03 03:58:32 +00005442 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005443 Changed = true;
5444 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005445 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005446 }
5447
5448 if (ESI.Type != EST_Dynamic)
5449 return false;
5450
5451 // Instantiate a dynamic exception specification's type.
5452 for (QualType T : ESI.Exceptions) {
5453 if (const PackExpansionType *PackExpansion =
5454 T->getAs<PackExpansionType>()) {
5455 Changed = true;
5456
5457 // We have a pack expansion. Instantiate it.
5458 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5459 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5460 Unexpanded);
5461 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5462
5463 // Determine whether the set of unexpanded parameter packs can and
5464 // should
5465 // be expanded.
5466 bool Expand = false;
5467 bool RetainExpansion = false;
5468 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5469 // FIXME: Track the location of the ellipsis (and track source location
5470 // information for the types in the exception specification in general).
5471 if (getDerived().TryExpandParameterPacks(
5472 Loc, SourceRange(), Unexpanded, Expand,
5473 RetainExpansion, NumExpansions))
5474 return true;
5475
5476 if (!Expand) {
5477 // We can't expand this pack expansion into separate arguments yet;
5478 // just substitute into the pattern and create a new pack expansion
5479 // type.
5480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5481 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5482 if (U.isNull())
5483 return true;
5484
5485 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5486 Exceptions.push_back(U);
5487 continue;
5488 }
5489
5490 // Substitute into the pack expansion pattern for each slice of the
5491 // pack.
5492 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5493 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5494
5495 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5496 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5497 return true;
5498
5499 Exceptions.push_back(U);
5500 }
5501 } else {
5502 QualType U = getDerived().TransformType(T);
5503 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5504 return true;
5505 if (T != U)
5506 Changed = true;
5507
5508 Exceptions.push_back(U);
5509 }
5510 }
5511
5512 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005513 if (ESI.Exceptions.empty())
5514 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005515 return false;
5516}
5517
5518template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005519QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005520 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005521 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005522 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005523 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005524 if (ResultType.isNull())
5525 return QualType();
5526
5527 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005528 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005529 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5530
5531 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005532 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005533 NewTL.setLParenLoc(TL.getLParenLoc());
5534 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005535 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005536
5537 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005538}
Mike Stump11289f42009-09-09 15:08:12 +00005539
John McCallb96ec562009-12-04 22:46:56 +00005540template<typename Derived> QualType
5541TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005542 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005543 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005544 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005545 if (!D)
5546 return QualType();
5547
5548 QualType Result = TL.getType();
5549 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005550 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005551 if (Result.isNull())
5552 return QualType();
5553 }
5554
5555 // We might get an arbitrary type spec type back. We should at
5556 // least always get a type spec type, though.
5557 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5558 NewTL.setNameLoc(TL.getNameLoc());
5559
5560 return Result;
5561}
5562
Douglas Gregord6ff3322009-08-04 16:50:30 +00005563template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005564QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005565 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005566 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005567 TypedefNameDecl *Typedef
5568 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5569 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570 if (!Typedef)
5571 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005572
John McCall550e0c22009-10-21 00:40:46 +00005573 QualType Result = TL.getType();
5574 if (getDerived().AlwaysRebuild() ||
5575 Typedef != T->getDecl()) {
5576 Result = getDerived().RebuildTypedefType(Typedef);
5577 if (Result.isNull())
5578 return QualType();
5579 }
Mike Stump11289f42009-09-09 15:08:12 +00005580
John McCall550e0c22009-10-21 00:40:46 +00005581 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5582 NewTL.setNameLoc(TL.getNameLoc());
5583
5584 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005585}
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregord6ff3322009-08-04 16:50:30 +00005587template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005588QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005589 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005590 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005591 EnterExpressionEvaluationContext Unevaluated(
5592 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5593 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005594
John McCalldadc5752010-08-24 06:29:42 +00005595 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005596 if (E.isInvalid())
5597 return QualType();
5598
Eli Friedmane4f22df2012-02-29 04:03:55 +00005599 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5600 if (E.isInvalid())
5601 return QualType();
5602
John McCall550e0c22009-10-21 00:40:46 +00005603 QualType Result = TL.getType();
5604 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005605 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005606 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005607 if (Result.isNull())
5608 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005609 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005610 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005611
John McCall550e0c22009-10-21 00:40:46 +00005612 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005613 NewTL.setTypeofLoc(TL.getTypeofLoc());
5614 NewTL.setLParenLoc(TL.getLParenLoc());
5615 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005616
5617 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618}
Mike Stump11289f42009-09-09 15:08:12 +00005619
5620template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005621QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005622 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005623 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5624 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5625 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005626 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005627
John McCall550e0c22009-10-21 00:40:46 +00005628 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005629 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5630 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005631 if (Result.isNull())
5632 return QualType();
5633 }
Mike Stump11289f42009-09-09 15:08:12 +00005634
John McCall550e0c22009-10-21 00:40:46 +00005635 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005636 NewTL.setTypeofLoc(TL.getTypeofLoc());
5637 NewTL.setLParenLoc(TL.getLParenLoc());
5638 NewTL.setRParenLoc(TL.getRParenLoc());
5639 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005640
5641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005642}
Mike Stump11289f42009-09-09 15:08:12 +00005643
5644template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005645QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005646 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005647 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005648
Douglas Gregore922c772009-08-04 22:27:00 +00005649 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005650 EnterExpressionEvaluationContext Unevaluated(
5651 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005652 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005653
John McCalldadc5752010-08-24 06:29:42 +00005654 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005655 if (E.isInvalid())
5656 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005657
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005658 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005659 if (E.isInvalid())
5660 return QualType();
5661
John McCall550e0c22009-10-21 00:40:46 +00005662 QualType Result = TL.getType();
5663 if (getDerived().AlwaysRebuild() ||
5664 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005665 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005666 if (Result.isNull())
5667 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005668 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005669 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005670
John McCall550e0c22009-10-21 00:40:46 +00005671 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5672 NewTL.setNameLoc(TL.getNameLoc());
5673
5674 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005675}
5676
5677template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005678QualType TreeTransform<Derived>::TransformUnaryTransformType(
5679 TypeLocBuilder &TLB,
5680 UnaryTransformTypeLoc TL) {
5681 QualType Result = TL.getType();
5682 if (Result->isDependentType()) {
5683 const UnaryTransformType *T = TL.getTypePtr();
5684 QualType NewBase =
5685 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5686 Result = getDerived().RebuildUnaryTransformType(NewBase,
5687 T->getUTTKind(),
5688 TL.getKWLoc());
5689 if (Result.isNull())
5690 return QualType();
5691 }
5692
5693 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5694 NewTL.setKWLoc(TL.getKWLoc());
5695 NewTL.setParensRange(TL.getParensRange());
5696 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5697 return Result;
5698}
5699
5700template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005701QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5702 AutoTypeLoc TL) {
5703 const AutoType *T = TL.getTypePtr();
5704 QualType OldDeduced = T->getDeducedType();
5705 QualType NewDeduced;
5706 if (!OldDeduced.isNull()) {
5707 NewDeduced = getDerived().TransformType(OldDeduced);
5708 if (NewDeduced.isNull())
5709 return QualType();
5710 }
5711
5712 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005713 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5714 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005715 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005716 if (Result.isNull())
5717 return QualType();
5718 }
5719
5720 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5721 NewTL.setNameLoc(TL.getNameLoc());
5722
5723 return Result;
5724}
5725
5726template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005727QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5728 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5729 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5730
5731 CXXScopeSpec SS;
5732 TemplateName TemplateName = getDerived().TransformTemplateName(
5733 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5734 if (TemplateName.isNull())
5735 return QualType();
5736
5737 QualType OldDeduced = T->getDeducedType();
5738 QualType NewDeduced;
5739 if (!OldDeduced.isNull()) {
5740 NewDeduced = getDerived().TransformType(OldDeduced);
5741 if (NewDeduced.isNull())
5742 return QualType();
5743 }
5744
5745 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5746 TemplateName, NewDeduced);
5747 if (Result.isNull())
5748 return QualType();
5749
5750 DeducedTemplateSpecializationTypeLoc NewTL =
5751 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5752 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5753
5754 return Result;
5755}
5756
5757template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005758QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005759 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005760 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005761 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005762 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5763 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005764 if (!Record)
5765 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005766
John McCall550e0c22009-10-21 00:40:46 +00005767 QualType Result = TL.getType();
5768 if (getDerived().AlwaysRebuild() ||
5769 Record != T->getDecl()) {
5770 Result = getDerived().RebuildRecordType(Record);
5771 if (Result.isNull())
5772 return QualType();
5773 }
Mike Stump11289f42009-09-09 15:08:12 +00005774
John McCall550e0c22009-10-21 00:40:46 +00005775 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5776 NewTL.setNameLoc(TL.getNameLoc());
5777
5778 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005779}
Mike Stump11289f42009-09-09 15:08:12 +00005780
5781template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005782QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005783 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005784 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005785 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005786 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5787 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005788 if (!Enum)
5789 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005790
John McCall550e0c22009-10-21 00:40:46 +00005791 QualType Result = TL.getType();
5792 if (getDerived().AlwaysRebuild() ||
5793 Enum != T->getDecl()) {
5794 Result = getDerived().RebuildEnumType(Enum);
5795 if (Result.isNull())
5796 return QualType();
5797 }
Mike Stump11289f42009-09-09 15:08:12 +00005798
John McCall550e0c22009-10-21 00:40:46 +00005799 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5800 NewTL.setNameLoc(TL.getNameLoc());
5801
5802 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005803}
John McCallfcc33b02009-09-05 00:15:47 +00005804
John McCalle78aac42010-03-10 03:28:59 +00005805template<typename Derived>
5806QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5807 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005808 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005809 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5810 TL.getTypePtr()->getDecl());
5811 if (!D) return QualType();
5812
5813 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5814 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5815 return T;
5816}
5817
Douglas Gregord6ff3322009-08-04 16:50:30 +00005818template<typename Derived>
5819QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005820 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005821 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005822 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005823}
5824
Mike Stump11289f42009-09-09 15:08:12 +00005825template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005826QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005827 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005828 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005829 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005830
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005831 // Substitute into the replacement type, which itself might involve something
5832 // that needs to be transformed. This only tends to occur with default
5833 // template arguments of template template parameters.
5834 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5835 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5836 if (Replacement.isNull())
5837 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005838
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005839 // Always canonicalize the replacement type.
5840 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5841 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005842 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005843 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005845 // Propagate type-source information.
5846 SubstTemplateTypeParmTypeLoc NewTL
5847 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5848 NewTL.setNameLoc(TL.getNameLoc());
5849 return Result;
5850
John McCallcebee162009-10-18 09:09:24 +00005851}
5852
5853template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005854QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5855 TypeLocBuilder &TLB,
5856 SubstTemplateTypeParmPackTypeLoc TL) {
5857 return TransformTypeSpecType(TLB, TL);
5858}
5859
5860template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005861QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005862 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005863 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005864 const TemplateSpecializationType *T = TL.getTypePtr();
5865
Douglas Gregordf846d12011-03-02 18:46:51 +00005866 // The nested-name-specifier never matters in a TemplateSpecializationType,
5867 // because we can't have a dependent nested-name-specifier anyway.
5868 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005869 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005870 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5871 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005872 if (Template.isNull())
5873 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005874
John McCall31f82722010-11-12 08:19:04 +00005875 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5876}
5877
Eli Friedman0dfb8892011-10-06 23:00:33 +00005878template<typename Derived>
5879QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5880 AtomicTypeLoc TL) {
5881 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5882 if (ValueType.isNull())
5883 return QualType();
5884
5885 QualType Result = TL.getType();
5886 if (getDerived().AlwaysRebuild() ||
5887 ValueType != TL.getValueLoc().getType()) {
5888 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5889 if (Result.isNull())
5890 return QualType();
5891 }
5892
5893 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5894 NewTL.setKWLoc(TL.getKWLoc());
5895 NewTL.setLParenLoc(TL.getLParenLoc());
5896 NewTL.setRParenLoc(TL.getRParenLoc());
5897
5898 return Result;
5899}
5900
Xiuli Pan9c14e282016-01-09 12:53:17 +00005901template <typename Derived>
5902QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5903 PipeTypeLoc TL) {
5904 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5905 if (ValueType.isNull())
5906 return QualType();
5907
5908 QualType Result = TL.getType();
5909 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005910 const PipeType *PT = Result->getAs<PipeType>();
5911 bool isReadPipe = PT->isReadOnly();
5912 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005913 if (Result.isNull())
5914 return QualType();
5915 }
5916
5917 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5918 NewTL.setKWLoc(TL.getKWLoc());
5919
5920 return Result;
5921}
5922
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005923 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005924 /// container that provides a \c getArgLoc() member function.
5925 ///
5926 /// This iterator is intended to be used with the iterator form of
5927 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5928 template<typename ArgLocContainer>
5929 class TemplateArgumentLocContainerIterator {
5930 ArgLocContainer *Container;
5931 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005932
Douglas Gregorfe921a72010-12-20 23:36:19 +00005933 public:
5934 typedef TemplateArgumentLoc value_type;
5935 typedef TemplateArgumentLoc reference;
5936 typedef int difference_type;
5937 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
Douglas Gregorfe921a72010-12-20 23:36:19 +00005939 class pointer {
5940 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005941
Douglas Gregorfe921a72010-12-20 23:36:19 +00005942 public:
5943 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005944
Douglas Gregorfe921a72010-12-20 23:36:19 +00005945 const TemplateArgumentLoc *operator->() const {
5946 return &Arg;
5947 }
5948 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005949
5950
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005951 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005952
Douglas Gregorfe921a72010-12-20 23:36:19 +00005953 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5954 unsigned Index)
5955 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005956
Douglas Gregorfe921a72010-12-20 23:36:19 +00005957 TemplateArgumentLocContainerIterator &operator++() {
5958 ++Index;
5959 return *this;
5960 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005961
Douglas Gregorfe921a72010-12-20 23:36:19 +00005962 TemplateArgumentLocContainerIterator operator++(int) {
5963 TemplateArgumentLocContainerIterator Old(*this);
5964 ++(*this);
5965 return Old;
5966 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005967
Douglas Gregorfe921a72010-12-20 23:36:19 +00005968 TemplateArgumentLoc operator*() const {
5969 return Container->getArgLoc(Index);
5970 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005971
Douglas Gregorfe921a72010-12-20 23:36:19 +00005972 pointer operator->() const {
5973 return pointer(Container->getArgLoc(Index));
5974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005975
Douglas Gregorfe921a72010-12-20 23:36:19 +00005976 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005977 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005978 return X.Container == Y.Container && X.Index == Y.Index;
5979 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005980
Douglas Gregorfe921a72010-12-20 23:36:19 +00005981 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005982 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005983 return !(X == Y);
5984 }
5985 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005986
5987
John McCall31f82722010-11-12 08:19:04 +00005988template <typename Derived>
5989QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5990 TypeLocBuilder &TLB,
5991 TemplateSpecializationTypeLoc TL,
5992 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005993 TemplateArgumentListInfo NewTemplateArgs;
5994 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5995 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005996 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5997 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005998 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005999 ArgIterator(TL, TL.getNumArgs()),
6000 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00006001 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006002
John McCall0ad16662009-10-29 08:12:44 +00006003 // FIXME: maybe don't rebuild if all the template arguments are the same.
6004
6005 QualType Result =
6006 getDerived().RebuildTemplateSpecializationType(Template,
6007 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00006008 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00006009
6010 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00006011 // Specializations of template template parameters are represented as
6012 // TemplateSpecializationTypes, and substitution of type alias templates
6013 // within a dependent context can transform them into
6014 // DependentTemplateSpecializationTypes.
6015 if (isa<DependentTemplateSpecializationType>(Result)) {
6016 DependentTemplateSpecializationTypeLoc NewTL
6017 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006018 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006019 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006020 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006021 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006022 NewTL.setLAngleLoc(TL.getLAngleLoc());
6023 NewTL.setRAngleLoc(TL.getRAngleLoc());
6024 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6025 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6026 return Result;
6027 }
6028
John McCall0ad16662009-10-29 08:12:44 +00006029 TemplateSpecializationTypeLoc NewTL
6030 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006031 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00006032 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6033 NewTL.setLAngleLoc(TL.getLAngleLoc());
6034 NewTL.setRAngleLoc(TL.getRAngleLoc());
6035 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6036 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006037 }
Mike Stump11289f42009-09-09 15:08:12 +00006038
John McCall0ad16662009-10-29 08:12:44 +00006039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006040}
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregor5a064722011-02-28 17:23:35 +00006042template <typename Derived>
6043QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6044 TypeLocBuilder &TLB,
6045 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00006046 TemplateName Template,
6047 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006048 TemplateArgumentListInfo NewTemplateArgs;
6049 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6050 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6051 typedef TemplateArgumentLocContainerIterator<
6052 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006053 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006054 ArgIterator(TL, TL.getNumArgs()),
6055 NewTemplateArgs))
6056 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006057
Douglas Gregor5a064722011-02-28 17:23:35 +00006058 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006059
Douglas Gregor5a064722011-02-28 17:23:35 +00006060 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6061 QualType Result
6062 = getSema().Context.getDependentTemplateSpecializationType(
6063 TL.getTypePtr()->getKeyword(),
6064 DTN->getQualifier(),
6065 DTN->getIdentifier(),
6066 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006067
Douglas Gregor5a064722011-02-28 17:23:35 +00006068 DependentTemplateSpecializationTypeLoc NewTL
6069 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006070 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006071 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006072 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006073 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006074 NewTL.setLAngleLoc(TL.getLAngleLoc());
6075 NewTL.setRAngleLoc(TL.getRAngleLoc());
6076 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6077 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6078 return Result;
6079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006080
6081 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006082 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006083 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006084 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006085
Douglas Gregor5a064722011-02-28 17:23:35 +00006086 if (!Result.isNull()) {
6087 /// FIXME: Wrap this in an elaborated-type-specifier?
6088 TemplateSpecializationTypeLoc NewTL
6089 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006090 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006091 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006092 NewTL.setLAngleLoc(TL.getLAngleLoc());
6093 NewTL.setRAngleLoc(TL.getRAngleLoc());
6094 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6095 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6096 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006097
Douglas Gregor5a064722011-02-28 17:23:35 +00006098 return Result;
6099}
6100
Mike Stump11289f42009-09-09 15:08:12 +00006101template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006102QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006103TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006104 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006105 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006106
Douglas Gregor844cb502011-03-01 18:12:44 +00006107 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006108 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006109 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006110 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006111 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6112 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006113 return QualType();
6114 }
Mike Stump11289f42009-09-09 15:08:12 +00006115
John McCall31f82722010-11-12 08:19:04 +00006116 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6117 if (NamedT.isNull())
6118 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006119
Richard Smith3f1b5d02011-05-05 21:57:07 +00006120 // C++0x [dcl.type.elab]p2:
6121 // If the identifier resolves to a typedef-name or the simple-template-id
6122 // resolves to an alias template specialization, the
6123 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006124 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6125 if (const TemplateSpecializationType *TST =
6126 NamedT->getAs<TemplateSpecializationType>()) {
6127 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006128 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6129 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006130 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006131 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006132 << TAT << Sema::NTK_TypeAliasTemplate
6133 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006134 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6135 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006136 }
6137 }
6138
John McCall550e0c22009-10-21 00:40:46 +00006139 QualType Result = TL.getType();
6140 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006141 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006142 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006143 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006144 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006145 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006146 if (Result.isNull())
6147 return QualType();
6148 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006149
Abramo Bagnara6150c882010-05-11 21:36:43 +00006150 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006151 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006152 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006153 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006154}
Mike Stump11289f42009-09-09 15:08:12 +00006155
6156template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006157QualType TreeTransform<Derived>::TransformAttributedType(
6158 TypeLocBuilder &TLB,
6159 AttributedTypeLoc TL) {
6160 const AttributedType *oldType = TL.getTypePtr();
6161 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6162 if (modifiedType.isNull())
6163 return QualType();
6164
Richard Smithe43e2b32018-08-20 21:47:29 +00006165 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6166 const Attr *oldAttr = TL.getAttr();
6167 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6168 if (oldAttr && !newAttr)
6169 return QualType();
6170
John McCall81904512011-01-06 01:58:22 +00006171 QualType result = TL.getType();
6172
6173 // FIXME: dependent operand expressions?
6174 if (getDerived().AlwaysRebuild() ||
6175 modifiedType != oldType->getModifiedType()) {
6176 // TODO: this is really lame; we should really be rebuilding the
6177 // equivalent type from first principles.
6178 QualType equivalentType
6179 = getDerived().TransformType(oldType->getEquivalentType());
6180 if (equivalentType.isNull())
6181 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006182
6183 // Check whether we can add nullability; it is only represented as
6184 // type sugar, and therefore cannot be diagnosed in any other way.
6185 if (auto nullability = oldType->getImmediateNullability()) {
6186 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006187 SemaRef.Diag(TL.getAttr()->getLocation(),
6188 diag::err_nullability_nonpointer)
6189 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006190 return QualType();
6191 }
6192 }
6193
Richard Smithe43e2b32018-08-20 21:47:29 +00006194 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006195 modifiedType,
6196 equivalentType);
6197 }
6198
6199 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006200 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006201 return result;
6202}
6203
6204template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006205QualType
6206TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6207 ParenTypeLoc TL) {
6208 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6209 if (Inner.isNull())
6210 return QualType();
6211
6212 QualType Result = TL.getType();
6213 if (getDerived().AlwaysRebuild() ||
6214 Inner != TL.getInnerLoc().getType()) {
6215 Result = getDerived().RebuildParenType(Inner);
6216 if (Result.isNull())
6217 return QualType();
6218 }
6219
6220 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6221 NewTL.setLParenLoc(TL.getLParenLoc());
6222 NewTL.setRParenLoc(TL.getRParenLoc());
6223 return Result;
6224}
6225
Leonard Chanc72aaf62019-05-07 03:20:17 +00006226template <typename Derived>
6227QualType
6228TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6229 MacroQualifiedTypeLoc TL) {
6230 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6231 if (Inner.isNull())
6232 return QualType();
6233
6234 QualType Result = TL.getType();
6235 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6236 Result =
6237 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6238 if (Result.isNull())
6239 return QualType();
6240 }
6241
6242 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6243 NewTL.setExpansionLoc(TL.getExpansionLoc());
6244 return Result;
6245}
6246
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006247template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006248QualType TreeTransform<Derived>::TransformDependentNameType(
6249 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6250 return TransformDependentNameType(TLB, TL, false);
6251}
6252
6253template<typename Derived>
6254QualType TreeTransform<Derived>::TransformDependentNameType(
6255 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006256 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006257
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006258 NestedNameSpecifierLoc QualifierLoc
6259 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6260 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006262
John McCallc392f372010-06-11 00:33:02 +00006263 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006264 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006265 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006266 QualifierLoc,
6267 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006268 TL.getNameLoc(),
6269 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006270 if (Result.isNull())
6271 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006272
Abramo Bagnarad7548482010-05-19 21:37:53 +00006273 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6274 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006275 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6276
Abramo Bagnarad7548482010-05-19 21:37:53 +00006277 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006278 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006279 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006280 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006281 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006282 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006283 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006284 NewTL.setNameLoc(TL.getNameLoc());
6285 }
John McCall550e0c22009-10-21 00:40:46 +00006286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006287}
Mike Stump11289f42009-09-09 15:08:12 +00006288
Douglas Gregord6ff3322009-08-04 16:50:30 +00006289template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006290QualType TreeTransform<Derived>::
6291 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006292 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006293 NestedNameSpecifierLoc QualifierLoc;
6294 if (TL.getQualifierLoc()) {
6295 QualifierLoc
6296 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6297 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006298 return QualType();
6299 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006300
John McCall31f82722010-11-12 08:19:04 +00006301 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006302 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006303}
6304
6305template<typename Derived>
6306QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006307TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6308 DependentTemplateSpecializationTypeLoc TL,
6309 NestedNameSpecifierLoc QualifierLoc) {
6310 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006311
Douglas Gregora7a795b2011-03-01 20:11:18 +00006312 TemplateArgumentListInfo NewTemplateArgs;
6313 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6314 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006315
Douglas Gregora7a795b2011-03-01 20:11:18 +00006316 typedef TemplateArgumentLocContainerIterator<
6317 DependentTemplateSpecializationTypeLoc> ArgIterator;
6318 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6319 ArgIterator(TL, TL.getNumArgs()),
6320 NewTemplateArgs))
6321 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006322
Richard Smithfd3dae02017-01-20 00:20:39 +00006323 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006324 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6325 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006326 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006327 if (Result.isNull())
6328 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006329
Douglas Gregora7a795b2011-03-01 20:11:18 +00006330 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6331 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregora7a795b2011-03-01 20:11:18 +00006333 // Copy information relevant to the template specialization.
6334 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006335 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006336 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006337 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006338 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6339 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006340 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006341 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006342
Douglas Gregora7a795b2011-03-01 20:11:18 +00006343 // Copy information relevant to the elaborated type.
6344 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006345 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006346 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006347 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6348 DependentTemplateSpecializationTypeLoc SpecTL
6349 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006350 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006351 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006352 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006353 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006354 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6355 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006356 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006357 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006358 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006359 TemplateSpecializationTypeLoc SpecTL
6360 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006361 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006362 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006363 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6364 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006365 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006366 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006367 }
6368 return Result;
6369}
6370
6371template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006372QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6373 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006374 QualType Pattern
6375 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006376 if (Pattern.isNull())
6377 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006378
6379 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006380 if (getDerived().AlwaysRebuild() ||
6381 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006382 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006383 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006384 TL.getEllipsisLoc(),
6385 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006386 if (Result.isNull())
6387 return QualType();
6388 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006389
Douglas Gregor822d0302011-01-12 17:07:58 +00006390 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6391 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6392 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006393}
6394
6395template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006396QualType
6397TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006398 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006399 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006400 TLB.pushFullCopy(TL);
6401 return TL.getType();
6402}
6403
6404template<typename Derived>
6405QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006406TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6407 ObjCTypeParamTypeLoc TL) {
6408 const ObjCTypeParamType *T = TL.getTypePtr();
6409 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6410 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6411 if (!OTP)
6412 return QualType();
6413
6414 QualType Result = TL.getType();
6415 if (getDerived().AlwaysRebuild() ||
6416 OTP != T->getDecl()) {
6417 Result = getDerived().RebuildObjCTypeParamType(OTP,
6418 TL.getProtocolLAngleLoc(),
6419 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6420 TL.getNumProtocols()),
6421 TL.getProtocolLocs(),
6422 TL.getProtocolRAngleLoc());
6423 if (Result.isNull())
6424 return QualType();
6425 }
6426
6427 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6428 if (TL.getNumProtocols()) {
6429 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6430 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6431 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6432 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6433 }
6434 return Result;
6435}
6436
6437template<typename Derived>
6438QualType
John McCall8b07ec22010-05-15 11:32:37 +00006439TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006440 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006441 // Transform base type.
6442 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6443 if (BaseType.isNull())
6444 return QualType();
6445
6446 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6447
6448 // Transform type arguments.
6449 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6450 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6451 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6452 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6453 QualType TypeArg = TypeArgInfo->getType();
6454 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6455 AnyChanged = true;
6456
6457 // We have a pack expansion. Instantiate it.
6458 const auto *PackExpansion = PackExpansionLoc.getType()
6459 ->castAs<PackExpansionType>();
6460 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6461 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6462 Unexpanded);
6463 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6464
6465 // Determine whether the set of unexpanded parameter packs can
6466 // and should be expanded.
6467 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6468 bool Expand = false;
6469 bool RetainExpansion = false;
6470 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6471 if (getDerived().TryExpandParameterPacks(
6472 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6473 Unexpanded, Expand, RetainExpansion, NumExpansions))
6474 return QualType();
6475
6476 if (!Expand) {
6477 // We can't expand this pack expansion into separate arguments yet;
6478 // just substitute into the pattern and create a new pack expansion
6479 // type.
6480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6481
6482 TypeLocBuilder TypeArgBuilder;
6483 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006484 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006485 PatternLoc);
6486 if (NewPatternType.isNull())
6487 return QualType();
6488
6489 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6490 NewPatternType, NumExpansions);
6491 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6492 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6493 NewTypeArgInfos.push_back(
6494 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6495 continue;
6496 }
6497
6498 // Substitute into the pack expansion pattern for each slice of the
6499 // pack.
6500 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6502
6503 TypeLocBuilder TypeArgBuilder;
6504 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6505
6506 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6507 PatternLoc);
6508 if (NewTypeArg.isNull())
6509 return QualType();
6510
6511 NewTypeArgInfos.push_back(
6512 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6513 }
6514
6515 continue;
6516 }
6517
6518 TypeLocBuilder TypeArgBuilder;
6519 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6520 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6521 if (NewTypeArg.isNull())
6522 return QualType();
6523
6524 // If nothing changed, just keep the old TypeSourceInfo.
6525 if (NewTypeArg == TypeArg) {
6526 NewTypeArgInfos.push_back(TypeArgInfo);
6527 continue;
6528 }
6529
6530 NewTypeArgInfos.push_back(
6531 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6532 AnyChanged = true;
6533 }
6534
6535 QualType Result = TL.getType();
6536 if (getDerived().AlwaysRebuild() || AnyChanged) {
6537 // Rebuild the type.
6538 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006539 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6540 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6541 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6542 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006543
6544 if (Result.isNull())
6545 return QualType();
6546 }
6547
6548 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006549 NewT.setHasBaseTypeAsWritten(true);
6550 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6551 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6552 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6553 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6554 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6555 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6556 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6557 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6558 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006559}
Mike Stump11289f42009-09-09 15:08:12 +00006560
6561template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006562QualType
6563TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006564 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006565 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6566 if (PointeeType.isNull())
6567 return QualType();
6568
6569 QualType Result = TL.getType();
6570 if (getDerived().AlwaysRebuild() ||
6571 PointeeType != TL.getPointeeLoc().getType()) {
6572 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6573 TL.getStarLoc());
6574 if (Result.isNull())
6575 return QualType();
6576 }
6577
6578 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6579 NewT.setStarLoc(TL.getStarLoc());
6580 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006581}
6582
Douglas Gregord6ff3322009-08-04 16:50:30 +00006583//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006584// Statement transformation
6585//===----------------------------------------------------------------------===//
6586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006587StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006588TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006589 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006590}
6591
6592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006593StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006594TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6595 return getDerived().TransformCompoundStmt(S, false);
6596}
6597
6598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006599StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006600TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006601 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006602 Sema::CompoundScopeRAII CompoundScope(getSema());
6603
John McCall1ababa62010-08-27 19:56:05 +00006604 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006605 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006606 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006607 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006608 StmtResult Result = getDerived().TransformStmt(
6609 B,
6610 IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006611
John McCall1ababa62010-08-27 19:56:05 +00006612 if (Result.isInvalid()) {
6613 // Immediately fail if this was a DeclStmt, since it's very
6614 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006615 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006616 return StmtError();
6617
6618 // Otherwise, just keep processing substatements and fail later.
6619 SubStmtInvalid = true;
6620 continue;
6621 }
Mike Stump11289f42009-09-09 15:08:12 +00006622
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006623 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006624 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006625 }
Mike Stump11289f42009-09-09 15:08:12 +00006626
John McCall1ababa62010-08-27 19:56:05 +00006627 if (SubStmtInvalid)
6628 return StmtError();
6629
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 if (!getDerived().AlwaysRebuild() &&
6631 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006632 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006633
6634 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006635 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006636 S->getRBracLoc(),
6637 IsStmtExpr);
6638}
Mike Stump11289f42009-09-09 15:08:12 +00006639
Douglas Gregorebe10102009-08-20 07:17:43 +00006640template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006641StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006642TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006643 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006644 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006645 EnterExpressionEvaluationContext Unevaluated(
6646 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006647
Eli Friedman06577382009-11-19 03:14:00 +00006648 // Transform the left-hand case value.
6649 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006650 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006651 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006652 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006653
Eli Friedman06577382009-11-19 03:14:00 +00006654 // Transform the right-hand case value (for the GNU case-range extension).
6655 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006656 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006657 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006658 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregorebe10102009-08-20 07:17:43 +00006661 // Build the case statement.
6662 // Case statements are always rebuilt so that they will attached to their
6663 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006664 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006665 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006666 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006667 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006668 S->getColonLoc());
6669 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006670 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregorebe10102009-08-20 07:17:43 +00006672 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006673 StmtResult SubStmt =
6674 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006675 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregorebe10102009-08-20 07:17:43 +00006678 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006679 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006680}
6681
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006682template <typename Derived>
6683StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006684 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006685 StmtResult SubStmt =
6686 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006687 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006688 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 // Default statements are always rebuilt
6691 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006692 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006693}
Mike Stump11289f42009-09-09 15:08:12 +00006694
Douglas Gregorebe10102009-08-20 07:17:43 +00006695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006696StmtResult
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006697TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6698 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006699 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006700 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006701
Chris Lattnercab02a62011-02-17 20:34:02 +00006702 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6703 S->getDecl());
6704 if (!LD)
6705 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006706
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006707 // If we're transforming "in-place" (we're not creating new local
6708 // declarations), assume we're replacing the old label statement
6709 // and clear out the reference to it.
6710 if (LD == S->getDecl())
6711 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006712
Douglas Gregorebe10102009-08-20 07:17:43 +00006713 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006714 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006715 cast<LabelDecl>(LD), SourceLocation(),
6716 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006717}
Mike Stump11289f42009-09-09 15:08:12 +00006718
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006719template <typename Derived>
6720const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6721 if (!R)
6722 return R;
6723
6724 switch (R->getKind()) {
6725// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6726#define ATTR(X)
6727#define PRAGMA_SPELLING_ATTR(X) \
6728 case attr::X: \
6729 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6730#include "clang/Basic/AttrList.inc"
6731 default:
6732 return R;
6733 }
6734}
6735
6736template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006737StmtResult
6738TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6739 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006740 bool AttrsChanged = false;
6741 SmallVector<const Attr *, 1> Attrs;
6742
6743 // Visit attributes and keep track if any are transformed.
6744 for (const auto *I : S->getAttrs()) {
6745 const Attr *R = getDerived().TransformAttr(I);
6746 AttrsChanged |= (I != R);
6747 Attrs.push_back(R);
6748 }
6749
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006750 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006751 if (SubStmt.isInvalid())
6752 return StmtError();
6753
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006754 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006755 return S;
6756
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006757 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006758 SubStmt.get());
6759}
6760
6761template<typename Derived>
6762StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006763TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006764 // Transform the initialization statement
6765 StmtResult Init = getDerived().TransformStmt(S->getInit());
6766 if (Init.isInvalid())
6767 return StmtError();
6768
Douglas Gregorebe10102009-08-20 07:17:43 +00006769 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006770 Sema::ConditionResult Cond = getDerived().TransformCondition(
6771 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006772 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6773 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006774 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006775 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006776
Richard Smithb130fe72016-06-23 19:16:49 +00006777 // If this is a constexpr if, determine which arm we should instantiate.
6778 llvm::Optional<bool> ConstexprConditionValue;
6779 if (S->isConstexpr())
6780 ConstexprConditionValue = Cond.getKnownValue();
6781
Douglas Gregorebe10102009-08-20 07:17:43 +00006782 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006783 StmtResult Then;
6784 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6785 Then = getDerived().TransformStmt(S->getThen());
6786 if (Then.isInvalid())
6787 return StmtError();
6788 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006789 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006790 }
Mike Stump11289f42009-09-09 15:08:12 +00006791
Douglas Gregorebe10102009-08-20 07:17:43 +00006792 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006793 StmtResult Else;
6794 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6795 Else = getDerived().TransformStmt(S->getElse());
6796 if (Else.isInvalid())
6797 return StmtError();
6798 }
Mike Stump11289f42009-09-09 15:08:12 +00006799
Douglas Gregorebe10102009-08-20 07:17:43 +00006800 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006801 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006802 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 Then.get() == S->getThen() &&
6804 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006805 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006806
Richard Smithb130fe72016-06-23 19:16:49 +00006807 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006808 Init.get(), Then.get(), S->getElseLoc(),
6809 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006810}
6811
6812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006813StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006814TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006815 // Transform the initialization statement
6816 StmtResult Init = getDerived().TransformStmt(S->getInit());
6817 if (Init.isInvalid())
6818 return StmtError();
6819
Douglas Gregorebe10102009-08-20 07:17:43 +00006820 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006821 Sema::ConditionResult Cond = getDerived().TransformCondition(
6822 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6823 Sema::ConditionKind::Switch);
6824 if (Cond.isInvalid())
6825 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006826
Douglas Gregorebe10102009-08-20 07:17:43 +00006827 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006828 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006829 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006830 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006831 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006832
Douglas Gregorebe10102009-08-20 07:17:43 +00006833 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006834 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006835 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006836 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006837
Douglas Gregorebe10102009-08-20 07:17:43 +00006838 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006839 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6840 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006841}
Mike Stump11289f42009-09-09 15:08:12 +00006842
Douglas Gregorebe10102009-08-20 07:17:43 +00006843template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006844StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006845TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006846 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006847 Sema::ConditionResult Cond = getDerived().TransformCondition(
6848 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6849 Sema::ConditionKind::Boolean);
6850 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006851 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006852
Douglas Gregorebe10102009-08-20 07:17:43 +00006853 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006854 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006855 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006856 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006857
Douglas Gregorebe10102009-08-20 07:17:43 +00006858 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006859 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006861 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006862
Richard Smith03a4aa32016-06-23 19:02:52 +00006863 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006864}
Mike Stump11289f42009-09-09 15:08:12 +00006865
Douglas Gregorebe10102009-08-20 07:17:43 +00006866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006867StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006868TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006869 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006870 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006871 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006872 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006873
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006874 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006875 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006876 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006878
Douglas Gregorebe10102009-08-20 07:17:43 +00006879 if (!getDerived().AlwaysRebuild() &&
6880 Cond.get() == S->getCond() &&
6881 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006882 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006883
John McCallb268a282010-08-23 23:25:46 +00006884 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6885 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006886 S->getRParenLoc());
6887}
Mike Stump11289f42009-09-09 15:08:12 +00006888
Douglas Gregorebe10102009-08-20 07:17:43 +00006889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006890StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006891TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006892 if (getSema().getLangOpts().OpenMP)
6893 getSema().startOpenMPLoop();
6894
Douglas Gregorebe10102009-08-20 07:17:43 +00006895 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006896 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006897 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006899
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006900 // In OpenMP loop region loop control variable must be captured and be
6901 // private. Perform analysis of first part (if any).
6902 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6903 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6904
Douglas Gregorebe10102009-08-20 07:17:43 +00006905 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006906 Sema::ConditionResult Cond = getDerived().TransformCondition(
6907 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6908 Sema::ConditionKind::Boolean);
6909 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006910 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006911
Douglas Gregorebe10102009-08-20 07:17:43 +00006912 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006913 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006914 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006915 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006916
Richard Smith945f8d32013-01-14 22:39:08 +00006917 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006918 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006920
Douglas Gregorebe10102009-08-20 07:17:43 +00006921 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006922 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006923 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006924 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006925
Douglas Gregorebe10102009-08-20 07:17:43 +00006926 if (!getDerived().AlwaysRebuild() &&
6927 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006928 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006929 Inc.get() == S->getInc() &&
6930 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006931 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006932
Douglas Gregorebe10102009-08-20 07:17:43 +00006933 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006934 Init.get(), Cond, FullInc,
6935 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006936}
6937
6938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006940TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006941 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6942 S->getLabel());
6943 if (!LD)
6944 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006945
Douglas Gregorebe10102009-08-20 07:17:43 +00006946 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006947 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006948 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006949}
6950
6951template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006952StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006953TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006954 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006955 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006956 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006957 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006958
Douglas Gregorebe10102009-08-20 07:17:43 +00006959 if (!getDerived().AlwaysRebuild() &&
6960 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006961 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006962
6963 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006964 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006965}
6966
6967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006968StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006969TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006970 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006971}
Mike Stump11289f42009-09-09 15:08:12 +00006972
Douglas Gregorebe10102009-08-20 07:17:43 +00006973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006974StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006975TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006976 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006977}
Mike Stump11289f42009-09-09 15:08:12 +00006978
Douglas Gregorebe10102009-08-20 07:17:43 +00006979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006980StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006981TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006982 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6983 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006984 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006985 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006986
Mike Stump11289f42009-09-09 15:08:12 +00006987 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006988 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006989 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006990}
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregorebe10102009-08-20 07:17:43 +00006992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006993StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006994TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006995 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006996 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006997 for (auto *D : S->decls()) {
6998 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006999 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00007000 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007001
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007002 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00007003 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregorebe10102009-08-20 07:17:43 +00007005 Decls.push_back(Transformed);
7006 }
Mike Stump11289f42009-09-09 15:08:12 +00007007
Douglas Gregorebe10102009-08-20 07:17:43 +00007008 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007009 return S;
Mike Stump11289f42009-09-09 15:08:12 +00007010
Stephen Kellya6e43582018-08-09 21:05:56 +00007011 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007012}
Mike Stump11289f42009-09-09 15:08:12 +00007013
Douglas Gregorebe10102009-08-20 07:17:43 +00007014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007015StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00007016TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007017
Benjamin Kramerf0623432012-08-23 22:51:59 +00007018 SmallVector<Expr*, 8> Constraints;
7019 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007020 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00007021
John McCalldadc5752010-08-24 06:29:42 +00007022 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007023 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007024
7025 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007026
Anders Carlssonaaeef072010-01-24 05:50:09 +00007027 // Go through the outputs.
7028 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007029 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007030
Anders Carlssonaaeef072010-01-24 05:50:09 +00007031 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007032 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007033
Anders Carlssonaaeef072010-01-24 05:50:09 +00007034 // Transform the output expr.
7035 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007036 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007037 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007038 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007039
Anders Carlssonaaeef072010-01-24 05:50:09 +00007040 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007041
John McCallb268a282010-08-23 23:25:46 +00007042 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007043 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007044
Anders Carlssonaaeef072010-01-24 05:50:09 +00007045 // Go through the inputs.
7046 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007047 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007048
Anders Carlssonaaeef072010-01-24 05:50:09 +00007049 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007050 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007051
Anders Carlssonaaeef072010-01-24 05:50:09 +00007052 // Transform the input expr.
7053 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007054 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007055 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007056 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007057
Anders Carlssonaaeef072010-01-24 05:50:09 +00007058 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007059
John McCallb268a282010-08-23 23:25:46 +00007060 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007061 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007062
Jennifer Yub8fee672019-06-03 15:57:25 +00007063 // Go through the Labels.
7064 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
7065 Names.push_back(S->getLabelIdentifier(I));
7066
7067 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
7068 if (Result.isInvalid())
7069 return StmtError();
7070 ExprsChanged |= Result.get() != S->getLabelExpr(I);
7071 Exprs.push_back(Result.get());
7072 }
Anders Carlssonaaeef072010-01-24 05:50:09 +00007073 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007074 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007075
7076 // Go through the clobbers.
7077 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00007078 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007079
7080 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007081 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007082 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7083 S->isVolatile(), S->getNumOutputs(),
7084 S->getNumInputs(), Names.data(),
7085 Constraints, Exprs, AsmString.get(),
Jennifer Yub8fee672019-06-03 15:57:25 +00007086 Clobbers, S->getNumLabels(),
7087 S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007088}
7089
Chad Rosier32503022012-06-11 20:47:18 +00007090template<typename Derived>
7091StmtResult
7092TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007093 ArrayRef<Token> AsmToks =
7094 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007095
John McCallf413f5e2013-05-03 00:10:13 +00007096 bool HadError = false, HadChange = false;
7097
7098 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7099 SmallVector<Expr*, 8> TransformedExprs;
7100 TransformedExprs.reserve(SrcExprs.size());
7101 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7102 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7103 if (!Result.isUsable()) {
7104 HadError = true;
7105 } else {
7106 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007107 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007108 }
7109 }
7110
7111 if (HadError) return StmtError();
7112 if (!HadChange && !getDerived().AlwaysRebuild())
7113 return Owned(S);
7114
Chad Rosierb6f46c12012-08-15 16:53:30 +00007115 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007116 AsmToks, S->getAsmString(),
7117 S->getNumOutputs(), S->getNumInputs(),
7118 S->getAllConstraints(), S->getClobbers(),
7119 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007120}
Douglas Gregorebe10102009-08-20 07:17:43 +00007121
Richard Smith9f690bd2015-10-27 06:02:45 +00007122// C++ Coroutines TS
7123
7124template<typename Derived>
7125StmtResult
7126TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007127 auto *ScopeInfo = SemaRef.getCurFunction();
7128 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007129 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007130 ScopeInfo->NeedsCoroutineSuspends &&
7131 ScopeInfo->CoroutineSuspends.first == nullptr &&
7132 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007133 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007134
7135 // Set that we have (possibly-invalid) suspend points before we do anything
7136 // that may fail.
7137 ScopeInfo->setNeedsCoroutineSuspends(false);
7138
7139 // The new CoroutinePromise object needs to be built and put into the current
7140 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007141 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7142 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007143 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7144 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007145 return StmtError();
Richard Smithb2997f52019-05-21 20:10:50 +00007146 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
Eric Fiselierbee782b2017-04-03 19:21:00 +00007147 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007148
7149 // Transform the implicit coroutine statements we built during the initial
7150 // parse.
7151 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7152 if (InitSuspend.isInvalid())
7153 return StmtError();
7154 StmtResult FinalSuspend =
7155 getDerived().TransformStmt(S->getFinalSuspendStmt());
7156 if (FinalSuspend.isInvalid())
7157 return StmtError();
7158 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7159 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007160
7161 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7162 if (BodyRes.isInvalid())
7163 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007164
Eric Fiselierbee782b2017-04-03 19:21:00 +00007165 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7166 if (Builder.isInvalid())
7167 return StmtError();
7168
7169 Expr *ReturnObject = S->getReturnValueInit();
7170 assert(ReturnObject && "the return object is expected to be valid");
7171 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7172 /*NoCopyInit*/ false);
7173 if (Res.isInvalid())
7174 return StmtError();
7175 Builder.ReturnValue = Res.get();
7176
7177 if (S->hasDependentPromiseType()) {
Brian Gesiak38f11822019-06-03 00:47:32 +00007178 // PR41909: We may find a generic coroutine lambda definition within a
7179 // template function that is being instantiated. In this case, the lambda
7180 // will have a dependent promise type, until it is used in an expression
7181 // that creates an instantiation with a non-dependent promise type. We
7182 // should not assert or build coroutine dependent statements for such a
7183 // generic lambda.
7184 auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD);
7185 if (!MD || !MD->getParent()->isGenericLambda()) {
7186 assert(!Promise->getType()->isDependentType() &&
7187 "the promise type must no longer be dependent");
7188 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7189 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7190 "these nodes should not have been built yet");
7191 if (!Builder.buildDependentStatements())
7192 return StmtError();
7193 }
Eric Fiselierbee782b2017-04-03 19:21:00 +00007194 } else {
7195 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7196 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7197 if (Res.isInvalid())
7198 return StmtError();
7199 Builder.OnFallthrough = Res.get();
7200 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007201
Eric Fiselierbee782b2017-04-03 19:21:00 +00007202 if (auto *OnException = S->getExceptionHandler()) {
7203 StmtResult Res = getDerived().TransformStmt(OnException);
7204 if (Res.isInvalid())
7205 return StmtError();
7206 Builder.OnException = Res.get();
7207 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007208
Eric Fiselierbee782b2017-04-03 19:21:00 +00007209 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7210 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7211 if (Res.isInvalid())
7212 return StmtError();
7213 Builder.ReturnStmtOnAllocFailure = Res.get();
7214 }
7215
7216 // Transform any additional statements we may have already built
7217 assert(S->getAllocate() && S->getDeallocate() &&
7218 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007219 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7220 if (AllocRes.isInvalid())
7221 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007222 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007223
7224 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7225 if (DeallocRes.isInvalid())
7226 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007227 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007228
7229 assert(S->getResultDecl() && "ResultDecl must already be built");
7230 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7231 if (ResultDecl.isInvalid())
7232 return StmtError();
7233 Builder.ResultDecl = ResultDecl.get();
7234
7235 if (auto *ReturnStmt = S->getReturnStmt()) {
7236 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7237 if (Res.isInvalid())
7238 return StmtError();
7239 Builder.ReturnStmt = Res.get();
7240 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007241 }
7242
Eric Fiselierbee782b2017-04-03 19:21:00 +00007243 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007244}
7245
7246template<typename Derived>
7247StmtResult
7248TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7249 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7250 /*NotCopyInit*/false);
7251 if (Result.isInvalid())
7252 return StmtError();
7253
7254 // Always rebuild; we don't know if this needs to be injected into a new
7255 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007256 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7257 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007258}
7259
7260template<typename Derived>
7261ExprResult
7262TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7263 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7264 /*NotCopyInit*/false);
7265 if (Result.isInvalid())
7266 return ExprError();
7267
7268 // Always rebuild; we don't know if this needs to be injected into a new
7269 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007270 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7271 E->isImplicit());
7272}
7273
7274template <typename Derived>
7275ExprResult
7276TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7277 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7278 /*NotCopyInit*/ false);
7279 if (OperandResult.isInvalid())
7280 return ExprError();
7281
7282 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7283 E->getOperatorCoawaitLookup());
7284
7285 if (LookupResult.isInvalid())
7286 return ExprError();
7287
7288 // Always rebuild; we don't know if this needs to be injected into a new
7289 // context or if the promise type has changed.
7290 return getDerived().RebuildDependentCoawaitExpr(
7291 E->getKeywordLoc(), OperandResult.get(),
7292 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007293}
7294
7295template<typename Derived>
7296ExprResult
7297TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7298 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7299 /*NotCopyInit*/false);
7300 if (Result.isInvalid())
7301 return ExprError();
7302
7303 // Always rebuild; we don't know if this needs to be injected into a new
7304 // context or if the promise type has changed.
7305 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7306}
7307
7308// Objective-C Statements.
7309
Douglas Gregorebe10102009-08-20 07:17:43 +00007310template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007311StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007312TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007313 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007314 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007315 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007316 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007317
Douglas Gregor96c79492010-04-23 22:50:49 +00007318 // Transform the @catch statements (if present).
7319 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007320 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007321 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007322 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007323 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007324 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007325 if (Catch.get() != S->getCatchStmt(I))
7326 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007327 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007328 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007329
Douglas Gregor306de2f2010-04-22 23:59:56 +00007330 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007331 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007332 if (S->getFinallyStmt()) {
7333 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7334 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007335 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007336 }
7337
7338 // If nothing changed, just retain this statement.
7339 if (!getDerived().AlwaysRebuild() &&
7340 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007341 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007342 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007343 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007344
Douglas Gregor306de2f2010-04-22 23:59:56 +00007345 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007346 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007347 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007348}
Mike Stump11289f42009-09-09 15:08:12 +00007349
Douglas Gregorebe10102009-08-20 07:17:43 +00007350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007351StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007352TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007353 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007354 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007355 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007356 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007357 if (FromVar->getTypeSourceInfo()) {
7358 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7359 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007360 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007361 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007362
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007363 QualType T;
7364 if (TSInfo)
7365 T = TSInfo->getType();
7366 else {
7367 T = getDerived().TransformType(FromVar->getType());
7368 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007369 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007370 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007371
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007372 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7373 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007374 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007375 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007376
John McCalldadc5752010-08-24 06:29:42 +00007377 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007378 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007379 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007380
7381 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007382 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007383 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007384}
Mike Stump11289f42009-09-09 15:08:12 +00007385
Douglas Gregorebe10102009-08-20 07:17:43 +00007386template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007387StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007388TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007389 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007390 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007391 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007392 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007393
Douglas Gregor306de2f2010-04-22 23:59:56 +00007394 // If nothing changed, just retain this statement.
7395 if (!getDerived().AlwaysRebuild() &&
7396 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007397 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007398
7399 // Build a new statement.
7400 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007401 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007402}
Mike Stump11289f42009-09-09 15:08:12 +00007403
Douglas Gregorebe10102009-08-20 07:17:43 +00007404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007406TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007407 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007408 if (S->getThrowExpr()) {
7409 Operand = getDerived().TransformExpr(S->getThrowExpr());
7410 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007411 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007412 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007413
Douglas Gregor2900c162010-04-22 21:44:01 +00007414 if (!getDerived().AlwaysRebuild() &&
7415 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007416 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007417
John McCallb268a282010-08-23 23:25:46 +00007418 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007419}
Mike Stump11289f42009-09-09 15:08:12 +00007420
Douglas Gregorebe10102009-08-20 07:17:43 +00007421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007422StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007423TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007424 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007425 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007426 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007427 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007428 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007429 Object =
7430 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7431 Object.get());
7432 if (Object.isInvalid())
7433 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007434
Douglas Gregor6148de72010-04-22 22:01:21 +00007435 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007436 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007437 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007438 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007439
Douglas Gregor6148de72010-04-22 22:01:21 +00007440 // If nothing change, just retain the current statement.
7441 if (!getDerived().AlwaysRebuild() &&
7442 Object.get() == S->getSynchExpr() &&
7443 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007444 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007445
7446 // Build a new statement.
7447 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007448 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007449}
7450
7451template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007452StmtResult
John McCall31168b02011-06-15 23:02:42 +00007453TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7454 ObjCAutoreleasePoolStmt *S) {
7455 // Transform the body.
7456 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7457 if (Body.isInvalid())
7458 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007459
John McCall31168b02011-06-15 23:02:42 +00007460 // If nothing changed, just retain this statement.
7461 if (!getDerived().AlwaysRebuild() &&
7462 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007463 return S;
John McCall31168b02011-06-15 23:02:42 +00007464
7465 // Build a new statement.
7466 return getDerived().RebuildObjCAutoreleasePoolStmt(
7467 S->getAtLoc(), Body.get());
7468}
7469
7470template<typename Derived>
7471StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007472TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007473 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007474 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007475 StmtResult Element =
7476 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007477 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007478 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007479
Douglas Gregorf68a5082010-04-22 23:10:45 +00007480 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007481 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007482 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007483 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007484
Douglas Gregorf68a5082010-04-22 23:10:45 +00007485 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007486 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007487 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007488 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007489
Douglas Gregorf68a5082010-04-22 23:10:45 +00007490 // If nothing changed, just retain this statement.
7491 if (!getDerived().AlwaysRebuild() &&
7492 Element.get() == S->getElement() &&
7493 Collection.get() == S->getCollection() &&
7494 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007495 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007496
Douglas Gregorf68a5082010-04-22 23:10:45 +00007497 // Build a new statement.
7498 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007499 Element.get(),
7500 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007501 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007502 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007503}
7504
David Majnemer5f7efef2013-10-15 09:50:08 +00007505template <typename Derived>
7506StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007507 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007508 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007509 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7510 TypeSourceInfo *T =
7511 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007512 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007513 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007514
David Majnemer5f7efef2013-10-15 09:50:08 +00007515 Var = getDerived().RebuildExceptionDecl(
7516 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7517 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007518 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007519 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007520 }
Mike Stump11289f42009-09-09 15:08:12 +00007521
Douglas Gregorebe10102009-08-20 07:17:43 +00007522 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007523 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007524 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007525 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007526
David Majnemer5f7efef2013-10-15 09:50:08 +00007527 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007528 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007529 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007530
David Majnemer5f7efef2013-10-15 09:50:08 +00007531 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007532}
Mike Stump11289f42009-09-09 15:08:12 +00007533
David Majnemer5f7efef2013-10-15 09:50:08 +00007534template <typename Derived>
7535StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007536 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007537 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007538 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007539 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007540
Douglas Gregorebe10102009-08-20 07:17:43 +00007541 // Transform the handlers.
7542 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007543 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007544 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007545 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007546 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007547 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007548
Douglas Gregorebe10102009-08-20 07:17:43 +00007549 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007550 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007551 }
Mike Stump11289f42009-09-09 15:08:12 +00007552
David Majnemer5f7efef2013-10-15 09:50:08 +00007553 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007554 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007555 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007556
John McCallb268a282010-08-23 23:25:46 +00007557 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007558 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007559}
Mike Stump11289f42009-09-09 15:08:12 +00007560
Richard Smith02e85f32011-04-14 22:09:26 +00007561template<typename Derived>
7562StmtResult
7563TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007564 StmtResult Init =
7565 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7566 if (Init.isInvalid())
7567 return StmtError();
7568
Richard Smith02e85f32011-04-14 22:09:26 +00007569 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7570 if (Range.isInvalid())
7571 return StmtError();
7572
Richard Smith01694c32016-03-20 10:33:40 +00007573 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7574 if (Begin.isInvalid())
7575 return StmtError();
7576 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7577 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007578 return StmtError();
7579
7580 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7581 if (Cond.isInvalid())
7582 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007583 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007584 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007585 if (Cond.isInvalid())
7586 return StmtError();
7587 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007588 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007589
7590 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7591 if (Inc.isInvalid())
7592 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007593 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007594 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007595
7596 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7597 if (LoopVar.isInvalid())
7598 return StmtError();
7599
7600 StmtResult NewStmt = S;
7601 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007602 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007603 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007604 Begin.get() != S->getBeginStmt() ||
7605 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007606 Cond.get() != S->getCond() ||
7607 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007608 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007609 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007610 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007611 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007612 Begin.get(), End.get(),
7613 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007614 Inc.get(), LoopVar.get(),
7615 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007616 if (NewStmt.isInvalid())
7617 return StmtError();
7618 }
Richard Smith02e85f32011-04-14 22:09:26 +00007619
7620 StmtResult Body = getDerived().TransformStmt(S->getBody());
7621 if (Body.isInvalid())
7622 return StmtError();
7623
7624 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7625 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007626 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007627 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007628 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007629 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007630 Begin.get(), End.get(),
7631 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007632 Inc.get(), LoopVar.get(),
7633 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007634 if (NewStmt.isInvalid())
7635 return StmtError();
7636 }
Richard Smith02e85f32011-04-14 22:09:26 +00007637
7638 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007639 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007640
7641 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7642}
7643
John Wiegley1c0675e2011-04-28 01:08:34 +00007644template<typename Derived>
7645StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007646TreeTransform<Derived>::TransformMSDependentExistsStmt(
7647 MSDependentExistsStmt *S) {
7648 // Transform the nested-name-specifier, if any.
7649 NestedNameSpecifierLoc QualifierLoc;
7650 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007651 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007652 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7653 if (!QualifierLoc)
7654 return StmtError();
7655 }
7656
7657 // Transform the declaration name.
7658 DeclarationNameInfo NameInfo = S->getNameInfo();
7659 if (NameInfo.getName()) {
7660 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7661 if (!NameInfo.getName())
7662 return StmtError();
7663 }
7664
7665 // Check whether anything changed.
7666 if (!getDerived().AlwaysRebuild() &&
7667 QualifierLoc == S->getQualifierLoc() &&
7668 NameInfo.getName() == S->getNameInfo().getName())
7669 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007670
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007671 // Determine whether this name exists, if we can.
7672 CXXScopeSpec SS;
7673 SS.Adopt(QualifierLoc);
7674 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007675 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007676 case Sema::IER_Exists:
7677 if (S->isIfExists())
7678 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007679
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007680 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7681
7682 case Sema::IER_DoesNotExist:
7683 if (S->isIfNotExists())
7684 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007685
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007686 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007687
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007688 case Sema::IER_Dependent:
7689 Dependent = true;
7690 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007691
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007692 case Sema::IER_Error:
7693 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007695
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007696 // We need to continue with the instantiation, so do so now.
7697 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7698 if (SubStmt.isInvalid())
7699 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007700
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007701 // If we have resolved the name, just transform to the substatement.
7702 if (!Dependent)
7703 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007704
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007705 // The name is still dependent, so build a dependent expression again.
7706 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7707 S->isIfExists(),
7708 QualifierLoc,
7709 NameInfo,
7710 SubStmt.get());
7711}
7712
7713template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007714ExprResult
7715TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7716 NestedNameSpecifierLoc QualifierLoc;
7717 if (E->getQualifierLoc()) {
7718 QualifierLoc
7719 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7720 if (!QualifierLoc)
7721 return ExprError();
7722 }
7723
7724 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7725 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7726 if (!PD)
7727 return ExprError();
7728
7729 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7730 if (Base.isInvalid())
7731 return ExprError();
7732
7733 return new (SemaRef.getASTContext())
7734 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7735 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7736 QualifierLoc, E->getMemberLoc());
7737}
7738
David Majnemerfad8f482013-10-15 09:33:02 +00007739template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007740ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7741 MSPropertySubscriptExpr *E) {
7742 auto BaseRes = getDerived().TransformExpr(E->getBase());
7743 if (BaseRes.isInvalid())
7744 return ExprError();
7745 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7746 if (IdxRes.isInvalid())
7747 return ExprError();
7748
7749 if (!getDerived().AlwaysRebuild() &&
7750 BaseRes.get() == E->getBase() &&
7751 IdxRes.get() == E->getIdx())
7752 return E;
7753
7754 return getDerived().RebuildArraySubscriptExpr(
7755 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7756}
7757
7758template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007759StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007760 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007761 if (TryBlock.isInvalid())
7762 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007763
7764 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007765 if (Handler.isInvalid())
7766 return StmtError();
7767
David Majnemerfad8f482013-10-15 09:33:02 +00007768 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7769 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007770 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007771
Warren Huntf6be4cb2014-07-25 20:52:51 +00007772 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7773 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007774}
7775
David Majnemerfad8f482013-10-15 09:33:02 +00007776template <typename Derived>
7777StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007778 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007779 if (Block.isInvalid())
7780 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007781
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007782 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007783}
7784
David Majnemerfad8f482013-10-15 09:33:02 +00007785template <typename Derived>
7786StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007787 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007788 if (FilterExpr.isInvalid())
7789 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007790
David Majnemer7e755502013-10-15 09:30:14 +00007791 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007792 if (Block.isInvalid())
7793 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007794
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007795 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7796 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007797}
7798
David Majnemerfad8f482013-10-15 09:33:02 +00007799template <typename Derived>
7800StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7801 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007802 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7803 else
7804 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7805}
7806
Nico Weber9b982072014-07-07 00:12:30 +00007807template<typename Derived>
7808StmtResult
7809TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7810 return S;
7811}
7812
Alexander Musman64d33f12014-06-04 07:53:32 +00007813//===----------------------------------------------------------------------===//
7814// OpenMP directive transformation
7815//===----------------------------------------------------------------------===//
7816template <typename Derived>
7817StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7818 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007819
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007820 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007821 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007822 ArrayRef<OMPClause *> Clauses = D->clauses();
7823 TClauses.reserve(Clauses.size());
7824 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7825 I != E; ++I) {
7826 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007827 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007828 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007829 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007830 if (Clause)
7831 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007832 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007833 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007834 }
7835 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007836 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007837 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007838 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7839 /*CurScope=*/nullptr);
7840 StmtResult Body;
7841 {
7842 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007843 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007844 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007845 }
7846 AssociatedStmt =
7847 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007848 if (AssociatedStmt.isInvalid()) {
7849 return StmtError();
7850 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007851 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007852 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007853 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007854 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007855
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007856 // Transform directive name for 'omp critical' directive.
7857 DeclarationNameInfo DirName;
7858 if (D->getDirectiveKind() == OMPD_critical) {
7859 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7860 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7861 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007862 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7863 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7864 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007865 } else if (D->getDirectiveKind() == OMPD_cancel) {
7866 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007867 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007868
Alexander Musman64d33f12014-06-04 07:53:32 +00007869 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007870 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007871 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007872}
7873
Alexander Musman64d33f12014-06-04 07:53:32 +00007874template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007875StmtResult
7876TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7877 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007878 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007879 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007880 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7881 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7882 return Res;
7883}
7884
Alexander Musman64d33f12014-06-04 07:53:32 +00007885template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007886StmtResult
7887TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7888 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007889 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007890 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007891 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7892 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007893 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007894}
7895
Alexey Bataevf29276e2014-06-18 04:14:57 +00007896template <typename Derived>
7897StmtResult
7898TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7899 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007900 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007901 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007902 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7903 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7904 return Res;
7905}
7906
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007907template <typename Derived>
7908StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007909TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7910 DeclarationNameInfo DirName;
7911 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007912 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007913 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7914 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7915 return Res;
7916}
7917
7918template <typename Derived>
7919StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007920TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7921 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007922 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007923 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007924 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7925 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7926 return Res;
7927}
7928
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007929template <typename Derived>
7930StmtResult
7931TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7932 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007933 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007934 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007935 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7936 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7937 return Res;
7938}
7939
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007940template <typename Derived>
7941StmtResult
7942TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7943 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007944 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007945 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007946 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7947 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7948 return Res;
7949}
7950
Alexey Bataev4acb8592014-07-07 13:01:15 +00007951template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007952StmtResult
7953TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7954 DeclarationNameInfo DirName;
7955 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007956 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007957 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7958 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7959 return Res;
7960}
7961
7962template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007963StmtResult
7964TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7965 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007966 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7969 return Res;
7970}
7971
7972template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007973StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7974 OMPParallelForDirective *D) {
7975 DeclarationNameInfo DirName;
7976 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007977 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7980 return Res;
7981}
7982
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007983template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007984StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7985 OMPParallelForSimdDirective *D) {
7986 DeclarationNameInfo DirName;
7987 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007988 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7991 return Res;
7992}
7993
7994template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007995StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7996 OMPParallelSectionsDirective *D) {
7997 DeclarationNameInfo DirName;
7998 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007999 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8001 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8002 return Res;
8003}
8004
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008005template <typename Derived>
8006StmtResult
8007TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
8008 DeclarationNameInfo DirName;
8009 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008010 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8013 return Res;
8014}
8015
Alexey Bataev68446b72014-07-18 07:47:19 +00008016template <typename Derived>
8017StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8018 OMPTaskyieldDirective *D) {
8019 DeclarationNameInfo DirName;
8020 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008021 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00008022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8024 return Res;
8025}
8026
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008027template <typename Derived>
8028StmtResult
8029TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8030 DeclarationNameInfo DirName;
8031 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008032 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8034 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8035 return Res;
8036}
8037
Alexey Bataev2df347a2014-07-18 10:17:07 +00008038template <typename Derived>
8039StmtResult
8040TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8041 DeclarationNameInfo DirName;
8042 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008043 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00008044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8046 return Res;
8047}
8048
Alexey Bataev6125da92014-07-21 11:26:11 +00008049template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008050StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8051 OMPTaskgroupDirective *D) {
8052 DeclarationNameInfo DirName;
8053 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008054 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8057 return Res;
8058}
8059
8060template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00008061StmtResult
8062TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8063 DeclarationNameInfo DirName;
8064 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008065 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8067 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8068 return Res;
8069}
8070
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008071template <typename Derived>
8072StmtResult
8073TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8074 DeclarationNameInfo DirName;
8075 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008076 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008077 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8078 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8079 return Res;
8080}
8081
Alexey Bataev0162e452014-07-22 10:10:35 +00008082template <typename Derived>
8083StmtResult
8084TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8085 DeclarationNameInfo DirName;
8086 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008087 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00008088 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8090 return Res;
8091}
8092
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008093template <typename Derived>
8094StmtResult
8095TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8096 DeclarationNameInfo DirName;
8097 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008098 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008099 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8100 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8101 return Res;
8102}
8103
Alexey Bataev13314bf2014-10-09 04:18:56 +00008104template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008105StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8106 OMPTargetDataDirective *D) {
8107 DeclarationNameInfo DirName;
8108 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008109 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8111 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8112 return Res;
8113}
8114
8115template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008116StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8117 OMPTargetEnterDataDirective *D) {
8118 DeclarationNameInfo DirName;
8119 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008120 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8122 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8123 return Res;
8124}
8125
8126template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008127StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8128 OMPTargetExitDataDirective *D) {
8129 DeclarationNameInfo DirName;
8130 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008131 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8133 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8134 return Res;
8135}
8136
8137template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008138StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8139 OMPTargetParallelDirective *D) {
8140 DeclarationNameInfo DirName;
8141 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008142 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8144 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8145 return Res;
8146}
8147
8148template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008149StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8150 OMPTargetParallelForDirective *D) {
8151 DeclarationNameInfo DirName;
8152 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008153 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8155 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8156 return Res;
8157}
8158
8159template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008160StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8161 OMPTargetUpdateDirective *D) {
8162 DeclarationNameInfo DirName;
8163 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008164 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8167 return Res;
8168}
8169
8170template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008171StmtResult
8172TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8173 DeclarationNameInfo DirName;
8174 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008175 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8177 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8178 return Res;
8179}
8180
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008181template <typename Derived>
8182StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8183 OMPCancellationPointDirective *D) {
8184 DeclarationNameInfo DirName;
8185 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008186 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008187 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8188 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8189 return Res;
8190}
8191
Alexey Bataev80909872015-07-02 11:25:17 +00008192template <typename Derived>
8193StmtResult
8194TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8195 DeclarationNameInfo DirName;
8196 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008197 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008198 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8199 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8200 return Res;
8201}
8202
Alexey Bataev49f6e782015-12-01 04:18:41 +00008203template <typename Derived>
8204StmtResult
8205TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8206 DeclarationNameInfo DirName;
8207 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008208 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008209 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8210 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8211 return Res;
8212}
8213
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008214template <typename Derived>
8215StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8216 OMPTaskLoopSimdDirective *D) {
8217 DeclarationNameInfo DirName;
8218 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008219 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8222 return Res;
8223}
8224
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008225template <typename Derived>
8226StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8227 OMPDistributeDirective *D) {
8228 DeclarationNameInfo DirName;
8229 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008230 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008231 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8232 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8233 return Res;
8234}
8235
Carlo Bertolli9925f152016-06-27 14:55:37 +00008236template <typename Derived>
8237StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8238 OMPDistributeParallelForDirective *D) {
8239 DeclarationNameInfo DirName;
8240 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008241 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008242 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8243 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8244 return Res;
8245}
8246
Kelvin Li4a39add2016-07-05 05:00:15 +00008247template <typename Derived>
8248StmtResult
8249TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8250 OMPDistributeParallelForSimdDirective *D) {
8251 DeclarationNameInfo DirName;
8252 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008253 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008254 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8255 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8256 return Res;
8257}
8258
Kelvin Li787f3fc2016-07-06 04:45:38 +00008259template <typename Derived>
8260StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8261 OMPDistributeSimdDirective *D) {
8262 DeclarationNameInfo DirName;
8263 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008264 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008265 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8266 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8267 return Res;
8268}
8269
Kelvin Lia579b912016-07-14 02:54:56 +00008270template <typename Derived>
8271StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8272 OMPTargetParallelForSimdDirective *D) {
8273 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008274 getDerived().getSema().StartOpenMPDSABlock(
8275 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008276 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8277 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8278 return Res;
8279}
8280
Kelvin Li986330c2016-07-20 22:57:10 +00008281template <typename Derived>
8282StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8283 OMPTargetSimdDirective *D) {
8284 DeclarationNameInfo DirName;
8285 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008286 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008287 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8288 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8289 return Res;
8290}
8291
Kelvin Li02532872016-08-05 14:37:37 +00008292template <typename Derived>
8293StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8294 OMPTeamsDistributeDirective *D) {
8295 DeclarationNameInfo DirName;
8296 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008297 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008298 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8299 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8300 return Res;
8301}
8302
Kelvin Li4e325f72016-10-25 12:50:55 +00008303template <typename Derived>
8304StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8305 OMPTeamsDistributeSimdDirective *D) {
8306 DeclarationNameInfo DirName;
8307 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008308 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8310 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8311 return Res;
8312}
8313
Kelvin Li579e41c2016-11-30 23:51:03 +00008314template <typename Derived>
8315StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8316 OMPTeamsDistributeParallelForSimdDirective *D) {
8317 DeclarationNameInfo DirName;
8318 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008319 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8320 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008321 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8322 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8323 return Res;
8324}
8325
Kelvin Li7ade93f2016-12-09 03:24:30 +00008326template <typename Derived>
8327StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8328 OMPTeamsDistributeParallelForDirective *D) {
8329 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008330 getDerived().getSema().StartOpenMPDSABlock(
8331 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008332 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8333 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8334 return Res;
8335}
8336
Kelvin Libf594a52016-12-17 05:48:59 +00008337template <typename Derived>
8338StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8339 OMPTargetTeamsDirective *D) {
8340 DeclarationNameInfo DirName;
8341 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008342 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008343 auto Res = getDerived().TransformOMPExecutableDirective(D);
8344 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8345 return Res;
8346}
Kelvin Li579e41c2016-11-30 23:51:03 +00008347
Kelvin Li83c451e2016-12-25 04:52:54 +00008348template <typename Derived>
8349StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8350 OMPTargetTeamsDistributeDirective *D) {
8351 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008352 getDerived().getSema().StartOpenMPDSABlock(
8353 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008354 auto Res = getDerived().TransformOMPExecutableDirective(D);
8355 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8356 return Res;
8357}
8358
Kelvin Li80e8f562016-12-29 22:16:30 +00008359template <typename Derived>
8360StmtResult
8361TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8362 OMPTargetTeamsDistributeParallelForDirective *D) {
8363 DeclarationNameInfo DirName;
8364 getDerived().getSema().StartOpenMPDSABlock(
8365 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008366 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008367 auto Res = getDerived().TransformOMPExecutableDirective(D);
8368 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8369 return Res;
8370}
8371
Kelvin Li1851df52017-01-03 05:23:48 +00008372template <typename Derived>
8373StmtResult TreeTransform<Derived>::
8374 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8375 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8376 DeclarationNameInfo DirName;
8377 getDerived().getSema().StartOpenMPDSABlock(
8378 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008379 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008380 auto Res = getDerived().TransformOMPExecutableDirective(D);
8381 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8382 return Res;
8383}
8384
Kelvin Lida681182017-01-10 18:08:18 +00008385template <typename Derived>
8386StmtResult
8387TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8388 OMPTargetTeamsDistributeSimdDirective *D) {
8389 DeclarationNameInfo DirName;
8390 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008391 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008392 auto Res = getDerived().TransformOMPExecutableDirective(D);
8393 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8394 return Res;
8395}
8396
Kelvin Li1851df52017-01-03 05:23:48 +00008397
Alexander Musman64d33f12014-06-04 07:53:32 +00008398//===----------------------------------------------------------------------===//
8399// OpenMP clause transformation
8400//===----------------------------------------------------------------------===//
8401template <typename Derived>
8402OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008403 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8404 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008405 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008406 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008407 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008408 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008409}
8410
Alexander Musman64d33f12014-06-04 07:53:32 +00008411template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008412OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8413 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8414 if (Cond.isInvalid())
8415 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008416 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008417 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008418}
8419
8420template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008421OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008422TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8423 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8424 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008425 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008426 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008427 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008428}
8429
Alexey Bataev62c87d22014-03-21 04:51:18 +00008430template <typename Derived>
8431OMPClause *
8432TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8433 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8434 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008435 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008436 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008437 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008438}
8439
Alexander Musman8bd31e62014-05-27 15:12:19 +00008440template <typename Derived>
8441OMPClause *
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00008442TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
8443 ExprResult E = getDerived().TransformExpr(C->getAllocator());
8444 if (E.isInvalid())
8445 return nullptr;
8446 return getDerived().RebuildOMPAllocatorClause(
8447 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
8448}
8449
8450template <typename Derived>
8451OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008452TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8453 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8454 if (E.isInvalid())
8455 return nullptr;
8456 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008457 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008458}
8459
8460template <typename Derived>
8461OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008462TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8463 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8464 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008465 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008466 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008467 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008468}
8469
Alexander Musman64d33f12014-06-04 07:53:32 +00008470template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008471OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008472TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008473 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008474 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008475 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008476}
8477
Alexander Musman64d33f12014-06-04 07:53:32 +00008478template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008479OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008480TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008481 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008482 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008483 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008484}
8485
Alexander Musman64d33f12014-06-04 07:53:32 +00008486template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008487OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008488TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8489 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8490 if (E.isInvalid())
8491 return nullptr;
8492 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008493 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008494 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008495 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008496 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008497}
8498
8499template <typename Derived>
8500OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008501TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008502 ExprResult E;
8503 if (auto *Num = C->getNumForLoops()) {
8504 E = getDerived().TransformExpr(Num);
8505 if (E.isInvalid())
8506 return nullptr;
8507 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008508 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008509 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008510}
8511
8512template <typename Derived>
8513OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008514TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8515 // No need to rebuild this clause, no template-dependent parameters.
8516 return C;
8517}
8518
8519template <typename Derived>
8520OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008521TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8522 // No need to rebuild this clause, no template-dependent parameters.
8523 return C;
8524}
8525
8526template <typename Derived>
8527OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008528TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8529 // No need to rebuild this clause, no template-dependent parameters.
8530 return C;
8531}
8532
8533template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008534OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8535 // No need to rebuild this clause, no template-dependent parameters.
8536 return C;
8537}
8538
8539template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008540OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8541 // No need to rebuild this clause, no template-dependent parameters.
8542 return C;
8543}
8544
8545template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008546OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008547TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8548 // No need to rebuild this clause, no template-dependent parameters.
8549 return C;
8550}
8551
8552template <typename Derived>
8553OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008554TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8555 // No need to rebuild this clause, no template-dependent parameters.
8556 return C;
8557}
8558
8559template <typename Derived>
8560OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008561TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8562 // No need to rebuild this clause, no template-dependent parameters.
8563 return C;
8564}
8565
8566template <typename Derived>
8567OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008568TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8569 // No need to rebuild this clause, no template-dependent parameters.
8570 return C;
8571}
8572
8573template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008574OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8575 // No need to rebuild this clause, no template-dependent parameters.
8576 return C;
8577}
8578
8579template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008580OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008581TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8582 // No need to rebuild this clause, no template-dependent parameters.
8583 return C;
8584}
8585
8586template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008587OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8588 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008589 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008590}
8591
8592template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008593OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8594 OMPUnifiedSharedMemoryClause *C) {
8595 llvm_unreachable(
8596 "unified_shared_memory clause cannot appear in dependent context");
8597}
8598
8599template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008600OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8601 OMPReverseOffloadClause *C) {
8602 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8603}
8604
8605template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008606OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8607 OMPDynamicAllocatorsClause *C) {
8608 llvm_unreachable(
8609 "dynamic_allocators clause cannot appear in dependent context");
8610}
8611
8612template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008613OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8614 OMPAtomicDefaultMemOrderClause *C) {
8615 llvm_unreachable(
8616 "atomic_default_mem_order clause cannot appear in dependent context");
8617}
8618
8619template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008620OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008621TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008622 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008623 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008624 for (auto *VE : C->varlists()) {
8625 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008626 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008627 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008628 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008629 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008630 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008631 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008632}
8633
Alexander Musman64d33f12014-06-04 07:53:32 +00008634template <typename Derived>
8635OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8636 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008637 llvm::SmallVector<Expr *, 16> Vars;
8638 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008639 for (auto *VE : C->varlists()) {
8640 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008641 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008642 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008643 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008644 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008645 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008646 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008647}
8648
Alexander Musman64d33f12014-06-04 07:53:32 +00008649template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008650OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008651TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8652 llvm::SmallVector<Expr *, 16> Vars;
8653 Vars.reserve(C->varlist_size());
8654 for (auto *VE : C->varlists()) {
8655 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8656 if (EVar.isInvalid())
8657 return nullptr;
8658 Vars.push_back(EVar.get());
8659 }
8660 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008661 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008662}
8663
8664template <typename Derived>
8665OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008666TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8667 llvm::SmallVector<Expr *, 16> Vars;
8668 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008669 for (auto *VE : C->varlists()) {
8670 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008671 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008672 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008673 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008674 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008675 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008676 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008677}
8678
Alexander Musman64d33f12014-06-04 07:53:32 +00008679template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008680OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008681TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8682 llvm::SmallVector<Expr *, 16> Vars;
8683 Vars.reserve(C->varlist_size());
8684 for (auto *VE : C->varlists()) {
8685 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8686 if (EVar.isInvalid())
8687 return nullptr;
8688 Vars.push_back(EVar.get());
8689 }
8690 CXXScopeSpec ReductionIdScopeSpec;
8691 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8692
8693 DeclarationNameInfo NameInfo = C->getNameInfo();
8694 if (NameInfo.getName()) {
8695 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8696 if (!NameInfo.getName())
8697 return nullptr;
8698 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008699 // Build a list of all UDR decls with the same names ranged by the Scopes.
8700 // The Scope boundary is a duplication of the previous decl.
8701 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8702 for (auto *E : C->reduction_ops()) {
8703 // Transform all the decls.
8704 if (E) {
8705 auto *ULE = cast<UnresolvedLookupExpr>(E);
8706 UnresolvedSet<8> Decls;
8707 for (auto *D : ULE->decls()) {
8708 NamedDecl *InstD =
8709 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8710 Decls.addDecl(InstD, InstD->getAccess());
8711 }
8712 UnresolvedReductions.push_back(
8713 UnresolvedLookupExpr::Create(
8714 SemaRef.Context, /*NamingClass=*/nullptr,
8715 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8716 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8717 Decls.begin(), Decls.end()));
8718 } else
8719 UnresolvedReductions.push_back(nullptr);
8720 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008721 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008722 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008723 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008724}
8725
8726template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008727OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8728 OMPTaskReductionClause *C) {
8729 llvm::SmallVector<Expr *, 16> Vars;
8730 Vars.reserve(C->varlist_size());
8731 for (auto *VE : C->varlists()) {
8732 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8733 if (EVar.isInvalid())
8734 return nullptr;
8735 Vars.push_back(EVar.get());
8736 }
8737 CXXScopeSpec ReductionIdScopeSpec;
8738 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8739
8740 DeclarationNameInfo NameInfo = C->getNameInfo();
8741 if (NameInfo.getName()) {
8742 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8743 if (!NameInfo.getName())
8744 return nullptr;
8745 }
8746 // Build a list of all UDR decls with the same names ranged by the Scopes.
8747 // The Scope boundary is a duplication of the previous decl.
8748 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8749 for (auto *E : C->reduction_ops()) {
8750 // Transform all the decls.
8751 if (E) {
8752 auto *ULE = cast<UnresolvedLookupExpr>(E);
8753 UnresolvedSet<8> Decls;
8754 for (auto *D : ULE->decls()) {
8755 NamedDecl *InstD =
8756 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8757 Decls.addDecl(InstD, InstD->getAccess());
8758 }
8759 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8760 SemaRef.Context, /*NamingClass=*/nullptr,
8761 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8762 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8763 } else
8764 UnresolvedReductions.push_back(nullptr);
8765 }
8766 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008767 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008768 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008769}
8770
8771template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008772OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008773TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8774 llvm::SmallVector<Expr *, 16> Vars;
8775 Vars.reserve(C->varlist_size());
8776 for (auto *VE : C->varlists()) {
8777 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8778 if (EVar.isInvalid())
8779 return nullptr;
8780 Vars.push_back(EVar.get());
8781 }
8782 CXXScopeSpec ReductionIdScopeSpec;
8783 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8784
8785 DeclarationNameInfo NameInfo = C->getNameInfo();
8786 if (NameInfo.getName()) {
8787 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8788 if (!NameInfo.getName())
8789 return nullptr;
8790 }
8791 // Build a list of all UDR decls with the same names ranged by the Scopes.
8792 // The Scope boundary is a duplication of the previous decl.
8793 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8794 for (auto *E : C->reduction_ops()) {
8795 // Transform all the decls.
8796 if (E) {
8797 auto *ULE = cast<UnresolvedLookupExpr>(E);
8798 UnresolvedSet<8> Decls;
8799 for (auto *D : ULE->decls()) {
8800 NamedDecl *InstD =
8801 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8802 Decls.addDecl(InstD, InstD->getAccess());
8803 }
8804 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8805 SemaRef.Context, /*NamingClass=*/nullptr,
8806 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8807 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8808 } else
8809 UnresolvedReductions.push_back(nullptr);
8810 }
8811 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008812 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008813 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008814}
8815
8816template <typename Derived>
8817OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008818TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8819 llvm::SmallVector<Expr *, 16> Vars;
8820 Vars.reserve(C->varlist_size());
8821 for (auto *VE : C->varlists()) {
8822 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8823 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008824 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008825 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008826 }
8827 ExprResult Step = getDerived().TransformExpr(C->getStep());
8828 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008829 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008830 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008831 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008832 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008833}
8834
Alexander Musman64d33f12014-06-04 07:53:32 +00008835template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008836OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008837TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8838 llvm::SmallVector<Expr *, 16> Vars;
8839 Vars.reserve(C->varlist_size());
8840 for (auto *VE : C->varlists()) {
8841 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8842 if (EVar.isInvalid())
8843 return nullptr;
8844 Vars.push_back(EVar.get());
8845 }
8846 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8847 if (Alignment.isInvalid())
8848 return nullptr;
8849 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008850 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008851 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008852}
8853
Alexander Musman64d33f12014-06-04 07:53:32 +00008854template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008855OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008856TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8857 llvm::SmallVector<Expr *, 16> Vars;
8858 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008859 for (auto *VE : C->varlists()) {
8860 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008861 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008862 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008863 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008864 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008865 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008866 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008867}
8868
Alexey Bataevbae9a792014-06-27 10:37:06 +00008869template <typename Derived>
8870OMPClause *
8871TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8872 llvm::SmallVector<Expr *, 16> Vars;
8873 Vars.reserve(C->varlist_size());
8874 for (auto *VE : C->varlists()) {
8875 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8876 if (EVar.isInvalid())
8877 return nullptr;
8878 Vars.push_back(EVar.get());
8879 }
8880 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008881 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008882}
8883
Alexey Bataev6125da92014-07-21 11:26:11 +00008884template <typename Derived>
8885OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8886 llvm::SmallVector<Expr *, 16> Vars;
8887 Vars.reserve(C->varlist_size());
8888 for (auto *VE : C->varlists()) {
8889 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8890 if (EVar.isInvalid())
8891 return nullptr;
8892 Vars.push_back(EVar.get());
8893 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008894 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008895 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008896}
8897
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008898template <typename Derived>
8899OMPClause *
8900TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8901 llvm::SmallVector<Expr *, 16> Vars;
8902 Vars.reserve(C->varlist_size());
8903 for (auto *VE : C->varlists()) {
8904 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8905 if (EVar.isInvalid())
8906 return nullptr;
8907 Vars.push_back(EVar.get());
8908 }
8909 return getDerived().RebuildOMPDependClause(
8910 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008911 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008912}
8913
Michael Wonge710d542015-08-07 16:16:36 +00008914template <typename Derived>
8915OMPClause *
8916TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8917 ExprResult E = getDerived().TransformExpr(C->getDevice());
8918 if (E.isInvalid())
8919 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008920 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008921 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008922}
8923
Michael Kruse01f670d2019-02-22 22:29:42 +00008924template <typename Derived, class T>
8925bool transformOMPMappableExprListClause(
8926 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
8927 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
8928 DeclarationNameInfo &MapperIdInfo,
8929 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
8930 // Transform expressions in the list.
Kelvin Li0bff7af2015-11-23 05:32:03 +00008931 Vars.reserve(C->varlist_size());
8932 for (auto *VE : C->varlists()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008933 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
Kelvin Li0bff7af2015-11-23 05:32:03 +00008934 if (EVar.isInvalid())
Michael Kruse01f670d2019-02-22 22:29:42 +00008935 return true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008936 Vars.push_back(EVar.get());
8937 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008938 // Transform mapper scope specifier and identifier.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008939 NestedNameSpecifierLoc QualifierLoc;
8940 if (C->getMapperQualifierLoc()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008941 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008942 C->getMapperQualifierLoc());
8943 if (!QualifierLoc)
Michael Kruse01f670d2019-02-22 22:29:42 +00008944 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008945 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00008946 MapperIdScopeSpec.Adopt(QualifierLoc);
Michael Kruse01f670d2019-02-22 22:29:42 +00008947 MapperIdInfo = C->getMapperIdInfo();
Michael Kruse4304e9d2019-02-19 16:38:20 +00008948 if (MapperIdInfo.getName()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008949 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
Michael Kruse4304e9d2019-02-19 16:38:20 +00008950 if (!MapperIdInfo.getName())
Michael Kruse01f670d2019-02-22 22:29:42 +00008951 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008952 }
8953 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
8954 // the previous user-defined mapper lookup in dependent environment.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008955 for (auto *E : C->mapperlists()) {
8956 // Transform all the decls.
8957 if (E) {
8958 auto *ULE = cast<UnresolvedLookupExpr>(E);
8959 UnresolvedSet<8> Decls;
8960 for (auto *D : ULE->decls()) {
8961 NamedDecl *InstD =
Michael Kruse01f670d2019-02-22 22:29:42 +00008962 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008963 Decls.addDecl(InstD, InstD->getAccess());
8964 }
8965 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
Michael Kruse01f670d2019-02-22 22:29:42 +00008966 TT.getSema().Context, /*NamingClass=*/nullptr,
8967 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
8968 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
8969 Decls.end()));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008970 } else {
8971 UnresolvedMappers.push_back(nullptr);
8972 }
8973 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008974 return false;
8975}
8976
8977template <typename Derived>
8978OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00008979 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00008980 llvm::SmallVector<Expr *, 16> Vars;
8981 CXXScopeSpec MapperIdScopeSpec;
8982 DeclarationNameInfo MapperIdInfo;
8983 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
8984 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
8985 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
8986 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008987 return getDerived().RebuildOMPMapClause(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008988 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
8989 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
8990 C->getColonLoc(), Vars, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00008991}
8992
Kelvin Li099bb8c2015-11-24 20:50:12 +00008993template <typename Derived>
8994OMPClause *
Alexey Bataeve04483e2019-03-27 14:14:31 +00008995TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
8996 Expr *Allocator = C->getAllocator();
8997 if (Allocator) {
8998 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
8999 if (AllocatorRes.isInvalid())
9000 return nullptr;
9001 Allocator = AllocatorRes.get();
9002 }
9003 llvm::SmallVector<Expr *, 16> Vars;
9004 Vars.reserve(C->varlist_size());
9005 for (auto *VE : C->varlists()) {
9006 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9007 if (EVar.isInvalid())
9008 return nullptr;
9009 Vars.push_back(EVar.get());
9010 }
9011 return getDerived().RebuildOMPAllocateClause(
9012 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
9013 C->getEndLoc());
9014}
9015
9016template <typename Derived>
9017OMPClause *
Kelvin Li099bb8c2015-11-24 20:50:12 +00009018TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
9019 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
9020 if (E.isInvalid())
9021 return nullptr;
9022 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009023 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00009024}
9025
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009026template <typename Derived>
9027OMPClause *
9028TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
9029 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
9030 if (E.isInvalid())
9031 return nullptr;
9032 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009033 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009034}
9035
Alexey Bataeva0569352015-12-01 10:17:31 +00009036template <typename Derived>
9037OMPClause *
9038TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
9039 ExprResult E = getDerived().TransformExpr(C->getPriority());
9040 if (E.isInvalid())
9041 return nullptr;
9042 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009043 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00009044}
9045
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009046template <typename Derived>
9047OMPClause *
9048TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
9049 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
9050 if (E.isInvalid())
9051 return nullptr;
9052 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009053 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009054}
9055
Alexey Bataev382967a2015-12-08 12:06:20 +00009056template <typename Derived>
9057OMPClause *
9058TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
9059 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
9060 if (E.isInvalid())
9061 return nullptr;
9062 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009063 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00009064}
9065
Alexey Bataev28c75412015-12-15 08:19:24 +00009066template <typename Derived>
9067OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
9068 ExprResult E = getDerived().TransformExpr(C->getHint());
9069 if (E.isInvalid())
9070 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009071 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009072 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00009073}
9074
Carlo Bertollib4adf552016-01-15 18:50:31 +00009075template <typename Derived>
9076OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
9077 OMPDistScheduleClause *C) {
9078 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9079 if (E.isInvalid())
9080 return nullptr;
9081 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009082 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009083 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00009084}
9085
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00009086template <typename Derived>
9087OMPClause *
9088TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
9089 return C;
9090}
9091
Samuel Antao661c0902016-05-26 17:39:58 +00009092template <typename Derived>
9093OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009094 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009095 llvm::SmallVector<Expr *, 16> Vars;
9096 CXXScopeSpec MapperIdScopeSpec;
9097 DeclarationNameInfo MapperIdInfo;
9098 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9099 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
9100 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9101 return nullptr;
9102 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo,
9103 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00009104}
9105
Samuel Antaoec172c62016-05-26 17:49:04 +00009106template <typename Derived>
9107OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009108 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse0336c752019-02-25 20:34:15 +00009109 llvm::SmallVector<Expr *, 16> Vars;
9110 CXXScopeSpec MapperIdScopeSpec;
9111 DeclarationNameInfo MapperIdInfo;
9112 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9113 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
9114 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9115 return nullptr;
9116 return getDerived().RebuildOMPFromClause(
9117 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00009118}
9119
Carlo Bertolli2404b172016-07-13 15:37:16 +00009120template <typename Derived>
9121OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
9122 OMPUseDevicePtrClause *C) {
9123 llvm::SmallVector<Expr *, 16> Vars;
9124 Vars.reserve(C->varlist_size());
9125 for (auto *VE : C->varlists()) {
9126 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9127 if (EVar.isInvalid())
9128 return nullptr;
9129 Vars.push_back(EVar.get());
9130 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009131 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9132 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00009133}
9134
Carlo Bertolli70594e92016-07-13 17:16:49 +00009135template <typename Derived>
9136OMPClause *
9137TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
9138 llvm::SmallVector<Expr *, 16> Vars;
9139 Vars.reserve(C->varlist_size());
9140 for (auto *VE : C->varlists()) {
9141 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9142 if (EVar.isInvalid())
9143 return nullptr;
9144 Vars.push_back(EVar.get());
9145 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009146 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9147 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00009148}
9149
Douglas Gregorebe10102009-08-20 07:17:43 +00009150//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00009151// Expression transformation
9152//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00009153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009154ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00009155TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
9156 return TransformExpr(E->getSubExpr());
9157}
9158
9159template<typename Derived>
9160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009161TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00009162 if (!E->isTypeDependent())
9163 return E;
9164
9165 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00009166 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00009167}
Mike Stump11289f42009-09-09 15:08:12 +00009168
9169template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009170ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009171TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009172 NestedNameSpecifierLoc QualifierLoc;
9173 if (E->getQualifierLoc()) {
9174 QualifierLoc
9175 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9176 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009177 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009178 }
John McCallce546572009-12-08 09:08:17 +00009179
9180 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009181 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9182 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009183 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009184 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009185
John McCall815039a2010-08-17 21:27:17 +00009186 DeclarationNameInfo NameInfo = E->getNameInfo();
9187 if (NameInfo.getName()) {
9188 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9189 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009190 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009191 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009192
9193 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009194 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009195 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009196 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009197 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009198
9199 // Mark it referenced in the new context regardless.
9200 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009201 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009202
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009203 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009204 }
John McCallce546572009-12-08 09:08:17 +00009205
Craig Topperc3ec1492014-05-26 06:22:03 +00009206 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009207 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009208 TemplateArgs = &TransArgs;
9209 TransArgs.setLAngleLoc(E->getLAngleLoc());
9210 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009211 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9212 E->getNumTemplateArgs(),
9213 TransArgs))
9214 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009215 }
9216
Chad Rosier1dcde962012-08-08 18:46:20 +00009217 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009218 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009219}
Mike Stump11289f42009-09-09 15:08:12 +00009220
Douglas Gregora16548e2009-08-11 05:31:07 +00009221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009223TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009225}
Mike Stump11289f42009-09-09 15:08:12 +00009226
Leonard Chandb01c3a2018-06-20 17:19:40 +00009227template <typename Derived>
9228ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9229 FixedPointLiteral *E) {
9230 return E;
9231}
9232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009235TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009236 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009237}
Mike Stump11289f42009-09-09 15:08:12 +00009238
Douglas Gregora16548e2009-08-11 05:31:07 +00009239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009240ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009241TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009242 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009243}
Mike Stump11289f42009-09-09 15:08:12 +00009244
Douglas Gregora16548e2009-08-11 05:31:07 +00009245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009247TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009248 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009249}
Mike Stump11289f42009-09-09 15:08:12 +00009250
Douglas Gregora16548e2009-08-11 05:31:07 +00009251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009253TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009254 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009255}
9256
9257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009258ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009259TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009260 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009261 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009262 return SemaRef.MaybeBindToTemporary(E);
9263}
9264
9265template<typename Derived>
9266ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009267TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9268 ExprResult ControllingExpr =
9269 getDerived().TransformExpr(E->getControllingExpr());
9270 if (ControllingExpr.isInvalid())
9271 return ExprError();
9272
Chris Lattner01cf8db2011-07-20 06:58:45 +00009273 SmallVector<Expr *, 4> AssocExprs;
9274 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009275 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9276 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9277 if (TSI) {
9278 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009279 if (!AssocType)
9280 return ExprError();
9281 AssocTypes.push_back(AssocType);
9282 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009283 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009284 }
9285
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009286 ExprResult AssocExpr =
9287 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009288 if (AssocExpr.isInvalid())
9289 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009290 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009291 }
9292
9293 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9294 E->getDefaultLoc(),
9295 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009296 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009297 AssocTypes,
9298 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009299}
9300
9301template<typename Derived>
9302ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009303TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009304 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009305 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009306 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009307
Douglas Gregora16548e2009-08-11 05:31:07 +00009308 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009309 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009310
John McCallb268a282010-08-23 23:25:46 +00009311 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009312 E->getRParen());
9313}
9314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009315/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009316/// allowed to refer to a non-static member of a class even if there's no 'this'
9317/// object available.
9318template<typename Derived>
9319ExprResult
9320TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9321 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009322 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009323 else
9324 return getDerived().TransformExpr(E);
9325}
9326
Mike Stump11289f42009-09-09 15:08:12 +00009327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009328ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009329TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009330 ExprResult SubExpr;
9331 if (E->getOpcode() == UO_AddrOf)
9332 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9333 else
9334 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009337
Douglas Gregora16548e2009-08-11 05:31:07 +00009338 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009339 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009340
Douglas Gregora16548e2009-08-11 05:31:07 +00009341 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9342 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009343 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009344}
Mike Stump11289f42009-09-09 15:08:12 +00009345
Douglas Gregora16548e2009-08-11 05:31:07 +00009346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009347ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009348TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9349 // Transform the type.
9350 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9351 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009352 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009353
Douglas Gregor882211c2010-04-28 22:16:22 +00009354 // Transform all of the components into components similar to what the
9355 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009356 // FIXME: It would be slightly more efficient in the non-dependent case to
9357 // just map FieldDecls, rather than requiring the rebuilder to look for
9358 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009359 // template code that we don't care.
9360 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009361 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009362 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009363 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009364 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009365 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009366 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009367 Comp.LocStart = ON.getSourceRange().getBegin();
9368 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009369 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009370 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009371 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009372 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009373 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009374 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009375
Douglas Gregor882211c2010-04-28 22:16:22 +00009376 ExprChanged = ExprChanged || Index.get() != FromIndex;
9377 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009378 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009379 break;
9380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009381
James Y Knight7281c352015-12-29 22:31:18 +00009382 case OffsetOfNode::Field:
9383 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009384 Comp.isBrackets = false;
9385 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009386 if (!Comp.U.IdentInfo)
9387 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009388
Douglas Gregor882211c2010-04-28 22:16:22 +00009389 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009390
James Y Knight7281c352015-12-29 22:31:18 +00009391 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009392 // Will be recomputed during the rebuild.
9393 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009394 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009395
Douglas Gregor882211c2010-04-28 22:16:22 +00009396 Components.push_back(Comp);
9397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009398
Douglas Gregor882211c2010-04-28 22:16:22 +00009399 // If nothing changed, retain the existing expression.
9400 if (!getDerived().AlwaysRebuild() &&
9401 Type == E->getTypeSourceInfo() &&
9402 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009403 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009404
Douglas Gregor882211c2010-04-28 22:16:22 +00009405 // Build a new offsetof expression.
9406 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009407 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009408}
9409
9410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009411ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009412TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009413 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009414 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009415 return E;
John McCall8d69a212010-11-15 23:31:06 +00009416}
9417
9418template<typename Derived>
9419ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009420TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9421 return E;
9422}
9423
9424template<typename Derived>
9425ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009426TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009427 // Rebuild the syntactic form. The original syntactic form has
9428 // opaque-value expressions in it, so strip those away and rebuild
9429 // the result. This is a really awful way of doing this, but the
9430 // better solution (rebuilding the semantic expressions and
9431 // rebinding OVEs as necessary) doesn't work; we'd need
9432 // TreeTransform to not strip away implicit conversions.
9433 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9434 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009435 if (result.isInvalid()) return ExprError();
9436
9437 // If that gives us a pseudo-object result back, the pseudo-object
9438 // expression must have been an lvalue-to-rvalue conversion which we
9439 // should reapply.
9440 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009441 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009442
9443 return result;
9444}
9445
9446template<typename Derived>
9447ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009448TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9449 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009451 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009452
John McCallbcd03502009-12-07 02:54:59 +00009453 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009454 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009456
John McCall4c98fd82009-11-04 07:28:41 +00009457 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009458 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009459
Peter Collingbournee190dee2011-03-11 19:24:49 +00009460 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9461 E->getKind(),
9462 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009463 }
Mike Stump11289f42009-09-09 15:08:12 +00009464
Eli Friedmane4f22df2012-02-29 04:03:55 +00009465 // C++0x [expr.sizeof]p1:
9466 // The operand is either an expression, which is an unevaluated operand
9467 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009468 EnterExpressionEvaluationContext Unevaluated(
9469 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9470 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009471
Reid Kleckner32506ed2014-06-12 23:03:48 +00009472 // Try to recover if we have something like sizeof(T::X) where X is a type.
9473 // Notably, there must be *exactly* one set of parens if X is a type.
9474 TypeSourceInfo *RecoveryTSI = nullptr;
9475 ExprResult SubExpr;
9476 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9477 if (auto *DRE =
9478 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9479 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9480 PE, DRE, false, &RecoveryTSI);
9481 else
9482 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9483
9484 if (RecoveryTSI) {
9485 return getDerived().RebuildUnaryExprOrTypeTrait(
9486 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9487 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009489
Eli Friedmane4f22df2012-02-29 04:03:55 +00009490 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009491 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009492
Peter Collingbournee190dee2011-03-11 19:24:49 +00009493 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9494 E->getOperatorLoc(),
9495 E->getKind(),
9496 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009497}
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009500ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009501TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009502 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009503 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009505
John McCalldadc5752010-08-24 06:29:42 +00009506 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009507 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009508 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009509
9510
Douglas Gregora16548e2009-08-11 05:31:07 +00009511 if (!getDerived().AlwaysRebuild() &&
9512 LHS.get() == E->getLHS() &&
9513 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009514 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009515
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009516 return getDerived().RebuildArraySubscriptExpr(
9517 LHS.get(),
9518 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009519}
Mike Stump11289f42009-09-09 15:08:12 +00009520
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009521template <typename Derived>
9522ExprResult
9523TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9524 ExprResult Base = getDerived().TransformExpr(E->getBase());
9525 if (Base.isInvalid())
9526 return ExprError();
9527
9528 ExprResult LowerBound;
9529 if (E->getLowerBound()) {
9530 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9531 if (LowerBound.isInvalid())
9532 return ExprError();
9533 }
9534
9535 ExprResult Length;
9536 if (E->getLength()) {
9537 Length = getDerived().TransformExpr(E->getLength());
9538 if (Length.isInvalid())
9539 return ExprError();
9540 }
9541
9542 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9543 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9544 return E;
9545
9546 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009547 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009548 Length.get(), E->getRBracketLoc());
9549}
9550
Mike Stump11289f42009-09-09 15:08:12 +00009551template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009552ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009553TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009555 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009556 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009557 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009558
9559 // Transform arguments.
9560 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009561 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009562 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009563 &ArgChanged))
9564 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009565
Douglas Gregora16548e2009-08-11 05:31:07 +00009566 if (!getDerived().AlwaysRebuild() &&
9567 Callee.get() == E->getCallee() &&
9568 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009569 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009570
Douglas Gregora16548e2009-08-11 05:31:07 +00009571 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009572 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009573 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009574 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009575 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009576 E->getRParenLoc());
9577}
Mike Stump11289f42009-09-09 15:08:12 +00009578
9579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009580ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009581TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009582 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009583 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009584 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009585
Douglas Gregorea972d32011-02-28 21:54:11 +00009586 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009587 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009588 QualifierLoc
9589 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009590
Douglas Gregorea972d32011-02-28 21:54:11 +00009591 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009592 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009593 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009594 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009595
Eli Friedman2cfcef62009-12-04 06:40:45 +00009596 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009597 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9598 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009599 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009601
John McCall16df1e52010-03-30 21:47:33 +00009602 NamedDecl *FoundDecl = E->getFoundDecl();
9603 if (FoundDecl == E->getMemberDecl()) {
9604 FoundDecl = Member;
9605 } else {
9606 FoundDecl = cast_or_null<NamedDecl>(
9607 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9608 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009609 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009610 }
9611
Douglas Gregora16548e2009-08-11 05:31:07 +00009612 if (!getDerived().AlwaysRebuild() &&
9613 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009614 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009615 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009616 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009617 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009618
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009619 // Mark it referenced in the new context regardless.
9620 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009621 SemaRef.MarkMemberReferenced(E);
9622
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009623 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009624 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009625
John McCall6b51f282009-11-23 01:53:49 +00009626 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009627 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009628 TransArgs.setLAngleLoc(E->getLAngleLoc());
9629 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009630 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9631 E->getNumTemplateArgs(),
9632 TransArgs))
9633 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009635
Douglas Gregora16548e2009-08-11 05:31:07 +00009636 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009637 SourceLocation FakeOperatorLoc =
9638 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009639
John McCall38836f02010-01-15 08:34:02 +00009640 // FIXME: to do this check properly, we will need to preserve the
9641 // first-qualifier-in-scope here, just in case we had a dependent
9642 // base (and therefore couldn't do the check) and a
9643 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009644 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009645 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9646 if (MemberNameInfo.getName()) {
9647 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9648 if (!MemberNameInfo.getName())
9649 return ExprError();
9650 }
John McCall38836f02010-01-15 08:34:02 +00009651
John McCallb268a282010-08-23 23:25:46 +00009652 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009653 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009654 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009655 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009656 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009657 Member,
John McCall16df1e52010-03-30 21:47:33 +00009658 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009659 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009660 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009661 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009662}
Mike Stump11289f42009-09-09 15:08:12 +00009663
Douglas Gregora16548e2009-08-11 05:31:07 +00009664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009666TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009667 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009668 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009670
John McCalldadc5752010-08-24 06:29:42 +00009671 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009672 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009673 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009674
Douglas Gregora16548e2009-08-11 05:31:07 +00009675 if (!getDerived().AlwaysRebuild() &&
9676 LHS.get() == E->getLHS() &&
9677 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009678 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009679
Lang Hames5de91cc2012-10-02 04:45:10 +00009680 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009681 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009682
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009684 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009685}
9686
Mike Stump11289f42009-09-09 15:08:12 +00009687template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009688ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009689TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009690 CompoundAssignOperator *E) {
9691 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009692}
Mike Stump11289f42009-09-09 15:08:12 +00009693
Douglas Gregora16548e2009-08-11 05:31:07 +00009694template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009695ExprResult TreeTransform<Derived>::
9696TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9697 // Just rebuild the common and RHS expressions and see whether we
9698 // get any changes.
9699
9700 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9701 if (commonExpr.isInvalid())
9702 return ExprError();
9703
9704 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9705 if (rhs.isInvalid())
9706 return ExprError();
9707
9708 if (!getDerived().AlwaysRebuild() &&
9709 commonExpr.get() == e->getCommon() &&
9710 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009711 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009712
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009713 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009714 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009715 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009716 e->getColonLoc(),
9717 rhs.get());
9718}
9719
9720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009722TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009723 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009724 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009726
John McCalldadc5752010-08-24 06:29:42 +00009727 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009728 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009729 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009730
John McCalldadc5752010-08-24 06:29:42 +00009731 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009732 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009733 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009734
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 if (!getDerived().AlwaysRebuild() &&
9736 Cond.get() == E->getCond() &&
9737 LHS.get() == E->getLHS() &&
9738 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009739 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009740
John McCallb268a282010-08-23 23:25:46 +00009741 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009742 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009743 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009744 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009745 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009746}
Mike Stump11289f42009-09-09 15:08:12 +00009747
9748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009750TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009751 // Implicit casts are eliminated during transformation, since they
9752 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009753 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009754}
Mike Stump11289f42009-09-09 15:08:12 +00009755
Douglas Gregora16548e2009-08-11 05:31:07 +00009756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009757ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009758TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009759 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9760 if (!Type)
9761 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009762
John McCalldadc5752010-08-24 06:29:42 +00009763 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009764 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009765 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009766 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009767
Douglas Gregora16548e2009-08-11 05:31:07 +00009768 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009769 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009770 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009771 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009772
John McCall97513962010-01-15 18:39:57 +00009773 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009774 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009775 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009776 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009777}
Mike Stump11289f42009-09-09 15:08:12 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009780ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009781TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009782 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9783 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9784 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009786
John McCalldadc5752010-08-24 06:29:42 +00009787 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009789 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009790
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009792 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009793 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009794 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009795
John McCall5d7aa7f2010-01-19 22:33:45 +00009796 // Note: the expression type doesn't necessarily match the
9797 // type-as-written, but that's okay, because it should always be
9798 // derivable from the initializer.
9799
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009800 return getDerived().RebuildCompoundLiteralExpr(
9801 E->getLParenLoc(), NewT,
9802 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009803}
Mike Stump11289f42009-09-09 15:08:12 +00009804
Douglas Gregora16548e2009-08-11 05:31:07 +00009805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009807TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009808 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009809 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009811
Douglas Gregora16548e2009-08-11 05:31:07 +00009812 if (!getDerived().AlwaysRebuild() &&
9813 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009814 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009815
Douglas Gregora16548e2009-08-11 05:31:07 +00009816 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009817 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009818 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009819 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009820 E->getAccessorLoc(),
9821 E->getAccessor());
9822}
Mike Stump11289f42009-09-09 15:08:12 +00009823
Douglas Gregora16548e2009-08-11 05:31:07 +00009824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009826TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009827 if (InitListExpr *Syntactic = E->getSyntacticForm())
9828 E = Syntactic;
9829
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009831
Richard Smith12938cf2018-09-26 04:36:55 +00009832 EnterExpressionEvaluationContext Context(
9833 getSema(), EnterExpressionEvaluationContext::InitList);
9834
Benjamin Kramerf0623432012-08-23 22:51:59 +00009835 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009836 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009837 Inits, &InitChanged))
9838 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009839
Richard Smith520449d2015-02-05 06:15:50 +00009840 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9841 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9842 // in some cases. We can't reuse it in general, because the syntactic and
9843 // semantic forms are linked, and we can't know that semantic form will
9844 // match even if the syntactic form does.
9845 }
Mike Stump11289f42009-09-09 15:08:12 +00009846
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009847 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009848 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009849}
Mike Stump11289f42009-09-09 15:08:12 +00009850
Douglas Gregora16548e2009-08-11 05:31:07 +00009851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009853TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009854 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009855
Douglas Gregorebe10102009-08-20 07:17:43 +00009856 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009857 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009858 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009860
Douglas Gregorebe10102009-08-20 07:17:43 +00009861 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009862 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009864 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9865 if (D.isFieldDesignator()) {
9866 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9867 D.getDotLoc(),
9868 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009869 if (D.getField()) {
9870 FieldDecl *Field = cast_or_null<FieldDecl>(
9871 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9872 if (Field != D.getField())
9873 // Rebuild the expression when the transformed FieldDecl is
9874 // different to the already assigned FieldDecl.
9875 ExprChanged = true;
9876 } else {
9877 // Ensure that the designator expression is rebuilt when there isn't
9878 // a resolved FieldDecl in the designator as we don't want to assign
9879 // a FieldDecl to a pattern designator that will be instantiated again.
9880 ExprChanged = true;
9881 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009882 continue;
9883 }
Mike Stump11289f42009-09-09 15:08:12 +00009884
David Majnemerf7e36092016-06-23 00:15:04 +00009885 if (D.isArrayDesignator()) {
9886 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009887 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009889
David Majnemerf7e36092016-06-23 00:15:04 +00009890 Desig.AddDesignator(
9891 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009892
David Majnemerf7e36092016-06-23 00:15:04 +00009893 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009894 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009895 continue;
9896 }
Mike Stump11289f42009-09-09 15:08:12 +00009897
David Majnemerf7e36092016-06-23 00:15:04 +00009898 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009899 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009900 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009901 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009902 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009903
David Majnemerf7e36092016-06-23 00:15:04 +00009904 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009905 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009906 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009907
9908 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009909 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009910 D.getLBracketLoc(),
9911 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009912
David Majnemerf7e36092016-06-23 00:15:04 +00009913 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9914 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009915
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009916 ArrayExprs.push_back(Start.get());
9917 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009918 }
Mike Stump11289f42009-09-09 15:08:12 +00009919
Douglas Gregora16548e2009-08-11 05:31:07 +00009920 if (!getDerived().AlwaysRebuild() &&
9921 Init.get() == E->getInit() &&
9922 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009923 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009924
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009925 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009926 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009927 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009928}
Mike Stump11289f42009-09-09 15:08:12 +00009929
Yunzhong Gaocb779302015-06-10 00:27:52 +00009930// Seems that if TransformInitListExpr() only works on the syntactic form of an
9931// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9932template<typename Derived>
9933ExprResult
9934TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9935 DesignatedInitUpdateExpr *E) {
9936 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9937 "initializer");
9938 return ExprError();
9939}
9940
9941template<typename Derived>
9942ExprResult
9943TreeTransform<Derived>::TransformNoInitExpr(
9944 NoInitExpr *E) {
9945 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9946 return ExprError();
9947}
9948
Douglas Gregora16548e2009-08-11 05:31:07 +00009949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009950ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009951TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9952 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9953 return ExprError();
9954}
9955
9956template<typename Derived>
9957ExprResult
9958TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9959 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9960 return ExprError();
9961}
9962
9963template<typename Derived>
9964ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009965TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009966 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009967 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009968
Douglas Gregor3da3c062009-10-28 00:29:27 +00009969 // FIXME: Will we ever have proper type location here? Will we actually
9970 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009971 QualType T = getDerived().TransformType(E->getType());
9972 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009974
Douglas Gregora16548e2009-08-11 05:31:07 +00009975 if (!getDerived().AlwaysRebuild() &&
9976 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009977 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009978
Douglas Gregora16548e2009-08-11 05:31:07 +00009979 return getDerived().RebuildImplicitValueInitExpr(T);
9980}
Mike Stump11289f42009-09-09 15:08:12 +00009981
Douglas Gregora16548e2009-08-11 05:31:07 +00009982template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009983ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009984TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009985 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9986 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009988
John McCalldadc5752010-08-24 06:29:42 +00009989 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009990 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009992
Douglas Gregora16548e2009-08-11 05:31:07 +00009993 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009994 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009995 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009996 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009997
John McCallb268a282010-08-23 23:25:46 +00009998 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009999 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010000}
10001
10002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010003ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010004TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010005 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010006 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +000010007 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
10008 &ArgumentChanged))
10009 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010010
Douglas Gregora16548e2009-08-11 05:31:07 +000010011 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010012 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +000010013 E->getRParenLoc());
10014}
Mike Stump11289f42009-09-09 15:08:12 +000010015
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010016/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010017///
10018/// By default, the transformation of an address-of-label expression always
10019/// rebuilds the expression, so that the label identifier can be resolved to
10020/// the corresponding label statement by semantic analysis.
10021template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010022ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010023TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +000010024 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
10025 E->getLabel());
10026 if (!LD)
10027 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010028
Douglas Gregora16548e2009-08-11 05:31:07 +000010029 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +000010030 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +000010031}
Mike Stump11289f42009-09-09 15:08:12 +000010032
10033template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010034ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010035TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +000010036 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +000010037 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +000010038 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +000010039 if (SubStmt.isInvalid()) {
10040 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +000010041 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +000010042 }
Mike Stump11289f42009-09-09 15:08:12 +000010043
Douglas Gregora16548e2009-08-11 05:31:07 +000010044 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +000010045 SubStmt.get() == E->getSubStmt()) {
10046 // Calling this an 'error' is unintuitive, but it does the right thing.
10047 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010048 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +000010049 }
Mike Stump11289f42009-09-09 15:08:12 +000010050
10051 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010052 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010053 E->getRParenLoc());
10054}
Mike Stump11289f42009-09-09 15:08:12 +000010055
Douglas Gregora16548e2009-08-11 05:31:07 +000010056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010058TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010059 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +000010060 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010062
John McCalldadc5752010-08-24 06:29:42 +000010063 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010064 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010066
John McCalldadc5752010-08-24 06:29:42 +000010067 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010068 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010069 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010070
Douglas Gregora16548e2009-08-11 05:31:07 +000010071 if (!getDerived().AlwaysRebuild() &&
10072 Cond.get() == E->getCond() &&
10073 LHS.get() == E->getLHS() &&
10074 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010075 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregora16548e2009-08-11 05:31:07 +000010077 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +000010078 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010079 E->getRParenLoc());
10080}
Mike Stump11289f42009-09-09 15:08:12 +000010081
Douglas Gregora16548e2009-08-11 05:31:07 +000010082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010083ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010084TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010085 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010086}
10087
10088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010089ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010090TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010091 switch (E->getOperator()) {
10092 case OO_New:
10093 case OO_Delete:
10094 case OO_Array_New:
10095 case OO_Array_Delete:
10096 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +000010097
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010098 case OO_Call: {
10099 // This is a call to an object's operator().
10100 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
10101
10102 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +000010103 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010104 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010105 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010106
10107 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +000010108 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010109 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010110
10111 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010112 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010113 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +000010114 Args))
10115 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010116
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010117 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
10118 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010119 }
10120
10121#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
10122 case OO_##Name:
10123#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
10124#include "clang/Basic/OperatorKinds.def"
10125 case OO_Subscript:
10126 // Handled below.
10127 break;
10128
10129 case OO_Conditional:
10130 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010131
10132 case OO_None:
10133 case NUM_OVERLOADED_OPERATORS:
10134 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010135 }
10136
John McCalldadc5752010-08-24 06:29:42 +000010137 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +000010138 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010139 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010140
Richard Smithdb2630f2012-10-21 03:28:35 +000010141 ExprResult First;
10142 if (E->getOperator() == OO_Amp)
10143 First = getDerived().TransformAddressOfOperand(E->getArg(0));
10144 else
10145 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +000010146 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010147 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010148
John McCalldadc5752010-08-24 06:29:42 +000010149 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +000010150 if (E->getNumArgs() == 2) {
10151 Second = getDerived().TransformExpr(E->getArg(1));
10152 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010153 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010154 }
Mike Stump11289f42009-09-09 15:08:12 +000010155
Douglas Gregora16548e2009-08-11 05:31:07 +000010156 if (!getDerived().AlwaysRebuild() &&
10157 Callee.get() == E->getCallee() &&
10158 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +000010159 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010160 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +000010161
Lang Hames5de91cc2012-10-02 04:45:10 +000010162 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +000010163 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +000010164
Douglas Gregora16548e2009-08-11 05:31:07 +000010165 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
10166 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +000010167 Callee.get(),
10168 First.get(),
10169 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010170}
Mike Stump11289f42009-09-09 15:08:12 +000010171
Douglas Gregora16548e2009-08-11 05:31:07 +000010172template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010173ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010174TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10175 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010176}
Mike Stump11289f42009-09-09 15:08:12 +000010177
Eric Fiselier708afb52019-05-16 21:04:15 +000010178template <typename Derived>
10179ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
10180 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
10181 getSema().CurContext != E->getParentContext();
10182
10183 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
10184 return E;
10185
10186 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
10187 E->getEndLoc(),
10188 getSema().CurContext);
10189}
10190
Douglas Gregora16548e2009-08-11 05:31:07 +000010191template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010192ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +000010193TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10194 // Transform the callee.
10195 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10196 if (Callee.isInvalid())
10197 return ExprError();
10198
10199 // Transform exec config.
10200 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10201 if (EC.isInvalid())
10202 return ExprError();
10203
10204 // Transform arguments.
10205 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010206 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010207 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010208 &ArgChanged))
10209 return ExprError();
10210
10211 if (!getDerived().AlwaysRebuild() &&
10212 Callee.get() == E->getCallee() &&
10213 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010214 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010215
10216 // FIXME: Wrong source location information for the '('.
10217 SourceLocation FakeLParenLoc
10218 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10219 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010220 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010221 E->getRParenLoc(), EC.get());
10222}
10223
10224template<typename Derived>
10225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010226TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010227 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10228 if (!Type)
10229 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010230
John McCalldadc5752010-08-24 06:29:42 +000010231 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010232 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010233 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010234 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010235
Douglas Gregora16548e2009-08-11 05:31:07 +000010236 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010237 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010238 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010239 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010240 return getDerived().RebuildCXXNamedCastExpr(
10241 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10242 Type, E->getAngleBrackets().getEnd(),
10243 // FIXME. this should be '(' location
10244 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010245}
Mike Stump11289f42009-09-09 15:08:12 +000010246
Douglas Gregora16548e2009-08-11 05:31:07 +000010247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010248ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010249TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10250 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010251}
Mike Stump11289f42009-09-09 15:08:12 +000010252
10253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010255TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10256 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010257}
10258
Douglas Gregora16548e2009-08-11 05:31:07 +000010259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010260ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010261TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010262 CXXReinterpretCastExpr *E) {
10263 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010264}
Mike Stump11289f42009-09-09 15:08:12 +000010265
Douglas Gregora16548e2009-08-11 05:31:07 +000010266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010268TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10269 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010270}
Mike Stump11289f42009-09-09 15:08:12 +000010271
Douglas Gregora16548e2009-08-11 05:31:07 +000010272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010273ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010274TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010275 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010276 TypeSourceInfo *Type =
10277 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010278 if (!Type)
10279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010280
John McCalldadc5752010-08-24 06:29:42 +000010281 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010282 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010283 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010284 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010285
Douglas Gregora16548e2009-08-11 05:31:07 +000010286 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010287 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010288 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010289 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010290
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010291 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010292 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010293 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010294 E->getRParenLoc(),
10295 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010296}
Mike Stump11289f42009-09-09 15:08:12 +000010297
Douglas Gregora16548e2009-08-11 05:31:07 +000010298template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010299ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010300TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010301 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010302 TypeSourceInfo *TInfo
10303 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10304 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010306
Douglas Gregora16548e2009-08-11 05:31:07 +000010307 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010308 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010309 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010310
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010311 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010312 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010313 }
Mike Stump11289f42009-09-09 15:08:12 +000010314
Eli Friedman456f0182012-01-20 01:26:23 +000010315 // We don't know whether the subexpression is potentially evaluated until
10316 // after we perform semantic analysis. We speculatively assume it is
10317 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010318 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010319 EnterExpressionEvaluationContext Unevaluated(
10320 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10321 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010322
John McCalldadc5752010-08-24 06:29:42 +000010323 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010324 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010325 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010326
Douglas Gregora16548e2009-08-11 05:31:07 +000010327 if (!getDerived().AlwaysRebuild() &&
10328 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010329 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010330
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010331 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010332 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010333}
10334
10335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010336ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010337TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10338 if (E->isTypeOperand()) {
10339 TypeSourceInfo *TInfo
10340 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10341 if (!TInfo)
10342 return ExprError();
10343
10344 if (!getDerived().AlwaysRebuild() &&
10345 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010346 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010347
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010348 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010349 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010350 }
10351
Faisal Valid143a0c2017-04-01 21:30:49 +000010352 EnterExpressionEvaluationContext Unevaluated(
10353 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010354
10355 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10356 if (SubExpr.isInvalid())
10357 return ExprError();
10358
10359 if (!getDerived().AlwaysRebuild() &&
10360 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010361 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010362
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010363 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010364 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010365}
10366
10367template<typename Derived>
10368ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010369TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010370 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010371}
Mike Stump11289f42009-09-09 15:08:12 +000010372
Douglas Gregora16548e2009-08-11 05:31:07 +000010373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010374ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010375TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010376 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010377 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010378}
Mike Stump11289f42009-09-09 15:08:12 +000010379
Douglas Gregora16548e2009-08-11 05:31:07 +000010380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010382TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010383 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010384
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010385 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
Richard Smith8458c9e2019-05-24 01:35:07 +000010386 // Mark it referenced in the new context regardless.
10387 // FIXME: this is a bit instantiation-specific.
10388 getSema().MarkThisReferenced(E);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010389 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010390 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010391
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010392 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010393}
Mike Stump11289f42009-09-09 15:08:12 +000010394
Douglas Gregora16548e2009-08-11 05:31:07 +000010395template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010396ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010397TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010398 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010399 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010400 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010401
Douglas Gregora16548e2009-08-11 05:31:07 +000010402 if (!getDerived().AlwaysRebuild() &&
10403 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010404 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010405
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010406 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10407 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010408}
Mike Stump11289f42009-09-09 15:08:12 +000010409
Douglas Gregora16548e2009-08-11 05:31:07 +000010410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010412TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010413 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10414 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010415 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010416 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010417
Eric Fiselier708afb52019-05-16 21:04:15 +000010418 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
10419 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010420 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010421
Douglas Gregor033f6752009-12-23 23:03:06 +000010422 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010423}
Mike Stump11289f42009-09-09 15:08:12 +000010424
Douglas Gregora16548e2009-08-11 05:31:07 +000010425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010426ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010427TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010428 FieldDecl *Field = cast_or_null<FieldDecl>(
10429 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010430 if (!Field)
10431 return ExprError();
10432
Eric Fiselier708afb52019-05-16 21:04:15 +000010433 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
10434 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010435 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010436
10437 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10438}
10439
10440template<typename Derived>
10441ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010442TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10443 CXXScalarValueInitExpr *E) {
10444 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10445 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010446 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010447
Douglas Gregora16548e2009-08-11 05:31:07 +000010448 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010449 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010450 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010451
Chad Rosier1dcde962012-08-08 18:46:20 +000010452 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010453 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010454 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010455}
Mike Stump11289f42009-09-09 15:08:12 +000010456
Douglas Gregora16548e2009-08-11 05:31:07 +000010457template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010458ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010459TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010460 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010461 TypeSourceInfo *AllocTypeInfo =
10462 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010463 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010465
Douglas Gregora16548e2009-08-11 05:31:07 +000010466 // Transform the size of the array we're allocating (if any).
Richard Smithb9fb1212019-05-06 03:47:15 +000010467 Optional<Expr *> ArraySize;
10468 if (Optional<Expr *> OldArraySize = E->getArraySize()) {
10469 ExprResult NewArraySize;
10470 if (*OldArraySize) {
10471 NewArraySize = getDerived().TransformExpr(*OldArraySize);
10472 if (NewArraySize.isInvalid())
10473 return ExprError();
10474 }
10475 ArraySize = NewArraySize.get();
10476 }
Mike Stump11289f42009-09-09 15:08:12 +000010477
Douglas Gregora16548e2009-08-11 05:31:07 +000010478 // Transform the placement arguments (if any).
10479 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010480 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010481 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010482 E->getNumPlacementArgs(), true,
10483 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010484 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010485
Sebastian Redl6047f072012-02-16 12:22:20 +000010486 // Transform the initializer (if any).
10487 Expr *OldInit = E->getInitializer();
10488 ExprResult NewInit;
10489 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010490 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010491 if (NewInit.isInvalid())
10492 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010493
Sebastian Redl6047f072012-02-16 12:22:20 +000010494 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010495 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010496 if (E->getOperatorNew()) {
10497 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010498 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010499 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010500 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010501 }
10502
Craig Topperc3ec1492014-05-26 06:22:03 +000010503 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010504 if (E->getOperatorDelete()) {
10505 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010506 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010507 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010508 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010509 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010510
Douglas Gregora16548e2009-08-11 05:31:07 +000010511 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010512 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Richard Smithb9fb1212019-05-06 03:47:15 +000010513 ArraySize == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010514 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010515 OperatorNew == E->getOperatorNew() &&
10516 OperatorDelete == E->getOperatorDelete() &&
10517 !ArgumentChanged) {
10518 // Mark any declarations we need as referenced.
10519 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010520 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010521 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010522 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010523 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010524
Sebastian Redl6047f072012-02-16 12:22:20 +000010525 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010526 QualType ElementType
10527 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10528 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10529 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10530 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010531 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010532 }
10533 }
10534 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010535
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010536 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010537 }
Mike Stump11289f42009-09-09 15:08:12 +000010538
Douglas Gregor0744ef62010-09-07 21:49:58 +000010539 QualType AllocType = AllocTypeInfo->getType();
Richard Smithb9fb1212019-05-06 03:47:15 +000010540 if (!ArraySize) {
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010541 // If no array size was specified, but the new expression was
10542 // instantiated with an array type (e.g., "new T" where T is
10543 // instantiated with "int[4]"), extract the outer bound from the
10544 // array type as our array size. We do this with constant and
10545 // dependently-sized array types.
10546 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10547 if (!ArrayT) {
10548 // Do nothing
10549 } else if (const ConstantArrayType *ConsArrayT
10550 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010551 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10552 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010553 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010554 AllocType = ConsArrayT->getElementType();
10555 } else if (const DependentSizedArrayType *DepArrayT
10556 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10557 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010558 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010559 AllocType = DepArrayT->getElementType();
10560 }
10561 }
10562 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010563
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010564 return getDerived().RebuildCXXNewExpr(
10565 E->getBeginLoc(), E->isGlobalNew(),
10566 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10567 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
Richard Smithb9fb1212019-05-06 03:47:15 +000010568 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010569}
Mike Stump11289f42009-09-09 15:08:12 +000010570
Douglas Gregora16548e2009-08-11 05:31:07 +000010571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010572ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010573TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010574 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010575 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010576 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010577
Douglas Gregord2d9da02010-02-26 00:38:10 +000010578 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010579 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010580 if (E->getOperatorDelete()) {
10581 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010582 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010583 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010584 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010585 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010586
Douglas Gregora16548e2009-08-11 05:31:07 +000010587 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010588 Operand.get() == E->getArgument() &&
10589 OperatorDelete == E->getOperatorDelete()) {
10590 // Mark any declarations we need as referenced.
10591 // FIXME: instantiation-specific.
10592 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010593 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010594
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010595 if (!E->getArgument()->isTypeDependent()) {
10596 QualType Destroyed = SemaRef.Context.getBaseElementType(
10597 E->getDestroyedType());
10598 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10599 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010600 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010601 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010602 }
10603 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010604
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010605 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010606 }
Mike Stump11289f42009-09-09 15:08:12 +000010607
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010608 return getDerived().RebuildCXXDeleteExpr(
10609 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010610}
Mike Stump11289f42009-09-09 15:08:12 +000010611
Douglas Gregora16548e2009-08-11 05:31:07 +000010612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010613ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010614TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010615 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010616 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010617 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010618 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010619
John McCallba7bf592010-08-24 05:47:05 +000010620 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010621 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010622 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010623 E->getOperatorLoc(),
10624 E->isArrow()? tok::arrow : tok::period,
10625 ObjectTypePtr,
10626 MayBePseudoDestructor);
10627 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010628 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010629
John McCallba7bf592010-08-24 05:47:05 +000010630 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010631 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10632 if (QualifierLoc) {
10633 QualifierLoc
10634 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10635 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010636 return ExprError();
10637 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010638 CXXScopeSpec SS;
10639 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010640
Douglas Gregor678f90d2010-02-25 01:56:36 +000010641 PseudoDestructorTypeStorage Destroyed;
10642 if (E->getDestroyedTypeInfo()) {
10643 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010644 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010645 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010646 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010647 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010648 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010649 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010650 // We aren't likely to be able to resolve the identifier down to a type
10651 // now anyway, so just retain the identifier.
10652 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10653 E->getDestroyedTypeLoc());
10654 } else {
10655 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010656 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010657 *E->getDestroyedTypeIdentifier(),
10658 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010659 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010660 SS, ObjectTypePtr,
10661 false);
10662 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010663 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010664
Douglas Gregor678f90d2010-02-25 01:56:36 +000010665 Destroyed
10666 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10667 E->getDestroyedTypeLoc());
10668 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010669
Craig Topperc3ec1492014-05-26 06:22:03 +000010670 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010671 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010672 CXXScopeSpec EmptySS;
10673 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010674 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010675 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010676 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010677 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010678
John McCallb268a282010-08-23 23:25:46 +000010679 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010680 E->getOperatorLoc(),
10681 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010682 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010683 ScopeTypeInfo,
10684 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010685 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010686 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010687}
Mike Stump11289f42009-09-09 15:08:12 +000010688
Richard Smith151c4562016-12-20 21:35:28 +000010689template <typename Derived>
10690bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10691 bool RequiresADL,
10692 LookupResult &R) {
10693 // Transform all the decls.
10694 bool AllEmptyPacks = true;
10695 for (auto *OldD : Old->decls()) {
10696 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10697 if (!InstD) {
10698 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10699 // This can happen because of dependent hiding.
10700 if (isa<UsingShadowDecl>(OldD))
10701 continue;
10702 else {
10703 R.clear();
10704 return true;
10705 }
10706 }
10707
10708 // Expand using pack declarations.
10709 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10710 ArrayRef<NamedDecl*> Decls = SingleDecl;
10711 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10712 Decls = UPD->expansions();
10713
10714 // Expand using declarations.
10715 for (auto *D : Decls) {
10716 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10717 for (auto *SD : UD->shadows())
10718 R.addDecl(SD);
10719 } else {
10720 R.addDecl(D);
10721 }
10722 }
10723
10724 AllEmptyPacks &= Decls.empty();
10725 };
10726
10727 // C++ [temp.res]/8.4.2:
10728 // The program is ill-formed, no diagnostic required, if [...] lookup for
10729 // a name in the template definition found a using-declaration, but the
10730 // lookup in the corresponding scope in the instantiation odoes not find
10731 // any declarations because the using-declaration was a pack expansion and
10732 // the corresponding pack is empty
10733 if (AllEmptyPacks && !RequiresADL) {
10734 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010735 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010736 return true;
10737 }
10738
10739 // Resolve a kind, but don't do any further analysis. If it's
10740 // ambiguous, the callee needs to deal with it.
10741 R.resolveKind();
10742 return false;
10743}
10744
Douglas Gregorad8a3362009-09-04 17:36:40 +000010745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010746ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010747TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010748 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010749 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10750 Sema::LookupOrdinaryName);
10751
Richard Smith151c4562016-12-20 21:35:28 +000010752 // Transform the declaration set.
10753 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10754 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010755
10756 // Rebuild the nested-name qualifier, if present.
10757 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010758 if (Old->getQualifierLoc()) {
10759 NestedNameSpecifierLoc QualifierLoc
10760 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10761 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010763
Douglas Gregor0da1d432011-02-28 20:01:57 +000010764 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010765 }
10766
Douglas Gregor9262f472010-04-27 18:19:34 +000010767 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010768 CXXRecordDecl *NamingClass
10769 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10770 Old->getNameLoc(),
10771 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010772 if (!NamingClass) {
10773 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010774 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010775 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010776
Douglas Gregorda7be082010-04-27 16:10:10 +000010777 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010778 }
10779
Abramo Bagnara7945c982012-01-27 09:46:47 +000010780 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10781
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010782 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010783 // it's a normal declaration name or member reference.
10784 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10785 NamedDecl *D = R.getAsSingle<NamedDecl>();
10786 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10787 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10788 // give a good diagnostic.
10789 if (D && D->isCXXInstanceMember()) {
10790 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10791 /*TemplateArgs=*/nullptr,
10792 /*Scope=*/nullptr);
10793 }
10794
John McCalle66edc12009-11-24 19:00:30 +000010795 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010796 }
John McCalle66edc12009-11-24 19:00:30 +000010797
10798 // If we have template arguments, rebuild them, then rebuild the
10799 // templateid expression.
10800 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010801 if (Old->hasExplicitTemplateArgs() &&
10802 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010803 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010804 TransArgs)) {
10805 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010806 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010807 }
John McCalle66edc12009-11-24 19:00:30 +000010808
Abramo Bagnara7945c982012-01-27 09:46:47 +000010809 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010810 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010811}
Mike Stump11289f42009-09-09 15:08:12 +000010812
Douglas Gregora16548e2009-08-11 05:31:07 +000010813template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010814ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010815TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10816 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010817 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010818 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10819 TypeSourceInfo *From = E->getArg(I);
10820 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010821 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010822 TypeLocBuilder TLB;
10823 TLB.reserve(FromTL.getFullDataSize());
10824 QualType To = getDerived().TransformType(TLB, FromTL);
10825 if (To.isNull())
10826 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010827
Douglas Gregor29c42f22012-02-24 07:38:34 +000010828 if (To == From->getType())
10829 Args.push_back(From);
10830 else {
10831 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10832 ArgChanged = true;
10833 }
10834 continue;
10835 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010836
Douglas Gregor29c42f22012-02-24 07:38:34 +000010837 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010838
Douglas Gregor29c42f22012-02-24 07:38:34 +000010839 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010840 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010841 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10842 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10843 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010844
Douglas Gregor29c42f22012-02-24 07:38:34 +000010845 // Determine whether the set of unexpanded parameter packs can and should
10846 // be expanded.
10847 bool Expand = true;
10848 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010849 Optional<unsigned> OrigNumExpansions =
10850 ExpansionTL.getTypePtr()->getNumExpansions();
10851 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010852 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10853 PatternTL.getSourceRange(),
10854 Unexpanded,
10855 Expand, RetainExpansion,
10856 NumExpansions))
10857 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010858
Douglas Gregor29c42f22012-02-24 07:38:34 +000010859 if (!Expand) {
10860 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010861 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010862 // expansion.
10863 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010864
Douglas Gregor29c42f22012-02-24 07:38:34 +000010865 TypeLocBuilder TLB;
10866 TLB.reserve(From->getTypeLoc().getFullDataSize());
10867
10868 QualType To = getDerived().TransformType(TLB, PatternTL);
10869 if (To.isNull())
10870 return ExprError();
10871
Chad Rosier1dcde962012-08-08 18:46:20 +000010872 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010873 PatternTL.getSourceRange(),
10874 ExpansionTL.getEllipsisLoc(),
10875 NumExpansions);
10876 if (To.isNull())
10877 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010878
Douglas Gregor29c42f22012-02-24 07:38:34 +000010879 PackExpansionTypeLoc ToExpansionTL
10880 = TLB.push<PackExpansionTypeLoc>(To);
10881 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10882 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10883 continue;
10884 }
10885
10886 // Expand the pack expansion by substituting for each argument in the
10887 // pack(s).
10888 for (unsigned I = 0; I != *NumExpansions; ++I) {
10889 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10890 TypeLocBuilder TLB;
10891 TLB.reserve(PatternTL.getFullDataSize());
10892 QualType To = getDerived().TransformType(TLB, PatternTL);
10893 if (To.isNull())
10894 return ExprError();
10895
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010896 if (To->containsUnexpandedParameterPack()) {
10897 To = getDerived().RebuildPackExpansionType(To,
10898 PatternTL.getSourceRange(),
10899 ExpansionTL.getEllipsisLoc(),
10900 NumExpansions);
10901 if (To.isNull())
10902 return ExprError();
10903
10904 PackExpansionTypeLoc ToExpansionTL
10905 = TLB.push<PackExpansionTypeLoc>(To);
10906 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10907 }
10908
Douglas Gregor29c42f22012-02-24 07:38:34 +000010909 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10910 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010911
Douglas Gregor29c42f22012-02-24 07:38:34 +000010912 if (!RetainExpansion)
10913 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010914
Douglas Gregor29c42f22012-02-24 07:38:34 +000010915 // If we're supposed to retain a pack expansion, do so by temporarily
10916 // forgetting the partially-substituted parameter pack.
10917 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10918
10919 TypeLocBuilder TLB;
10920 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010921
Douglas Gregor29c42f22012-02-24 07:38:34 +000010922 QualType To = getDerived().TransformType(TLB, PatternTL);
10923 if (To.isNull())
10924 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010925
10926 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010927 PatternTL.getSourceRange(),
10928 ExpansionTL.getEllipsisLoc(),
10929 NumExpansions);
10930 if (To.isNull())
10931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010932
Douglas Gregor29c42f22012-02-24 07:38:34 +000010933 PackExpansionTypeLoc ToExpansionTL
10934 = TLB.push<PackExpansionTypeLoc>(To);
10935 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10936 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10937 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010938
Douglas Gregor29c42f22012-02-24 07:38:34 +000010939 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010940 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010941
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010942 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010943 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010944}
10945
10946template<typename Derived>
10947ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010948TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10949 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10950 if (!T)
10951 return ExprError();
10952
10953 if (!getDerived().AlwaysRebuild() &&
10954 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010955 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010956
10957 ExprResult SubExpr;
10958 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010959 EnterExpressionEvaluationContext Unevaluated(
10960 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010961 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10962 if (SubExpr.isInvalid())
10963 return ExprError();
10964
10965 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010966 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010967 }
10968
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010969 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010970 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010971}
10972
10973template<typename Derived>
10974ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010975TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10976 ExprResult SubExpr;
10977 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010978 EnterExpressionEvaluationContext Unevaluated(
10979 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010980 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10981 if (SubExpr.isInvalid())
10982 return ExprError();
10983
10984 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010985 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010986 }
10987
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010988 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010989 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010990}
10991
Reid Kleckner32506ed2014-06-12 23:03:48 +000010992template <typename Derived>
10993ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10994 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10995 TypeSourceInfo **RecoveryTSI) {
10996 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10997 DRE, AddrTaken, RecoveryTSI);
10998
10999 // Propagate both errors and recovered types, which return ExprEmpty.
11000 if (!NewDRE.isUsable())
11001 return NewDRE;
11002
11003 // We got an expr, wrap it up in parens.
11004 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
11005 return PE;
11006 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
11007 PE->getRParen());
11008}
11009
11010template <typename Derived>
11011ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11012 DependentScopeDeclRefExpr *E) {
11013 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
11014 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000011015}
11016
11017template<typename Derived>
11018ExprResult
11019TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11020 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000011021 bool IsAddressOfOperand,
11022 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000011023 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011024 NestedNameSpecifierLoc QualifierLoc
11025 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11026 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011027 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000011028 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000011029
John McCall31f82722010-11-12 08:19:04 +000011030 // TODO: If this is a conversion-function-id, verify that the
11031 // destination type name (if present) resolves the same way after
11032 // instantiation as it did in the local scope.
11033
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011034 DeclarationNameInfo NameInfo
11035 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
11036 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011038
John McCalle66edc12009-11-24 19:00:30 +000011039 if (!E->hasExplicitTemplateArgs()) {
11040 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011041 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011042 // Note: it is sufficient to compare the Name component of NameInfo:
11043 // if name has not changed, DNLoc has not changed either.
11044 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011045 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011046
Reid Kleckner32506ed2014-06-12 23:03:48 +000011047 return getDerived().RebuildDependentScopeDeclRefExpr(
11048 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
11049 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000011050 }
John McCall6b51f282009-11-23 01:53:49 +000011051
11052 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011053 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11054 E->getNumTemplateArgs(),
11055 TransArgs))
11056 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011057
Reid Kleckner32506ed2014-06-12 23:03:48 +000011058 return getDerived().RebuildDependentScopeDeclRefExpr(
11059 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
11060 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000011061}
11062
11063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011065TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000011066 // CXXConstructExprs other than for list-initialization and
11067 // CXXTemporaryObjectExpr are always implicit, so when we have
11068 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000011069 if ((E->getNumArgs() == 1 ||
11070 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000011071 (!getDerived().DropCallArgument(E->getArg(0))) &&
11072 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000011073 return getDerived().TransformExpr(E->getArg(0));
11074
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011075 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000011076
11077 QualType T = getDerived().TransformType(E->getType());
11078 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000011079 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011080
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011081 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11082 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011083 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011084 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011085
Douglas Gregora16548e2009-08-11 05:31:07 +000011086 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011087 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000011088 {
11089 EnterExpressionEvaluationContext Context(
11090 getSema(), EnterExpressionEvaluationContext::InitList,
11091 E->isListInitialization());
11092 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11093 &ArgumentChanged))
11094 return ExprError();
11095 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011096
Douglas Gregora16548e2009-08-11 05:31:07 +000011097 if (!getDerived().AlwaysRebuild() &&
11098 T == E->getType() &&
11099 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000011100 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000011101 // Mark the constructor as referenced.
11102 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011103 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011104 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000011105 }
Mike Stump11289f42009-09-09 15:08:12 +000011106
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011107 return getDerived().RebuildCXXConstructExpr(
11108 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
11109 E->hadMultipleCandidates(), E->isListInitialization(),
11110 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
11111 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000011112}
Mike Stump11289f42009-09-09 15:08:12 +000011113
Richard Smith5179eb72016-06-28 19:03:57 +000011114template<typename Derived>
11115ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
11116 CXXInheritedCtorInitExpr *E) {
11117 QualType T = getDerived().TransformType(E->getType());
11118 if (T.isNull())
11119 return ExprError();
11120
11121 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011122 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000011123 if (!Constructor)
11124 return ExprError();
11125
11126 if (!getDerived().AlwaysRebuild() &&
11127 T == E->getType() &&
11128 Constructor == E->getConstructor()) {
11129 // Mark the constructor as referenced.
11130 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011131 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000011132 return E;
11133 }
11134
11135 return getDerived().RebuildCXXInheritedCtorInitExpr(
11136 T, E->getLocation(), Constructor,
11137 E->constructsVBase(), E->inheritedFromVBase());
11138}
11139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011140/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000011141///
Douglas Gregor363b1512009-12-24 18:51:59 +000011142/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
11143/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011146TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011147 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011148}
Mike Stump11289f42009-09-09 15:08:12 +000011149
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011150/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000011151/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000011152///
John McCall5d413782010-12-06 08:20:24 +000011153/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000011154/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011156ExprResult
John McCall5d413782010-12-06 08:20:24 +000011157TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011158 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011159}
Mike Stump11289f42009-09-09 15:08:12 +000011160
Douglas Gregora16548e2009-08-11 05:31:07 +000011161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011162ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011163TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000011164 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011165 TypeSourceInfo *T =
11166 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011167 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011168 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011169
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011170 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11171 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011172 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011174
Douglas Gregora16548e2009-08-11 05:31:07 +000011175 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011176 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000011177 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000011178 {
11179 EnterExpressionEvaluationContext Context(
11180 getSema(), EnterExpressionEvaluationContext::InitList,
11181 E->isListInitialization());
11182 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11183 &ArgumentChanged))
11184 return ExprError();
11185 }
Mike Stump11289f42009-09-09 15:08:12 +000011186
Douglas Gregora16548e2009-08-11 05:31:07 +000011187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011188 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011189 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011190 !ArgumentChanged) {
11191 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011192 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000011193 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011194 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011195
Vedant Kumara14a1f92018-01-17 18:53:51 +000011196 // FIXME: We should just pass E->isListInitialization(), but we're not
11197 // prepared to handle list-initialization without a child InitListExpr.
11198 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11199 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011200 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011201 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011202}
Mike Stump11289f42009-09-09 15:08:12 +000011203
Douglas Gregora16548e2009-08-11 05:31:07 +000011204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011205ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011206TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011207 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011208 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011209 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smithb2997f52019-05-21 20:10:50 +000011210 struct TransformedInitCapture {
11211 // The location of the ... if the result is retaining a pack expansion.
11212 SourceLocation EllipsisLoc;
11213 // Zero or more expansions of the init-capture.
11214 SmallVector<InitCaptureInfoTy, 4> Expansions;
11215 };
11216 SmallVector<TransformedInitCapture, 4> InitCaptures;
11217 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011218 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011219 CEnd = E->capture_end();
11220 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011221 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011222 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000011223
Richard Smithb2997f52019-05-21 20:10:50 +000011224 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011225 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011226
11227 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
11228 Optional<unsigned> NumExpansions) {
Richard Smithb2997f52019-05-21 20:10:50 +000011229 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11230 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
11231
11232 if (NewExprInitResult.isInvalid()) {
11233 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
11234 return;
11235 }
11236 Expr *NewExprInit = NewExprInitResult.get();
11237
11238 QualType NewInitCaptureType =
11239 getSema().buildLambdaInitCaptureInitialization(
11240 C->getLocation(), OldVD->getType()->isReferenceType(),
11241 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
11242 C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
11243 NewExprInit);
11244 Result.Expansions.push_back(
11245 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
11246 };
11247
11248 // If this is an init-capture pack, consider expanding the pack now.
11249 if (OldVD->isParameterPack()) {
11250 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
11251 ->getTypeLoc()
11252 .castAs<PackExpansionTypeLoc>();
11253 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11254 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
11255
11256 // Determine whether the set of unexpanded parameter packs can and should
11257 // be expanded.
11258 bool Expand = true;
11259 bool RetainExpansion = false;
11260 Optional<unsigned> OrigNumExpansions =
11261 ExpansionTL.getTypePtr()->getNumExpansions();
11262 Optional<unsigned> NumExpansions = OrigNumExpansions;
11263 if (getDerived().TryExpandParameterPacks(
11264 ExpansionTL.getEllipsisLoc(),
11265 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
11266 RetainExpansion, NumExpansions))
11267 return ExprError();
11268 if (Expand) {
11269 for (unsigned I = 0; I != *NumExpansions; ++I) {
11270 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11271 SubstInitCapture(SourceLocation(), None);
11272 }
11273 }
11274 if (!Expand || RetainExpansion) {
11275 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11276 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
11277 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
11278 }
11279 } else {
11280 SubstInitCapture(SourceLocation(), None);
11281 }
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011282 }
11283
Faisal Vali2cba1332013-10-23 06:44:28 +000011284 // Transform the template parameters, and add them to the current
11285 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011286 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011287 E->getTemplateParameterList());
11288
Richard Smith01014ce2014-11-20 23:53:14 +000011289 // Transform the type of the original lambda's call operator.
11290 // The transformation MUST be done in the CurrentInstantiationScope since
11291 // it introduces a mapping of the original to the newly created
11292 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011293 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011294 {
11295 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011296 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011297 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011298
11299 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011300 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011301 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011302 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011303 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011304 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11305 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11306 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011307 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011308 if (NewCallOpType.isNull())
11309 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011310 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11311 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011312 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011313
Richard Smithc38498f2015-04-27 21:27:54 +000011314 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11315 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11316 LSI->GLTemplateParameterList = TPL;
11317
Eli Friedmand564afb2012-09-19 01:18:11 +000011318 // Create the local class that will describe the lambda.
Richard Smith87346a12019-06-02 18:53:44 +000011319 CXXRecordDecl *OldClass = E->getLambdaClass();
Eli Friedmand564afb2012-09-19 01:18:11 +000011320 CXXRecordDecl *Class
11321 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011322 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011323 /*KnownDependent=*/false,
11324 E->getCaptureDefault());
Richard Smith87346a12019-06-02 18:53:44 +000011325 getDerived().transformedLocalDecl(OldClass, {Class});
11326
11327 Optional<std::pair<unsigned, Decl*>> Mangling;
11328 if (getDerived().ReplacingOriginal())
11329 Mangling = std::make_pair(OldClass->getLambdaManglingNumber(),
11330 OldClass->getLambdaContextDecl());
Eli Friedmand564afb2012-09-19 01:18:11 +000011331
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011332 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011333 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11334 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011335 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011336 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
Richard Smith87346a12019-06-02 18:53:44 +000011337 E->getCallOperator()->isConstexpr(), Mangling);
Faisal Valia734ab92016-03-26 16:11:37 +000011338
Faisal Vali2cba1332013-10-23 06:44:28 +000011339 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011340
Akira Hatanaka402818462016-12-16 21:16:57 +000011341 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11342 I != NumParams; ++I) {
11343 auto *P = NewCallOperator->getParamDecl(I);
11344 if (P->hasUninstantiatedDefaultArg()) {
11345 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011346 getSema(),
11347 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011348 ExprResult R = getDerived().TransformExpr(
11349 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11350 P->setDefaultArg(R.get());
11351 }
11352 }
11353
Faisal Vali2cba1332013-10-23 06:44:28 +000011354 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithb2997f52019-05-21 20:10:50 +000011355 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
Richard Smithba71c082013-05-16 06:20:58 +000011356
Douglas Gregorb4328232012-02-14 00:00:48 +000011357 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011358 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011359 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011360
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011361 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011362 getSema().buildLambdaScope(LSI, NewCallOperator,
11363 E->getIntroducerRange(),
11364 E->getCaptureDefault(),
11365 E->getCaptureDefaultLoc(),
11366 E->hasExplicitParameters(),
11367 E->hasExplicitResultType(),
11368 E->isMutable());
11369
11370 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011371
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011372 // Transform captures.
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011373 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011374 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011375 CEnd = E->capture_end();
11376 C != CEnd; ++C) {
11377 // When we hit the first implicit capture, tell Sema that we've finished
11378 // the list of explicit captures.
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011379 if (!FinishedExplicitCaptures && C->isImplicit()) {
11380 getSema().finishLambdaExplicitCaptures(LSI);
11381 FinishedExplicitCaptures = true;
11382 }
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 }
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011491 if (!FinishedExplicitCaptures)
11492 getSema().finishLambdaExplicitCaptures(LSI);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011493
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011494 // Enter a new evaluation context to insulate the lambda from any
11495 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011496 getSema().PushExpressionEvaluationContext(
11497 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011498
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011499 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011500 StmtResult Body =
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011501 Invalid ? StmtError() : getDerived().TransformLambdaBody(E->getBody());
Richard Smithc38498f2015-04-27 21:27:54 +000011502
11503 // ActOnLambda* will pop the function scope for us.
11504 FuncScopeCleanup.disable();
11505
Douglas Gregorb4328232012-02-14 00:00:48 +000011506 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011507 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011508 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011509 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011510 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011511 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011512
Richard Smithc38498f2015-04-27 21:27:54 +000011513 // Copy the LSI before ActOnFinishFunctionBody removes it.
11514 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11515 // the call operator.
11516 auto LSICopy = *LSI;
11517 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11518 /*IsInstantiation*/ true);
11519 SavedContext.pop();
11520
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011521 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011522 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011523}
11524
11525template<typename Derived>
Richard Smith87346a12019-06-02 18:53:44 +000011526StmtResult
Simon Pilgrimc716e5d2019-06-03 09:56:09 +000011527TreeTransform<Derived>::TransformLambdaBody(Stmt *S) {
Richard Smith87346a12019-06-02 18:53:44 +000011528 return TransformStmt(S);
11529}
11530
11531template<typename Derived>
Douglas Gregore31e6062012-02-07 10:09:13 +000011532ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011533TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011534 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011535 TypeSourceInfo *T =
11536 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011537 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011539
Douglas Gregora16548e2009-08-11 05:31:07 +000011540 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011541 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011542 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011543 {
11544 EnterExpressionEvaluationContext Context(
11545 getSema(), EnterExpressionEvaluationContext::InitList,
11546 E->isListInitialization());
11547 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11548 &ArgumentChanged))
11549 return ExprError();
11550 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011551
Douglas Gregora16548e2009-08-11 05:31:07 +000011552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011553 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011554 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011555 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011556
Douglas Gregora16548e2009-08-11 05:31:07 +000011557 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011558 return getDerived().RebuildCXXUnresolvedConstructExpr(
11559 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011560}
Mike Stump11289f42009-09-09 15:08:12 +000011561
Douglas Gregora16548e2009-08-11 05:31:07 +000011562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011563ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011564TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011565 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011566 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011567 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011568 Expr *OldBase;
11569 QualType BaseType;
11570 QualType ObjectType;
11571 if (!E->isImplicitAccess()) {
11572 OldBase = E->getBase();
11573 Base = getDerived().TransformExpr(OldBase);
11574 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011575 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011576
John McCall2d74de92009-12-01 22:10:20 +000011577 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011578 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011579 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011580 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011581 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011582 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011583 ObjectTy,
11584 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011585 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011586 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011587
John McCallba7bf592010-08-24 05:47:05 +000011588 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011589 BaseType = ((Expr*) Base.get())->getType();
11590 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011591 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011592 BaseType = getDerived().TransformType(E->getBaseType());
11593 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11594 }
Mike Stump11289f42009-09-09 15:08:12 +000011595
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011596 // Transform the first part of the nested-name-specifier that qualifies
11597 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011598 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011599 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011600 E->getFirstQualifierFoundInScope(),
11601 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011602
Douglas Gregore16af532011-02-28 18:50:33 +000011603 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011604 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011605 QualifierLoc
11606 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11607 ObjectType,
11608 FirstQualifierInScope);
11609 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011610 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011611 }
Mike Stump11289f42009-09-09 15:08:12 +000011612
Abramo Bagnara7945c982012-01-27 09:46:47 +000011613 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11614
John McCall31f82722010-11-12 08:19:04 +000011615 // TODO: If this is a conversion-function-id, verify that the
11616 // destination type name (if present) resolves the same way after
11617 // instantiation as it did in the local scope.
11618
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011619 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011620 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011621 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011622 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011623
John McCall2d74de92009-12-01 22:10:20 +000011624 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011625 // This is a reference to a member without an explicitly-specified
11626 // template argument list. Optimize for this common case.
11627 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011628 Base.get() == OldBase &&
11629 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011630 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011631 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011632 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011633 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011634
John McCallb268a282010-08-23 23:25:46 +000011635 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011636 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011637 E->isArrow(),
11638 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011639 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011640 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011641 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011642 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011643 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011644 }
11645
John McCall6b51f282009-11-23 01:53:49 +000011646 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011647 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11648 E->getNumTemplateArgs(),
11649 TransArgs))
11650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011651
John McCallb268a282010-08-23 23:25:46 +000011652 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011653 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011654 E->isArrow(),
11655 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011656 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011657 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011658 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011659 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011660 &TransArgs);
11661}
11662
11663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011665TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011666 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011667 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011668 QualType BaseType;
11669 if (!Old->isImplicitAccess()) {
11670 Base = getDerived().TransformExpr(Old->getBase());
11671 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011672 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011673 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011674 Old->isArrow());
11675 if (Base.isInvalid())
11676 return ExprError();
11677 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011678 } else {
11679 BaseType = getDerived().TransformType(Old->getBaseType());
11680 }
John McCall10eae182009-11-30 22:42:35 +000011681
Douglas Gregor0da1d432011-02-28 20:01:57 +000011682 NestedNameSpecifierLoc QualifierLoc;
11683 if (Old->getQualifierLoc()) {
11684 QualifierLoc
11685 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11686 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011687 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011688 }
11689
Abramo Bagnara7945c982012-01-27 09:46:47 +000011690 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11691
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011692 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011693 Sema::LookupOrdinaryName);
11694
Richard Smith151c4562016-12-20 21:35:28 +000011695 // Transform the declaration set.
11696 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11697 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011698
Douglas Gregor9262f472010-04-27 18:19:34 +000011699 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011700 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011701 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011702 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011703 Old->getMemberLoc(),
11704 Old->getNamingClass()));
11705 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011706 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011707
Douglas Gregorda7be082010-04-27 16:10:10 +000011708 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011709 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011710
John McCall10eae182009-11-30 22:42:35 +000011711 TemplateArgumentListInfo TransArgs;
11712 if (Old->hasExplicitTemplateArgs()) {
11713 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11714 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011715 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11716 Old->getNumTemplateArgs(),
11717 TransArgs))
11718 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011719 }
John McCall38836f02010-01-15 08:34:02 +000011720
11721 // FIXME: to do this check properly, we will need to preserve the
11722 // first-qualifier-in-scope here, just in case we had a dependent
11723 // base (and therefore couldn't do the check) and a
11724 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011725 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011726
John McCallb268a282010-08-23 23:25:46 +000011727 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011728 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011729 Old->getOperatorLoc(),
11730 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011731 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011732 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011733 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011734 R,
11735 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011736 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011737}
11738
11739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011740ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011741TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011742 EnterExpressionEvaluationContext Unevaluated(
11743 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011744 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11745 if (SubExpr.isInvalid())
11746 return ExprError();
11747
11748 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011749 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011750
11751 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11752}
11753
11754template<typename Derived>
11755ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011756TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011757 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11758 if (Pattern.isInvalid())
11759 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011760
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011761 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011762 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011763
Douglas Gregorb8840002011-01-14 21:20:45 +000011764 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11765 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011766}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011767
11768template<typename Derived>
11769ExprResult
11770TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11771 // If E is not value-dependent, then nothing will change when we transform it.
11772 // Note: This is an instantiation-centric view.
11773 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011774 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011775
Faisal Valid143a0c2017-04-01 21:30:49 +000011776 EnterExpressionEvaluationContext Unevaluated(
11777 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011778
Richard Smithd784e682015-09-23 21:41:42 +000011779 ArrayRef<TemplateArgument> PackArgs;
11780 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011781
Richard Smithd784e682015-09-23 21:41:42 +000011782 // Find the argument list to transform.
11783 if (E->isPartiallySubstituted()) {
11784 PackArgs = E->getPartialArguments();
11785 } else if (E->isValueDependent()) {
11786 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11787 bool ShouldExpand = false;
11788 bool RetainExpansion = false;
11789 Optional<unsigned> NumExpansions;
11790 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11791 Unexpanded,
11792 ShouldExpand, RetainExpansion,
11793 NumExpansions))
11794 return ExprError();
11795
11796 // If we need to expand the pack, build a template argument from it and
11797 // expand that.
11798 if (ShouldExpand) {
11799 auto *Pack = E->getPack();
11800 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11801 ArgStorage = getSema().Context.getPackExpansionType(
11802 getSema().Context.getTypeDeclType(TTPD), None);
11803 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11804 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11805 } else {
11806 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011807 ExprResult DRE = getSema().BuildDeclRefExpr(
11808 VD, VD->getType().getNonLValueExprType(getSema().Context),
11809 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11810 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011811 if (DRE.isInvalid())
11812 return ExprError();
11813 ArgStorage = new (getSema().Context) PackExpansionExpr(
11814 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11815 }
11816 PackArgs = ArgStorage;
11817 }
11818 }
11819
11820 // If we're not expanding the pack, just transform the decl.
11821 if (!PackArgs.size()) {
11822 auto *Pack = cast_or_null<NamedDecl>(
11823 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011824 if (!Pack)
11825 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011826 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11827 E->getPackLoc(),
11828 E->getRParenLoc(), None, None);
11829 }
11830
Richard Smithc5452ed2016-10-19 22:18:42 +000011831 // Try to compute the result without performing a partial substitution.
11832 Optional<unsigned> Result = 0;
11833 for (const TemplateArgument &Arg : PackArgs) {
11834 if (!Arg.isPackExpansion()) {
11835 Result = *Result + 1;
11836 continue;
11837 }
11838
11839 TemplateArgumentLoc ArgLoc;
11840 InventTemplateArgumentLoc(Arg, ArgLoc);
11841
11842 // Find the pattern of the pack expansion.
11843 SourceLocation Ellipsis;
11844 Optional<unsigned> OrigNumExpansions;
11845 TemplateArgumentLoc Pattern =
11846 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11847 OrigNumExpansions);
11848
11849 // Substitute under the pack expansion. Do not expand the pack (yet).
11850 TemplateArgumentLoc OutPattern;
11851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11852 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11853 /*Uneval*/ true))
11854 return true;
11855
11856 // See if we can determine the number of arguments from the result.
11857 Optional<unsigned> NumExpansions =
11858 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11859 if (!NumExpansions) {
11860 // No: we must be in an alias template expansion, and we're going to need
11861 // to actually expand the packs.
11862 Result = None;
11863 break;
11864 }
11865
11866 Result = *Result + *NumExpansions;
11867 }
11868
11869 // Common case: we could determine the number of expansions without
11870 // substituting.
11871 if (Result)
11872 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11873 E->getPackLoc(),
11874 E->getRParenLoc(), *Result, None);
11875
Richard Smithd784e682015-09-23 21:41:42 +000011876 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11877 E->getPackLoc());
11878 {
11879 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11880 typedef TemplateArgumentLocInventIterator<
11881 Derived, const TemplateArgument*> PackLocIterator;
11882 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11883 PackLocIterator(*this, PackArgs.end()),
11884 TransformedPackArgs, /*Uneval*/true))
11885 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011886 }
11887
Richard Smithc5452ed2016-10-19 22:18:42 +000011888 // Check whether we managed to fully-expand the pack.
11889 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011890 SmallVector<TemplateArgument, 8> Args;
11891 bool PartialSubstitution = false;
11892 for (auto &Loc : TransformedPackArgs.arguments()) {
11893 Args.push_back(Loc.getArgument());
11894 if (Loc.getArgument().isPackExpansion())
11895 PartialSubstitution = true;
11896 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011897
Richard Smithd784e682015-09-23 21:41:42 +000011898 if (PartialSubstitution)
11899 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11900 E->getPackLoc(),
11901 E->getRParenLoc(), None, Args);
11902
11903 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011904 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011905 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011906}
11907
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011908template<typename Derived>
11909ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011910TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11911 SubstNonTypeTemplateParmPackExpr *E) {
11912 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011913 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011914}
11915
11916template<typename Derived>
11917ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011918TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11919 SubstNonTypeTemplateParmExpr *E) {
11920 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011921 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011922}
11923
11924template<typename Derived>
11925ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011926TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11927 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011928 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011929}
11930
11931template<typename Derived>
11932ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011933TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11934 MaterializeTemporaryExpr *E) {
11935 return getDerived().TransformExpr(E->GetTemporaryExpr());
11936}
Chad Rosier1dcde962012-08-08 18:46:20 +000011937
Douglas Gregorfe314812011-06-21 17:03:29 +000011938template<typename Derived>
11939ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011940TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11941 Expr *Pattern = E->getPattern();
11942
11943 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11944 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11945 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11946
11947 // Determine whether the set of unexpanded parameter packs can and should
11948 // be expanded.
11949 bool Expand = true;
11950 bool RetainExpansion = false;
Richard Smithc7214f62019-05-13 08:31:14 +000011951 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
11952 NumExpansions = OrigNumExpansions;
Richard Smith0f0af192014-11-08 05:07:16 +000011953 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11954 Pattern->getSourceRange(),
11955 Unexpanded,
11956 Expand, RetainExpansion,
11957 NumExpansions))
11958 return true;
11959
11960 if (!Expand) {
11961 // Do not expand any packs here, just transform and rebuild a fold
11962 // expression.
11963 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11964
11965 ExprResult LHS =
11966 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11967 if (LHS.isInvalid())
11968 return true;
11969
11970 ExprResult RHS =
11971 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11972 if (RHS.isInvalid())
11973 return true;
11974
11975 if (!getDerived().AlwaysRebuild() &&
11976 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11977 return E;
11978
11979 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011980 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000011981 RHS.get(), E->getEndLoc(), NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000011982 }
11983
11984 // The transform has determined that we should perform an elementwise
11985 // expansion of the pattern. Do so.
11986 ExprResult Result = getDerived().TransformExpr(E->getInit());
11987 if (Result.isInvalid())
11988 return true;
11989 bool LeftFold = E->isLeftFold();
11990
11991 // If we're retaining an expansion for a right fold, it is the innermost
11992 // component and takes the init (if any).
11993 if (!LeftFold && RetainExpansion) {
11994 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11995
11996 ExprResult Out = getDerived().TransformExpr(Pattern);
11997 if (Out.isInvalid())
11998 return true;
11999
12000 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012001 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012002 Result.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012003 if (Result.isInvalid())
12004 return true;
12005 }
12006
12007 for (unsigned I = 0; I != *NumExpansions; ++I) {
12008 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
12009 getSema(), LeftFold ? I : *NumExpansions - I - 1);
12010 ExprResult Out = getDerived().TransformExpr(Pattern);
12011 if (Out.isInvalid())
12012 return true;
12013
12014 if (Out.get()->containsUnexpandedParameterPack()) {
12015 // We still have a pack; retain a pack expansion for this slice.
12016 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012017 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000012018 E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012019 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
12020 OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012021 } else if (Result.isUsable()) {
12022 // We've got down to a single element; build a binary operator.
12023 Result = getDerived().RebuildBinaryOperator(
12024 E->getEllipsisLoc(), E->getOperator(),
12025 LeftFold ? Result.get() : Out.get(),
12026 LeftFold ? Out.get() : Result.get());
12027 } else
12028 Result = Out;
12029
12030 if (Result.isInvalid())
12031 return true;
12032 }
12033
12034 // If we're retaining an expansion for a left fold, it is the outermost
12035 // component and takes the complete expansion so far as its init (if any).
12036 if (LeftFold && RetainExpansion) {
12037 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12038
12039 ExprResult Out = getDerived().TransformExpr(Pattern);
12040 if (Out.isInvalid())
12041 return true;
12042
12043 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012044 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012045 Out.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012046 if (Result.isInvalid())
12047 return true;
12048 }
12049
12050 // If we had no init and an empty pack, and we're not retaining an expansion,
12051 // then produce a fallback value or error.
12052 if (Result.isUnset())
12053 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
12054 E->getOperator());
12055
12056 return Result;
12057}
12058
12059template<typename Derived>
12060ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000012061TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
12062 CXXStdInitializerListExpr *E) {
12063 return getDerived().TransformExpr(E->getSubExpr());
12064}
12065
12066template<typename Derived>
12067ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012068TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012069 return SemaRef.MaybeBindToTemporary(E);
12070}
12071
12072template<typename Derived>
12073ExprResult
12074TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012075 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012076}
12077
12078template<typename Derived>
12079ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000012080TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
12081 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12082 if (SubExpr.isInvalid())
12083 return ExprError();
12084
12085 if (!getDerived().AlwaysRebuild() &&
12086 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012087 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000012088
12089 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000012090}
12091
12092template<typename Derived>
12093ExprResult
12094TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
12095 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012096 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012097 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000012098 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012099 /*IsCall=*/false, Elements, &ArgChanged))
12100 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012101
Ted Kremeneke65b0862012-03-06 20:05:56 +000012102 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12103 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012104
Ted Kremeneke65b0862012-03-06 20:05:56 +000012105 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
12106 Elements.data(),
12107 Elements.size());
12108}
12109
12110template<typename Derived>
12111ExprResult
12112TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000012113 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012114 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012115 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012116 bool ArgChanged = false;
12117 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
12118 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000012119
Ted Kremeneke65b0862012-03-06 20:05:56 +000012120 if (OrigElement.isPackExpansion()) {
12121 // This key/value element is a pack expansion.
12122 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12123 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
12124 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
12125 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12126
12127 // Determine whether the set of unexpanded parameter packs can
12128 // and should be expanded.
12129 bool Expand = true;
12130 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000012131 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
12132 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012133 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000012134 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012135 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
12136 PatternRange, Unexpanded, Expand,
12137 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000012138 return ExprError();
12139
12140 if (!Expand) {
12141 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000012142 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000012143 // expansion.
12144 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12145 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12146 if (Key.isInvalid())
12147 return ExprError();
12148
12149 if (Key.get() != OrigElement.Key)
12150 ArgChanged = true;
12151
12152 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12153 if (Value.isInvalid())
12154 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012155
Ted Kremeneke65b0862012-03-06 20:05:56 +000012156 if (Value.get() != OrigElement.Value)
12157 ArgChanged = true;
12158
Chad Rosier1dcde962012-08-08 18:46:20 +000012159 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012160 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
12161 };
12162 Elements.push_back(Expansion);
12163 continue;
12164 }
12165
12166 // Record right away that the argument was changed. This needs
12167 // to happen even if the array expands to nothing.
12168 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012169
Ted Kremeneke65b0862012-03-06 20:05:56 +000012170 // The transform has determined that we should perform an elementwise
12171 // expansion of the pattern. Do so.
12172 for (unsigned I = 0; I != *NumExpansions; ++I) {
12173 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
12174 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12175 if (Key.isInvalid())
12176 return ExprError();
12177
12178 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12179 if (Value.isInvalid())
12180 return ExprError();
12181
Chad Rosier1dcde962012-08-08 18:46:20 +000012182 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012183 Key.get(), Value.get(), SourceLocation(), NumExpansions
12184 };
12185
12186 // If any unexpanded parameter packs remain, we still have a
12187 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000012188 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000012189 if (Key.get()->containsUnexpandedParameterPack() ||
12190 Value.get()->containsUnexpandedParameterPack())
12191 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000012192
Ted Kremeneke65b0862012-03-06 20:05:56 +000012193 Elements.push_back(Element);
12194 }
12195
Richard Smith9467be42014-06-06 17:33:35 +000012196 // FIXME: Retain a pack expansion if RetainExpansion is true.
12197
Ted Kremeneke65b0862012-03-06 20:05:56 +000012198 // We've finished with this pack expansion.
12199 continue;
12200 }
12201
12202 // Transform and check key.
12203 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12204 if (Key.isInvalid())
12205 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012206
Ted Kremeneke65b0862012-03-06 20:05:56 +000012207 if (Key.get() != OrigElement.Key)
12208 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012209
Ted Kremeneke65b0862012-03-06 20:05:56 +000012210 // Transform and check value.
12211 ExprResult Value
12212 = getDerived().TransformExpr(OrigElement.Value);
12213 if (Value.isInvalid())
12214 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012215
Ted Kremeneke65b0862012-03-06 20:05:56 +000012216 if (Value.get() != OrigElement.Value)
12217 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012218
12219 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000012220 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000012221 };
12222 Elements.push_back(Element);
12223 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012224
Ted Kremeneke65b0862012-03-06 20:05:56 +000012225 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12226 return SemaRef.MaybeBindToTemporary(E);
12227
12228 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000012229 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000012230}
12231
Mike Stump11289f42009-09-09 15:08:12 +000012232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012233ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012234TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000012235 TypeSourceInfo *EncodedTypeInfo
12236 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
12237 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012239
Douglas Gregora16548e2009-08-11 05:31:07 +000012240 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000012241 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012242 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012243
12244 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000012245 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000012246 E->getRParenLoc());
12247}
Mike Stump11289f42009-09-09 15:08:12 +000012248
Douglas Gregora16548e2009-08-11 05:31:07 +000012249template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000012250ExprResult TreeTransform<Derived>::
12251TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000012252 // This is a kind of implicit conversion, and it needs to get dropped
12253 // and recomputed for the same general reasons that ImplicitCastExprs
12254 // do, as well a more specific one: this expression is only valid when
12255 // it appears *immediately* as an argument expression.
12256 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000012257}
12258
12259template<typename Derived>
12260ExprResult TreeTransform<Derived>::
12261TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000012262 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000012263 = getDerived().TransformType(E->getTypeInfoAsWritten());
12264 if (!TSInfo)
12265 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012266
John McCall31168b02011-06-15 23:02:42 +000012267 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012268 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012269 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012270
John McCall31168b02011-06-15 23:02:42 +000012271 if (!getDerived().AlwaysRebuild() &&
12272 TSInfo == E->getTypeInfoAsWritten() &&
12273 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012274 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012275
John McCall31168b02011-06-15 23:02:42 +000012276 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012277 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012278 Result.get());
12279}
12280
Erik Pilkington29099de2016-07-16 00:35:23 +000012281template <typename Derived>
12282ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12283 ObjCAvailabilityCheckExpr *E) {
12284 return E;
12285}
12286
John McCall31168b02011-06-15 23:02:42 +000012287template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012288ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012289TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012290 // Transform arguments.
12291 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012292 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012293 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012294 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012295 &ArgChanged))
12296 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012297
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012298 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12299 // Class message: transform the receiver type.
12300 TypeSourceInfo *ReceiverTypeInfo
12301 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12302 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012303 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012304
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012305 // If nothing changed, just retain the existing message send.
12306 if (!getDerived().AlwaysRebuild() &&
12307 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012308 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012309
12310 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012311 SmallVector<SourceLocation, 16> SelLocs;
12312 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012313 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12314 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012315 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012316 E->getMethodDecl(),
12317 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012318 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012319 E->getRightLoc());
12320 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012321 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12322 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012323 if (!E->getMethodDecl())
12324 return ExprError();
12325
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012326 // Build a new class message send to 'super'.
12327 SmallVector<SourceLocation, 16> SelLocs;
12328 E->getSelectorLocs(SelLocs);
12329 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12330 E->getSelector(),
12331 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012332 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012333 E->getMethodDecl(),
12334 E->getLeftLoc(),
12335 Args,
12336 E->getRightLoc());
12337 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012338
12339 // Instance message: transform the receiver
12340 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12341 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012342 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012343 = getDerived().TransformExpr(E->getInstanceReceiver());
12344 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012345 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012346
12347 // If nothing changed, just retain the existing message send.
12348 if (!getDerived().AlwaysRebuild() &&
12349 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012350 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012351
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012352 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012353 SmallVector<SourceLocation, 16> SelLocs;
12354 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012355 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012356 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012357 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012358 E->getMethodDecl(),
12359 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012360 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012361 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012362}
12363
Mike Stump11289f42009-09-09 15:08:12 +000012364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012365ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012366TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012367 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012368}
12369
Mike Stump11289f42009-09-09 15:08:12 +000012370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012371ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012372TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012373 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012374}
12375
Mike Stump11289f42009-09-09 15:08:12 +000012376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012378TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012379 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012380 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012381 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012382 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012383
12384 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012385
Douglas Gregord51d90d2010-04-26 20:11:03 +000012386 // If nothing changed, just retain the existing expression.
12387 if (!getDerived().AlwaysRebuild() &&
12388 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012389 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012390
John McCallb268a282010-08-23 23:25:46 +000012391 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012392 E->getLocation(),
12393 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012394}
12395
Mike Stump11289f42009-09-09 15:08:12 +000012396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012397ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012398TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012399 // 'super' and types never change. Property never changes. Just
12400 // retain the existing expression.
12401 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012402 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012403
Douglas Gregor9faee212010-04-26 20:47:02 +000012404 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012405 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012406 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012408
Douglas Gregor9faee212010-04-26 20:47:02 +000012409 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012410
Douglas Gregor9faee212010-04-26 20:47:02 +000012411 // If nothing changed, just retain the existing expression.
12412 if (!getDerived().AlwaysRebuild() &&
12413 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012414 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012415
John McCallb7bd14f2010-12-02 01:19:52 +000012416 if (E->isExplicitProperty())
12417 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12418 E->getExplicitProperty(),
12419 E->getLocation());
12420
12421 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012422 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012423 E->getImplicitPropertyGetter(),
12424 E->getImplicitPropertySetter(),
12425 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012426}
12427
Mike Stump11289f42009-09-09 15:08:12 +000012428template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012429ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012430TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12431 // Transform the base expression.
12432 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12433 if (Base.isInvalid())
12434 return ExprError();
12435
12436 // Transform the key expression.
12437 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12438 if (Key.isInvalid())
12439 return ExprError();
12440
12441 // If nothing changed, just retain the existing expression.
12442 if (!getDerived().AlwaysRebuild() &&
12443 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012444 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012445
Chad Rosier1dcde962012-08-08 18:46:20 +000012446 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012447 Base.get(), Key.get(),
12448 E->getAtIndexMethodDecl(),
12449 E->setAtIndexMethodDecl());
12450}
12451
12452template<typename Derived>
12453ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012454TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012455 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012456 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012457 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012458 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012459
Douglas Gregord51d90d2010-04-26 20:11:03 +000012460 // If nothing changed, just retain the existing expression.
12461 if (!getDerived().AlwaysRebuild() &&
12462 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012463 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012464
John McCallb268a282010-08-23 23:25:46 +000012465 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012466 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012467 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012468}
12469
Mike Stump11289f42009-09-09 15:08:12 +000012470template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012471ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012472TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012473 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012474 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012475 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012476 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012477 SubExprs, &ArgumentChanged))
12478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012479
Douglas Gregora16548e2009-08-11 05:31:07 +000012480 if (!getDerived().AlwaysRebuild() &&
12481 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012482 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012483
Douglas Gregora16548e2009-08-11 05:31:07 +000012484 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012485 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012486 E->getRParenLoc());
12487}
12488
Mike Stump11289f42009-09-09 15:08:12 +000012489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012490ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012491TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12492 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12493 if (SrcExpr.isInvalid())
12494 return ExprError();
12495
12496 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12497 if (!Type)
12498 return ExprError();
12499
12500 if (!getDerived().AlwaysRebuild() &&
12501 Type == E->getTypeSourceInfo() &&
12502 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012503 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012504
12505 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12506 SrcExpr.get(), Type,
12507 E->getRParenLoc());
12508}
12509
12510template<typename Derived>
12511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012512TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012513 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012514
Craig Topperc3ec1492014-05-26 06:22:03 +000012515 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012516 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12517
12518 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012519 blockScope->TheDecl->setBlockMissingReturnType(
12520 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012521
Chris Lattner01cf8db2011-07-20 06:58:45 +000012522 SmallVector<ParmVarDecl*, 4> params;
12523 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012524
John McCallc8e321d2016-03-01 02:09:25 +000012525 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12526
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012527 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012528 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012529 if (getDerived().TransformFunctionTypeParams(
12530 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12531 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12532 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012533 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012534 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012535 }
John McCall490112f2011-02-04 18:33:18 +000012536
Eli Friedman34b49062012-01-26 03:00:14 +000012537 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012538 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012539
John McCallc8e321d2016-03-01 02:09:25 +000012540 auto epi = exprFunctionType->getExtProtoInfo();
12541 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12542
Jordan Rose5c382722013-03-08 21:51:21 +000012543 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012544 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012545 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012546
12547 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012548 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012549 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012550
12551 if (!oldBlock->blockMissingReturnType()) {
12552 blockScope->HasImplicitReturnType = false;
12553 blockScope->ReturnType = exprResultType;
12554 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012555
John McCall3882ace2011-01-05 12:14:39 +000012556 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012557 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012558 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012559 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012560 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012561 }
John McCall3882ace2011-01-05 12:14:39 +000012562
John McCall490112f2011-02-04 18:33:18 +000012563#ifndef NDEBUG
12564 // In builds with assertions, make sure that we captured everything we
12565 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012566 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012567 for (const auto &I : oldBlock->captures()) {
12568 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012569
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012570 // Ignore parameter packs.
Richard Smithb2997f52019-05-21 20:10:50 +000012571 if (oldCapture->isParameterPack())
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012572 continue;
John McCall490112f2011-02-04 18:33:18 +000012573
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012574 VarDecl *newCapture =
12575 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12576 oldCapture));
12577 assert(blockScope->CaptureMap.count(newCapture));
12578 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012579 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012580 }
12581#endif
12582
12583 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012584 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012585}
12586
Mike Stump11289f42009-09-09 15:08:12 +000012587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012588ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012589TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012590 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012591}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012592
12593template<typename Derived>
12594ExprResult
12595TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012596 QualType RetTy = getDerived().TransformType(E->getType());
12597 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012598 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012599 SubExprs.reserve(E->getNumSubExprs());
12600 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12601 SubExprs, &ArgumentChanged))
12602 return ExprError();
12603
12604 if (!getDerived().AlwaysRebuild() &&
12605 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012606 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012607
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012608 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012609 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012610}
Chad Rosier1dcde962012-08-08 18:46:20 +000012611
Douglas Gregora16548e2009-08-11 05:31:07 +000012612//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012613// Type reconstruction
12614//===----------------------------------------------------------------------===//
12615
Mike Stump11289f42009-09-09 15:08:12 +000012616template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012617QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12618 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012619 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012620 getDerived().getBaseEntity());
12621}
12622
Mike Stump11289f42009-09-09 15:08:12 +000012623template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012624QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12625 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012626 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012627 getDerived().getBaseEntity());
12628}
12629
Mike Stump11289f42009-09-09 15:08:12 +000012630template<typename Derived>
12631QualType
John McCall70dd5f62009-10-30 00:06:24 +000012632TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12633 bool WrittenAsLValue,
12634 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012635 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012636 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012637}
12638
12639template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012640QualType
John McCall70dd5f62009-10-30 00:06:24 +000012641TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12642 QualType ClassType,
12643 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012644 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12645 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012646}
12647
12648template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012649QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12650 const ObjCTypeParamDecl *Decl,
12651 SourceLocation ProtocolLAngleLoc,
12652 ArrayRef<ObjCProtocolDecl *> Protocols,
12653 ArrayRef<SourceLocation> ProtocolLocs,
12654 SourceLocation ProtocolRAngleLoc) {
12655 return SemaRef.BuildObjCTypeParamType(Decl,
12656 ProtocolLAngleLoc, Protocols,
12657 ProtocolLocs, ProtocolRAngleLoc,
12658 /*FailOnError=*/true);
12659}
12660
12661template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012662QualType TreeTransform<Derived>::RebuildObjCObjectType(
12663 QualType BaseType,
12664 SourceLocation Loc,
12665 SourceLocation TypeArgsLAngleLoc,
12666 ArrayRef<TypeSourceInfo *> TypeArgs,
12667 SourceLocation TypeArgsRAngleLoc,
12668 SourceLocation ProtocolLAngleLoc,
12669 ArrayRef<ObjCProtocolDecl *> Protocols,
12670 ArrayRef<SourceLocation> ProtocolLocs,
12671 SourceLocation ProtocolRAngleLoc) {
12672 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12673 TypeArgs, TypeArgsRAngleLoc,
12674 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12675 ProtocolRAngleLoc,
12676 /*FailOnError=*/true);
12677}
12678
12679template<typename Derived>
12680QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12681 QualType PointeeType,
12682 SourceLocation Star) {
12683 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12684}
12685
12686template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012687QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012688TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12689 ArrayType::ArraySizeModifier SizeMod,
12690 const llvm::APInt *Size,
12691 Expr *SizeExpr,
12692 unsigned IndexTypeQuals,
12693 SourceRange BracketsRange) {
12694 if (SizeExpr || !Size)
12695 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12696 IndexTypeQuals, BracketsRange,
12697 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012698
12699 QualType Types[] = {
12700 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12701 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12702 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012703 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012704 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012705 QualType SizeType;
12706 for (unsigned I = 0; I != NumTypes; ++I)
12707 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12708 SizeType = Types[I];
12709 break;
12710 }
Mike Stump11289f42009-09-09 15:08:12 +000012711
Eli Friedman9562f392012-01-25 23:20:27 +000012712 // Note that we can return a VariableArrayType here in the case where
12713 // the element type was a dependent VariableArrayType.
12714 IntegerLiteral *ArraySize
12715 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12716 /*FIXME*/BracketsRange.getBegin());
12717 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012718 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012719 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012720}
Mike Stump11289f42009-09-09 15:08:12 +000012721
Douglas Gregord6ff3322009-08-04 16:50:30 +000012722template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012723QualType
12724TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012725 ArrayType::ArraySizeModifier SizeMod,
12726 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012727 unsigned IndexTypeQuals,
12728 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012729 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012730 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012731}
12732
12733template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012734QualType
Mike Stump11289f42009-09-09 15:08:12 +000012735TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012736 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012737 unsigned IndexTypeQuals,
12738 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012739 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012740 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012741}
Mike Stump11289f42009-09-09 15:08:12 +000012742
Douglas Gregord6ff3322009-08-04 16:50:30 +000012743template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012744QualType
12745TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012746 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012747 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012748 unsigned IndexTypeQuals,
12749 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012750 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012751 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012752 IndexTypeQuals, BracketsRange);
12753}
12754
12755template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012756QualType
12757TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012758 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012759 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012760 unsigned IndexTypeQuals,
12761 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012762 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012763 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012764 IndexTypeQuals, BracketsRange);
12765}
12766
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012767template <typename Derived>
12768QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12769 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12770 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12771 AttributeLoc);
12772}
12773
12774template <typename Derived>
12775QualType
12776TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12777 unsigned NumElements,
12778 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012779 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012780 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012781}
Mike Stump11289f42009-09-09 15:08:12 +000012782
Erich Keanef702b022018-07-13 19:46:04 +000012783template <typename Derived>
12784QualType TreeTransform<Derived>::RebuildDependentVectorType(
12785 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12786 VectorType::VectorKind VecKind) {
12787 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12788}
12789
Douglas Gregord6ff3322009-08-04 16:50:30 +000012790template<typename Derived>
12791QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12792 unsigned NumElements,
12793 SourceLocation AttributeLoc) {
12794 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12795 NumElements, true);
12796 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012797 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12798 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012799 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012800}
Mike Stump11289f42009-09-09 15:08:12 +000012801
Douglas Gregord6ff3322009-08-04 16:50:30 +000012802template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012803QualType
12804TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012805 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012806 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012807 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012808}
Mike Stump11289f42009-09-09 15:08:12 +000012809
Douglas Gregord6ff3322009-08-04 16:50:30 +000012810template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012811QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12812 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012813 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012814 const FunctionProtoType::ExtProtoInfo &EPI) {
12815 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012816 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012817 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012818 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012819}
Mike Stump11289f42009-09-09 15:08:12 +000012820
Douglas Gregord6ff3322009-08-04 16:50:30 +000012821template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012822QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12823 return SemaRef.Context.getFunctionNoProtoType(T);
12824}
12825
12826template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012827QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12828 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012829 assert(D && "no decl found");
12830 if (D->isInvalidDecl()) return QualType();
12831
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012832 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012833 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012834 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12835 // A valid resolved using typename pack expansion decl can have multiple
12836 // UsingDecls, but they must each have exactly one type, and it must be
12837 // the same type in every case. But we must have at least one expansion!
12838 if (UPD->expansions().empty()) {
12839 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12840 << UPD->isCXXClassMember() << UPD;
12841 return QualType();
12842 }
12843
12844 // We might still have some unresolved types. Try to pick a resolved type
12845 // if we can. The final instantiation will check that the remaining
12846 // unresolved types instantiate to the type we pick.
12847 QualType FallbackT;
12848 QualType T;
12849 for (auto *E : UPD->expansions()) {
12850 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12851 if (ThisT.isNull())
12852 continue;
12853 else if (ThisT->getAs<UnresolvedUsingType>())
12854 FallbackT = ThisT;
12855 else if (T.isNull())
12856 T = ThisT;
12857 else
12858 assert(getSema().Context.hasSameType(ThisT, T) &&
12859 "mismatched resolved types in using pack expansion");
12860 }
12861 return T.isNull() ? FallbackT : T;
12862 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012863 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012864 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12865
12866 // A valid resolved using typename decl points to exactly one type decl.
12867 assert(++Using->shadow_begin() == Using->shadow_end());
12868 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012869 } else {
12870 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12871 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12872 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12873 }
12874
12875 return SemaRef.Context.getTypeDeclType(Ty);
12876}
12877
12878template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012879QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12880 SourceLocation Loc) {
12881 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012882}
12883
12884template<typename Derived>
12885QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12886 return SemaRef.Context.getTypeOfType(Underlying);
12887}
12888
12889template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012890QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12891 SourceLocation Loc) {
12892 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012893}
12894
12895template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012896QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12897 UnaryTransformType::UTTKind UKind,
12898 SourceLocation Loc) {
12899 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12900}
12901
12902template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012903QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012904 TemplateName Template,
12905 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012906 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012907 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012908}
Mike Stump11289f42009-09-09 15:08:12 +000012909
Douglas Gregor1135c352009-08-06 05:28:30 +000012910template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012911QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12912 SourceLocation KWLoc) {
12913 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12914}
12915
12916template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012917QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012918 SourceLocation KWLoc,
12919 bool isReadPipe) {
12920 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12921 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012922}
12923
12924template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012925TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012926TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012927 bool TemplateKW,
12928 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012929 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012930 Template);
12931}
12932
12933template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012934TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012935TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012936 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012937 const IdentifierInfo &Name,
12938 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012939 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012940 NamedDecl *FirstQualifierInScope,
12941 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012942 UnqualifiedId TemplateName;
12943 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012944 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012945 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012946 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012947 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012948 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012949 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012950 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012951}
Mike Stump11289f42009-09-09 15:08:12 +000012952
Douglas Gregora16548e2009-08-11 05:31:07 +000012953template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012954TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012955TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012956 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012957 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012958 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012959 QualType ObjectType,
12960 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012961 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012962 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012963 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012964 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012965 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012966 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012967 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012968 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012969 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012970 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012971 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012972}
Chad Rosier1dcde962012-08-08 18:46:20 +000012973
Douglas Gregor71395fa2009-11-04 00:56:37 +000012974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012975ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012976TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12977 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012978 Expr *OrigCallee,
12979 Expr *First,
12980 Expr *Second) {
12981 Expr *Callee = OrigCallee->IgnoreParenCasts();
12982 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012983
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012984 if (First->getObjectKind() == OK_ObjCProperty) {
12985 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12986 if (BinaryOperator::isAssignmentOp(Opc))
12987 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12988 First, Second);
12989 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12990 if (Result.isInvalid())
12991 return ExprError();
12992 First = Result.get();
12993 }
12994
12995 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12996 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12997 if (Result.isInvalid())
12998 return ExprError();
12999 Second = Result.get();
13000 }
13001
Douglas Gregora16548e2009-08-11 05:31:07 +000013002 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000013003 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000013004 if (!First->getType()->isOverloadableType() &&
13005 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013006 return getSema().CreateBuiltinArraySubscriptExpr(
13007 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000013008 } else if (Op == OO_Arrow) {
13009 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000013010 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
13011 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000013012 if (!First->getType()->isOverloadableType() ||
13013 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
13014 // The argument is not of overloadable type, or this is an expression
13015 // of the form &Class::member, so try to create a built-in unary
13016 // operation.
John McCalle3027922010-08-25 11:45:40 +000013017 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013018 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000013019
John McCallb268a282010-08-23 23:25:46 +000013020 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000013021 }
13022 } else {
John McCallb268a282010-08-23 23:25:46 +000013023 if (!First->getType()->isOverloadableType() &&
13024 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000013025 // Neither of the arguments is an overloadable type, so try to
13026 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000013027 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000013028 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000013029 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000013030 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013032
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013033 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013034 }
13035 }
Mike Stump11289f42009-09-09 15:08:12 +000013036
13037 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000013038 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000013039 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000013040 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000013041
John McCallb268a282010-08-23 23:25:46 +000013042 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000013043 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000013044 // If the overload could not be resolved in the template definition
13045 // (because we had a dependent argument), ADL is performed as part of
13046 // template instantiation.
13047 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000013048 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000013049 // If we've resolved this to a particular non-member function, just call
13050 // that function. If we resolved it to a member function,
13051 // CreateOverloaded* will find that function for us.
13052 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
13053 if (!isa<CXXMethodDecl>(ND))
13054 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000013055 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000013056 }
Mike Stump11289f42009-09-09 15:08:12 +000013057
Douglas Gregora16548e2009-08-11 05:31:07 +000013058 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000013059 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000013060 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000013061
Douglas Gregora16548e2009-08-11 05:31:07 +000013062 // Create the overloaded operator invocation for unary operators.
13063 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000013064 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013065 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000013066 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
13067 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013068 }
Mike Stump11289f42009-09-09 15:08:12 +000013069
Douglas Gregore9d62932011-07-15 16:25:15 +000013070 if (Op == OO_Subscript) {
13071 SourceLocation LBrace;
13072 SourceLocation RBrace;
13073
13074 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000013075 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000013076 LBrace = SourceLocation::getFromRawEncoding(
13077 NameLoc.CXXOperatorName.BeginOpNameLoc);
13078 RBrace = SourceLocation::getFromRawEncoding(
13079 NameLoc.CXXOperatorName.EndOpNameLoc);
13080 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013081 LBrace = Callee->getBeginLoc();
13082 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000013083 }
13084
13085 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
13086 First, Second);
13087 }
Sebastian Redladba46e2009-10-29 20:17:01 +000013088
Douglas Gregora16548e2009-08-11 05:31:07 +000013089 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000013090 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000013091 ExprResult Result = SemaRef.CreateOverloadedBinOp(
13092 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013093 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013095
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013096 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013097}
Mike Stump11289f42009-09-09 15:08:12 +000013098
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013099template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000013100ExprResult
John McCallb268a282010-08-23 23:25:46 +000013101TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013102 SourceLocation OperatorLoc,
13103 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000013104 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013105 TypeSourceInfo *ScopeType,
13106 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000013107 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000013108 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000013109 QualType BaseType = Base->getType();
13110 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013111 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000013112 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000013113 !BaseType->getAs<PointerType>()->getPointeeType()
13114 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013115 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000013116 return SemaRef.BuildPseudoDestructorExpr(
13117 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
13118 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013119 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013120
Douglas Gregor678f90d2010-02-25 01:56:36 +000013121 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013122 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
13123 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
13124 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
13125 NameInfo.setNamedTypeInfo(DestroyedType);
13126
Richard Smith8e4a3862012-05-15 06:15:11 +000013127 // The scope type is now known to be a valid nested name specifier
13128 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000013129 if (ScopeType) {
13130 if (!ScopeType->getType()->getAs<TagType>()) {
13131 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
13132 diag::err_expected_class_or_namespace)
13133 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
13134 return ExprError();
13135 }
13136 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
13137 CCLoc);
13138 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013139
Abramo Bagnara7945c982012-01-27 09:46:47 +000013140 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000013141 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013142 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013143 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000013144 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013145 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000013146 /*TemplateArgs*/ nullptr,
13147 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013148}
13149
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013150template<typename Derived>
13151StmtResult
13152TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013153 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000013154 CapturedDecl *CD = S->getCapturedDecl();
13155 unsigned NumParams = CD->getNumParams();
13156 unsigned ContextParamPos = CD->getContextParamPosition();
13157 SmallVector<Sema::CapturedParamNameType, 4> Params;
13158 for (unsigned I = 0; I < NumParams; ++I) {
13159 if (I != ContextParamPos) {
13160 Params.push_back(
13161 std::make_pair(
13162 CD->getParam(I)->getName(),
13163 getDerived().TransformType(CD->getParam(I)->getType())));
13164 } else {
13165 Params.push_back(std::make_pair(StringRef(), QualType()));
13166 }
13167 }
Craig Topperc3ec1492014-05-26 06:22:03 +000013168 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000013169 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000013170 StmtResult Body;
13171 {
13172 Sema::CompoundScopeRAII CompoundScope(getSema());
13173 Body = getDerived().TransformStmt(S->getCapturedStmt());
13174 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000013175
13176 if (Body.isInvalid()) {
13177 getSema().ActOnCapturedRegionError();
13178 return StmtError();
13179 }
13180
Nikola Smiljanic01a75982014-05-29 10:55:11 +000013181 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013182}
13183
Douglas Gregord6ff3322009-08-04 16:50:30 +000013184} // end namespace clang
13185
Hans Wennborg59dbe862015-09-29 20:56:43 +000013186#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H