blob: 8df18b5c27844bda6a38b770abd1f48939f5c4de [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattnercab02a62011-02-17 20:34:02 +00006//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
Chris Lattnercab02a62011-02-17 20:34:02 +000011//===----------------------------------------------------------------------===//
12
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000013#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000015
Eric Fiselierbee782b2017-04-03 19:21:00 +000016#include "CoroutineStmtBuilder.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000043/// A semantic tree transformation that allows one to transform one
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
Alexander Kornienko2a8c18d2018-04-06 15:14:32 +000059/// overriding function should not be virtual.
Douglas Gregord6ff3322009-08-04 16:50:30 +000060///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000096 /// Private RAII object that helps us forget and then re-remember
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000116 /// The set of local declarations that have been transformed, for
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000122 /// Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000125 /// Retrieves a reference to the derived class.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000128 /// Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000136 /// Retrieves a reference to the semantic analysis object used for
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000140 /// Whether the transformation should always rebuild AST nodes, even
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Richard Smith87346a12019-06-02 18:53:44 +0000151 /// Whether the transformation is forming an expression or statement that
152 /// replaces the original. In this case, we'll reuse mangling numbers from
153 /// existing lambdas.
154 bool ReplacingOriginal() { return false; }
155
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000156 /// Returns the location of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000157 /// information was not available elsewhere in the AST.
158 ///
Mike Stump11289f42009-09-09 15:08:12 +0000159 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// provide an alternative implementation that provides better location
161 /// information.
162 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000163
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000164 /// Returns the name of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// information was not available elsewhere in the AST.
166 ///
167 /// By default, returns an empty name. Subclasses can provide an alternative
168 /// implementation with a more precise name.
169 DeclarationName getBaseEntity() { return DeclarationName(); }
170
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000171 /// Sets the "base" location and entity when that
Douglas Gregora16548e2009-08-11 05:31:07 +0000172 /// information is known based on another transformation.
173 ///
174 /// By default, the source location and entity are ignored. Subclasses can
175 /// override this function to provide a customized implementation.
176 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000178 /// RAII object that temporarily sets the base location and entity
Douglas Gregora16548e2009-08-11 05:31:07 +0000179 /// used for reporting diagnostics in types.
180 class TemporaryBase {
181 TreeTransform &Self;
182 SourceLocation OldLocation;
183 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000184
Douglas Gregora16548e2009-08-11 05:31:07 +0000185 public:
186 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000187 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 OldLocation = Self.getDerived().getBaseLocation();
189 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000190
Douglas Gregora518d5b2011-01-25 17:51:48 +0000191 if (Location.isValid())
192 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000193 }
Mike Stump11289f42009-09-09 15:08:12 +0000194
Douglas Gregora16548e2009-08-11 05:31:07 +0000195 ~TemporaryBase() {
196 Self.getDerived().setBase(OldLocation, OldEntity);
197 }
198 };
Mike Stump11289f42009-09-09 15:08:12 +0000199
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000200 /// Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// transformed.
202 ///
203 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000204 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000205 /// not change. For example, template instantiation need not traverse
206 /// non-dependent types.
207 bool AlreadyTransformed(QualType T) {
208 return T.isNull();
209 }
210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000211 /// Determine whether the given call argument should be dropped, e.g.,
Douglas Gregord196a582009-12-14 19:27:10 +0000212 /// because it is a default argument.
213 ///
214 /// Subclasses can provide an alternative implementation of this routine to
215 /// determine which kinds of call arguments get dropped. By default,
216 /// CXXDefaultArgument nodes are dropped (prior to transformation).
217 bool DropCallArgument(Expr *E) {
218 return E->isDefaultArgument();
219 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000220
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000221 /// Determine whether we should expand a pack expansion with the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// given set of parameter packs into separate arguments by repeatedly
223 /// transforming the pattern.
224 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000225 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000226 /// Subclasses can override this routine to provide different behavior.
227 ///
228 /// \param EllipsisLoc The location of the ellipsis that identifies the
229 /// pack expansion.
230 ///
231 /// \param PatternRange The source range that covers the entire pattern of
232 /// the pack expansion.
233 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000234 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000235 /// pattern.
236 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000237 /// \param ShouldExpand Will be set to \c true if the transformer should
238 /// expand the corresponding pack expansions into separate arguments. When
239 /// set, \c NumExpansions must also be set.
240 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000241 /// \param RetainExpansion Whether the caller should add an unexpanded
242 /// pack expansion after all of the expanded arguments. This is used
243 /// when extending explicitly-specified template argument packs per
244 /// C++0x [temp.arg.explicit]p9.
245 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000246 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000247 /// the expanded form of the corresponding pack expansion. This is both an
248 /// input and an output parameter, which can be set by the caller if the
249 /// number of expansions is known a priori (e.g., due to a prior substitution)
250 /// and will be set by the callee when the number of expansions is known.
251 /// The callee must set this value when \c ShouldExpand is \c true; it may
252 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000254 /// \returns true if an error occurred (e.g., because the parameter packs
255 /// are to be instantiated with arguments of different lengths), false
256 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 /// must be set.
258 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
259 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000260 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000261 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000262 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000263 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000264 ShouldExpand = false;
265 return false;
266 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000267
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000268 /// "Forget" about the partially-substituted pack template argument,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000269 /// when performing an instantiation that must preserve the parameter pack
270 /// use.
271 ///
272 /// This routine is meant to be overridden by the template instantiator.
273 TemplateArgument ForgetPartiallySubstitutedPack() {
274 return TemplateArgument();
275 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000276
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000277 /// "Remember" the partially-substituted pack template argument
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000278 /// after performing an instantiation that must preserve the parameter pack
279 /// use.
280 ///
281 /// This routine is meant to be overridden by the template instantiator.
282 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000284 /// Note to the derived class when a function parameter pack is
Douglas Gregorf3010112011-01-07 16:43:16 +0000285 /// being expanded.
286 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000288 /// Transforms the given type into another type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000291 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000292 /// function. This is expensive, but we don't mind, because
293 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000294 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000295 ///
296 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000297 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000298
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000299 /// Transforms the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000300 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000301 ///
John McCall550e0c22009-10-21 00:40:46 +0000302 /// By default, this routine transforms a type by delegating to the
303 /// appropriate TransformXXXType to build a new type. Subclasses
304 /// may override this function (to take over all type
305 /// transformations) or some set of the TransformXXXType functions
306 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000307 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000309 /// Transform the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000310 /// type, collecting location information in the given builder
311 /// as necessary.
312 ///
John McCall31f82722010-11-12 08:19:04 +0000313 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000314
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000315 /// Transform a type that is permitted to produce a
Richard Smithee579842017-01-30 20:39:26 +0000316 /// DeducedTemplateSpecializationType.
317 ///
318 /// This is used in the (relatively rare) contexts where it is acceptable
319 /// for transformation to produce a class template type with deduced
320 /// template arguments.
321 /// @{
322 QualType TransformTypeWithDeducedTST(QualType T);
323 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
324 /// @}
325
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000326 /// The reason why the value of a statement is not discarded, if any.
327 enum StmtDiscardKind {
328 SDK_Discarded,
329 SDK_NotDiscarded,
330 SDK_StmtExprResult,
331 };
332
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000333 /// Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000334 ///
Mike Stump11289f42009-09-09 15:08:12 +0000335 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000336 /// appropriate TransformXXXStmt function to transform a specific kind of
337 /// statement or the TransformExpr() function to transform an expression.
338 /// Subclasses may override this function to transform statements using some
339 /// other mechanism.
340 ///
341 /// \returns the transformed statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000342 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
Mike Stump11289f42009-09-09 15:08:12 +0000343
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000344 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000345 ///
346 /// By default, this routine transforms a statement by delegating to the
347 /// appropriate TransformOMPXXXClause function to transform a specific kind
348 /// of clause. Subclasses may override this function to transform statements
349 /// using some other mechanism.
350 ///
351 /// \returns the transformed OpenMP clause.
352 OMPClause *TransformOMPClause(OMPClause *S);
353
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000354 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000355 ///
356 /// By default, this routine transforms a statement by delegating to the
357 /// appropriate TransformXXXAttr function to transform a specific kind
358 /// of attribute. Subclasses may override this function to transform
359 /// attributed statements using some other mechanism.
360 ///
361 /// \returns the transformed attribute
362 const Attr *TransformAttr(const Attr *S);
363
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000364/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000365///
366/// Subclasses should override the transformation of attributes with a pragma
367/// spelling to transform expressions stored within the attribute.
368///
369/// \returns the transformed attribute.
370#define ATTR(X)
371#define PRAGMA_SPELLING_ATTR(X) \
372 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
373#include "clang/Basic/AttrList.inc"
374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000375 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000376 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000377 /// By default, this routine transforms an expression by delegating to the
378 /// appropriate TransformXXXExpr function to build a new expression.
379 /// Subclasses may override this function to transform expressions using some
380 /// other mechanism.
381 ///
382 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000383 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000384
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000385 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000386 ///
387 /// By default, this routine transforms an initializer by stripping off the
388 /// semantic nodes added by initialization, then passing the result to
389 /// TransformExpr or TransformExprs.
390 ///
391 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000392 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000393
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000394 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000395 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// This routine transforms a list of expressions by invoking
397 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000398 /// support for variadic templates by expanding any pack expansions (if the
399 /// derived class permits such expansion) along the way. When pack expansions
400 /// are present, the number of outputs may not equal the number of inputs.
401 ///
402 /// \param Inputs The set of expressions to be transformed.
403 ///
404 /// \param NumInputs The number of expressions in \c Inputs.
405 ///
406 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000407 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000408 /// be.
409 ///
410 /// \param Outputs The transformed input expressions will be added to this
411 /// vector.
412 ///
413 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
414 /// due to transformation.
415 ///
416 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000417 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000418 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000419 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000420
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000421 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 /// or expression.
423 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// By default, acts as the identity function on declarations, unless the
425 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000426 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000427 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000428 llvm::DenseMap<Decl *, Decl *>::iterator Known
429 = TransformedLocalDecls.find(D);
430 if (Known != TransformedLocalDecls.end())
431 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000432
433 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000435
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000436 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000437 ///
438 /// By default, this transforms the variable and expression and rebuilds
439 /// the condition.
440 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
441 Expr *Expr,
442 Sema::ConditionKind Kind);
443
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000444 /// Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000445 /// place them on the new declaration.
446 ///
447 /// By default, this operation does nothing. Subclasses may override this
448 /// behavior to transform attributes.
449 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000451 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000452 /// transformer.
453 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000454 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000455 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
456 /// the transformer itself has to transform the declarations. This routine
457 /// can be overridden by a subclass that keeps track of such mappings.
Richard Smithb2997f52019-05-21 20:10:50 +0000458 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) {
459 assert(New.size() == 1 &&
460 "must override transformedLocalDecl if performing pack expansion");
461 TransformedLocalDecls[Old] = New.front();
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000462 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000463
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000464 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000465 ///
Mike Stump11289f42009-09-09 15:08:12 +0000466 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
469 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000470 }
Mike Stump11289f42009-09-09 15:08:12 +0000471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000472 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000473 /// nested-name-specifier in a member access expression.
474 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000475 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000476 /// identifier in a nested-name-specifier of a member access expression, e.g.,
477 /// the \c T in \c x->T::member
478 ///
479 /// By default, invokes TransformDecl() to transform the declaration.
480 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
482 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000483 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000484
Richard Smith151c4562016-12-20 21:35:28 +0000485 /// Transform the set of declarations in an OverloadExpr.
486 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
487 LookupResult &R);
488
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000489 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000490 /// information.
491 ///
492 /// By default, transforms all of the types and declarations within the
493 /// nested-name-specifier. Subclasses may override this function to provide
494 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000495 NestedNameSpecifierLoc
496 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
497 QualType ObjectType = QualType(),
498 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000499
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000500 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000501 ///
502 /// By default, transforms the types of conversion function, constructor,
503 /// and destructor names and then (if needed) rebuilds the declaration name.
504 /// Identifiers and selectors are returned unmodified. Sublcasses may
505 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000506 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000507 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000509 /// Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000510 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000511 /// \param SS The nested-name-specifier that qualifies the template
512 /// name. This nested-name-specifier must already have been transformed.
513 ///
514 /// \param Name The template name to transform.
515 ///
516 /// \param NameLoc The source location of the template name.
517 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000518 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000519 /// access expression, this is the type of the object whose member template
520 /// is being referenced.
521 ///
522 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
523 /// also refers to a name within the current (lexical) scope, this is the
524 /// declaration it refers to.
525 ///
526 /// By default, transforms the template name by transforming the declarations
527 /// and nested-name-specifiers that occur within the template name.
528 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000529 TemplateName
530 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
531 SourceLocation NameLoc,
532 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000533 NamedDecl *FirstQualifierInScope = nullptr,
534 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000535
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000536 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537 ///
Mike Stump11289f42009-09-09 15:08:12 +0000538 /// By default, this operation transforms the type, expression, or
539 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000540 /// new template argument from the transformed result. Subclasses may
541 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000542 ///
543 /// Returns true if there was an error.
544 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000545 TemplateArgumentLoc &Output,
546 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000547
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000548 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000549 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000550 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000551 /// in the input set using \c TransformTemplateArgument(), and appends
552 /// the transformed arguments to the output list.
553 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000554 /// Note that this overload of \c TransformTemplateArguments() is merely
555 /// a convenience function. Subclasses that wish to override this behavior
556 /// should override the iterator-based member template version.
557 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000558 /// \param Inputs The set of template arguments to be transformed.
559 ///
560 /// \param NumInputs The number of template arguments in \p Inputs.
561 ///
562 /// \param Outputs The set of transformed template arguments output by this
563 /// routine.
564 ///
565 /// Returns true if an error occurred.
566 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
567 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000568 TemplateArgumentListInfo &Outputs,
569 bool Uneval = false) {
570 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
571 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000572 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000573
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000574 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000575 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000576 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000577 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000578 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000579 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000580 /// \param First An iterator to the first template argument.
581 ///
582 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000583 ///
584 /// \param Outputs The set of transformed template arguments output by this
585 /// routine.
586 ///
587 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000588 template<typename InputIterator>
589 bool TransformTemplateArguments(InputIterator First,
590 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000591 TemplateArgumentListInfo &Outputs,
592 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000593
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000594 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000595 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
596 TemplateArgumentLoc &ArgLoc);
597
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000598 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000599 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
600 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000601 getDerived().getBaseLocation());
602 }
Mike Stump11289f42009-09-09 15:08:12 +0000603
John McCall550e0c22009-10-21 00:40:46 +0000604#define ABSTRACT_TYPELOC(CLASS, PARENT)
605#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000606 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000607#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000608
Richard Smith2e321552014-11-12 02:00:47 +0000609 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000610 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
611 FunctionProtoTypeLoc TL,
612 CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +0000613 Qualifiers ThisTypeQuals,
Richard Smith2e321552014-11-12 02:00:47 +0000614 Fn TransformExceptionSpec);
615
616 bool TransformExceptionSpec(SourceLocation Loc,
617 FunctionProtoType::ExceptionSpecInfo &ESI,
618 SmallVectorImpl<QualType> &Exceptions,
619 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000620
David Majnemerfad8f482013-10-15 09:33:02 +0000621 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000622
Chad Rosier1dcde962012-08-08 18:46:20 +0000623 QualType
John McCall31f82722010-11-12 08:19:04 +0000624 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
625 TemplateSpecializationTypeLoc TL,
626 TemplateName Template);
627
Chad Rosier1dcde962012-08-08 18:46:20 +0000628 QualType
John McCall31f82722010-11-12 08:19:04 +0000629 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
630 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000631 TemplateName Template,
632 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000633
Nico Weberc153d242014-07-28 00:02:09 +0000634 QualType TransformDependentTemplateSpecializationType(
635 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
636 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000638 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000639 /// given vectors.
640 ///
641 /// The result vectors should be kept in sync; null entries in the
642 /// variables vector are acceptable.
643 ///
644 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000645 bool TransformFunctionTypeParams(
646 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
647 const QualType *ParamTypes,
648 const FunctionProtoType::ExtParameterInfo *ParamInfos,
649 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
650 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000651
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000652 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000653 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000654 ///
655 /// \param indexAdjustment - A number to add to the parameter's
656 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000657 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000658 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000659 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000660 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000661
Richard Smith87346a12019-06-02 18:53:44 +0000662 /// Transform the body of a lambda-expression.
Richard Smith7bf8f6f2019-06-04 17:17:20 +0000663 StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
664 /// Alternative implementation of TransformLambdaBody that skips transforming
665 /// the body.
666 StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
Richard Smith87346a12019-06-02 18:53:44 +0000667
John McCall31f82722010-11-12 08:19:04 +0000668 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000669
John McCalldadc5752010-08-24 06:29:42 +0000670 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
671 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000672
Faisal Vali2cba1332013-10-23 06:44:28 +0000673 TemplateParameterList *TransformTemplateParameterList(
674 TemplateParameterList *TPL) {
675 return TPL;
676 }
677
Richard Smithdb2630f2012-10-21 03:28:35 +0000678 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000679
Richard Smithdb2630f2012-10-21 03:28:35 +0000680 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000681 bool IsAddressOfOperand,
682 TypeSourceInfo **RecoveryTSI);
683
684 ExprResult TransformParenDependentScopeDeclRefExpr(
685 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
686 TypeSourceInfo **RecoveryTSI);
687
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000688 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000689
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000690// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
691// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000692#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000693 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000694 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000695#define VALUESTMT(Node, Parent) \
696 LLVM_ATTRIBUTE_NOINLINE \
697 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000698#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000699 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000700 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000701#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000702#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000703
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000704#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000705 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000706 OMPClause *Transform ## Class(Class *S);
707#include "clang/Basic/OpenMPKinds.def"
708
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000709 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000710 ///
711 /// By default, this routine adds type qualifiers only to types that can
712 /// have qualifiers, and silently suppresses those qualifiers that are not
713 /// permitted. Subclasses may override this routine to provide different
714 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000715 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000716
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000717 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ///
719 /// By default, performs semantic analysis when building the pointer type.
720 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000721 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000723 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 ///
Mike Stump11289f42009-09-09 15:08:12 +0000725 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000726 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000727 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000729 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 ///
John McCall70dd5f62009-10-30 00:06:24 +0000731 /// By default, performs semantic analysis when building the
732 /// reference type. Subclasses may override this routine to provide
733 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ///
John McCall70dd5f62009-10-30 00:06:24 +0000735 /// \param LValue whether the type was written with an lvalue sigil
736 /// or an rvalue sigil.
737 QualType RebuildReferenceType(QualType ReferentType,
738 bool LValue,
739 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000740
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000741 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000742 /// class type it refers into.
743 ///
744 /// By default, performs semantic analysis when building the member pointer
745 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000746 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
747 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000748
Manman Rene6be26c2016-09-13 17:25:08 +0000749 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
750 SourceLocation ProtocolLAngleLoc,
751 ArrayRef<ObjCProtocolDecl *> Protocols,
752 ArrayRef<SourceLocation> ProtocolLocs,
753 SourceLocation ProtocolRAngleLoc);
754
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000755 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000756 ///
757 /// By default, performs semantic analysis when building the object type.
758 /// Subclasses may override this routine to provide different behavior.
759 QualType RebuildObjCObjectType(QualType BaseType,
760 SourceLocation Loc,
761 SourceLocation TypeArgsLAngleLoc,
762 ArrayRef<TypeSourceInfo *> TypeArgs,
763 SourceLocation TypeArgsRAngleLoc,
764 SourceLocation ProtocolLAngleLoc,
765 ArrayRef<ObjCProtocolDecl *> Protocols,
766 ArrayRef<SourceLocation> ProtocolLocs,
767 SourceLocation ProtocolRAngleLoc);
768
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000769 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000770 ///
771 /// By default, directly builds the pointer type, with no additional semantic
772 /// analysis.
773 QualType RebuildObjCObjectPointerType(QualType PointeeType,
774 SourceLocation Star);
775
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000776 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000777 /// modifier, size of the array (if known), size expression, and index type
778 /// qualifiers.
779 ///
780 /// By default, performs semantic analysis when building the array type.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000783 QualType RebuildArrayType(QualType ElementType,
784 ArrayType::ArraySizeModifier SizeMod,
785 const llvm::APInt *Size,
786 Expr *SizeExpr,
787 unsigned IndexTypeQuals,
788 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000789
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000790 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000791 /// modifier, (known) size of the array, and index type qualifiers.
792 ///
793 /// By default, performs semantic analysis when building the array type.
794 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000795 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 ArrayType::ArraySizeModifier SizeMod,
797 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000798 unsigned IndexTypeQuals,
799 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000801 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000802 /// modifier, and index type qualifiers.
803 ///
804 /// By default, performs semantic analysis when building the array type.
805 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000806 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000808 unsigned IndexTypeQuals,
809 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000811 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000812 /// size modifier, size expression, and index type qualifiers.
813 ///
814 /// By default, performs semantic analysis when building the array type.
815 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000816 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000817 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000818 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000819 unsigned IndexTypeQuals,
820 SourceRange BracketsRange);
821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000822 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000823 /// size modifier, size expression, and index type qualifiers.
824 ///
825 /// By default, performs semantic analysis when building the array type.
826 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000827 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000828 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000829 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 unsigned IndexTypeQuals,
831 SourceRange BracketsRange);
832
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000833 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000834 /// number of elements.
835 ///
836 /// By default, performs semantic analysis when building the vector type.
837 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000838 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000839 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000840
Erich Keanef702b022018-07-13 19:46:04 +0000841 /// Build a new potentially dependently-sized extended vector type
842 /// given the element type and number of elements.
843 ///
844 /// By default, performs semantic analysis when building the vector type.
845 /// Subclasses may override this routine to provide different behavior.
846 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
847 SourceLocation AttributeLoc,
848 VectorType::VectorKind);
849
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000850 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000851 /// number of elements.
852 ///
853 /// By default, performs semantic analysis when building the vector type.
854 /// Subclasses may override this routine to provide different behavior.
855 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
856 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000857
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000858 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// given the element type and number of elements.
860 ///
861 /// By default, performs semantic analysis when building the vector type.
862 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000863 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000864 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000865 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000867 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000868 /// type variable with the correct address space (retrieved from
869 /// AddrSpaceExpr) applied to it. The former will be returned in cases
870 /// where the address space remains dependent.
871 ///
872 /// By default, performs semantic analysis when building the type with address
873 /// space applied. Subclasses may override this routine to provide different
874 /// behavior.
875 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
876 Expr *AddrSpaceExpr,
877 SourceLocation AttributeLoc);
878
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000879 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000880 ///
881 /// By default, performs semantic analysis when building the function type.
882 /// Subclasses may override this routine to provide different behavior.
883 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000884 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000885 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000888 QualType RebuildFunctionNoProtoType(QualType ResultType);
889
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000890 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000891 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000892 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000893
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000894 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000895 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000896 return SemaRef.Context.getTypeDeclType(Typedef);
897 }
898
Leonard Chanc72aaf62019-05-07 03:20:17 +0000899 /// Build a new MacroDefined type.
900 QualType RebuildMacroQualifiedType(QualType T,
901 const IdentifierInfo *MacroII) {
902 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
903 }
904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000905 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000906 QualType RebuildRecordType(RecordDecl *Record) {
907 return SemaRef.Context.getTypeDeclType(Record);
908 }
909
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000910 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000911 QualType RebuildEnumType(EnumDecl *Enum) {
912 return SemaRef.Context.getTypeDeclType(Enum);
913 }
John McCallfcc33b02009-09-05 00:15:47 +0000914
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000915 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000916 ///
917 /// By default, performs semantic analysis when building the typeof type.
918 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000919 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000920
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000921 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000922 ///
923 /// By default, builds a new TypeOfType with the given underlying type.
924 QualType RebuildTypeOfType(QualType Underlying);
925
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000926 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000927 QualType RebuildUnaryTransformType(QualType BaseType,
928 UnaryTransformType::UTTKind UKind,
929 SourceLocation Loc);
930
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000931 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000932 ///
933 /// By default, performs semantic analysis when building the decltype type.
934 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000935 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000937 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000938 ///
939 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000940 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000941 // Note, IsDependent is always false here: we implicitly convert an 'auto'
942 // which has been deduced to a dependent type into an undeduced 'auto', so
943 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000944 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000945 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000946 }
947
Richard Smith600b5262017-01-26 20:40:47 +0000948 /// By default, builds a new DeducedTemplateSpecializationType with the given
949 /// deduced type.
950 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
951 QualType Deduced) {
952 return SemaRef.Context.getDeducedTemplateSpecializationType(
953 Template, Deduced, /*IsDependent*/ false);
954 }
955
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000956 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000957 ///
958 /// By default, performs semantic analysis when building the template
959 /// specialization type. Subclasses may override this routine to provide
960 /// different behavior.
961 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000962 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000963 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000964
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000965 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000966 ///
967 /// By default, builds a new ParenType type from the inner type.
968 /// Subclasses may override this routine to provide different behavior.
969 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000970 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000971 }
972
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000973 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000974 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000975 /// By default, builds a new ElaboratedType type from the keyword,
976 /// the nested-name-specifier and the named type.
977 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000978 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
979 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000980 NestedNameSpecifierLoc QualifierLoc,
981 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000982 return SemaRef.Context.getElaboratedType(Keyword,
983 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000984 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000985 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000986
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000987 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000988 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000989 /// By default, builds a new DependentNameType type from the
990 /// nested-name-specifier and the given type. Subclasses may override
991 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000992 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 ElaboratedTypeKeyword Keyword,
994 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000995 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000996 const IdentifierInfo *Name,
997 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000998 TemplateArgumentListInfo &Args,
999 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00001000 // Rebuild the template name.
1001 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +00001002 CXXScopeSpec SS;
1003 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +00001004 TemplateName InstName = getDerived().RebuildTemplateName(
1005 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1006 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +00001007
Douglas Gregora7a795b2011-03-01 20:11:18 +00001008 if (InstName.isNull())
1009 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001010
Douglas Gregora7a795b2011-03-01 20:11:18 +00001011 // If it's still dependent, make a dependent specialization.
1012 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +00001013 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
1014 QualifierLoc.getNestedNameSpecifier(),
1015 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +00001016 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +00001017
Douglas Gregora7a795b2011-03-01 20:11:18 +00001018 // Otherwise, make an elaborated type wrapping a non-dependent
1019 // specialization.
1020 QualType T =
1021 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1022 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001023
Craig Topperc3ec1492014-05-26 06:22:03 +00001024 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001025 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001026
1027 return SemaRef.Context.getElaboratedType(Keyword,
1028 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001029 T);
1030 }
1031
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001032 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001033 ///
1034 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001035 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001036 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001037 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001038 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001039 NestedNameSpecifierLoc QualifierLoc,
1040 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001041 SourceLocation IdLoc,
1042 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001043 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001044 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001045
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001046 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001047 // If the name is still dependent, just build a new dependent name type.
1048 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001049 return SemaRef.Context.getDependentNameType(Keyword,
1050 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001051 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001052 }
1053
Richard Smithee579842017-01-30 20:39:26 +00001054 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1055 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1056 *Id, IdLoc);
1057 // If a dependent name resolves to a deduced template specialization type,
1058 // check that we're in one of the syntactic contexts permitting it.
1059 if (!DeducedTSTContext) {
1060 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1061 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1062 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1063 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1064 Deduced->getTemplateName())
1065 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1066 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1067 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1068 return QualType();
1069 }
1070 }
1071 return T;
1072 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001073
1074 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1075
Abramo Bagnarad7548482010-05-19 21:37:53 +00001076 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001077 // into a non-dependent elaborated-type-specifier. Find the tag we're
1078 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001079 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001080 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1081 if (!DC)
1082 return QualType();
1083
John McCallbf8c5192010-05-27 06:40:31 +00001084 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1085 return QualType();
1086
Craig Topperc3ec1492014-05-26 06:22:03 +00001087 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001088 SemaRef.LookupQualifiedName(Result, DC);
1089 switch (Result.getResultKind()) {
1090 case LookupResult::NotFound:
1091 case LookupResult::NotFoundInCurrentInstantiation:
1092 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001093
Douglas Gregore677daf2010-03-31 22:19:08 +00001094 case LookupResult::Found:
1095 Tag = Result.getAsSingle<TagDecl>();
1096 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001097
Douglas Gregore677daf2010-03-31 22:19:08 +00001098 case LookupResult::FoundOverloaded:
1099 case LookupResult::FoundUnresolvedValue:
1100 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001101
Douglas Gregore677daf2010-03-31 22:19:08 +00001102 case LookupResult::Ambiguous:
1103 // Let the LookupResult structure handle ambiguities.
1104 return QualType();
1105 }
1106
1107 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001108 // Check where the name exists but isn't a tag type and use that to emit
1109 // better diagnostics.
1110 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1111 SemaRef.LookupQualifiedName(Result, DC);
1112 switch (Result.getResultKind()) {
1113 case LookupResult::Found:
1114 case LookupResult::FoundOverloaded:
1115 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001116 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001117 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1118 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1119 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001120 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1121 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001122 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001123 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001124 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001125 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001126 break;
1127 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001128 return QualType();
1129 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001130
Richard Trieucaa33d32011-06-10 03:11:26 +00001131 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001132 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001133 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001134 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1135 return QualType();
1136 }
1137
1138 // Build the elaborated-type-specifier type.
1139 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001140 return SemaRef.Context.getElaboratedType(Keyword,
1141 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001142 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001145 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001146 ///
1147 /// By default, builds a new PackExpansionType type from the given pattern.
1148 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001149 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001150 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001151 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001152 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001153 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1154 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001155 }
1156
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001157 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001158 ///
1159 /// By default, performs semantic analysis when building the atomic type.
1160 /// Subclasses may override this routine to provide different behavior.
1161 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1162
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001163 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001164 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1165 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001166
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001167 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001168 /// indicating whether the "template" keyword was provided, and the template
1169 /// that the template name refers to.
1170 ///
1171 /// By default, builds the new template name directly. Subclasses may override
1172 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001173 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001174 bool TemplateKW,
1175 TemplateDecl *Template);
1176
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001177 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001178 /// name that is referred to as a template.
1179 ///
1180 /// By default, performs semantic analysis to determine whether the name can
1181 /// be resolved to a specific template, then builds the appropriate kind of
1182 /// template name. Subclasses may override this routine to provide different
1183 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001184 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001185 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001186 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001187 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001188 NamedDecl *FirstQualifierInScope,
1189 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001190
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001191 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001192 /// overloaded operator name that is referred to as a template.
1193 ///
1194 /// By default, performs semantic analysis to determine whether the name can
1195 /// be resolved to a specific template, then builds the appropriate kind of
1196 /// template name. Subclasses may override this routine to provide different
1197 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001198 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001199 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001200 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001201 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001202 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001203
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001204 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001205 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001206 ///
1207 /// By default, performs semantic analysis to determine whether the name can
1208 /// be resolved to a specific template, then builds the appropriate kind of
1209 /// template name. Subclasses may override this routine to provide different
1210 /// behavior.
1211 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1212 const TemplateArgument &ArgPack) {
1213 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1214 }
1215
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001216 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 ///
1218 /// By default, performs semantic analysis to build the new statement.
1219 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001220 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 MultiStmtArg Statements,
1222 SourceLocation RBraceLoc,
1223 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001224 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 IsStmtExpr);
1226 }
1227
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001228 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001232 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001233 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001234 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001235 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 ColonLoc);
1239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001241 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 ///
1243 /// By default, performs semantic analysis to build the new statement.
1244 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001245 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001246 getSema().ActOnCaseStmtBody(S, Body);
1247 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001250 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001251 ///
1252 /// By default, performs semantic analysis to build the new statement.
1253 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001254 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001256 Stmt *SubStmt) {
1257 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001258 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001261 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001265 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1266 SourceLocation ColonLoc, Stmt *SubStmt) {
1267 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001270 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001274 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1275 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001276 Stmt *SubStmt) {
1277 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1278 }
1279
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001280 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001281 ///
1282 /// By default, performs semantic analysis to build the new statement.
1283 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001284 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001285 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001286 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001287 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001288 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001291 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001292 ///
1293 /// By default, performs semantic analysis to build the new statement.
1294 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001295 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001296 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001297 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001300 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001301 ///
1302 /// By default, performs semantic analysis to build the new statement.
1303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001304 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001305 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001306 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001307 }
1308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001309 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001310 ///
1311 /// By default, performs semantic analysis to build the new statement.
1312 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001313 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1314 Sema::ConditionResult Cond, Stmt *Body) {
1315 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001316 }
Mike Stump11289f42009-09-09 15:08:12 +00001317
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001318 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001319 ///
1320 /// By default, performs semantic analysis to build the new statement.
1321 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001322 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001323 SourceLocation WhileLoc, SourceLocation LParenLoc,
1324 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001325 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1326 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001327 }
1328
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001329 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 ///
1331 /// By default, performs semantic analysis to build the new statement.
1332 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001333 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001334 Stmt *Init, Sema::ConditionResult Cond,
1335 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1336 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001337 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001338 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001341 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001342 ///
1343 /// By default, performs semantic analysis to build the new statement.
1344 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001345 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1346 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001347 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001348 }
1349
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001350 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001354 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001355 SourceLocation StarLoc,
1356 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001357 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001358 }
Mike Stump11289f42009-09-09 15:08:12 +00001359
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001360 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001364 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001365 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001368 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001369 ///
1370 /// By default, performs semantic analysis to build the new statement.
1371 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001372 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001373 SourceLocation StartLoc, SourceLocation EndLoc) {
1374 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001375 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001376 }
Mike Stump11289f42009-09-09 15:08:12 +00001377
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001378 /// Build a new inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001379 ///
1380 /// By default, performs semantic analysis to build the new statement.
1381 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001382 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1383 bool IsVolatile, unsigned NumOutputs,
1384 unsigned NumInputs, IdentifierInfo **Names,
1385 MultiExprArg Constraints, MultiExprArg Exprs,
1386 Expr *AsmString, MultiExprArg Clobbers,
Jennifer Yub8fee672019-06-03 15:57:25 +00001387 unsigned NumLabels,
Chad Rosierde70e0e2012-08-25 00:11:56 +00001388 SourceLocation RParenLoc) {
1389 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1390 NumInputs, Names, Constraints, Exprs,
Jennifer Yub8fee672019-06-03 15:57:25 +00001391 AsmString, Clobbers, NumLabels, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001392 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001393
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001394 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001395 ///
1396 /// By default, performs semantic analysis to build the new statement.
1397 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001398 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001399 ArrayRef<Token> AsmToks,
1400 StringRef AsmString,
1401 unsigned NumOutputs, unsigned NumInputs,
1402 ArrayRef<StringRef> Constraints,
1403 ArrayRef<StringRef> Clobbers,
1404 ArrayRef<Expr*> Exprs,
1405 SourceLocation EndLoc) {
1406 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1407 NumOutputs, NumInputs,
1408 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001409 }
1410
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001411 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001415 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1416 bool IsImplicit) {
1417 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001418 }
1419
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001420 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001424 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1425 bool IsImplicit) {
1426 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1427 }
1428
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001429 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001430 ///
1431 /// By default, performs semantic analysis to build the new expression.
1432 /// Subclasses may override this routine to provide different behavior.
1433 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1434 Expr *Result,
1435 UnresolvedLookupExpr *Lookup) {
1436 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001437 }
1438
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001439 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001440 ///
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
1443 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1444 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1445 }
1446
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001447 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1448 return getSema().BuildCoroutineBodyStmt(Args);
1449 }
1450
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001451 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001452 ///
1453 /// By default, performs semantic analysis to build the new statement.
1454 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001455 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001456 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001457 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001458 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001459 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001460 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001461 }
1462
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001463 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001464 ///
1465 /// By default, performs semantic analysis to build the new declaration.
1466 /// Subclasses may override this routine to provide different behavior.
1467 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1468 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001469 return getSema().BuildObjCExceptionDecl(TInfo, T,
1470 ExceptionDecl->getInnerLocStart(),
1471 ExceptionDecl->getLocation(),
1472 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001473 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001474
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001475 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001476 ///
1477 /// By default, performs semantic analysis to build the new statement.
1478 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001479 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001480 SourceLocation RParenLoc,
1481 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001482 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001483 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001484 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001485 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001486
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001487 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001488 ///
1489 /// By default, performs semantic analysis to build the new statement.
1490 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001491 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001492 Stmt *Body) {
1493 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001494 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001495
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001496 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001501 Expr *Operand) {
1502 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001503 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001504
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001505 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001506 ///
1507 /// By default, performs semantic analysis to build the new statement.
1508 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001509 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001510 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001511 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001512 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001513 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001514 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001515 return getSema().ActOnOpenMPExecutableDirective(
1516 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001517 }
1518
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001519 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001520 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001521 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001522 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001523 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1524 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001525 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001526 SourceLocation NameModifierLoc,
1527 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001528 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001529 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1530 LParenLoc, NameModifierLoc, ColonLoc,
1531 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001532 }
1533
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001534 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001535 ///
1536 /// By default, performs semantic analysis to build the new OpenMP clause.
1537 /// Subclasses may override this routine to provide different behavior.
1538 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1539 SourceLocation LParenLoc,
1540 SourceLocation EndLoc) {
1541 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1542 EndLoc);
1543 }
1544
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001545 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001546 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001547 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001548 /// Subclasses may override this routine to provide different behavior.
1549 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1550 SourceLocation StartLoc,
1551 SourceLocation LParenLoc,
1552 SourceLocation EndLoc) {
1553 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1554 LParenLoc, EndLoc);
1555 }
1556
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001557 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001558 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001559 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001560 /// Subclasses may override this routine to provide different behavior.
1561 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1562 SourceLocation LParenLoc,
1563 SourceLocation EndLoc) {
1564 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1565 }
1566
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001567 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001568 ///
1569 /// By default, performs semantic analysis to build the new OpenMP clause.
1570 /// Subclasses may override this routine to provide different behavior.
1571 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1572 SourceLocation LParenLoc,
1573 SourceLocation EndLoc) {
1574 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1575 }
1576
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001577 /// Build a new OpenMP 'allocator' clause.
1578 ///
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
1582 SourceLocation LParenLoc,
1583 SourceLocation EndLoc) {
1584 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1585 }
1586
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001587 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001588 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001589 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001590 /// Subclasses may override this routine to provide different behavior.
1591 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1592 SourceLocation LParenLoc,
1593 SourceLocation EndLoc) {
1594 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1595 EndLoc);
1596 }
1597
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001598 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001599 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001600 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001601 /// Subclasses may override this routine to provide different behavior.
1602 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1603 SourceLocation KindKwLoc,
1604 SourceLocation StartLoc,
1605 SourceLocation LParenLoc,
1606 SourceLocation EndLoc) {
1607 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1608 StartLoc, LParenLoc, EndLoc);
1609 }
1610
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001611 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001612 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001613 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001614 /// Subclasses may override this routine to provide different behavior.
1615 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1616 SourceLocation KindKwLoc,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation EndLoc) {
1620 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1621 StartLoc, LParenLoc, EndLoc);
1622 }
1623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001624 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001625 ///
1626 /// By default, performs semantic analysis to build the new OpenMP clause.
1627 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001628 OMPClause *RebuildOMPScheduleClause(
1629 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1630 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1631 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1632 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001633 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001634 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1635 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001636 }
1637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001638 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001639 ///
1640 /// By default, performs semantic analysis to build the new OpenMP clause.
1641 /// Subclasses may override this routine to provide different behavior.
1642 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1643 SourceLocation EndLoc,
1644 SourceLocation LParenLoc, Expr *Num) {
1645 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1646 }
1647
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001648 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001649 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001650 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001651 /// Subclasses may override this routine to provide different behavior.
1652 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1653 SourceLocation StartLoc,
1654 SourceLocation LParenLoc,
1655 SourceLocation EndLoc) {
1656 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1657 EndLoc);
1658 }
1659
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001660 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001661 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001662 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001663 /// Subclasses may override this routine to provide different behavior.
1664 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1665 SourceLocation StartLoc,
1666 SourceLocation LParenLoc,
1667 SourceLocation EndLoc) {
1668 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1669 EndLoc);
1670 }
1671
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001672 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001673 ///
1674 /// By default, performs semantic analysis to build the new OpenMP clause.
1675 /// Subclasses may override this routine to provide different behavior.
1676 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1677 SourceLocation StartLoc,
1678 SourceLocation LParenLoc,
1679 SourceLocation EndLoc) {
1680 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1681 EndLoc);
1682 }
1683
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001684 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001685 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001686 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001687 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001688 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1689 SourceLocation StartLoc,
1690 SourceLocation LParenLoc,
1691 SourceLocation EndLoc) {
1692 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1693 EndLoc);
1694 }
1695
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001696 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001697 ///
1698 /// By default, performs semantic analysis to build the new statement.
1699 /// Subclasses may override this routine to provide different behavior.
1700 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1701 SourceLocation StartLoc,
1702 SourceLocation LParenLoc,
1703 SourceLocation ColonLoc,
1704 SourceLocation EndLoc,
1705 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001706 const DeclarationNameInfo &ReductionId,
1707 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001708 return getSema().ActOnOpenMPReductionClause(
1709 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001710 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001711 }
1712
Alexey Bataev169d96a2017-07-18 20:17:46 +00001713 /// Build a new OpenMP 'task_reduction' clause.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPTaskReductionClause(
1718 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1719 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1720 CXXScopeSpec &ReductionIdScopeSpec,
1721 const DeclarationNameInfo &ReductionId,
1722 ArrayRef<Expr *> UnresolvedReductions) {
1723 return getSema().ActOnOpenMPTaskReductionClause(
1724 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1725 ReductionId, UnresolvedReductions);
1726 }
1727
Alexey Bataevfa312f32017-07-21 18:48:21 +00001728 /// Build a new OpenMP 'in_reduction' clause.
1729 ///
1730 /// By default, performs semantic analysis to build the new statement.
1731 /// Subclasses may override this routine to provide different behavior.
1732 OMPClause *
1733 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1734 SourceLocation LParenLoc, SourceLocation ColonLoc,
1735 SourceLocation EndLoc,
1736 CXXScopeSpec &ReductionIdScopeSpec,
1737 const DeclarationNameInfo &ReductionId,
1738 ArrayRef<Expr *> UnresolvedReductions) {
1739 return getSema().ActOnOpenMPInReductionClause(
1740 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1741 ReductionId, UnresolvedReductions);
1742 }
1743
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001744 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001745 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001746 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001747 /// Subclasses may override this routine to provide different behavior.
1748 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1749 SourceLocation StartLoc,
1750 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001751 OpenMPLinearClauseKind Modifier,
1752 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001753 SourceLocation ColonLoc,
1754 SourceLocation EndLoc) {
1755 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001756 Modifier, ModifierLoc, ColonLoc,
1757 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001758 }
1759
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001760 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001761 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001762 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001763 /// Subclasses may override this routine to provide different behavior.
1764 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation ColonLoc,
1768 SourceLocation EndLoc) {
1769 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1770 LParenLoc, ColonLoc, EndLoc);
1771 }
1772
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001773 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001774 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001775 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001776 /// Subclasses may override this routine to provide different behavior.
1777 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1778 SourceLocation StartLoc,
1779 SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1782 EndLoc);
1783 }
1784
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001785 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001786 ///
1787 /// By default, performs semantic analysis to build the new OpenMP clause.
1788 /// Subclasses may override this routine to provide different behavior.
1789 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1790 SourceLocation StartLoc,
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001797 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1801 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1802 SourceLocation StartLoc,
1803 SourceLocation LParenLoc,
1804 SourceLocation EndLoc) {
1805 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1806 EndLoc);
1807 }
1808
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001809 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001810 ///
1811 /// By default, performs semantic analysis to build the new OpenMP clause.
1812 /// Subclasses may override this routine to provide different behavior.
1813 OMPClause *
1814 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1815 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1816 SourceLocation StartLoc, SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
1818 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1819 StartLoc, LParenLoc, EndLoc);
1820 }
1821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001822 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001823 ///
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1826 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1827 SourceLocation LParenLoc,
1828 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001829 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001830 EndLoc);
1831 }
1832
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001833 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001834 ///
1835 /// By default, performs semantic analysis to build the new OpenMP clause.
1836 /// Subclasses may override this routine to provide different behavior.
Michael Kruse4304e9d2019-02-19 16:38:20 +00001837 OMPClause *RebuildOMPMapClause(
1838 ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1839 ArrayRef<SourceLocation> MapTypeModifiersLoc,
1840 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
1841 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1842 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1843 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
Kelvin Lief579432018-12-18 22:18:41 +00001844 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001845 MapperIdScopeSpec, MapperId, MapType,
1846 IsMapTypeImplicit, MapLoc, ColonLoc,
1847 VarList, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001848 }
1849
Alexey Bataeve04483e2019-03-27 14:14:31 +00001850 /// Build a new OpenMP 'allocate' clause.
1851 ///
1852 /// By default, performs semantic analysis to build the new OpenMP clause.
1853 /// Subclasses may override this routine to provide different behavior.
1854 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
1855 SourceLocation StartLoc,
1856 SourceLocation LParenLoc,
1857 SourceLocation ColonLoc,
1858 SourceLocation EndLoc) {
1859 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
1860 LParenLoc, ColonLoc, EndLoc);
1861 }
1862
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001863 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001864 ///
1865 /// By default, performs semantic analysis to build the new statement.
1866 /// Subclasses may override this routine to provide different behavior.
1867 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1868 SourceLocation LParenLoc,
1869 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001870 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001871 EndLoc);
1872 }
1873
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001874 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001875 ///
1876 /// By default, performs semantic analysis to build the new statement.
1877 /// Subclasses may override this routine to provide different behavior.
1878 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1879 SourceLocation StartLoc,
1880 SourceLocation LParenLoc,
1881 SourceLocation EndLoc) {
1882 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1883 LParenLoc, EndLoc);
1884 }
1885
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001886 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001887 ///
1888 /// By default, performs semantic analysis to build the new statement.
1889 /// Subclasses may override this routine to provide different behavior.
1890 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1893 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1894 EndLoc);
1895 }
1896
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001897 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001898 ///
1899 /// By default, performs semantic analysis to build the new statement.
1900 /// Subclasses may override this routine to provide different behavior.
1901 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1902 SourceLocation LParenLoc,
1903 SourceLocation EndLoc) {
1904 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1905 EndLoc);
1906 }
1907
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001908 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001909 ///
1910 /// By default, performs semantic analysis to build the new statement.
1911 /// Subclasses may override this routine to provide different behavior.
1912 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1913 SourceLocation LParenLoc,
1914 SourceLocation EndLoc) {
1915 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1916 EndLoc);
1917 }
1918
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001919 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001920 ///
1921 /// By default, performs semantic analysis to build the new statement.
1922 /// Subclasses may override this routine to provide different behavior.
1923 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1924 SourceLocation LParenLoc,
1925 SourceLocation EndLoc) {
1926 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1927 }
1928
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001929 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001930 ///
1931 /// By default, performs semantic analysis to build the new OpenMP clause.
1932 /// Subclasses may override this routine to provide different behavior.
1933 OMPClause *
1934 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1935 Expr *ChunkSize, SourceLocation StartLoc,
1936 SourceLocation LParenLoc, SourceLocation KindLoc,
1937 SourceLocation CommaLoc, SourceLocation EndLoc) {
1938 return getSema().ActOnOpenMPDistScheduleClause(
1939 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1940 }
1941
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001942 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001943 ///
1944 /// By default, performs semantic analysis to build the new statement.
1945 /// Subclasses may override this routine to provide different behavior.
1946 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
Michael Kruse01f670d2019-02-22 22:29:42 +00001947 CXXScopeSpec &MapperIdScopeSpec,
1948 DeclarationNameInfo &MapperId,
1949 const OMPVarListLocTy &Locs,
1950 ArrayRef<Expr *> UnresolvedMappers) {
1951 return getSema().ActOnOpenMPToClause(VarList, MapperIdScopeSpec, MapperId,
1952 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00001953 }
1954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001955 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001956 ///
1957 /// By default, performs semantic analysis to build the new statement.
1958 /// Subclasses may override this routine to provide different behavior.
1959 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
Michael Kruse0336c752019-02-25 20:34:15 +00001960 CXXScopeSpec &MapperIdScopeSpec,
1961 DeclarationNameInfo &MapperId,
1962 const OMPVarListLocTy &Locs,
1963 ArrayRef<Expr *> UnresolvedMappers) {
1964 return getSema().ActOnOpenMPFromClause(VarList, MapperIdScopeSpec, MapperId,
1965 Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00001966 }
1967
Carlo Bertolli2404b172016-07-13 15:37:16 +00001968 /// Build a new OpenMP 'use_device_ptr' clause.
1969 ///
1970 /// By default, performs semantic analysis to build the new OpenMP clause.
1971 /// Subclasses may override this routine to provide different behavior.
1972 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001973 const OMPVarListLocTy &Locs) {
1974 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00001975 }
1976
Carlo Bertolli70594e92016-07-13 17:16:49 +00001977 /// Build a new OpenMP 'is_device_ptr' clause.
1978 ///
1979 /// By default, performs semantic analysis to build the new OpenMP clause.
1980 /// Subclasses may override this routine to provide different behavior.
1981 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
Michael Kruse4304e9d2019-02-19 16:38:20 +00001982 const OMPVarListLocTy &Locs) {
1983 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00001984 }
1985
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001986 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001987 ///
1988 /// By default, performs semantic analysis to build the new statement.
1989 /// Subclasses may override this routine to provide different behavior.
1990 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1991 Expr *object) {
1992 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1993 }
1994
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001995 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001996 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001997 /// By default, performs semantic analysis to build the new statement.
1998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001999 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00002000 Expr *Object, Stmt *Body) {
2001 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00002002 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00002003
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002004 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00002005 ///
2006 /// By default, performs semantic analysis to build the new statement.
2007 /// Subclasses may override this routine to provide different behavior.
2008 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
2009 Stmt *Body) {
2010 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2011 }
John McCall53848232011-07-27 01:07:15 +00002012
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002013 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00002014 ///
2015 /// By default, performs semantic analysis to build the new statement.
2016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002017 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002018 Stmt *Element,
2019 Expr *Collection,
2020 SourceLocation RParenLoc,
2021 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00002022 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002023 Element,
John McCallb268a282010-08-23 23:25:46 +00002024 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00002025 RParenLoc);
2026 if (ForEachStmt.isInvalid())
2027 return StmtError();
2028
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002029 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00002030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002031
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002032 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00002033 ///
2034 /// By default, performs semantic analysis to build the new decaration.
2035 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00002036 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00002037 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00002038 SourceLocation StartLoc,
2039 SourceLocation IdLoc,
2040 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002041 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002042 StartLoc, IdLoc, Id);
2043 if (Var)
2044 getSema().CurContext->addDecl(Var);
2045 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002046 }
2047
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002048 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002049 ///
2050 /// By default, performs semantic analysis to build the new statement.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002053 VarDecl *ExceptionDecl,
2054 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002055 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2056 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002059 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002060 ///
2061 /// By default, performs semantic analysis to build the new statement.
2062 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002063 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2064 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002065 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002068 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002069 ///
2070 /// By default, performs semantic analysis to build the new statement.
2071 /// Subclasses may override this routine to provide different behavior.
2072 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002073 SourceLocation CoawaitLoc, Stmt *Init,
2074 SourceLocation ColonLoc, Stmt *Range,
2075 Stmt *Begin, Stmt *End, Expr *Cond,
2076 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002077 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002078 // If we've just learned that the range is actually an Objective-C
2079 // collection, treat this as an Objective-C fast enumeration loop.
2080 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2081 if (RangeStmt->isSingleDecl()) {
2082 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002083 if (RangeVar->isInvalidDecl())
2084 return StmtError();
2085
Douglas Gregorf7106af2013-04-08 18:40:13 +00002086 Expr *RangeExpr = RangeVar->getInit();
2087 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002088 RangeExpr->getType()->isObjCObjectPointerType()) {
2089 // FIXME: Support init-statements in Objective-C++20 ranged for
2090 // statement.
2091 if (Init) {
2092 return SemaRef.Diag(Init->getBeginLoc(),
2093 diag::err_objc_for_range_init_stmt)
2094 << Init->getSourceRange();
2095 }
2096 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2097 RangeExpr, RParenLoc);
2098 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002099 }
2100 }
2101 }
2102
Richard Smith8baa5002018-09-28 18:44:09 +00002103 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2104 Range, Begin, End, Cond, Inc, LoopVar,
2105 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002106 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002107
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002108 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002109 ///
2110 /// By default, performs semantic analysis to build the new statement.
2111 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002112 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002113 bool IsIfExists,
2114 NestedNameSpecifierLoc QualifierLoc,
2115 DeclarationNameInfo NameInfo,
2116 Stmt *Nested) {
2117 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2118 QualifierLoc, NameInfo, Nested);
2119 }
2120
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002121 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002122 ///
2123 /// By default, performs semantic analysis to finish the new statement.
2124 /// Subclasses may override this routine to provide different behavior.
2125 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2126 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002128
David Majnemerfad8f482013-10-15 09:33:02 +00002129 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002130 Stmt *TryBlock, Stmt *Handler) {
2131 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002132 }
2133
David Majnemerfad8f482013-10-15 09:33:02 +00002134 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002135 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002136 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002137 }
2138
David Majnemerfad8f482013-10-15 09:33:02 +00002139 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002140 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002141 }
2142
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002143 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002144 ///
2145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
2147 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002148 PredefinedExpr::IdentKind IK) {
2149 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002150 }
2151
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002152 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 ///
2154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002157 LookupResult &R,
2158 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002159 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2160 }
2161
2162
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002163 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002167 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002168 ValueDecl *VD,
2169 const DeclarationNameInfo &NameInfo,
2170 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002171 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002172 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002173
2174 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002175
2176 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002179 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002180 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002181 /// By default, performs semantic analysis to build the new expression.
2182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002185 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 }
2187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002188 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002189 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002190 /// By default, performs semantic analysis to build the new expression.
2191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002192 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002193 SourceLocation OperatorLoc,
2194 bool isArrow,
2195 CXXScopeSpec &SS,
2196 TypeSourceInfo *ScopeType,
2197 SourceLocation CCLoc,
2198 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002199 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002200
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002201 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002202 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 /// By default, performs semantic analysis to build the new expression.
2204 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002205 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002206 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002207 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002208 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 }
Mike Stump11289f42009-09-09 15:08:12 +00002210
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002211 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002216 TypeSourceInfo *Type,
2217 ArrayRef<Sema::OffsetOfComponent> Components,
2218 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002219 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002220 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002221 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002222
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002223 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002224 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002225 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002228 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2229 SourceLocation OpLoc,
2230 UnaryExprOrTypeTrait ExprKind,
2231 SourceRange R) {
2232 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002235 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002236 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002240 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2241 UnaryExprOrTypeTrait ExprKind,
2242 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002244 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002247
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002248 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 }
Mike Stump11289f42009-09-09 15:08:12 +00002250
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002251 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002252 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002253 /// By default, performs semantic analysis to build the new expression.
2254 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002255 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002257 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002259 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002260 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 RBracketLoc);
2262 }
2263
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002264 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2269 Expr *LowerBound,
2270 SourceLocation ColonLoc, Expr *Length,
2271 SourceLocation RBracketLoc) {
2272 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2273 ColonLoc, Length, RBracketLoc);
2274 }
2275
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002276 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002277 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// By default, performs semantic analysis to build the new expression.
2279 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002280 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002282 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002283 Expr *ExecConfig = nullptr) {
Richard Smith255b85f2019-05-08 01:36:36 +00002284 return getSema().BuildCallExpr(/*Scope=*/nullptr, Callee, LParenLoc, Args,
2285 RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 }
2287
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002288 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 /// By default, performs semantic analysis to build the new expression.
2291 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002292 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002293 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002294 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002295 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002296 const DeclarationNameInfo &MemberNameInfo,
2297 ValueDecl *Member,
2298 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002299 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002300 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002301 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2302 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002303 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002304 // We have a reference to an unnamed field. This is always the
2305 // base of an anonymous struct/union member access, i.e. the
2306 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002307 assert(Member->getType()->isRecordType() &&
2308 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002309
Richard Smithcab9a7d2011-10-26 19:06:56 +00002310 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002311 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002312 QualifierLoc.getNestedNameSpecifier(),
2313 FoundDecl, Member);
2314 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002315 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002316 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002317
2318 CXXScopeSpec EmptySS;
2319 return getSema().BuildFieldReferenceExpr(
2320 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2321 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002322 }
Mike Stump11289f42009-09-09 15:08:12 +00002323
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002324 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002325 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002326
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002327 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002328 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002329
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002330 if (isArrow && !BaseType->isPointerType())
2331 return ExprError();
2332
John McCall16df1e52010-03-30 21:47:33 +00002333 // FIXME: this involves duplicating earlier analysis in a lot of
2334 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002335 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002336 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002337 R.resolveKind();
2338
John McCallb268a282010-08-23 23:25:46 +00002339 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002340 SS, TemplateKWLoc,
2341 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002342 R, ExplicitTemplateArgs,
2343 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 }
Mike Stump11289f42009-09-09 15:08:12 +00002345
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002346 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002347 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 /// By default, performs semantic analysis to build the new expression.
2349 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002351 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002352 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002353 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002354 }
2355
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002356 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 /// By default, performs semantic analysis to build the new expression.
2359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002360 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002361 SourceLocation QuestionLoc,
2362 Expr *LHS,
2363 SourceLocation ColonLoc,
2364 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002365 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2366 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 }
2368
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002369 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002370 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 /// By default, performs semantic analysis to build the new expression.
2372 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002373 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002374 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002376 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002377 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002378 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 }
Mike Stump11289f42009-09-09 15:08:12 +00002380
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002381 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002382 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002385 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002386 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002387 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002388 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002389 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002390 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002391 }
Mike Stump11289f42009-09-09 15:08:12 +00002392
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002393 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002394 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002395 /// By default, performs semantic analysis to build the new expression.
2396 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 SourceLocation OpLoc,
2399 SourceLocation AccessorLoc,
2400 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002401
John McCall10eae182009-11-30 22:42:35 +00002402 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002403 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002404 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002405 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002406 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002407 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002408 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002409 /* TemplateArgs */ nullptr,
2410 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 }
Mike Stump11289f42009-09-09 15:08:12 +00002412
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002413 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002414 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 /// By default, performs semantic analysis to build the new expression.
2416 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002417 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002418 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002419 SourceLocation RBraceLoc) {
2420 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
Mike Stump11289f42009-09-09 15:08:12 +00002422
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002423 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002424 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 /// By default, performs semantic analysis to build the new expression.
2426 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002427 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 MultiExprArg ArrayExprs,
2429 SourceLocation EqualOrColonLoc,
2430 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002431 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002434 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002437
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002438 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 }
Mike Stump11289f42009-09-09 15:08:12 +00002440
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002441 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002442 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002443 /// By default, builds the implicit value initialization without performing
2444 /// any semantic analysis. Subclasses may override this routine to provide
2445 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002446 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002447 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002448 }
Mike Stump11289f42009-09-09 15:08:12 +00002449
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002450 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002451 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002454 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002455 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002456 SourceLocation RParenLoc) {
2457 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002458 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002459 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 }
2461
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002462 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002463 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002466 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002467 MultiExprArg SubExprs,
2468 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002469 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 }
Mike Stump11289f42009-09-09 15:08:12 +00002471
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002472 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002473 ///
2474 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 /// rather than attempting to map the label statement itself.
2476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002478 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002479 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 }
Mike Stump11289f42009-09-09 15:08:12 +00002481
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002482 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002483 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 /// By default, performs semantic analysis to build the new expression.
2485 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002486 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002487 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002489 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 }
Mike Stump11289f42009-09-09 15:08:12 +00002491
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002492 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002493 ///
2494 /// By default, performs semantic analysis to build the new expression.
2495 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002496 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002497 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 SourceLocation RParenLoc) {
2499 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 RParenLoc);
2502 }
Mike Stump11289f42009-09-09 15:08:12 +00002503
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002504 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002505 ///
2506 /// By default, performs semantic analysis to build the new expression.
2507 /// Subclasses may override this routine to provide different behavior.
2508 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2509 SourceLocation DefaultLoc,
2510 SourceLocation RParenLoc,
2511 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002512 ArrayRef<TypeSourceInfo *> Types,
2513 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002514 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002515 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002516 }
2517
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002518 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 ///
2520 /// By default, performs semantic analysis to build the new expression.
2521 /// The semantic analysis provides the behavior of template instantiation,
2522 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002523 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 /// argument-dependent lookup, etc. Subclasses may override this routine to
2525 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002526 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002527 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002528 Expr *Callee,
2529 Expr *First,
2530 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002531
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002532 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 /// reinterpret_cast.
2534 ///
2535 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002536 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002538 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 Stmt::StmtClass Class,
2540 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002541 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 SourceLocation RAngleLoc,
2543 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002544 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002545 SourceLocation RParenLoc) {
2546 switch (Class) {
2547 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002548 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002549 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002550 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002551
2552 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002553 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002554 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002555 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002556
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002558 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002559 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002560 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002562
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002564 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002565 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002566 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002569 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 }
Mike Stump11289f42009-09-09 15:08:12 +00002572
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002573 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 ///
2575 /// By default, performs semantic analysis to build the new expression.
2576 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002577 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002578 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002579 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 SourceLocation RAngleLoc,
2581 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002582 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002584 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002585 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002586 SourceRange(LAngleLoc, RAngleLoc),
2587 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 }
2589
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002590 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 ///
2592 /// By default, performs semantic analysis to build the new expression.
2593 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002594 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002596 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002597 SourceLocation RAngleLoc,
2598 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002599 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002601 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002602 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002603 SourceRange(LAngleLoc, RAngleLoc),
2604 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002605 }
2606
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002607 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002608 ///
2609 /// By default, performs semantic analysis to build the new expression.
2610 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002611 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002612 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002613 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 SourceLocation RAngleLoc,
2615 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002616 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002618 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002619 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002620 SourceRange(LAngleLoc, RAngleLoc),
2621 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 }
2623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002624 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 ///
2626 /// By default, performs semantic analysis to build the new expression.
2627 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002628 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002629 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002630 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002631 SourceLocation RAngleLoc,
2632 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002633 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002634 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002635 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002636 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002637 SourceRange(LAngleLoc, RAngleLoc),
2638 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002639 }
Mike Stump11289f42009-09-09 15:08:12 +00002640
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002641 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002645 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2646 SourceLocation LParenLoc,
2647 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002648 SourceLocation RParenLoc,
2649 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002650 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002651 MultiExprArg(&Sub, 1), RParenLoc,
2652 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 }
Mike Stump11289f42009-09-09 15:08:12 +00002654
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00002655 /// Build a new C++ __builtin_bit_cast expression.
2656 ///
2657 /// By default, performs semantic analysis to build the new expression.
2658 /// Subclasses may override this routine to provide different behavior.
2659 ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc,
2660 TypeSourceInfo *TSI, Expr *Sub,
2661 SourceLocation RParenLoc) {
2662 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
2663 }
2664
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002665 /// Build a new C++ typeid(type) 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,
2671 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002672 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002673 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002674 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 }
Mike Stump11289f42009-09-09 15:08:12 +00002676
Francois Pichet9f4f2072010-09-08 12:20:18 +00002677
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002678 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002679 ///
2680 /// By default, performs semantic analysis to build the new expression.
2681 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002682 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002683 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002684 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002685 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002686 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002687 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002688 }
2689
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002690 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002691 ///
2692 /// By default, performs semantic analysis to build the new expression.
2693 /// Subclasses may override this routine to provide different behavior.
2694 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2695 SourceLocation TypeidLoc,
2696 TypeSourceInfo *Operand,
2697 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002698 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002699 RParenLoc);
2700 }
2701
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002702 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002703 ///
2704 /// By default, performs semantic analysis to build the new expression.
2705 /// Subclasses may override this routine to provide different behavior.
2706 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2707 SourceLocation TypeidLoc,
2708 Expr *Operand,
2709 SourceLocation RParenLoc) {
2710 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2711 RParenLoc);
2712 }
2713
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002714 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002715 ///
2716 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002717 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002718 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002719 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002720 QualType ThisType,
2721 bool isImplicit) {
Richard Smith8458c9e2019-05-24 01:35:07 +00002722 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 }
2724
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002725 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002726 ///
2727 /// By default, performs semantic analysis to build the new expression.
2728 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002729 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2730 bool IsThrownVariableInScope) {
2731 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 }
2733
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002734 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002735 ///
2736 /// By default, builds a new default-argument expression, which does not
2737 /// require any semantic analysis. Subclasses may override this routine to
2738 /// provide different behavior.
Eric Fiselier708afb52019-05-16 21:04:15 +00002739 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
2740 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
2741 getSema().CurContext);
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 }
2743
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002744 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002745 ///
2746 /// By default, builds a new default field initialization expression, which
2747 /// does not require any semantic analysis. Subclasses may override this
2748 /// routine to provide different behavior.
2749 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2750 FieldDecl *Field) {
Eric Fiselier708afb52019-05-16 21:04:15 +00002751 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
2752 getSema().CurContext);
Richard Smith852c9db2013-04-20 22:23:05 +00002753 }
2754
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002755 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002756 ///
2757 /// By default, performs semantic analysis to build the new expression.
2758 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002759 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2760 SourceLocation LParenLoc,
2761 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002762 return getSema().BuildCXXTypeConstructExpr(
2763 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002764 }
Mike Stump11289f42009-09-09 15:08:12 +00002765
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002766 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002767 ///
2768 /// By default, performs semantic analysis to build the new expression.
2769 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002770 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002771 bool UseGlobal,
2772 SourceLocation PlacementLParen,
2773 MultiExprArg PlacementArgs,
2774 SourceLocation PlacementRParen,
2775 SourceRange TypeIdParens,
2776 QualType AllocatedType,
2777 TypeSourceInfo *AllocatedTypeInfo,
Richard Smithb9fb1212019-05-06 03:47:15 +00002778 Optional<Expr *> ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002779 SourceRange DirectInitRange,
2780 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002781 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002782 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002783 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002784 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002785 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002786 AllocatedType,
2787 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002788 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002789 DirectInitRange,
2790 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002791 }
Mike Stump11289f42009-09-09 15:08:12 +00002792
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002793 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002794 ///
2795 /// By default, performs semantic analysis to build the new expression.
2796 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002797 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002798 bool IsGlobalDelete,
2799 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002800 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002801 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002802 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002803 }
Mike Stump11289f42009-09-09 15:08:12 +00002804
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002805 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2809 ExprResult RebuildTypeTrait(TypeTrait Trait,
2810 SourceLocation StartLoc,
2811 ArrayRef<TypeSourceInfo *> Args,
2812 SourceLocation RParenLoc) {
2813 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2814 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002815
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002816 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
2820 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2821 SourceLocation StartLoc,
2822 TypeSourceInfo *TSInfo,
2823 Expr *DimExpr,
2824 SourceLocation RParenLoc) {
2825 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2826 }
2827
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002828 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002829 ///
2830 /// By default, performs semantic analysis to build the new expression.
2831 /// Subclasses may override this routine to provide different behavior.
2832 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2833 SourceLocation StartLoc,
2834 Expr *Queried,
2835 SourceLocation RParenLoc) {
2836 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2837 }
2838
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002839 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002840 /// expression.
2841 ///
2842 /// By default, performs semantic analysis to build the new expression.
2843 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002844 ExprResult RebuildDependentScopeDeclRefExpr(
2845 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002846 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002847 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002848 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002849 bool IsAddressOfOperand,
2850 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002851 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002852 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002853
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002854 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002855 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2856 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002857
Reid Kleckner32506ed2014-06-12 23:03:48 +00002858 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002859 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002860 }
2861
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002862 /// Build a new template-id 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 RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002867 SourceLocation TemplateKWLoc,
2868 LookupResult &R,
2869 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002870 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002871 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2872 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002873 }
2874
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002875 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002876 ///
2877 /// By default, performs semantic analysis to build the new expression.
2878 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002879 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002880 SourceLocation Loc,
2881 CXXConstructorDecl *Constructor,
2882 bool IsElidable,
2883 MultiExprArg Args,
2884 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002885 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002886 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002887 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002888 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002889 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002890 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002891 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002892 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002893 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002894
Richard Smithc83bf822016-06-10 00:58:19 +00002895 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002896 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002897 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002898 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002899 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002900 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002901 RequiresZeroInit, ConstructKind,
2902 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002903 }
2904
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002905 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002906 /// expression.
2907 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2908 CXXConstructorDecl *Constructor,
2909 bool ConstructsVBase,
2910 bool InheritedFromVBase) {
2911 return new (getSema().Context) CXXInheritedCtorInitExpr(
2912 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2913 }
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 RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002920 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002921 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002922 SourceLocation RParenOrBraceLoc,
2923 bool ListInitialization) {
2924 return getSema().BuildCXXTypeConstructExpr(
2925 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002926 }
2927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002928 /// Build a new object-construction 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.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002932 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2933 SourceLocation LParenLoc,
2934 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002935 SourceLocation RParenLoc,
2936 bool ListInitialization) {
2937 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2938 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002939 }
Mike Stump11289f42009-09-09 15:08:12 +00002940
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002941 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002942 ///
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002945 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002946 QualType BaseType,
2947 bool IsArrow,
2948 SourceLocation OperatorLoc,
2949 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002950 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002951 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002952 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002953 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002954 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002955 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002956
John McCallb268a282010-08-23 23:25:46 +00002957 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002958 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002959 SS, TemplateKWLoc,
2960 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002961 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002962 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002963 }
2964
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002965 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002966 ///
2967 /// By default, performs semantic analysis to build the new expression.
2968 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002969 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2970 SourceLocation OperatorLoc,
2971 bool IsArrow,
2972 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002973 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002974 NamedDecl *FirstQualifierInScope,
2975 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002976 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002977 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002978 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002979
John McCallb268a282010-08-23 23:25:46 +00002980 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002981 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002982 SS, TemplateKWLoc,
2983 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002984 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002985 }
Mike Stump11289f42009-09-09 15:08:12 +00002986
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002987 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002988 ///
2989 /// By default, performs semantic analysis to build the new expression.
2990 /// Subclasses may override this routine to provide different behavior.
2991 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2992 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2993 }
2994
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002995 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002996 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2997 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002998 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002999 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00003000 Optional<unsigned> Length,
3001 ArrayRef<TemplateArgument> PartialArgs) {
3002 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3003 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00003004 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00003005
Eric Fiselier708afb52019-05-16 21:04:15 +00003006 /// Build a new expression representing a call to a source location
3007 /// builtin.
3008 ///
3009 /// By default, performs semantic analysis to build the new expression.
3010 /// Subclasses may override this routine to provide different behavior.
3011 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
3012 SourceLocation BuiltinLoc,
3013 SourceLocation RPLoc,
3014 DeclContext *ParentContext) {
3015 return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
3016 }
3017
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003018 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00003019 ///
3020 /// By default, performs semantic analysis to build the new expression.
3021 /// Subclasses may override this routine to provide different behavior.
3022 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
3023 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3024 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003025
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003026 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003027 ///
3028 /// By default, performs semantic analysis to build the new expression.
3029 /// Subclasses may override this routine to provide different behavior.
3030 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
3031 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003032 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003033 MultiExprArg(Elements, NumElements));
3034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003035
3036 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00003037 Expr *Base, Expr *Key,
3038 ObjCMethodDecl *getterMethod,
3039 ObjCMethodDecl *setterMethod) {
3040 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3041 getterMethod, setterMethod);
3042 }
3043
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003044 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00003045 ///
3046 /// By default, performs semantic analysis to build the new expression.
3047 /// Subclasses may override this routine to provide different behavior.
3048 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00003049 MutableArrayRef<ObjCDictionaryElement> Elements) {
3050 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00003051 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003052
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003053 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003054 ///
3055 /// By default, performs semantic analysis to build the new expression.
3056 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003057 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00003058 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00003059 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003060 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003061 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003062
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003063 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003064 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003065 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003066 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003067 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003068 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003069 MultiExprArg Args,
3070 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003071 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3072 ReceiverTypeInfo->getType(),
3073 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003074 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003075 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003076 }
3077
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003078 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003079 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003080 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003081 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003082 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003083 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003084 MultiExprArg Args,
3085 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003086 return SemaRef.BuildInstanceMessage(Receiver,
3087 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003088 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003089 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003090 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003091 }
3092
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003093 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003094 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3095 Selector Sel,
3096 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003097 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003098 ObjCMethodDecl *Method,
3099 SourceLocation LBracLoc,
3100 MultiExprArg Args,
3101 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003102 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003103 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003104 SuperLoc,
3105 Sel, Method, LBracLoc, SelectorLocs,
3106 RBracLoc, Args)
3107 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003108 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003109 SuperLoc,
3110 Sel, Method, LBracLoc, SelectorLocs,
3111 RBracLoc, Args);
3112
Fangrui Song6907ce22018-07-30 19:24:48 +00003113
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003114 }
3115
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003116 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003117 ///
3118 /// By default, performs semantic analysis to build the new expression.
3119 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003120 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003121 SourceLocation IvarLoc,
3122 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003123 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003124 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003125 ExprResult Result = getSema().BuildMemberReferenceExpr(
3126 BaseArg, BaseArg->getType(),
3127 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3128 /*FirstQualifierInScope=*/nullptr, NameInfo,
3129 /*TemplateArgs=*/nullptr,
3130 /*S=*/nullptr);
3131 if (IsFreeIvar && Result.isUsable())
3132 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3133 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003134 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003135
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003136 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003137 ///
3138 /// By default, performs semantic analysis to build the new expression.
3139 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003140 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003141 ObjCPropertyDecl *Property,
3142 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003143 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003144 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3145 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3146 /*FIXME:*/PropertyLoc,
3147 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003148 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003149 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003150 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003151 /*TemplateArgs=*/nullptr,
3152 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003153 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003154
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003155 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003156 ///
3157 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003158 /// Subclasses may override this routine to provide different behavior.
3159 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3160 ObjCMethodDecl *Getter,
3161 ObjCMethodDecl *Setter,
3162 SourceLocation PropertyLoc) {
3163 // Since these expressions can only be value-dependent, we do not
3164 // need to perform semantic analysis again.
3165 return Owned(
3166 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3167 VK_LValue, OK_ObjCProperty,
3168 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003169 }
3170
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003171 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003172 ///
3173 /// By default, performs semantic analysis to build the new expression.
3174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003175 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003176 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003177 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003178 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3179 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003180 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003181 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003182 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003183 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003184 /*TemplateArgs=*/nullptr,
3185 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003186 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003188 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003189 ///
3190 /// By default, performs semantic analysis to build the new expression.
3191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003192 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003193 MultiExprArg SubExprs,
3194 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003195 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003196 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003197 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3198 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3199 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003200 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregora16548e2009-08-11 05:31:07 +00003202 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003203 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003204 Expr *Callee = new (SemaRef.Context)
3205 DeclRefExpr(SemaRef.Context, Builtin, false,
3206 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003207 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3208 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003209 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003210
3211 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003212 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003213 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003214 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003215
Douglas Gregora16548e2009-08-11 05:31:07 +00003216 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003217 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003218 }
John McCall31f82722010-11-12 08:19:04 +00003219
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003220 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003221 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3222 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3223 SourceLocation RParenLoc) {
3224 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3225 BuiltinLoc, RParenLoc);
3226 }
3227
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003228 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003229 ///
3230 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003231 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003232 /// different behavior.
3233 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003234 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003235 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003236 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003237 case TemplateArgument::Expression: {
3238 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003239 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3240 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003241 if (Result.isInvalid())
3242 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003243
Douglas Gregor98318c22011-01-03 21:37:45 +00003244 return TemplateArgumentLoc(Result.get(), Result.get());
3245 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003246
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003247 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003248 return TemplateArgumentLoc(TemplateArgument(
3249 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003250 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003251 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003252 Pattern.getTemplateNameLoc(),
3253 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003254
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003255 case TemplateArgument::Null:
3256 case TemplateArgument::Integral:
3257 case TemplateArgument::Declaration:
3258 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003259 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003260 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003261 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003262
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003263 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003264 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003265 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003266 EllipsisLoc,
3267 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003268 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3269 Expansion);
3270 break;
3271 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003272
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003273 return TemplateArgumentLoc();
3274 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003275
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003276 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003277 ///
3278 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003279 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003280 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003281 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003282 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003283 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003284 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003285
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003286 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003287 ///
3288 /// By default, performs semantic analysis in order to build a new fold
3289 /// expression.
3290 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3291 BinaryOperatorKind Operator,
3292 SourceLocation EllipsisLoc, Expr *RHS,
Richard Smithc7214f62019-05-13 08:31:14 +00003293 SourceLocation RParenLoc,
3294 Optional<unsigned> NumExpansions) {
Richard Smith0f0af192014-11-08 05:07:16 +00003295 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
Richard Smithc7214f62019-05-13 08:31:14 +00003296 RHS, RParenLoc, NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +00003297 }
3298
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003299 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003300 ///
3301 /// By default, produces the fallback value for the fold-expression, or
3302 /// produce an error if there is no fallback value.
3303 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3304 BinaryOperatorKind Operator) {
3305 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3306 }
3307
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003308 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003309 ///
3310 /// By default, performs semantic analysis to build the new expression.
3311 /// Subclasses may override this routine to provide different behavior.
3312 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3313 MultiExprArg SubExprs,
3314 QualType RetTy,
3315 AtomicExpr::AtomicOp Op,
3316 SourceLocation RParenLoc) {
3317 // Just create the expression; there is not any interesting semantic
3318 // analysis here because we can't actually build an AtomicExpr until
3319 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003320 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003321 RParenLoc);
3322 }
3323
John McCall31f82722010-11-12 08:19:04 +00003324private:
Douglas Gregor14454802011-02-25 02:25:35 +00003325 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3326 QualType ObjectType,
3327 NamedDecl *FirstQualifierInScope,
3328 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003329
3330 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3331 QualType ObjectType,
3332 NamedDecl *FirstQualifierInScope,
3333 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003334
3335 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3336 NamedDecl *FirstQualifierInScope,
3337 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003338
3339 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3340 DependentNameTypeLoc TL,
3341 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003342};
Douglas Gregora16548e2009-08-11 05:31:07 +00003343
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003344template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003345StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003346 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003347 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 switch (S->getStmtClass()) {
3350 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003351
Douglas Gregorebe10102009-08-20 07:17:43 +00003352 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003353 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003354#define STMT(Node, Parent) \
3355 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003356#define VALUESTMT(Node, Parent) \
3357 case Stmt::Node##Class: \
3358 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003359#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003360#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003361#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 // Transform expressions by calling TransformExpr.
3364#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003365#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003366#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003367#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003368 {
John McCalldadc5752010-08-24 06:29:42 +00003369 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003370
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003371 if (SDK == SDK_StmtExprResult)
3372 E = getSema().ActOnStmtExprResult(E);
3373 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003374 }
Mike Stump11289f42009-09-09 15:08:12 +00003375 }
3376
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003377 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003378}
Mike Stump11289f42009-09-09 15:08:12 +00003379
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003380template<typename Derived>
3381OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3382 if (!S)
3383 return S;
3384
3385 switch (S->getClauseKind()) {
3386 default: break;
3387 // Transform individual clause nodes
3388#define OPENMP_CLAUSE(Name, Class) \
3389 case OMPC_ ## Name : \
3390 return getDerived().Transform ## Class(cast<Class>(S));
3391#include "clang/Basic/OpenMPKinds.def"
3392 }
3393
3394 return S;
3395}
3396
Mike Stump11289f42009-09-09 15:08:12 +00003397
Douglas Gregore922c772009-08-04 22:27:00 +00003398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003399ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003400 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003401 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003402
3403 switch (E->getStmtClass()) {
3404 case Stmt::NoStmtClass: break;
3405#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003406#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003407#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003408 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003409#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003410 }
3411
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003412 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003413}
3414
3415template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003416ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003417 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003418 // Initializers are instantiated like expressions, except that various outer
3419 // layers are stripped.
3420 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003421 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003422
Bill Wendling7c44da22018-10-31 03:48:47 +00003423 if (auto *FE = dyn_cast<FullExpr>(Init))
3424 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003425
Richard Smith410306b2016-12-12 02:53:20 +00003426 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3427 Init = AIL->getCommonExpr();
3428
Richard Smithe6ca4752013-05-30 22:40:16 +00003429 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3430 Init = MTE->GetTemporaryExpr();
3431
Richard Smithd59b8322012-12-19 01:39:02 +00003432 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3433 Init = Binder->getSubExpr();
3434
3435 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3436 Init = ICE->getSubExprAsWritten();
3437
Richard Smithcc1b96d2013-06-12 22:31:48 +00003438 if (CXXStdInitializerListExpr *ILE =
3439 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003440 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003441
Richard Smithc6abd962014-07-25 01:12:44 +00003442 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003443 // InitListExprs. Other forms of copy-initialization will be a no-op if
3444 // the initializer is already the right type.
3445 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003446 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003447 return getDerived().TransformExpr(Init);
3448
3449 // Revert value-initialization back to empty parens.
3450 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3451 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003452 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003453 Parens.getEnd());
3454 }
3455
3456 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3457 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003458 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003459 SourceLocation());
3460
3461 // Revert initialization by constructor back to a parenthesized or braced list
3462 // of expressions. Any other form of initializer can just be reused directly.
3463 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003464 return getDerived().TransformExpr(Init);
3465
Richard Smithf8adcdc2014-07-17 05:12:35 +00003466 // If the initialization implicitly converted an initializer list to a
3467 // std::initializer_list object, unwrap the std::initializer_list too.
3468 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003469 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003470
Richard Smith12938cf2018-09-26 04:36:55 +00003471 // Enter a list-init context if this was list initialization.
3472 EnterExpressionEvaluationContext Context(
3473 getSema(), EnterExpressionEvaluationContext::InitList,
3474 Construct->isListInitialization());
3475
Richard Smithd59b8322012-12-19 01:39:02 +00003476 SmallVector<Expr*, 8> NewArgs;
3477 bool ArgChanged = false;
3478 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003479 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003480 return ExprError();
3481
Richard Smithd1036122018-01-12 22:21:33 +00003482 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003483 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003484 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003485 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003486
Richard Smithd59b8322012-12-19 01:39:02 +00003487 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003488 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003489 if (Parens.isInvalid()) {
3490 // This was a variable declaration's initialization for which no initializer
3491 // was specified.
3492 assert(NewArgs.empty() &&
3493 "no parens or braces but have direct init with arguments?");
3494 return ExprEmpty();
3495 }
Richard Smithd59b8322012-12-19 01:39:02 +00003496 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3497 Parens.getEnd());
3498}
3499
3500template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003501bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003502 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003503 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003504 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003505 bool *ArgChanged) {
3506 for (unsigned I = 0; I != NumInputs; ++I) {
3507 // If requested, drop call arguments that need to be dropped.
3508 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3509 if (ArgChanged)
3510 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003511
Douglas Gregora3efea12011-01-03 19:04:46 +00003512 break;
3513 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003514
Douglas Gregor968f23a2011-01-03 19:31:53 +00003515 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3516 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003517
Chris Lattner01cf8db2011-07-20 06:58:45 +00003518 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003519 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3520 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003521
Douglas Gregor968f23a2011-01-03 19:31:53 +00003522 // Determine whether the set of unexpanded parameter packs can and should
3523 // be expanded.
3524 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003525 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003526 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3527 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003528 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3529 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003530 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003531 Expand, RetainExpansion,
3532 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003533 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregor968f23a2011-01-03 19:31:53 +00003535 if (!Expand) {
3536 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003537 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003538 // expansion.
3539 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3540 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3541 if (OutPattern.isInvalid())
3542 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
3544 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003545 Expansion->getEllipsisLoc(),
3546 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003547 if (Out.isInvalid())
3548 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003549
Douglas Gregor968f23a2011-01-03 19:31:53 +00003550 if (ArgChanged)
3551 *ArgChanged = true;
3552 Outputs.push_back(Out.get());
3553 continue;
3554 }
John McCall542e7c62011-07-06 07:30:07 +00003555
3556 // Record right away that the argument was changed. This needs
3557 // to happen even if the array expands to nothing.
3558 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Douglas Gregor968f23a2011-01-03 19:31:53 +00003560 // The transform has determined that we should perform an elementwise
3561 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003562 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003563 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3564 ExprResult Out = getDerived().TransformExpr(Pattern);
3565 if (Out.isInvalid())
3566 return true;
3567
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003568 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003569 Out = getDerived().RebuildPackExpansion(
3570 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003571 if (Out.isInvalid())
3572 return true;
3573 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003574
Douglas Gregor968f23a2011-01-03 19:31:53 +00003575 Outputs.push_back(Out.get());
3576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Richard Smith9467be42014-06-06 17:33:35 +00003578 // If we're supposed to retain a pack expansion, do so by temporarily
3579 // forgetting the partially-substituted parameter pack.
3580 if (RetainExpansion) {
3581 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3582
3583 ExprResult Out = getDerived().TransformExpr(Pattern);
3584 if (Out.isInvalid())
3585 return true;
3586
3587 Out = getDerived().RebuildPackExpansion(
3588 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3589 if (Out.isInvalid())
3590 return true;
3591
3592 Outputs.push_back(Out.get());
3593 }
3594
Douglas Gregor968f23a2011-01-03 19:31:53 +00003595 continue;
3596 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003597
Richard Smithd59b8322012-12-19 01:39:02 +00003598 ExprResult Result =
3599 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3600 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003601 if (Result.isInvalid())
3602 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Douglas Gregora3efea12011-01-03 19:04:46 +00003604 if (Result.get() != Inputs[I] && ArgChanged)
3605 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003606
3607 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003608 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregora3efea12011-01-03 19:04:46 +00003610 return false;
3611}
3612
Richard Smith03a4aa32016-06-23 19:02:52 +00003613template <typename Derived>
3614Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3615 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3616 if (Var) {
3617 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3618 getDerived().TransformDefinition(Var->getLocation(), Var));
3619
3620 if (!ConditionVar)
3621 return Sema::ConditionError();
3622
3623 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3624 }
3625
3626 if (Expr) {
3627 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3628
3629 if (CondExpr.isInvalid())
3630 return Sema::ConditionError();
3631
3632 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3633 }
3634
3635 return Sema::ConditionResult();
3636}
3637
Douglas Gregora3efea12011-01-03 19:04:46 +00003638template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003639NestedNameSpecifierLoc
3640TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3641 NestedNameSpecifierLoc NNS,
3642 QualType ObjectType,
3643 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003644 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003645 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003646 Qualifier = Qualifier.getPrefix())
3647 Qualifiers.push_back(Qualifier);
3648
3649 CXXScopeSpec SS;
3650 while (!Qualifiers.empty()) {
3651 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3652 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregor14454802011-02-25 02:25:35 +00003654 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003655 case NestedNameSpecifier::Identifier: {
3656 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3657 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3658 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3659 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003660 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003661 }
Douglas Gregor14454802011-02-25 02:25:35 +00003662 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor14454802011-02-25 02:25:35 +00003664 case NestedNameSpecifier::Namespace: {
3665 NamespaceDecl *NS
3666 = cast_or_null<NamespaceDecl>(
3667 getDerived().TransformDecl(
3668 Q.getLocalBeginLoc(),
3669 QNNS->getAsNamespace()));
3670 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3671 break;
3672 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003673
Douglas Gregor14454802011-02-25 02:25:35 +00003674 case NestedNameSpecifier::NamespaceAlias: {
3675 NamespaceAliasDecl *Alias
3676 = cast_or_null<NamespaceAliasDecl>(
3677 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3678 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003679 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003680 Q.getLocalEndLoc());
3681 break;
3682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003683
Douglas Gregor14454802011-02-25 02:25:35 +00003684 case NestedNameSpecifier::Global:
3685 // There is no meaningful transformation that one could perform on the
3686 // global scope.
3687 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3688 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003689
Nikola Smiljanic67860242014-09-26 00:28:20 +00003690 case NestedNameSpecifier::Super: {
3691 CXXRecordDecl *RD =
3692 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3693 SourceLocation(), QNNS->getAsRecordDecl()));
3694 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3695 break;
3696 }
3697
Douglas Gregor14454802011-02-25 02:25:35 +00003698 case NestedNameSpecifier::TypeSpecWithTemplate:
3699 case NestedNameSpecifier::TypeSpec: {
3700 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3701 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor14454802011-02-25 02:25:35 +00003703 if (!TL)
3704 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregor14454802011-02-25 02:25:35 +00003706 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003707 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003708 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003709 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003710 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003711 if (TL.getType()->isEnumeralType())
3712 SemaRef.Diag(TL.getBeginLoc(),
3713 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003714 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3715 Q.getLocalEndLoc());
3716 break;
3717 }
Richard Trieude756fb2011-05-07 01:36:37 +00003718 // If the nested-name-specifier is an invalid type def, don't emit an
3719 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003720 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3721 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003722 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003723 << TL.getType() << SS.getRange();
3724 }
Douglas Gregor14454802011-02-25 02:25:35 +00003725 return NestedNameSpecifierLoc();
3726 }
Douglas Gregore16af532011-02-28 18:50:33 +00003727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregore16af532011-02-28 18:50:33 +00003729 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003730 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003731 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003732 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Douglas Gregor14454802011-02-25 02:25:35 +00003734 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003735 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003736 !getDerived().AlwaysRebuild())
3737 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003738
3739 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003740 // nested-name-specifier, do so.
3741 if (SS.location_size() == NNS.getDataLength() &&
3742 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3743 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3744
3745 // Allocate new nested-name-specifier location information.
3746 return SS.getWithLocInContext(SemaRef.Context);
3747}
3748
3749template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003750DeclarationNameInfo
3751TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003752::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003753 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003754 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003755 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003756
3757 switch (Name.getNameKind()) {
3758 case DeclarationName::Identifier:
3759 case DeclarationName::ObjCZeroArgSelector:
3760 case DeclarationName::ObjCOneArgSelector:
3761 case DeclarationName::ObjCMultiArgSelector:
3762 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003763 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003764 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003765 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003766
Richard Smith35845152017-02-07 01:37:30 +00003767 case DeclarationName::CXXDeductionGuideName: {
3768 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3769 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3770 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3771 if (!NewTemplate)
3772 return DeclarationNameInfo();
3773
3774 DeclarationNameInfo NewNameInfo(NameInfo);
3775 NewNameInfo.setName(
3776 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3777 return NewNameInfo;
3778 }
3779
Douglas Gregorf816bd72009-09-03 22:13:48 +00003780 case DeclarationName::CXXConstructorName:
3781 case DeclarationName::CXXDestructorName:
3782 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003783 TypeSourceInfo *NewTInfo;
3784 CanQualType NewCanTy;
3785 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003786 NewTInfo = getDerived().TransformType(OldTInfo);
3787 if (!NewTInfo)
3788 return DeclarationNameInfo();
3789 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003790 }
3791 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003792 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003793 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003794 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003795 if (NewT.isNull())
3796 return DeclarationNameInfo();
3797 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3798 }
Mike Stump11289f42009-09-09 15:08:12 +00003799
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003800 DeclarationName NewName
3801 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3802 NewCanTy);
3803 DeclarationNameInfo NewNameInfo(NameInfo);
3804 NewNameInfo.setName(NewName);
3805 NewNameInfo.setNamedTypeInfo(NewTInfo);
3806 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003807 }
Mike Stump11289f42009-09-09 15:08:12 +00003808 }
3809
David Blaikie83d382b2011-09-23 05:06:16 +00003810 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003811}
3812
3813template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003814TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003815TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3816 TemplateName Name,
3817 SourceLocation NameLoc,
3818 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003819 NamedDecl *FirstQualifierInScope,
3820 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003821 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3822 TemplateDecl *Template = QTN->getTemplateDecl();
3823 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Douglas Gregor9db53502011-03-02 18:07:45 +00003825 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003826 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003827 Template));
3828 if (!TransTemplate)
3829 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
Douglas Gregor9db53502011-03-02 18:07:45 +00003831 if (!getDerived().AlwaysRebuild() &&
3832 SS.getScopeRep() == QTN->getQualifier() &&
3833 TransTemplate == Template)
3834 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003835
Douglas Gregor9db53502011-03-02 18:07:45 +00003836 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3837 TransTemplate);
3838 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003839
Douglas Gregor9db53502011-03-02 18:07:45 +00003840 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3841 if (SS.getScopeRep()) {
3842 // These apply to the scope specifier, not the template.
3843 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003844 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003845 }
3846
Douglas Gregor9db53502011-03-02 18:07:45 +00003847 if (!getDerived().AlwaysRebuild() &&
3848 SS.getScopeRep() == DTN->getQualifier() &&
3849 ObjectType.isNull())
3850 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
Richard Smith79810042018-05-11 02:43:08 +00003852 // FIXME: Preserve the location of the "template" keyword.
3853 SourceLocation TemplateKWLoc = NameLoc;
3854
Douglas Gregor9db53502011-03-02 18:07:45 +00003855 if (DTN->isIdentifier()) {
3856 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003857 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003858 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003859 NameLoc,
3860 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003861 FirstQualifierInScope,
3862 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003864
Richard Smith79810042018-05-11 02:43:08 +00003865 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3866 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003867 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003869
Douglas Gregor9db53502011-03-02 18:07:45 +00003870 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3871 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003872 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003873 Template));
3874 if (!TransTemplate)
3875 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
Douglas Gregor9db53502011-03-02 18:07:45 +00003877 if (!getDerived().AlwaysRebuild() &&
3878 TransTemplate == Template)
3879 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003880
Douglas Gregor9db53502011-03-02 18:07:45 +00003881 return TemplateName(TransTemplate);
3882 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003883
Douglas Gregor9db53502011-03-02 18:07:45 +00003884 if (SubstTemplateTemplateParmPackStorage *SubstPack
3885 = Name.getAsSubstTemplateTemplateParmPack()) {
3886 TemplateTemplateParmDecl *TransParam
3887 = cast_or_null<TemplateTemplateParmDecl>(
3888 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3889 if (!TransParam)
3890 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003891
Douglas Gregor9db53502011-03-02 18:07:45 +00003892 if (!getDerived().AlwaysRebuild() &&
3893 TransParam == SubstPack->getParameterPack())
3894 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003895
3896 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003897 SubstPack->getArgumentPack());
3898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Douglas Gregor9db53502011-03-02 18:07:45 +00003900 // These should be getting filtered out before they reach the AST.
3901 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003902}
3903
3904template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003905void TreeTransform<Derived>::InventTemplateArgumentLoc(
3906 const TemplateArgument &Arg,
3907 TemplateArgumentLoc &Output) {
3908 SourceLocation Loc = getDerived().getBaseLocation();
3909 switch (Arg.getKind()) {
3910 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003911 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003912 break;
3913
3914 case TemplateArgument::Type:
3915 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003916 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003917
John McCall0ad16662009-10-29 08:12:44 +00003918 break;
3919
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003920 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003921 case TemplateArgument::TemplateExpansion: {
3922 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003923 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003924 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3925 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3926 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3927 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003928
Douglas Gregor9d802122011-03-02 17:09:35 +00003929 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003930 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003931 Builder.getWithLocInContext(SemaRef.Context),
3932 Loc);
3933 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003934 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003935 Builder.getWithLocInContext(SemaRef.Context),
3936 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003937
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003938 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003939 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003940
John McCall0ad16662009-10-29 08:12:44 +00003941 case TemplateArgument::Expression:
3942 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3943 break;
3944
3945 case TemplateArgument::Declaration:
3946 case TemplateArgument::Integral:
3947 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003948 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003949 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003950 break;
3951 }
3952}
3953
3954template<typename Derived>
3955bool TreeTransform<Derived>::TransformTemplateArgument(
3956 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003957 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003958 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003959 switch (Arg.getKind()) {
3960 case TemplateArgument::Null:
3961 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003962 case TemplateArgument::Pack:
3963 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003964 case TemplateArgument::NullPtr:
3965 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregore922c772009-08-04 22:27:00 +00003967 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003968 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003969 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003970 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003971
3972 DI = getDerived().TransformType(DI);
3973 if (!DI) return true;
3974
3975 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3976 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003977 }
Mike Stump11289f42009-09-09 15:08:12 +00003978
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003979 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003980 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3981 if (QualifierLoc) {
3982 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3983 if (!QualifierLoc)
3984 return true;
3985 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003986
Douglas Gregordf846d12011-03-02 18:46:51 +00003987 CXXScopeSpec SS;
3988 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003989 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003990 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3991 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003992 if (Template.isNull())
3993 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Douglas Gregor9d802122011-03-02 17:09:35 +00003995 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003996 Input.getTemplateNameLoc());
3997 return false;
3998 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003999
4000 case TemplateArgument::TemplateExpansion:
4001 llvm_unreachable("Caller should expand pack expansions");
4002
Douglas Gregore922c772009-08-04 22:27:00 +00004003 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00004004 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00004005 EnterExpressionEvaluationContext Unevaluated(
Richard Smithdcd7eb72019-06-25 20:40:27 +00004006 getSema(),
4007 Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
4008 : Sema::ExpressionEvaluationContext::ConstantEvaluated,
4009 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
4010 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
Mike Stump11289f42009-09-09 15:08:12 +00004011
John McCall0ad16662009-10-29 08:12:44 +00004012 Expr *InputExpr = Input.getSourceExpression();
4013 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
4014
Chris Lattnercdb591a2011-04-25 20:37:58 +00004015 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004016 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00004017 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004018 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00004019 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00004020 }
Douglas Gregore922c772009-08-04 22:27:00 +00004021 }
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregore922c772009-08-04 22:27:00 +00004023 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00004024 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00004025}
4026
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004027/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00004028/// for each of the template arguments in its underlying iterator.
4029template<typename Derived, typename InputIterator>
4030class TemplateArgumentLocInventIterator {
4031 TreeTransform<Derived> &Self;
4032 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00004033
Douglas Gregorfe921a72010-12-20 23:36:19 +00004034public:
4035 typedef TemplateArgumentLoc value_type;
4036 typedef TemplateArgumentLoc reference;
4037 typedef typename std::iterator_traits<InputIterator>::difference_type
4038 difference_type;
4039 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00004040
Douglas Gregorfe921a72010-12-20 23:36:19 +00004041 class pointer {
4042 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00004043
Douglas Gregorfe921a72010-12-20 23:36:19 +00004044 public:
4045 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
Douglas Gregorfe921a72010-12-20 23:36:19 +00004047 const TemplateArgumentLoc *operator->() const { return &Arg; }
4048 };
Chad Rosier1dcde962012-08-08 18:46:20 +00004049
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00004050 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004051
Douglas Gregorfe921a72010-12-20 23:36:19 +00004052 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
4053 InputIterator Iter)
4054 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00004055
Douglas Gregorfe921a72010-12-20 23:36:19 +00004056 TemplateArgumentLocInventIterator &operator++() {
4057 ++Iter;
4058 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004059 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004060
Douglas Gregorfe921a72010-12-20 23:36:19 +00004061 TemplateArgumentLocInventIterator operator++(int) {
4062 TemplateArgumentLocInventIterator Old(*this);
4063 ++(*this);
4064 return Old;
4065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004066
Douglas Gregorfe921a72010-12-20 23:36:19 +00004067 reference operator*() const {
4068 TemplateArgumentLoc Result;
4069 Self.InventTemplateArgumentLoc(*Iter, Result);
4070 return Result;
4071 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004072
Douglas Gregorfe921a72010-12-20 23:36:19 +00004073 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004074
Douglas Gregorfe921a72010-12-20 23:36:19 +00004075 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4076 const TemplateArgumentLocInventIterator &Y) {
4077 return X.Iter == Y.Iter;
4078 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004079
Douglas Gregorfe921a72010-12-20 23:36:19 +00004080 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4081 const TemplateArgumentLocInventIterator &Y) {
4082 return X.Iter != Y.Iter;
4083 }
4084};
Chad Rosier1dcde962012-08-08 18:46:20 +00004085
Douglas Gregor42cafa82010-12-20 17:42:22 +00004086template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004087template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004088bool TreeTransform<Derived>::TransformTemplateArguments(
4089 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4090 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004091 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004092 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004093 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004094
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004095 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4096 // Unpack argument packs, which we translate them into separate
4097 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004098 // FIXME: We could do much better if we could guarantee that the
4099 // TemplateArgumentLocInfo for the pack expansion would be usable for
4100 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004101 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004102 TemplateArgument::pack_iterator>
4103 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004104 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004105 In.getArgument().pack_begin()),
4106 PackLocIterator(*this,
4107 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004108 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004109 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004111 continue;
4112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004114 if (In.getArgument().isPackExpansion()) {
4115 // We have a pack expansion, for which we will be substituting into
4116 // the pattern.
4117 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004118 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004119 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004120 = getSema().getTemplateArgumentPackExpansionPattern(
4121 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004122
Chris Lattner01cf8db2011-07-20 06:58:45 +00004123 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004124 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4125 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004126
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004127 // Determine whether the set of unexpanded parameter packs can and should
4128 // be expanded.
4129 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004130 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004131 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004132 if (getDerived().TryExpandParameterPacks(Ellipsis,
4133 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004134 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004135 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004136 RetainExpansion,
4137 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004138 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004139
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004140 if (!Expand) {
4141 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004142 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004143 // expansion.
4144 TemplateArgumentLoc OutPattern;
4145 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004146 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004147 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004148
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004149 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4150 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004151 if (Out.getArgument().isNull())
4152 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004153
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004154 Outputs.addArgument(Out);
4155 continue;
4156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004157
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004158 // The transform has determined that we should perform an elementwise
4159 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004160 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004161 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4162
Richard Smithd784e682015-09-23 21:41:42 +00004163 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004164 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004165
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004166 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004167 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4168 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004169 if (Out.getArgument().isNull())
4170 return true;
4171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004172
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004173 Outputs.addArgument(Out);
4174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004175
Douglas Gregor48d24112011-01-10 20:53:55 +00004176 // If we're supposed to retain a pack expansion, do so by temporarily
4177 // forgetting the partially-substituted parameter pack.
4178 if (RetainExpansion) {
4179 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004180
Richard Smithd784e682015-09-23 21:41:42 +00004181 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004182 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004183
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004184 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4185 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004186 if (Out.getArgument().isNull())
4187 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004188
Douglas Gregor48d24112011-01-10 20:53:55 +00004189 Outputs.addArgument(Out);
4190 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004191
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004192 continue;
4193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004194
4195 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004196 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004197 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004198
Douglas Gregor42cafa82010-12-20 17:42:22 +00004199 Outputs.addArgument(Out);
4200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004201
Douglas Gregor42cafa82010-12-20 17:42:22 +00004202 return false;
4203
4204}
4205
Douglas Gregord6ff3322009-08-04 16:50:30 +00004206//===----------------------------------------------------------------------===//
4207// Type transformation
4208//===----------------------------------------------------------------------===//
4209
4210template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004211QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004212 if (getDerived().AlreadyTransformed(T))
4213 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall550e0c22009-10-21 00:40:46 +00004215 // Temporary workaround. All of these transformations should
4216 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004217 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4218 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004219
John McCall31f82722010-11-12 08:19:04 +00004220 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004221
John McCall550e0c22009-10-21 00:40:46 +00004222 if (!NewDI)
4223 return QualType();
4224
4225 return NewDI->getType();
4226}
4227
4228template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004229TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004230 // Refine the base location to the type's location.
4231 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4232 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004233 if (getDerived().AlreadyTransformed(DI->getType()))
4234 return DI;
4235
4236 TypeLocBuilder TLB;
4237
4238 TypeLoc TL = DI->getTypeLoc();
4239 TLB.reserve(TL.getFullDataSize());
4240
John McCall31f82722010-11-12 08:19:04 +00004241 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004242 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004243 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004244
John McCallbcd03502009-12-07 02:54:59 +00004245 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004246}
4247
4248template<typename Derived>
4249QualType
John McCall31f82722010-11-12 08:19:04 +00004250TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004251 switch (T.getTypeLocClass()) {
4252#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004253#define TYPELOC(CLASS, PARENT) \
4254 case TypeLoc::CLASS: \
4255 return getDerived().Transform##CLASS##Type(TLB, \
4256 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004257#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004258 }
Mike Stump11289f42009-09-09 15:08:12 +00004259
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004260 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004261}
4262
Richard Smithee579842017-01-30 20:39:26 +00004263template<typename Derived>
4264QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4265 if (!isa<DependentNameType>(T))
4266 return TransformType(T);
4267
4268 if (getDerived().AlreadyTransformed(T))
4269 return T;
4270 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4271 getDerived().getBaseLocation());
4272 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4273 return NewDI ? NewDI->getType() : QualType();
4274}
4275
4276template<typename Derived>
4277TypeSourceInfo *
4278TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4279 if (!isa<DependentNameType>(DI->getType()))
4280 return TransformType(DI);
4281
4282 // Refine the base location to the type's location.
4283 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4284 getDerived().getBaseEntity());
4285 if (getDerived().AlreadyTransformed(DI->getType()))
4286 return DI;
4287
4288 TypeLocBuilder TLB;
4289
4290 TypeLoc TL = DI->getTypeLoc();
4291 TLB.reserve(TL.getFullDataSize());
4292
Richard Smithee579842017-01-30 20:39:26 +00004293 auto QTL = TL.getAs<QualifiedTypeLoc>();
4294 if (QTL)
4295 TL = QTL.getUnqualifiedLoc();
4296
4297 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4298
4299 QualType Result = getDerived().TransformDependentNameType(
4300 TLB, DNTL, /*DeducedTSTContext*/true);
4301 if (Result.isNull())
4302 return nullptr;
4303
4304 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004305 Result = getDerived().RebuildQualifiedType(Result, QTL);
4306 if (Result.isNull())
4307 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004308 TLB.TypeWasModifiedSafely(Result);
4309 }
4310
4311 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4312}
4313
John McCall550e0c22009-10-21 00:40:46 +00004314template<typename Derived>
4315QualType
4316TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004317 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004318 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004319 if (Result.isNull())
4320 return QualType();
4321
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004322 Result = getDerived().RebuildQualifiedType(Result, T);
4323
4324 if (Result.isNull())
4325 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004326
4327 // RebuildQualifiedType might have updated the type, but not in a way
4328 // that invalidates the TypeLoc. (There's no location information for
4329 // qualifiers.)
4330 TLB.TypeWasModifiedSafely(Result);
4331
4332 return Result;
4333}
4334
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004335template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004336QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004337 QualifiedTypeLoc TL) {
4338
4339 SourceLocation Loc = TL.getBeginLoc();
4340 Qualifiers Quals = TL.getType().getLocalQualifiers();
4341
4342 if (((T.getAddressSpace() != LangAS::Default &&
4343 Quals.getAddressSpace() != LangAS::Default)) &&
4344 T.getAddressSpace() != Quals.getAddressSpace()) {
4345 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4346 << TL.getType() << T;
4347 return QualType();
4348 }
4349
Richard Smithee579842017-01-30 20:39:26 +00004350 // C++ [dcl.fct]p7:
4351 // [When] adding cv-qualifications on top of the function type [...] the
4352 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004353 if (T->isFunctionType()) {
4354 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4355 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004356 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004357 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004358
Richard Smithee579842017-01-30 20:39:26 +00004359 // C++ [dcl.ref]p1:
4360 // when the cv-qualifiers are introduced through the use of a typedef-name
4361 // or decltype-specifier [...] the cv-qualifiers are ignored.
4362 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4363 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004364 if (T->isReferenceType()) {
4365 // The only qualifier that applies to a reference type is restrict.
4366 if (!Quals.hasRestrict())
4367 return T;
4368 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4369 }
Mike Stump11289f42009-09-09 15:08:12 +00004370
John McCall31168b02011-06-15 23:02:42 +00004371 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004372 // resulting type.
4373 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004374 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004375 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004376 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004377 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004378 // A lifetime qualifier applied to a substituted template parameter
4379 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004380 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004381 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004382 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004383 QualType Replacement = SubstTypeParam->getReplacementType();
4384 Qualifiers Qs = Replacement.getQualifiers();
4385 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004386 Replacement = SemaRef.Context.getQualifiedType(
4387 Replacement.getUnqualifiedType(), Qs);
4388 T = SemaRef.Context.getSubstTemplateTypeParmType(
4389 SubstTypeParam->getReplacedParameter(), Replacement);
4390 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004391 // 'auto' types behave the same way as template parameters.
4392 QualType Deduced = AutoTy->getDeducedType();
4393 Qualifiers Qs = Deduced.getQualifiers();
4394 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004395 Deduced =
4396 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4397 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4398 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004399 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004400 // Otherwise, complain about the addition of a qualifier to an
4401 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004402 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4403 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004404 Quals.removeObjCLifetime();
4405 }
4406 }
4407 }
John McCall550e0c22009-10-21 00:40:46 +00004408
Richard Smithee579842017-01-30 20:39:26 +00004409 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004410}
4411
Douglas Gregor14454802011-02-25 02:25:35 +00004412template<typename Derived>
4413TypeLoc
4414TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4415 QualType ObjectType,
4416 NamedDecl *UnqualLookup,
4417 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004418 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004419 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004420
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004421 TypeSourceInfo *TSI =
4422 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4423 if (TSI)
4424 return TSI->getTypeLoc();
4425 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004426}
4427
Douglas Gregor579c15f2011-03-02 18:32:08 +00004428template<typename Derived>
4429TypeSourceInfo *
4430TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4431 QualType ObjectType,
4432 NamedDecl *UnqualLookup,
4433 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004434 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004435 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004436
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004437 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4438 UnqualLookup, SS);
4439}
4440
4441template <typename Derived>
4442TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4443 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4444 CXXScopeSpec &SS) {
4445 QualType T = TL.getType();
4446 assert(!getDerived().AlreadyTransformed(T));
4447
Douglas Gregor579c15f2011-03-02 18:32:08 +00004448 TypeLocBuilder TLB;
4449 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004450
Douglas Gregor579c15f2011-03-02 18:32:08 +00004451 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004452 TemplateSpecializationTypeLoc SpecTL =
4453 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004454
Richard Smithfd3dae02017-01-20 00:20:39 +00004455 TemplateName Template = getDerived().TransformTemplateName(
4456 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4457 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004458 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004459 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
4461 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004462 Template);
4463 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004464 DependentTemplateSpecializationTypeLoc SpecTL =
4465 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004466
Douglas Gregor579c15f2011-03-02 18:32:08 +00004467 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004468 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004469 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004470 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004471 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004472 ObjectType, UnqualLookup,
4473 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004474 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004475 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004476
4477 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004478 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004479 Template,
4480 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004481 } else {
4482 // Nothing special needs to be done for these.
4483 Result = getDerived().TransformType(TLB, TL);
4484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004485
4486 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004487 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004488
Douglas Gregor579c15f2011-03-02 18:32:08 +00004489 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4490}
4491
John McCall550e0c22009-10-21 00:40:46 +00004492template <class TyLoc> static inline
4493QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4494 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4495 NewT.setNameLoc(T.getNameLoc());
4496 return T.getType();
4497}
4498
John McCall550e0c22009-10-21 00:40:46 +00004499template<typename Derived>
4500QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004501 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004502 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4503 NewT.setBuiltinLoc(T.getBuiltinLoc());
4504 if (T.needsExtraLocalData())
4505 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4506 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004507}
Mike Stump11289f42009-09-09 15:08:12 +00004508
Douglas Gregord6ff3322009-08-04 16:50:30 +00004509template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004510QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004511 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004512 // FIXME: recurse?
4513 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004514}
Mike Stump11289f42009-09-09 15:08:12 +00004515
Reid Kleckner0503a872013-12-05 01:23:43 +00004516template <typename Derived>
4517QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4518 AdjustedTypeLoc TL) {
4519 // Adjustments applied during transformation are handled elsewhere.
4520 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4521}
4522
Douglas Gregord6ff3322009-08-04 16:50:30 +00004523template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004524QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4525 DecayedTypeLoc TL) {
4526 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4527 if (OriginalType.isNull())
4528 return QualType();
4529
4530 QualType Result = TL.getType();
4531 if (getDerived().AlwaysRebuild() ||
4532 OriginalType != TL.getOriginalLoc().getType())
4533 Result = SemaRef.Context.getDecayedType(OriginalType);
4534 TLB.push<DecayedTypeLoc>(Result);
4535 // Nothing to set for DecayedTypeLoc.
4536 return Result;
4537}
4538
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004539/// Helper to deduce addr space of a pointee type in OpenCL mode.
4540/// If the type is updated it will be overwritten in PointeeType param.
4541static void deduceOpenCLPointeeAddrSpace(Sema &SemaRef, QualType &PointeeType) {
4542 if (PointeeType.getAddressSpace() == LangAS::Default)
4543 PointeeType = SemaRef.Context.getAddrSpaceQualType(PointeeType,
4544 LangAS::opencl_generic);
4545}
4546
Reid Kleckner8a365022013-06-24 17:51:48 +00004547template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004548QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004549 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004550 QualType PointeeType
4551 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004552 if (PointeeType.isNull())
4553 return QualType();
4554
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004555 if (SemaRef.getLangOpts().OpenCL)
4556 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4557
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004558 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004559 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004560 // A dependent pointer type 'T *' has is being transformed such
4561 // that an Objective-C class type is being replaced for 'T'. The
4562 // resulting pointer type is an ObjCObjectPointerType, not a
4563 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004564 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004565
John McCall8b07ec22010-05-15 11:32:37 +00004566 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4567 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004568 return Result;
4569 }
John McCall31f82722010-11-12 08:19:04 +00004570
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004571 if (getDerived().AlwaysRebuild() ||
4572 PointeeType != TL.getPointeeLoc().getType()) {
4573 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4574 if (Result.isNull())
4575 return QualType();
4576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004577
John McCall31168b02011-06-15 23:02:42 +00004578 // Objective-C ARC can add lifetime qualifiers to the type that we're
4579 // pointing to.
4580 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004581
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004582 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4583 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004584 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004585}
Mike Stump11289f42009-09-09 15:08:12 +00004586
4587template<typename Derived>
4588QualType
John McCall550e0c22009-10-21 00:40:46 +00004589TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004590 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004591 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004592 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4593 if (PointeeType.isNull())
4594 return QualType();
4595
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004596 if (SemaRef.getLangOpts().OpenCL)
4597 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4598
Chad Rosier1dcde962012-08-08 18:46:20 +00004599 QualType Result = TL.getType();
4600 if (getDerived().AlwaysRebuild() ||
4601 PointeeType != TL.getPointeeLoc().getType()) {
4602 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004603 TL.getSigilLoc());
4604 if (Result.isNull())
4605 return QualType();
4606 }
4607
Douglas Gregor049211a2010-04-22 16:50:51 +00004608 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004609 NewT.setSigilLoc(TL.getSigilLoc());
4610 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004611}
4612
John McCall70dd5f62009-10-30 00:06:24 +00004613/// Transforms a reference type. Note that somewhat paradoxically we
4614/// don't care whether the type itself is an l-value type or an r-value
4615/// type; we only care if the type was *written* as an l-value type
4616/// or an r-value type.
4617template<typename Derived>
4618QualType
4619TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004620 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004621 const ReferenceType *T = TL.getTypePtr();
4622
4623 // Note that this works with the pointee-as-written.
4624 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4625 if (PointeeType.isNull())
4626 return QualType();
4627
Anastasia Stulovad6f34bf2019-07-15 13:02:21 +00004628 if (SemaRef.getLangOpts().OpenCL)
4629 deduceOpenCLPointeeAddrSpace(SemaRef, PointeeType);
4630
John McCall70dd5f62009-10-30 00:06:24 +00004631 QualType Result = TL.getType();
4632 if (getDerived().AlwaysRebuild() ||
4633 PointeeType != T->getPointeeTypeAsWritten()) {
4634 Result = getDerived().RebuildReferenceType(PointeeType,
4635 T->isSpelledAsLValue(),
4636 TL.getSigilLoc());
4637 if (Result.isNull())
4638 return QualType();
4639 }
4640
John McCall31168b02011-06-15 23:02:42 +00004641 // Objective-C ARC can add lifetime qualifiers to the type that we're
4642 // referring to.
4643 TLB.TypeWasModifiedSafely(
4644 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4645
John McCall70dd5f62009-10-30 00:06:24 +00004646 // r-value references can be rebuilt as l-value references.
4647 ReferenceTypeLoc NewTL;
4648 if (isa<LValueReferenceType>(Result))
4649 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4650 else
4651 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4652 NewTL.setSigilLoc(TL.getSigilLoc());
4653
4654 return Result;
4655}
4656
Mike Stump11289f42009-09-09 15:08:12 +00004657template<typename Derived>
4658QualType
John McCall550e0c22009-10-21 00:40:46 +00004659TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004660 LValueReferenceTypeLoc TL) {
4661 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004662}
4663
Mike Stump11289f42009-09-09 15:08:12 +00004664template<typename Derived>
4665QualType
John McCall550e0c22009-10-21 00:40:46 +00004666TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004667 RValueReferenceTypeLoc TL) {
4668 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregord6ff3322009-08-04 16:50:30 +00004671template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004672QualType
John McCall550e0c22009-10-21 00:40:46 +00004673TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004674 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004675 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004676 if (PointeeType.isNull())
4677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004678
Abramo Bagnara509357842011-03-05 14:42:21 +00004679 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004680 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004681 if (OldClsTInfo) {
4682 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4683 if (!NewClsTInfo)
4684 return QualType();
4685 }
4686
4687 const MemberPointerType *T = TL.getTypePtr();
4688 QualType OldClsType = QualType(T->getClass(), 0);
4689 QualType NewClsType;
4690 if (NewClsTInfo)
4691 NewClsType = NewClsTInfo->getType();
4692 else {
4693 NewClsType = getDerived().TransformType(OldClsType);
4694 if (NewClsType.isNull())
4695 return QualType();
4696 }
Mike Stump11289f42009-09-09 15:08:12 +00004697
John McCall550e0c22009-10-21 00:40:46 +00004698 QualType Result = TL.getType();
4699 if (getDerived().AlwaysRebuild() ||
4700 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004701 NewClsType != OldClsType) {
4702 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004703 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004704 if (Result.isNull())
4705 return QualType();
4706 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004707
Reid Kleckner0503a872013-12-05 01:23:43 +00004708 // If we had to adjust the pointee type when building a member pointer, make
4709 // sure to push TypeLoc info for it.
4710 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4711 if (MPT && PointeeType != MPT->getPointeeType()) {
4712 assert(isa<AdjustedType>(MPT->getPointeeType()));
4713 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4714 }
4715
John McCall550e0c22009-10-21 00:40:46 +00004716 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4717 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004718 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004719
4720 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004721}
4722
Mike Stump11289f42009-09-09 15:08:12 +00004723template<typename Derived>
4724QualType
John McCall550e0c22009-10-21 00:40:46 +00004725TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004726 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004727 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004728 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729 if (ElementType.isNull())
4730 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004731
John McCall550e0c22009-10-21 00:40:46 +00004732 QualType Result = TL.getType();
4733 if (getDerived().AlwaysRebuild() ||
4734 ElementType != T->getElementType()) {
4735 Result = getDerived().RebuildConstantArrayType(ElementType,
4736 T->getSizeModifier(),
4737 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004738 T->getIndexTypeCVRQualifiers(),
4739 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004740 if (Result.isNull())
4741 return QualType();
4742 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004743
4744 // We might have either a ConstantArrayType or a VariableArrayType now:
4745 // a ConstantArrayType is allowed to have an element type which is a
4746 // VariableArrayType if the type is dependent. Fortunately, all array
4747 // types have the same location layout.
4748 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004749 NewTL.setLBracketLoc(TL.getLBracketLoc());
4750 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004751
John McCall550e0c22009-10-21 00:40:46 +00004752 Expr *Size = TL.getSizeExpr();
4753 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004754 EnterExpressionEvaluationContext Unevaluated(
4755 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004756 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4757 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004758 }
4759 NewTL.setSizeExpr(Size);
4760
4761 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004762}
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregord6ff3322009-08-04 16:50:30 +00004764template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004765QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004766 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004767 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004768 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004769 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004770 if (ElementType.isNull())
4771 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004772
John McCall550e0c22009-10-21 00:40:46 +00004773 QualType Result = TL.getType();
4774 if (getDerived().AlwaysRebuild() ||
4775 ElementType != T->getElementType()) {
4776 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004777 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004778 T->getIndexTypeCVRQualifiers(),
4779 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004780 if (Result.isNull())
4781 return QualType();
4782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004783
John McCall550e0c22009-10-21 00:40:46 +00004784 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4785 NewTL.setLBracketLoc(TL.getLBracketLoc());
4786 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004787 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004788
4789 return Result;
4790}
4791
4792template<typename Derived>
4793QualType
4794TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004795 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004796 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004797 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4798 if (ElementType.isNull())
4799 return QualType();
4800
Tim Shenb34d0ef2017-02-14 23:46:37 +00004801 ExprResult SizeResult;
4802 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004803 EnterExpressionEvaluationContext Context(
4804 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004805 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4806 }
4807 if (SizeResult.isInvalid())
4808 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004809 SizeResult =
4810 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004811 if (SizeResult.isInvalid())
4812 return QualType();
4813
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004814 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004815
4816 QualType Result = TL.getType();
4817 if (getDerived().AlwaysRebuild() ||
4818 ElementType != T->getElementType() ||
4819 Size != T->getSizeExpr()) {
4820 Result = getDerived().RebuildVariableArrayType(ElementType,
4821 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004822 Size,
John McCall550e0c22009-10-21 00:40:46 +00004823 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004824 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004825 if (Result.isNull())
4826 return QualType();
4827 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004828
Serge Pavlov774c6d02014-02-06 03:49:11 +00004829 // We might have constant size array now, but fortunately it has the same
4830 // location layout.
4831 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004832 NewTL.setLBracketLoc(TL.getLBracketLoc());
4833 NewTL.setRBracketLoc(TL.getRBracketLoc());
4834 NewTL.setSizeExpr(Size);
4835
4836 return Result;
4837}
4838
4839template<typename Derived>
4840QualType
4841TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004842 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004843 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004844 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4845 if (ElementType.isNull())
4846 return QualType();
4847
Richard Smith764d2fe2011-12-20 02:08:33 +00004848 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004849 EnterExpressionEvaluationContext Unevaluated(
4850 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004851
John McCall33ddac02011-01-19 10:06:00 +00004852 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4853 Expr *origSize = TL.getSizeExpr();
4854 if (!origSize) origSize = T->getSizeExpr();
4855
4856 ExprResult sizeResult
4857 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004858 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004859 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004860 return QualType();
4861
John McCall33ddac02011-01-19 10:06:00 +00004862 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004863
4864 QualType Result = TL.getType();
4865 if (getDerived().AlwaysRebuild() ||
4866 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004867 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004868 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4869 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004870 size,
John McCall550e0c22009-10-21 00:40:46 +00004871 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004872 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004873 if (Result.isNull())
4874 return QualType();
4875 }
John McCall550e0c22009-10-21 00:40:46 +00004876
4877 // We might have any sort of array type now, but fortunately they
4878 // all have the same location layout.
4879 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4880 NewTL.setLBracketLoc(TL.getLBracketLoc());
4881 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004882 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004883
4884 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004885}
Mike Stump11289f42009-09-09 15:08:12 +00004886
Erich Keanef702b022018-07-13 19:46:04 +00004887template <typename Derived>
4888QualType TreeTransform<Derived>::TransformDependentVectorType(
4889 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4890 const DependentVectorType *T = TL.getTypePtr();
4891 QualType ElementType = getDerived().TransformType(T->getElementType());
4892 if (ElementType.isNull())
4893 return QualType();
4894
4895 EnterExpressionEvaluationContext Unevaluated(
4896 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4897
4898 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4899 Size = SemaRef.ActOnConstantExpression(Size);
4900 if (Size.isInvalid())
4901 return QualType();
4902
4903 QualType Result = TL.getType();
4904 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4905 Size.get() != T->getSizeExpr()) {
4906 Result = getDerived().RebuildDependentVectorType(
4907 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4908 if (Result.isNull())
4909 return QualType();
4910 }
4911
4912 // Result might be dependent or not.
4913 if (isa<DependentVectorType>(Result)) {
4914 DependentVectorTypeLoc NewTL =
4915 TLB.push<DependentVectorTypeLoc>(Result);
4916 NewTL.setNameLoc(TL.getNameLoc());
4917 } else {
4918 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4919 NewTL.setNameLoc(TL.getNameLoc());
4920 }
4921
4922 return Result;
4923}
4924
Mike Stump11289f42009-09-09 15:08:12 +00004925template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004926QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004927 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004928 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004929 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004930
4931 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004932 QualType ElementType = getDerived().TransformType(T->getElementType());
4933 if (ElementType.isNull())
4934 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004935
Richard Smith764d2fe2011-12-20 02:08:33 +00004936 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004937 EnterExpressionEvaluationContext Unevaluated(
4938 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004939
John McCalldadc5752010-08-24 06:29:42 +00004940 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004941 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004942 if (Size.isInvalid())
4943 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004944
John McCall550e0c22009-10-21 00:40:46 +00004945 QualType Result = TL.getType();
4946 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004947 ElementType != T->getElementType() ||
4948 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004949 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004950 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004951 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004952 if (Result.isNull())
4953 return QualType();
4954 }
John McCall550e0c22009-10-21 00:40:46 +00004955
4956 // Result might be dependent or not.
4957 if (isa<DependentSizedExtVectorType>(Result)) {
4958 DependentSizedExtVectorTypeLoc NewTL
4959 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4960 NewTL.setNameLoc(TL.getNameLoc());
4961 } else {
4962 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4963 NewTL.setNameLoc(TL.getNameLoc());
4964 }
4965
4966 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004967}
Mike Stump11289f42009-09-09 15:08:12 +00004968
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004969template <typename Derived>
4970QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4971 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4972 const DependentAddressSpaceType *T = TL.getTypePtr();
4973
4974 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4975
4976 if (pointeeType.isNull())
4977 return QualType();
4978
4979 // Address spaces are constant expressions.
4980 EnterExpressionEvaluationContext Unevaluated(
4981 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4982
4983 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4984 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4985 if (AddrSpace.isInvalid())
4986 return QualType();
4987
4988 QualType Result = TL.getType();
4989 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4990 AddrSpace.get() != T->getAddrSpaceExpr()) {
4991 Result = getDerived().RebuildDependentAddressSpaceType(
4992 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4993 if (Result.isNull())
4994 return QualType();
4995 }
4996
4997 // Result might be dependent or not.
4998 if (isa<DependentAddressSpaceType>(Result)) {
4999 DependentAddressSpaceTypeLoc NewTL =
5000 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5001
5002 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5003 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5004 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5005
5006 } else {
5007 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5008 Result, getDerived().getBaseLocation());
5009 TransformType(TLB, DI->getTypeLoc());
5010 }
5011
5012 return Result;
5013}
5014
5015template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005016QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005017 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005018 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005019 QualType ElementType = getDerived().TransformType(T->getElementType());
5020 if (ElementType.isNull())
5021 return QualType();
5022
John McCall550e0c22009-10-21 00:40:46 +00005023 QualType Result = TL.getType();
5024 if (getDerived().AlwaysRebuild() ||
5025 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00005026 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00005027 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00005028 if (Result.isNull())
5029 return QualType();
5030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005031
John McCall550e0c22009-10-21 00:40:46 +00005032 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5033 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005034
John McCall550e0c22009-10-21 00:40:46 +00005035 return Result;
5036}
5037
5038template<typename Derived>
5039QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005040 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005041 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005042 QualType ElementType = getDerived().TransformType(T->getElementType());
5043 if (ElementType.isNull())
5044 return QualType();
5045
5046 QualType Result = TL.getType();
5047 if (getDerived().AlwaysRebuild() ||
5048 ElementType != T->getElementType()) {
5049 Result = getDerived().RebuildExtVectorType(ElementType,
5050 T->getNumElements(),
5051 /*FIXME*/ SourceLocation());
5052 if (Result.isNull())
5053 return QualType();
5054 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005055
John McCall550e0c22009-10-21 00:40:46 +00005056 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5057 NewTL.setNameLoc(TL.getNameLoc());
5058
5059 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005060}
Mike Stump11289f42009-09-09 15:08:12 +00005061
David Blaikie05785d12013-02-20 22:23:23 +00005062template <typename Derived>
5063ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
5064 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
5065 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00005066 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00005067 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005068
Douglas Gregor715e4612011-01-14 22:40:04 +00005069 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005070 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005071 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00005072 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005073 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00005074
Douglas Gregor715e4612011-01-14 22:40:04 +00005075 TypeLocBuilder TLB;
5076 TypeLoc NewTL = OldDI->getTypeLoc();
5077 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005078
5079 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005080 OldExpansionTL.getPatternLoc());
5081 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005082 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005083
5084 Result = RebuildPackExpansionType(Result,
5085 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005086 OldExpansionTL.getEllipsisLoc(),
5087 NumExpansions);
5088 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005089 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005090
Douglas Gregor715e4612011-01-14 22:40:04 +00005091 PackExpansionTypeLoc NewExpansionTL
5092 = TLB.push<PackExpansionTypeLoc>(Result);
5093 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5094 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5095 } else
5096 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005097 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005098 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005099
John McCall8fb0d9d2011-05-01 22:35:37 +00005100 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005101 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005102
5103 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5104 OldParm->getDeclContext(),
5105 OldParm->getInnerLocStart(),
5106 OldParm->getLocation(),
5107 OldParm->getIdentifier(),
5108 NewDI->getType(),
5109 NewDI,
5110 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005111 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005112 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5113 OldParm->getFunctionScopeIndex() + indexAdjustment);
5114 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005115}
5116
David Majnemer59f77922016-06-24 04:05:48 +00005117template <typename Derived>
5118bool TreeTransform<Derived>::TransformFunctionTypeParams(
5119 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5120 const QualType *ParamTypes,
5121 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5122 SmallVectorImpl<QualType> &OutParamTypes,
5123 SmallVectorImpl<ParmVarDecl *> *PVars,
5124 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005125 int indexAdjustment = 0;
5126
David Majnemer59f77922016-06-24 04:05:48 +00005127 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005128 for (unsigned i = 0; i != NumParams; ++i) {
5129 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005130 assert(OldParm->getFunctionScopeIndex() == i);
5131
David Blaikie05785d12013-02-20 22:23:23 +00005132 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005133 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005134 if (OldParm->isParameterPack()) {
5135 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005136 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005137
Douglas Gregor5499af42011-01-05 23:12:31 +00005138 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005139 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005140 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005141 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5142 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005143 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5144
Douglas Gregor5499af42011-01-05 23:12:31 +00005145 // Determine whether we should expand the parameter packs.
5146 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005147 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005148 Optional<unsigned> OrigNumExpansions =
5149 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005150 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005151 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5152 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005153 Unexpanded,
5154 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005155 RetainExpansion,
5156 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005157 return true;
5158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregor5499af42011-01-05 23:12:31 +00005160 if (ShouldExpand) {
5161 // Expand the function parameter pack into multiple, separate
5162 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005163 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005164 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005165 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005166 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005167 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005168 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005169 OrigNumExpansions,
5170 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005171 if (!NewParm)
5172 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005173
John McCallc8e321d2016-03-01 02:09:25 +00005174 if (ParamInfos)
5175 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005176 OutParamTypes.push_back(NewParm->getType());
5177 if (PVars)
5178 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005179 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005180
5181 // If we're supposed to retain a pack expansion, do so by temporarily
5182 // forgetting the partially-substituted parameter pack.
5183 if (RetainExpansion) {
5184 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005185 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005186 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005187 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005188 OrigNumExpansions,
5189 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005190 if (!NewParm)
5191 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005192
John McCallc8e321d2016-03-01 02:09:25 +00005193 if (ParamInfos)
5194 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005195 OutParamTypes.push_back(NewParm->getType());
5196 if (PVars)
5197 PVars->push_back(NewParm);
5198 }
5199
John McCall8fb0d9d2011-05-01 22:35:37 +00005200 // The next parameter should have the same adjustment as the
5201 // last thing we pushed, but we post-incremented indexAdjustment
5202 // on every push. Also, if we push nothing, the adjustment should
5203 // go down by one.
5204 indexAdjustment--;
5205
Douglas Gregor5499af42011-01-05 23:12:31 +00005206 // We're done with the pack expansion.
5207 continue;
5208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005209
5210 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005211 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005212 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5213 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005214 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005215 NumExpansions,
5216 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005217 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005218 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005219 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005220 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005221
John McCall58f10c32010-03-11 09:03:00 +00005222 if (!NewParm)
5223 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005224
John McCallc8e321d2016-03-01 02:09:25 +00005225 if (ParamInfos)
5226 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005227 OutParamTypes.push_back(NewParm->getType());
5228 if (PVars)
5229 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005230 continue;
5231 }
John McCall58f10c32010-03-11 09:03:00 +00005232
5233 // Deal with the possibility that we don't have a parameter
5234 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005235 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005236 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005237 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005238 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005239 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005240 = dyn_cast<PackExpansionType>(OldType)) {
5241 // We have a function parameter pack that may need to be expanded.
5242 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005243 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005244 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005245
Douglas Gregor5499af42011-01-05 23:12:31 +00005246 // Determine whether we should expand the parameter packs.
5247 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005248 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005249 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005250 Unexpanded,
5251 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005252 RetainExpansion,
5253 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005254 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregor5499af42011-01-05 23:12:31 +00005257 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005258 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005259 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005260 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005261 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5262 QualType NewType = getDerived().TransformType(Pattern);
5263 if (NewType.isNull())
5264 return true;
John McCall58f10c32010-03-11 09:03:00 +00005265
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005266 if (NewType->containsUnexpandedParameterPack()) {
5267 NewType =
5268 getSema().getASTContext().getPackExpansionType(NewType, None);
5269
5270 if (NewType.isNull())
5271 return true;
5272 }
5273
John McCallc8e321d2016-03-01 02:09:25 +00005274 if (ParamInfos)
5275 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005276 OutParamTypes.push_back(NewType);
5277 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005278 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregor5499af42011-01-05 23:12:31 +00005281 // We're done with the pack expansion.
5282 continue;
5283 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005284
Douglas Gregor48d24112011-01-10 20:53:55 +00005285 // If we're supposed to retain a pack expansion, do so by temporarily
5286 // forgetting the partially-substituted parameter pack.
5287 if (RetainExpansion) {
5288 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5289 QualType NewType = getDerived().TransformType(Pattern);
5290 if (NewType.isNull())
5291 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005292
John McCallc8e321d2016-03-01 02:09:25 +00005293 if (ParamInfos)
5294 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005295 OutParamTypes.push_back(NewType);
5296 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005297 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005298 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005299
Chad Rosier1dcde962012-08-08 18:46:20 +00005300 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005301 // expansion.
5302 OldType = Expansion->getPattern();
5303 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005304 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5305 NewType = getDerived().TransformType(OldType);
5306 } else {
5307 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005309
Douglas Gregor5499af42011-01-05 23:12:31 +00005310 if (NewType.isNull())
5311 return true;
5312
5313 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005314 NewType = getSema().Context.getPackExpansionType(NewType,
5315 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005316
John McCallc8e321d2016-03-01 02:09:25 +00005317 if (ParamInfos)
5318 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005319 OutParamTypes.push_back(NewType);
5320 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005321 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005322 }
5323
John McCall8fb0d9d2011-05-01 22:35:37 +00005324#ifndef NDEBUG
5325 if (PVars) {
5326 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5327 if (ParmVarDecl *parm = (*PVars)[i])
5328 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005329 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005330#endif
5331
5332 return false;
5333}
John McCall58f10c32010-03-11 09:03:00 +00005334
5335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005336QualType
John McCall550e0c22009-10-21 00:40:46 +00005337TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005338 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005339 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005340 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005341 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005342 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005343 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5344 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5345 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005346 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005347}
5348
Richard Smith2e321552014-11-12 02:00:47 +00005349template<typename Derived> template<typename Fn>
5350QualType TreeTransform<Derived>::TransformFunctionProtoType(
5351 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005352 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005353
Douglas Gregor4afc2362010-08-31 00:26:14 +00005354 // Transform the parameters and return type.
5355 //
Richard Smithf623c962012-04-17 00:58:00 +00005356 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005357 // When the function has a trailing return type, we instantiate the
5358 // parameters before the return type, since the return type can then refer
5359 // to the parameters themselves (via decltype, sizeof, etc.).
5360 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005361 SmallVector<QualType, 4> ParamTypes;
5362 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005363 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005364 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005365
Douglas Gregor7fb25412010-10-01 18:44:50 +00005366 QualType ResultType;
5367
Richard Smith1226c602012-08-14 22:51:13 +00005368 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005369 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005370 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005371 TL.getTypePtr()->param_type_begin(),
5372 T->getExtParameterInfosOrNull(),
5373 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005374 return QualType();
5375
Douglas Gregor3024f072012-04-16 07:05:22 +00005376 {
5377 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005378 // If a declaration declares a member function or member function
5379 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005380 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005381 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005382 // declarator.
5383 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005384
Alp Toker42a16a62014-01-25 23:51:36 +00005385 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005386 if (ResultType.isNull())
5387 return QualType();
5388 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005389 }
5390 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005391 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005392 if (ResultType.isNull())
5393 return QualType();
5394
Alp Toker9cacbab2014-01-20 20:26:09 +00005395 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005396 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005397 TL.getTypePtr()->param_type_begin(),
5398 T->getExtParameterInfosOrNull(),
5399 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005400 return QualType();
5401 }
5402
Richard Smith2e321552014-11-12 02:00:47 +00005403 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5404
5405 bool EPIChanged = false;
5406 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5407 return QualType();
5408
John McCallc8e321d2016-03-01 02:09:25 +00005409 // Handle extended parameter information.
5410 if (auto NewExtParamInfos =
5411 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5412 if (!EPI.ExtParameterInfos ||
5413 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5414 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5415 EPIChanged = true;
5416 }
5417 EPI.ExtParameterInfos = NewExtParamInfos;
5418 } else if (EPI.ExtParameterInfos) {
5419 EPIChanged = true;
5420 EPI.ExtParameterInfos = nullptr;
5421 }
Richard Smithf623c962012-04-17 00:58:00 +00005422
John McCall550e0c22009-10-21 00:40:46 +00005423 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005424 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005425 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005426 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005427 if (Result.isNull())
5428 return QualType();
5429 }
Mike Stump11289f42009-09-09 15:08:12 +00005430
John McCall550e0c22009-10-21 00:40:46 +00005431 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005432 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005433 NewTL.setLParenLoc(TL.getLParenLoc());
5434 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005435 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005436 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005437 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5438 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005439
5440 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005441}
Mike Stump11289f42009-09-09 15:08:12 +00005442
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005444bool TreeTransform<Derived>::TransformExceptionSpec(
5445 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5446 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5447 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5448
5449 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005450 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005451 EnterExpressionEvaluationContext Unevaluated(
5452 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005453 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5454 if (NoexceptExpr.isInvalid())
5455 return true;
5456
Richard Smitheaf11ad2018-05-03 03:58:32 +00005457 ExceptionSpecificationType EST = ESI.Type;
5458 NoexceptExpr =
5459 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005460 if (NoexceptExpr.isInvalid())
5461 return true;
5462
Richard Smitheaf11ad2018-05-03 03:58:32 +00005463 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005464 Changed = true;
5465 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005466 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005467 }
5468
5469 if (ESI.Type != EST_Dynamic)
5470 return false;
5471
5472 // Instantiate a dynamic exception specification's type.
5473 for (QualType T : ESI.Exceptions) {
5474 if (const PackExpansionType *PackExpansion =
5475 T->getAs<PackExpansionType>()) {
5476 Changed = true;
5477
5478 // We have a pack expansion. Instantiate it.
5479 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5480 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5481 Unexpanded);
5482 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5483
5484 // Determine whether the set of unexpanded parameter packs can and
5485 // should
5486 // be expanded.
5487 bool Expand = false;
5488 bool RetainExpansion = false;
5489 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5490 // FIXME: Track the location of the ellipsis (and track source location
5491 // information for the types in the exception specification in general).
5492 if (getDerived().TryExpandParameterPacks(
5493 Loc, SourceRange(), Unexpanded, Expand,
5494 RetainExpansion, NumExpansions))
5495 return true;
5496
5497 if (!Expand) {
5498 // We can't expand this pack expansion into separate arguments yet;
5499 // just substitute into the pattern and create a new pack expansion
5500 // type.
5501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5502 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5503 if (U.isNull())
5504 return true;
5505
5506 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5507 Exceptions.push_back(U);
5508 continue;
5509 }
5510
5511 // Substitute into the pack expansion pattern for each slice of the
5512 // pack.
5513 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5514 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5515
5516 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5517 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5518 return true;
5519
5520 Exceptions.push_back(U);
5521 }
5522 } else {
5523 QualType U = getDerived().TransformType(T);
5524 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5525 return true;
5526 if (T != U)
5527 Changed = true;
5528
5529 Exceptions.push_back(U);
5530 }
5531 }
5532
5533 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005534 if (ESI.Exceptions.empty())
5535 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005536 return false;
5537}
5538
5539template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005540QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005541 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005542 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005543 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005544 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005545 if (ResultType.isNull())
5546 return QualType();
5547
5548 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005549 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005550 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5551
5552 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005553 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005554 NewTL.setLParenLoc(TL.getLParenLoc());
5555 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005556 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005557
5558 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
John McCallb96ec562009-12-04 22:46:56 +00005561template<typename Derived> QualType
5562TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005563 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005564 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005565 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005566 if (!D)
5567 return QualType();
5568
5569 QualType Result = TL.getType();
5570 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005571 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005572 if (Result.isNull())
5573 return QualType();
5574 }
5575
5576 // We might get an arbitrary type spec type back. We should at
5577 // least always get a type spec type, though.
5578 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5579 NewTL.setNameLoc(TL.getNameLoc());
5580
5581 return Result;
5582}
5583
Douglas Gregord6ff3322009-08-04 16:50:30 +00005584template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005585QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005586 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005587 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005588 TypedefNameDecl *Typedef
5589 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5590 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005591 if (!Typedef)
5592 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005593
John McCall550e0c22009-10-21 00:40:46 +00005594 QualType Result = TL.getType();
5595 if (getDerived().AlwaysRebuild() ||
5596 Typedef != T->getDecl()) {
5597 Result = getDerived().RebuildTypedefType(Typedef);
5598 if (Result.isNull())
5599 return QualType();
5600 }
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCall550e0c22009-10-21 00:40:46 +00005602 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5603 NewTL.setNameLoc(TL.getNameLoc());
5604
5605 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005606}
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregord6ff3322009-08-04 16:50:30 +00005608template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005609QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005610 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005611 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005612 EnterExpressionEvaluationContext Unevaluated(
5613 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5614 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005615
John McCalldadc5752010-08-24 06:29:42 +00005616 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005617 if (E.isInvalid())
5618 return QualType();
5619
Eli Friedmane4f22df2012-02-29 04:03:55 +00005620 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5621 if (E.isInvalid())
5622 return QualType();
5623
John McCall550e0c22009-10-21 00:40:46 +00005624 QualType Result = TL.getType();
5625 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005626 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005627 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005628 if (Result.isNull())
5629 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005630 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005631 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005632
John McCall550e0c22009-10-21 00:40:46 +00005633 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005634 NewTL.setTypeofLoc(TL.getTypeofLoc());
5635 NewTL.setLParenLoc(TL.getLParenLoc());
5636 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005637
5638 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005639}
Mike Stump11289f42009-09-09 15:08:12 +00005640
5641template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005642QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005643 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005644 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5645 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5646 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005647 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005648
John McCall550e0c22009-10-21 00:40:46 +00005649 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005650 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5651 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005652 if (Result.isNull())
5653 return QualType();
5654 }
Mike Stump11289f42009-09-09 15:08:12 +00005655
John McCall550e0c22009-10-21 00:40:46 +00005656 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005657 NewTL.setTypeofLoc(TL.getTypeofLoc());
5658 NewTL.setLParenLoc(TL.getLParenLoc());
5659 NewTL.setRParenLoc(TL.getRParenLoc());
5660 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005661
5662 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005663}
Mike Stump11289f42009-09-09 15:08:12 +00005664
5665template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005666QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005667 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005668 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005669
Douglas Gregore922c772009-08-04 22:27:00 +00005670 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005671 EnterExpressionEvaluationContext Unevaluated(
5672 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005673 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005674
John McCalldadc5752010-08-24 06:29:42 +00005675 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005676 if (E.isInvalid())
5677 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005678
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005679 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005680 if (E.isInvalid())
5681 return QualType();
5682
John McCall550e0c22009-10-21 00:40:46 +00005683 QualType Result = TL.getType();
5684 if (getDerived().AlwaysRebuild() ||
5685 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005686 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005687 if (Result.isNull())
5688 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005689 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005690 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005691
John McCall550e0c22009-10-21 00:40:46 +00005692 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5693 NewTL.setNameLoc(TL.getNameLoc());
5694
5695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005696}
5697
5698template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005699QualType TreeTransform<Derived>::TransformUnaryTransformType(
5700 TypeLocBuilder &TLB,
5701 UnaryTransformTypeLoc TL) {
5702 QualType Result = TL.getType();
5703 if (Result->isDependentType()) {
5704 const UnaryTransformType *T = TL.getTypePtr();
5705 QualType NewBase =
5706 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5707 Result = getDerived().RebuildUnaryTransformType(NewBase,
5708 T->getUTTKind(),
5709 TL.getKWLoc());
5710 if (Result.isNull())
5711 return QualType();
5712 }
5713
5714 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5715 NewTL.setKWLoc(TL.getKWLoc());
5716 NewTL.setParensRange(TL.getParensRange());
5717 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5718 return Result;
5719}
5720
5721template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005722QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5723 AutoTypeLoc TL) {
5724 const AutoType *T = TL.getTypePtr();
5725 QualType OldDeduced = T->getDeducedType();
5726 QualType NewDeduced;
5727 if (!OldDeduced.isNull()) {
5728 NewDeduced = getDerived().TransformType(OldDeduced);
5729 if (NewDeduced.isNull())
5730 return QualType();
5731 }
5732
5733 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005734 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5735 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005736 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005737 if (Result.isNull())
5738 return QualType();
5739 }
5740
5741 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5742 NewTL.setNameLoc(TL.getNameLoc());
5743
5744 return Result;
5745}
5746
5747template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005748QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5749 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5750 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5751
5752 CXXScopeSpec SS;
5753 TemplateName TemplateName = getDerived().TransformTemplateName(
5754 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5755 if (TemplateName.isNull())
5756 return QualType();
5757
5758 QualType OldDeduced = T->getDeducedType();
5759 QualType NewDeduced;
5760 if (!OldDeduced.isNull()) {
5761 NewDeduced = getDerived().TransformType(OldDeduced);
5762 if (NewDeduced.isNull())
5763 return QualType();
5764 }
5765
5766 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5767 TemplateName, NewDeduced);
5768 if (Result.isNull())
5769 return QualType();
5770
5771 DeducedTemplateSpecializationTypeLoc NewTL =
5772 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5773 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5774
5775 return Result;
5776}
5777
5778template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005779QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005780 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005781 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005782 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005783 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5784 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005785 if (!Record)
5786 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005787
John McCall550e0c22009-10-21 00:40:46 +00005788 QualType Result = TL.getType();
5789 if (getDerived().AlwaysRebuild() ||
5790 Record != T->getDecl()) {
5791 Result = getDerived().RebuildRecordType(Record);
5792 if (Result.isNull())
5793 return QualType();
5794 }
Mike Stump11289f42009-09-09 15:08:12 +00005795
John McCall550e0c22009-10-21 00:40:46 +00005796 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5797 NewTL.setNameLoc(TL.getNameLoc());
5798
5799 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005800}
Mike Stump11289f42009-09-09 15:08:12 +00005801
5802template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005803QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005804 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005805 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005806 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005807 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5808 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005809 if (!Enum)
5810 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005811
John McCall550e0c22009-10-21 00:40:46 +00005812 QualType Result = TL.getType();
5813 if (getDerived().AlwaysRebuild() ||
5814 Enum != T->getDecl()) {
5815 Result = getDerived().RebuildEnumType(Enum);
5816 if (Result.isNull())
5817 return QualType();
5818 }
Mike Stump11289f42009-09-09 15:08:12 +00005819
John McCall550e0c22009-10-21 00:40:46 +00005820 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5821 NewTL.setNameLoc(TL.getNameLoc());
5822
5823 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005824}
John McCallfcc33b02009-09-05 00:15:47 +00005825
John McCalle78aac42010-03-10 03:28:59 +00005826template<typename Derived>
5827QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5828 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005829 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005830 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5831 TL.getTypePtr()->getDecl());
5832 if (!D) return QualType();
5833
5834 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5835 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5836 return T;
5837}
5838
Douglas Gregord6ff3322009-08-04 16:50:30 +00005839template<typename Derived>
5840QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005841 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005842 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005843 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005844}
5845
Mike Stump11289f42009-09-09 15:08:12 +00005846template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005847QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005848 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005849 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005850 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005851
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005852 // Substitute into the replacement type, which itself might involve something
5853 // that needs to be transformed. This only tends to occur with default
5854 // template arguments of template template parameters.
5855 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5856 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5857 if (Replacement.isNull())
5858 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005859
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005860 // Always canonicalize the replacement type.
5861 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5862 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005863 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005864 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005866 // Propagate type-source information.
5867 SubstTemplateTypeParmTypeLoc NewTL
5868 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5869 NewTL.setNameLoc(TL.getNameLoc());
5870 return Result;
5871
John McCallcebee162009-10-18 09:09:24 +00005872}
5873
5874template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005875QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5876 TypeLocBuilder &TLB,
5877 SubstTemplateTypeParmPackTypeLoc TL) {
5878 return TransformTypeSpecType(TLB, TL);
5879}
5880
5881template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005882QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005883 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005884 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005885 const TemplateSpecializationType *T = TL.getTypePtr();
5886
Douglas Gregordf846d12011-03-02 18:46:51 +00005887 // The nested-name-specifier never matters in a TemplateSpecializationType,
5888 // because we can't have a dependent nested-name-specifier anyway.
5889 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005890 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005891 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5892 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005893 if (Template.isNull())
5894 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005895
John McCall31f82722010-11-12 08:19:04 +00005896 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5897}
5898
Eli Friedman0dfb8892011-10-06 23:00:33 +00005899template<typename Derived>
5900QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5901 AtomicTypeLoc TL) {
5902 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5903 if (ValueType.isNull())
5904 return QualType();
5905
5906 QualType Result = TL.getType();
5907 if (getDerived().AlwaysRebuild() ||
5908 ValueType != TL.getValueLoc().getType()) {
5909 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5910 if (Result.isNull())
5911 return QualType();
5912 }
5913
5914 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5915 NewTL.setKWLoc(TL.getKWLoc());
5916 NewTL.setLParenLoc(TL.getLParenLoc());
5917 NewTL.setRParenLoc(TL.getRParenLoc());
5918
5919 return Result;
5920}
5921
Xiuli Pan9c14e282016-01-09 12:53:17 +00005922template <typename Derived>
5923QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5924 PipeTypeLoc TL) {
5925 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5926 if (ValueType.isNull())
5927 return QualType();
5928
5929 QualType Result = TL.getType();
5930 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005931 const PipeType *PT = Result->getAs<PipeType>();
5932 bool isReadPipe = PT->isReadOnly();
5933 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005934 if (Result.isNull())
5935 return QualType();
5936 }
5937
5938 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5939 NewTL.setKWLoc(TL.getKWLoc());
5940
5941 return Result;
5942}
5943
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005944 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005945 /// container that provides a \c getArgLoc() member function.
5946 ///
5947 /// This iterator is intended to be used with the iterator form of
5948 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5949 template<typename ArgLocContainer>
5950 class TemplateArgumentLocContainerIterator {
5951 ArgLocContainer *Container;
5952 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005953
Douglas Gregorfe921a72010-12-20 23:36:19 +00005954 public:
5955 typedef TemplateArgumentLoc value_type;
5956 typedef TemplateArgumentLoc reference;
5957 typedef int difference_type;
5958 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005959
Douglas Gregorfe921a72010-12-20 23:36:19 +00005960 class pointer {
5961 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005962
Douglas Gregorfe921a72010-12-20 23:36:19 +00005963 public:
5964 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005965
Douglas Gregorfe921a72010-12-20 23:36:19 +00005966 const TemplateArgumentLoc *operator->() const {
5967 return &Arg;
5968 }
5969 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005970
5971
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005972 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005973
Douglas Gregorfe921a72010-12-20 23:36:19 +00005974 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5975 unsigned Index)
5976 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005977
Douglas Gregorfe921a72010-12-20 23:36:19 +00005978 TemplateArgumentLocContainerIterator &operator++() {
5979 ++Index;
5980 return *this;
5981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005982
Douglas Gregorfe921a72010-12-20 23:36:19 +00005983 TemplateArgumentLocContainerIterator operator++(int) {
5984 TemplateArgumentLocContainerIterator Old(*this);
5985 ++(*this);
5986 return Old;
5987 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005988
Douglas Gregorfe921a72010-12-20 23:36:19 +00005989 TemplateArgumentLoc operator*() const {
5990 return Container->getArgLoc(Index);
5991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005992
Douglas Gregorfe921a72010-12-20 23:36:19 +00005993 pointer operator->() const {
5994 return pointer(Container->getArgLoc(Index));
5995 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005996
Douglas Gregorfe921a72010-12-20 23:36:19 +00005997 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005998 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005999 return X.Container == Y.Container && X.Index == Y.Index;
6000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006001
Douglas Gregorfe921a72010-12-20 23:36:19 +00006002 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00006003 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00006004 return !(X == Y);
6005 }
6006 };
Chad Rosier1dcde962012-08-08 18:46:20 +00006007
6008
John McCall31f82722010-11-12 08:19:04 +00006009template <typename Derived>
6010QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
6011 TypeLocBuilder &TLB,
6012 TemplateSpecializationTypeLoc TL,
6013 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00006014 TemplateArgumentListInfo NewTemplateArgs;
6015 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6016 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00006017 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
6018 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006019 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00006020 ArgIterator(TL, TL.getNumArgs()),
6021 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00006022 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006023
John McCall0ad16662009-10-29 08:12:44 +00006024 // FIXME: maybe don't rebuild if all the template arguments are the same.
6025
6026 QualType Result =
6027 getDerived().RebuildTemplateSpecializationType(Template,
6028 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00006029 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00006030
6031 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00006032 // Specializations of template template parameters are represented as
6033 // TemplateSpecializationTypes, and substitution of type alias templates
6034 // within a dependent context can transform them into
6035 // DependentTemplateSpecializationTypes.
6036 if (isa<DependentTemplateSpecializationType>(Result)) {
6037 DependentTemplateSpecializationTypeLoc NewTL
6038 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006039 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006040 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006041 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006042 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00006043 NewTL.setLAngleLoc(TL.getLAngleLoc());
6044 NewTL.setRAngleLoc(TL.getRAngleLoc());
6045 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6046 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6047 return Result;
6048 }
6049
John McCall0ad16662009-10-29 08:12:44 +00006050 TemplateSpecializationTypeLoc NewTL
6051 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006052 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00006053 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6054 NewTL.setLAngleLoc(TL.getLAngleLoc());
6055 NewTL.setRAngleLoc(TL.getRAngleLoc());
6056 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6057 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006058 }
Mike Stump11289f42009-09-09 15:08:12 +00006059
John McCall0ad16662009-10-29 08:12:44 +00006060 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006061}
Mike Stump11289f42009-09-09 15:08:12 +00006062
Douglas Gregor5a064722011-02-28 17:23:35 +00006063template <typename Derived>
6064QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
6065 TypeLocBuilder &TLB,
6066 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00006067 TemplateName Template,
6068 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006069 TemplateArgumentListInfo NewTemplateArgs;
6070 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6071 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6072 typedef TemplateArgumentLocContainerIterator<
6073 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006074 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006075 ArgIterator(TL, TL.getNumArgs()),
6076 NewTemplateArgs))
6077 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006078
Douglas Gregor5a064722011-02-28 17:23:35 +00006079 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006080
Douglas Gregor5a064722011-02-28 17:23:35 +00006081 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6082 QualType Result
6083 = getSema().Context.getDependentTemplateSpecializationType(
6084 TL.getTypePtr()->getKeyword(),
6085 DTN->getQualifier(),
6086 DTN->getIdentifier(),
6087 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Douglas Gregor5a064722011-02-28 17:23:35 +00006089 DependentTemplateSpecializationTypeLoc NewTL
6090 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006091 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006092 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006093 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006094 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006095 NewTL.setLAngleLoc(TL.getLAngleLoc());
6096 NewTL.setRAngleLoc(TL.getRAngleLoc());
6097 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6098 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6099 return Result;
6100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006101
6102 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006103 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006104 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006105 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
Douglas Gregor5a064722011-02-28 17:23:35 +00006107 if (!Result.isNull()) {
6108 /// FIXME: Wrap this in an elaborated-type-specifier?
6109 TemplateSpecializationTypeLoc NewTL
6110 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006111 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006112 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006113 NewTL.setLAngleLoc(TL.getLAngleLoc());
6114 NewTL.setRAngleLoc(TL.getRAngleLoc());
6115 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6116 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006118
Douglas Gregor5a064722011-02-28 17:23:35 +00006119 return Result;
6120}
6121
Mike Stump11289f42009-09-09 15:08:12 +00006122template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006123QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006124TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006125 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006126 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006127
Douglas Gregor844cb502011-03-01 18:12:44 +00006128 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006129 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006130 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006131 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006132 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6133 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006134 return QualType();
6135 }
Mike Stump11289f42009-09-09 15:08:12 +00006136
John McCall31f82722010-11-12 08:19:04 +00006137 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6138 if (NamedT.isNull())
6139 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006140
Richard Smith3f1b5d02011-05-05 21:57:07 +00006141 // C++0x [dcl.type.elab]p2:
6142 // If the identifier resolves to a typedef-name or the simple-template-id
6143 // resolves to an alias template specialization, the
6144 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006145 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6146 if (const TemplateSpecializationType *TST =
6147 NamedT->getAs<TemplateSpecializationType>()) {
6148 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006149 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6150 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006151 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006152 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006153 << TAT << Sema::NTK_TypeAliasTemplate
6154 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006155 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6156 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006157 }
6158 }
6159
John McCall550e0c22009-10-21 00:40:46 +00006160 QualType Result = TL.getType();
6161 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006162 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006163 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006164 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006165 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006166 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006167 if (Result.isNull())
6168 return QualType();
6169 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006170
Abramo Bagnara6150c882010-05-11 21:36:43 +00006171 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006172 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006173 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006175}
Mike Stump11289f42009-09-09 15:08:12 +00006176
6177template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006178QualType TreeTransform<Derived>::TransformAttributedType(
6179 TypeLocBuilder &TLB,
6180 AttributedTypeLoc TL) {
6181 const AttributedType *oldType = TL.getTypePtr();
6182 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6183 if (modifiedType.isNull())
6184 return QualType();
6185
Richard Smithe43e2b32018-08-20 21:47:29 +00006186 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6187 const Attr *oldAttr = TL.getAttr();
6188 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6189 if (oldAttr && !newAttr)
6190 return QualType();
6191
John McCall81904512011-01-06 01:58:22 +00006192 QualType result = TL.getType();
6193
6194 // FIXME: dependent operand expressions?
6195 if (getDerived().AlwaysRebuild() ||
6196 modifiedType != oldType->getModifiedType()) {
6197 // TODO: this is really lame; we should really be rebuilding the
6198 // equivalent type from first principles.
6199 QualType equivalentType
6200 = getDerived().TransformType(oldType->getEquivalentType());
6201 if (equivalentType.isNull())
6202 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006203
6204 // Check whether we can add nullability; it is only represented as
6205 // type sugar, and therefore cannot be diagnosed in any other way.
6206 if (auto nullability = oldType->getImmediateNullability()) {
6207 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006208 SemaRef.Diag(TL.getAttr()->getLocation(),
6209 diag::err_nullability_nonpointer)
6210 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006211 return QualType();
6212 }
6213 }
6214
Richard Smithe43e2b32018-08-20 21:47:29 +00006215 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006216 modifiedType,
6217 equivalentType);
6218 }
6219
6220 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006221 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006222 return result;
6223}
6224
6225template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006226QualType
6227TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6228 ParenTypeLoc TL) {
6229 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6230 if (Inner.isNull())
6231 return QualType();
6232
6233 QualType Result = TL.getType();
6234 if (getDerived().AlwaysRebuild() ||
6235 Inner != TL.getInnerLoc().getType()) {
6236 Result = getDerived().RebuildParenType(Inner);
6237 if (Result.isNull())
6238 return QualType();
6239 }
6240
6241 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6242 NewTL.setLParenLoc(TL.getLParenLoc());
6243 NewTL.setRParenLoc(TL.getRParenLoc());
6244 return Result;
6245}
6246
Leonard Chanc72aaf62019-05-07 03:20:17 +00006247template <typename Derived>
6248QualType
6249TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
6250 MacroQualifiedTypeLoc TL) {
6251 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6252 if (Inner.isNull())
6253 return QualType();
6254
6255 QualType Result = TL.getType();
6256 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
6257 Result =
6258 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
6259 if (Result.isNull())
6260 return QualType();
6261 }
6262
6263 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
6264 NewTL.setExpansionLoc(TL.getExpansionLoc());
6265 return Result;
6266}
6267
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006268template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006269QualType TreeTransform<Derived>::TransformDependentNameType(
6270 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6271 return TransformDependentNameType(TLB, TL, false);
6272}
6273
6274template<typename Derived>
6275QualType TreeTransform<Derived>::TransformDependentNameType(
6276 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006277 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006278
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006279 NestedNameSpecifierLoc QualifierLoc
6280 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6281 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006282 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006283
John McCallc392f372010-06-11 00:33:02 +00006284 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006285 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006286 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006287 QualifierLoc,
6288 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006289 TL.getNameLoc(),
6290 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006291 if (Result.isNull())
6292 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006293
Abramo Bagnarad7548482010-05-19 21:37:53 +00006294 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6295 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006296 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6297
Abramo Bagnarad7548482010-05-19 21:37:53 +00006298 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006299 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006300 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006301 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006302 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006303 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006304 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006305 NewTL.setNameLoc(TL.getNameLoc());
6306 }
John McCall550e0c22009-10-21 00:40:46 +00006307 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006308}
Mike Stump11289f42009-09-09 15:08:12 +00006309
Douglas Gregord6ff3322009-08-04 16:50:30 +00006310template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006311QualType TreeTransform<Derived>::
6312 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006313 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006314 NestedNameSpecifierLoc QualifierLoc;
6315 if (TL.getQualifierLoc()) {
6316 QualifierLoc
6317 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6318 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006319 return QualType();
6320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006321
John McCall31f82722010-11-12 08:19:04 +00006322 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006323 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006324}
6325
6326template<typename Derived>
6327QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006328TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6329 DependentTemplateSpecializationTypeLoc TL,
6330 NestedNameSpecifierLoc QualifierLoc) {
6331 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Douglas Gregora7a795b2011-03-01 20:11:18 +00006333 TemplateArgumentListInfo NewTemplateArgs;
6334 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6335 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006336
Douglas Gregora7a795b2011-03-01 20:11:18 +00006337 typedef TemplateArgumentLocContainerIterator<
6338 DependentTemplateSpecializationTypeLoc> ArgIterator;
6339 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6340 ArgIterator(TL, TL.getNumArgs()),
6341 NewTemplateArgs))
6342 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006343
Richard Smithfd3dae02017-01-20 00:20:39 +00006344 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006345 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6346 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006347 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006348 if (Result.isNull())
6349 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006350
Douglas Gregora7a795b2011-03-01 20:11:18 +00006351 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6352 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006353
Douglas Gregora7a795b2011-03-01 20:11:18 +00006354 // Copy information relevant to the template specialization.
6355 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006356 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006357 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006358 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006359 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6360 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006361 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006362 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006363
Douglas Gregora7a795b2011-03-01 20:11:18 +00006364 // Copy information relevant to the elaborated type.
6365 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006366 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006367 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006368 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6369 DependentTemplateSpecializationTypeLoc SpecTL
6370 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006371 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006372 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006373 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006374 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006375 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6376 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006377 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006378 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006379 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006380 TemplateSpecializationTypeLoc SpecTL
6381 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006382 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006383 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006384 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6385 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006386 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006387 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006388 }
6389 return Result;
6390}
6391
6392template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006393QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6394 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006395 QualType Pattern
6396 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006397 if (Pattern.isNull())
6398 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006399
6400 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006401 if (getDerived().AlwaysRebuild() ||
6402 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006403 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006404 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006405 TL.getEllipsisLoc(),
6406 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006407 if (Result.isNull())
6408 return QualType();
6409 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006410
Douglas Gregor822d0302011-01-12 17:07:58 +00006411 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6412 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6413 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006414}
6415
6416template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006417QualType
6418TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006419 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006420 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006421 TLB.pushFullCopy(TL);
6422 return TL.getType();
6423}
6424
6425template<typename Derived>
6426QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006427TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6428 ObjCTypeParamTypeLoc TL) {
6429 const ObjCTypeParamType *T = TL.getTypePtr();
6430 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6431 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6432 if (!OTP)
6433 return QualType();
6434
6435 QualType Result = TL.getType();
6436 if (getDerived().AlwaysRebuild() ||
6437 OTP != T->getDecl()) {
6438 Result = getDerived().RebuildObjCTypeParamType(OTP,
6439 TL.getProtocolLAngleLoc(),
6440 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6441 TL.getNumProtocols()),
6442 TL.getProtocolLocs(),
6443 TL.getProtocolRAngleLoc());
6444 if (Result.isNull())
6445 return QualType();
6446 }
6447
6448 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6449 if (TL.getNumProtocols()) {
6450 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6451 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6452 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6453 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6454 }
6455 return Result;
6456}
6457
6458template<typename Derived>
6459QualType
John McCall8b07ec22010-05-15 11:32:37 +00006460TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006461 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006462 // Transform base type.
6463 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6464 if (BaseType.isNull())
6465 return QualType();
6466
6467 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6468
6469 // Transform type arguments.
6470 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6471 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6472 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6473 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6474 QualType TypeArg = TypeArgInfo->getType();
6475 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6476 AnyChanged = true;
6477
6478 // We have a pack expansion. Instantiate it.
6479 const auto *PackExpansion = PackExpansionLoc.getType()
6480 ->castAs<PackExpansionType>();
6481 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6482 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6483 Unexpanded);
6484 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6485
6486 // Determine whether the set of unexpanded parameter packs can
6487 // and should be expanded.
6488 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6489 bool Expand = false;
6490 bool RetainExpansion = false;
6491 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6492 if (getDerived().TryExpandParameterPacks(
6493 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6494 Unexpanded, Expand, RetainExpansion, NumExpansions))
6495 return QualType();
6496
6497 if (!Expand) {
6498 // We can't expand this pack expansion into separate arguments yet;
6499 // just substitute into the pattern and create a new pack expansion
6500 // type.
6501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6502
6503 TypeLocBuilder TypeArgBuilder;
6504 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006505 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006506 PatternLoc);
6507 if (NewPatternType.isNull())
6508 return QualType();
6509
6510 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6511 NewPatternType, NumExpansions);
6512 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6513 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6514 NewTypeArgInfos.push_back(
6515 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6516 continue;
6517 }
6518
6519 // Substitute into the pack expansion pattern for each slice of the
6520 // pack.
6521 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6522 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6523
6524 TypeLocBuilder TypeArgBuilder;
6525 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6526
6527 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6528 PatternLoc);
6529 if (NewTypeArg.isNull())
6530 return QualType();
6531
6532 NewTypeArgInfos.push_back(
6533 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6534 }
6535
6536 continue;
6537 }
6538
6539 TypeLocBuilder TypeArgBuilder;
6540 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6541 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6542 if (NewTypeArg.isNull())
6543 return QualType();
6544
6545 // If nothing changed, just keep the old TypeSourceInfo.
6546 if (NewTypeArg == TypeArg) {
6547 NewTypeArgInfos.push_back(TypeArgInfo);
6548 continue;
6549 }
6550
6551 NewTypeArgInfos.push_back(
6552 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6553 AnyChanged = true;
6554 }
6555
6556 QualType Result = TL.getType();
6557 if (getDerived().AlwaysRebuild() || AnyChanged) {
6558 // Rebuild the type.
6559 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006560 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6561 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6562 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6563 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006564
6565 if (Result.isNull())
6566 return QualType();
6567 }
6568
6569 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006570 NewT.setHasBaseTypeAsWritten(true);
6571 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6572 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6573 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6574 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6575 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6576 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6577 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6578 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6579 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006580}
Mike Stump11289f42009-09-09 15:08:12 +00006581
6582template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006583QualType
6584TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006585 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006586 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6587 if (PointeeType.isNull())
6588 return QualType();
6589
6590 QualType Result = TL.getType();
6591 if (getDerived().AlwaysRebuild() ||
6592 PointeeType != TL.getPointeeLoc().getType()) {
6593 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6594 TL.getStarLoc());
6595 if (Result.isNull())
6596 return QualType();
6597 }
6598
6599 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6600 NewT.setStarLoc(TL.getStarLoc());
6601 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006602}
6603
Douglas Gregord6ff3322009-08-04 16:50:30 +00006604//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006605// Statement transformation
6606//===----------------------------------------------------------------------===//
6607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006608StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006609TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006610 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006611}
6612
6613template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006614StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006615TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6616 return getDerived().TransformCompoundStmt(S, false);
6617}
6618
6619template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006620StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006621TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006622 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006623 Sema::CompoundScopeRAII CompoundScope(getSema());
6624
Aaron Ballmanb1e511b2019-07-09 15:02:07 +00006625 const Stmt *ExprResult = S->getStmtExprResult();
John McCall1ababa62010-08-27 19:56:05 +00006626 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006627 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006628 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006629 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006630 StmtResult Result = getDerived().TransformStmt(
Aaron Ballmanb1e511b2019-07-09 15:02:07 +00006631 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006632
John McCall1ababa62010-08-27 19:56:05 +00006633 if (Result.isInvalid()) {
6634 // Immediately fail if this was a DeclStmt, since it's very
6635 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006636 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006637 return StmtError();
6638
6639 // Otherwise, just keep processing substatements and fail later.
6640 SubStmtInvalid = true;
6641 continue;
6642 }
Mike Stump11289f42009-09-09 15:08:12 +00006643
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006644 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006645 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006646 }
Mike Stump11289f42009-09-09 15:08:12 +00006647
John McCall1ababa62010-08-27 19:56:05 +00006648 if (SubStmtInvalid)
6649 return StmtError();
6650
Douglas Gregorebe10102009-08-20 07:17:43 +00006651 if (!getDerived().AlwaysRebuild() &&
6652 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006653 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006654
6655 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006656 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006657 S->getRBracLoc(),
6658 IsStmtExpr);
6659}
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregorebe10102009-08-20 07:17:43 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006663TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006664 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006665 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006666 EnterExpressionEvaluationContext Unevaluated(
6667 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006668
Eli Friedman06577382009-11-19 03:14:00 +00006669 // Transform the left-hand case value.
6670 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006671 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006672 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006673 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006674
Eli Friedman06577382009-11-19 03:14:00 +00006675 // Transform the right-hand case value (for the GNU case-range extension).
6676 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006677 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006678 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006679 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006680 }
Mike Stump11289f42009-09-09 15:08:12 +00006681
Douglas Gregorebe10102009-08-20 07:17:43 +00006682 // Build the case statement.
6683 // Case statements are always rebuilt so that they will attached to their
6684 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006685 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006686 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006687 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006688 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006689 S->getColonLoc());
6690 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006691 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006692
Douglas Gregorebe10102009-08-20 07:17:43 +00006693 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006694 StmtResult SubStmt =
6695 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006696 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006698
Douglas Gregorebe10102009-08-20 07:17:43 +00006699 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006700 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006701}
6702
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006703template <typename Derived>
6704StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006705 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006706 StmtResult SubStmt =
6707 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006708 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006709 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregorebe10102009-08-20 07:17:43 +00006711 // Default statements are always rebuilt
6712 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006713 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006714}
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregorebe10102009-08-20 07:17:43 +00006716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006717StmtResult
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006718TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6719 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006720 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006721 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006722
Chris Lattnercab02a62011-02-17 20:34:02 +00006723 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6724 S->getDecl());
6725 if (!LD)
6726 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006727
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006728 // If we're transforming "in-place" (we're not creating new local
6729 // declarations), assume we're replacing the old label statement
6730 // and clear out the reference to it.
6731 if (LD == S->getDecl())
6732 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006733
Douglas Gregorebe10102009-08-20 07:17:43 +00006734 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006735 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006736 cast<LabelDecl>(LD), SourceLocation(),
6737 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006738}
Mike Stump11289f42009-09-09 15:08:12 +00006739
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006740template <typename Derived>
6741const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6742 if (!R)
6743 return R;
6744
6745 switch (R->getKind()) {
6746// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6747#define ATTR(X)
6748#define PRAGMA_SPELLING_ATTR(X) \
6749 case attr::X: \
6750 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6751#include "clang/Basic/AttrList.inc"
6752 default:
6753 return R;
6754 }
6755}
6756
6757template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006758StmtResult
6759TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6760 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006761 bool AttrsChanged = false;
6762 SmallVector<const Attr *, 1> Attrs;
6763
6764 // Visit attributes and keep track if any are transformed.
6765 for (const auto *I : S->getAttrs()) {
6766 const Attr *R = getDerived().TransformAttr(I);
6767 AttrsChanged |= (I != R);
6768 Attrs.push_back(R);
6769 }
6770
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006771 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006772 if (SubStmt.isInvalid())
6773 return StmtError();
6774
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006775 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006776 return S;
6777
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006778 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006779 SubStmt.get());
6780}
6781
6782template<typename Derived>
6783StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006784TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006785 // Transform the initialization statement
6786 StmtResult Init = getDerived().TransformStmt(S->getInit());
6787 if (Init.isInvalid())
6788 return StmtError();
6789
Douglas Gregorebe10102009-08-20 07:17:43 +00006790 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006791 Sema::ConditionResult Cond = getDerived().TransformCondition(
6792 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006793 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6794 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006795 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006796 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006797
Richard Smithb130fe72016-06-23 19:16:49 +00006798 // If this is a constexpr if, determine which arm we should instantiate.
6799 llvm::Optional<bool> ConstexprConditionValue;
6800 if (S->isConstexpr())
6801 ConstexprConditionValue = Cond.getKnownValue();
6802
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006804 StmtResult Then;
6805 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6806 Then = getDerived().TransformStmt(S->getThen());
6807 if (Then.isInvalid())
6808 return StmtError();
6809 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006810 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006811 }
Mike Stump11289f42009-09-09 15:08:12 +00006812
Douglas Gregorebe10102009-08-20 07:17:43 +00006813 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006814 StmtResult Else;
6815 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6816 Else = getDerived().TransformStmt(S->getElse());
6817 if (Else.isInvalid())
6818 return StmtError();
6819 }
Mike Stump11289f42009-09-09 15:08:12 +00006820
Douglas Gregorebe10102009-08-20 07:17:43 +00006821 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006822 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006823 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006824 Then.get() == S->getThen() &&
6825 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006826 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006827
Richard Smithb130fe72016-06-23 19:16:49 +00006828 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006829 Init.get(), Then.get(), S->getElseLoc(),
6830 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006831}
6832
6833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006835TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006836 // Transform the initialization statement
6837 StmtResult Init = getDerived().TransformStmt(S->getInit());
6838 if (Init.isInvalid())
6839 return StmtError();
6840
Douglas Gregorebe10102009-08-20 07:17:43 +00006841 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006842 Sema::ConditionResult Cond = getDerived().TransformCondition(
6843 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6844 Sema::ConditionKind::Switch);
6845 if (Cond.isInvalid())
6846 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregorebe10102009-08-20 07:17:43 +00006848 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006849 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006850 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006851 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006852 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006855 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006856 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006857 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006858
Douglas Gregorebe10102009-08-20 07:17:43 +00006859 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006860 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6861 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006862}
Mike Stump11289f42009-09-09 15:08:12 +00006863
Douglas Gregorebe10102009-08-20 07:17:43 +00006864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006865StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006866TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006867 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006868 Sema::ConditionResult Cond = getDerived().TransformCondition(
6869 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6870 Sema::ConditionKind::Boolean);
6871 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006872 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006873
Douglas Gregorebe10102009-08-20 07:17:43 +00006874 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006875 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006876 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006877 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006878
Douglas Gregorebe10102009-08-20 07:17:43 +00006879 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006880 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006881 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006882 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006883
Richard Smith03a4aa32016-06-23 19:02:52 +00006884 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006885}
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregorebe10102009-08-20 07:17:43 +00006887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006888StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006889TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006890 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006891 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006892 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006893 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006894
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006895 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006896 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006897 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006898 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006899
Douglas Gregorebe10102009-08-20 07:17:43 +00006900 if (!getDerived().AlwaysRebuild() &&
6901 Cond.get() == S->getCond() &&
6902 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006903 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006904
John McCallb268a282010-08-23 23:25:46 +00006905 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6906 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006907 S->getRParenLoc());
6908}
Mike Stump11289f42009-09-09 15:08:12 +00006909
Douglas Gregorebe10102009-08-20 07:17:43 +00006910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006911StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006912TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006913 if (getSema().getLangOpts().OpenMP)
6914 getSema().startOpenMPLoop();
6915
Douglas Gregorebe10102009-08-20 07:17:43 +00006916 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006917 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006918 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006919 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006920
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006921 // In OpenMP loop region loop control variable must be captured and be
6922 // private. Perform analysis of first part (if any).
6923 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6924 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6925
Douglas Gregorebe10102009-08-20 07:17:43 +00006926 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006927 Sema::ConditionResult Cond = getDerived().TransformCondition(
6928 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6929 Sema::ConditionKind::Boolean);
6930 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006932
Douglas Gregorebe10102009-08-20 07:17:43 +00006933 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006934 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006935 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006936 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006937
Richard Smith945f8d32013-01-14 22:39:08 +00006938 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006939 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006940 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006941
Douglas Gregorebe10102009-08-20 07:17:43 +00006942 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006943 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006944 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006945 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006946
Douglas Gregorebe10102009-08-20 07:17:43 +00006947 if (!getDerived().AlwaysRebuild() &&
6948 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006949 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006950 Inc.get() == S->getInc() &&
6951 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006952 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006953
Douglas Gregorebe10102009-08-20 07:17:43 +00006954 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006955 Init.get(), Cond, FullInc,
6956 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006957}
6958
6959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006960StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006961TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006962 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6963 S->getLabel());
6964 if (!LD)
6965 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006966
Douglas Gregorebe10102009-08-20 07:17:43 +00006967 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006968 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006969 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006970}
6971
6972template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006973StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006974TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006975 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006976 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006977 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006978 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006979
Douglas Gregorebe10102009-08-20 07:17:43 +00006980 if (!getDerived().AlwaysRebuild() &&
6981 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006982 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006983
6984 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006985 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006986}
6987
6988template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006989StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006990TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006991 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006992}
Mike Stump11289f42009-09-09 15:08:12 +00006993
Douglas Gregorebe10102009-08-20 07:17:43 +00006994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006995StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006996TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006997 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006998}
Mike Stump11289f42009-09-09 15:08:12 +00006999
Douglas Gregorebe10102009-08-20 07:17:43 +00007000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007001StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007002TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00007003 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
7004 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00007005 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007006 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007007
Mike Stump11289f42009-09-09 15:08:12 +00007008 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00007009 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00007010 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007011}
Mike Stump11289f42009-09-09 15:08:12 +00007012
Douglas Gregorebe10102009-08-20 07:17:43 +00007013template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007014StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007015TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007016 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007017 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007018 for (auto *D : S->decls()) {
7019 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00007020 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00007021 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007022
Aaron Ballman535bbcc2014-03-14 17:01:24 +00007023 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00007024 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00007025
Douglas Gregorebe10102009-08-20 07:17:43 +00007026 Decls.push_back(Transformed);
7027 }
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregorebe10102009-08-20 07:17:43 +00007029 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007030 return S;
Mike Stump11289f42009-09-09 15:08:12 +00007031
Stephen Kellya6e43582018-08-09 21:05:56 +00007032 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007033}
Mike Stump11289f42009-09-09 15:08:12 +00007034
Douglas Gregorebe10102009-08-20 07:17:43 +00007035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007036StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00007037TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007038
Benjamin Kramerf0623432012-08-23 22:51:59 +00007039 SmallVector<Expr*, 8> Constraints;
7040 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007041 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00007042
John McCalldadc5752010-08-24 06:29:42 +00007043 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007044 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007045
7046 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00007047
Anders Carlssonaaeef072010-01-24 05:50:09 +00007048 // Go through the outputs.
7049 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007050 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007051
Anders Carlssonaaeef072010-01-24 05:50:09 +00007052 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007053 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007054
Anders Carlssonaaeef072010-01-24 05:50:09 +00007055 // Transform the output expr.
7056 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007057 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007058 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007059 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007060
Anders Carlssonaaeef072010-01-24 05:50:09 +00007061 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007062
John McCallb268a282010-08-23 23:25:46 +00007063 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007064 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007065
Anders Carlssonaaeef072010-01-24 05:50:09 +00007066 // Go through the inputs.
7067 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00007068 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007069
Anders Carlssonaaeef072010-01-24 05:50:09 +00007070 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00007071 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00007072
Anders Carlssonaaeef072010-01-24 05:50:09 +00007073 // Transform the input expr.
7074 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00007075 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00007076 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007077 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007078
Anders Carlssonaaeef072010-01-24 05:50:09 +00007079 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00007080
John McCallb268a282010-08-23 23:25:46 +00007081 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00007082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007083
Jennifer Yub8fee672019-06-03 15:57:25 +00007084 // Go through the Labels.
7085 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
7086 Names.push_back(S->getLabelIdentifier(I));
7087
7088 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
7089 if (Result.isInvalid())
7090 return StmtError();
7091 ExprsChanged |= Result.get() != S->getLabelExpr(I);
7092 Exprs.push_back(Result.get());
7093 }
Anders Carlssonaaeef072010-01-24 05:50:09 +00007094 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007095 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00007096
7097 // Go through the clobbers.
7098 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00007099 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007100
7101 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007102 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007103 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7104 S->isVolatile(), S->getNumOutputs(),
7105 S->getNumInputs(), Names.data(),
7106 Constraints, Exprs, AsmString.get(),
Jennifer Yub8fee672019-06-03 15:57:25 +00007107 Clobbers, S->getNumLabels(),
7108 S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007109}
7110
Chad Rosier32503022012-06-11 20:47:18 +00007111template<typename Derived>
7112StmtResult
7113TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007114 ArrayRef<Token> AsmToks =
7115 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007116
John McCallf413f5e2013-05-03 00:10:13 +00007117 bool HadError = false, HadChange = false;
7118
7119 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7120 SmallVector<Expr*, 8> TransformedExprs;
7121 TransformedExprs.reserve(SrcExprs.size());
7122 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7123 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7124 if (!Result.isUsable()) {
7125 HadError = true;
7126 } else {
7127 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007128 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007129 }
7130 }
7131
7132 if (HadError) return StmtError();
7133 if (!HadChange && !getDerived().AlwaysRebuild())
7134 return Owned(S);
7135
Chad Rosierb6f46c12012-08-15 16:53:30 +00007136 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007137 AsmToks, S->getAsmString(),
7138 S->getNumOutputs(), S->getNumInputs(),
7139 S->getAllConstraints(), S->getClobbers(),
7140 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007141}
Douglas Gregorebe10102009-08-20 07:17:43 +00007142
Richard Smith9f690bd2015-10-27 06:02:45 +00007143// C++ Coroutines TS
7144
7145template<typename Derived>
7146StmtResult
7147TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007148 auto *ScopeInfo = SemaRef.getCurFunction();
7149 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007150 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007151 ScopeInfo->NeedsCoroutineSuspends &&
7152 ScopeInfo->CoroutineSuspends.first == nullptr &&
7153 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007154 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007155
7156 // Set that we have (possibly-invalid) suspend points before we do anything
7157 // that may fail.
7158 ScopeInfo->setNeedsCoroutineSuspends(false);
7159
7160 // The new CoroutinePromise object needs to be built and put into the current
7161 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007162 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7163 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007164 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7165 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007166 return StmtError();
Richard Smithb2997f52019-05-21 20:10:50 +00007167 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
Eric Fiselierbee782b2017-04-03 19:21:00 +00007168 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007169
7170 // Transform the implicit coroutine statements we built during the initial
7171 // parse.
7172 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7173 if (InitSuspend.isInvalid())
7174 return StmtError();
7175 StmtResult FinalSuspend =
7176 getDerived().TransformStmt(S->getFinalSuspendStmt());
7177 if (FinalSuspend.isInvalid())
7178 return StmtError();
7179 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7180 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007181
7182 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7183 if (BodyRes.isInvalid())
7184 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007185
Eric Fiselierbee782b2017-04-03 19:21:00 +00007186 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7187 if (Builder.isInvalid())
7188 return StmtError();
7189
7190 Expr *ReturnObject = S->getReturnValueInit();
7191 assert(ReturnObject && "the return object is expected to be valid");
7192 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7193 /*NoCopyInit*/ false);
7194 if (Res.isInvalid())
7195 return StmtError();
7196 Builder.ReturnValue = Res.get();
7197
7198 if (S->hasDependentPromiseType()) {
Brian Gesiak38f11822019-06-03 00:47:32 +00007199 // PR41909: We may find a generic coroutine lambda definition within a
7200 // template function that is being instantiated. In this case, the lambda
7201 // will have a dependent promise type, until it is used in an expression
7202 // that creates an instantiation with a non-dependent promise type. We
7203 // should not assert or build coroutine dependent statements for such a
7204 // generic lambda.
7205 auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD);
7206 if (!MD || !MD->getParent()->isGenericLambda()) {
7207 assert(!Promise->getType()->isDependentType() &&
7208 "the promise type must no longer be dependent");
7209 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7210 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7211 "these nodes should not have been built yet");
7212 if (!Builder.buildDependentStatements())
7213 return StmtError();
7214 }
Eric Fiselierbee782b2017-04-03 19:21:00 +00007215 } else {
7216 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7217 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7218 if (Res.isInvalid())
7219 return StmtError();
7220 Builder.OnFallthrough = Res.get();
7221 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007222
Eric Fiselierbee782b2017-04-03 19:21:00 +00007223 if (auto *OnException = S->getExceptionHandler()) {
7224 StmtResult Res = getDerived().TransformStmt(OnException);
7225 if (Res.isInvalid())
7226 return StmtError();
7227 Builder.OnException = Res.get();
7228 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007229
Eric Fiselierbee782b2017-04-03 19:21:00 +00007230 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7231 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7232 if (Res.isInvalid())
7233 return StmtError();
7234 Builder.ReturnStmtOnAllocFailure = Res.get();
7235 }
7236
7237 // Transform any additional statements we may have already built
7238 assert(S->getAllocate() && S->getDeallocate() &&
7239 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007240 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7241 if (AllocRes.isInvalid())
7242 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007243 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007244
7245 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7246 if (DeallocRes.isInvalid())
7247 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007248 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007249
7250 assert(S->getResultDecl() && "ResultDecl must already be built");
7251 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7252 if (ResultDecl.isInvalid())
7253 return StmtError();
7254 Builder.ResultDecl = ResultDecl.get();
7255
7256 if (auto *ReturnStmt = S->getReturnStmt()) {
7257 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7258 if (Res.isInvalid())
7259 return StmtError();
7260 Builder.ReturnStmt = Res.get();
7261 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007262 }
7263
Eric Fiselierbee782b2017-04-03 19:21:00 +00007264 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007265}
7266
7267template<typename Derived>
7268StmtResult
7269TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7270 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7271 /*NotCopyInit*/false);
7272 if (Result.isInvalid())
7273 return StmtError();
7274
7275 // Always rebuild; we don't know if this needs to be injected into a new
7276 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007277 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7278 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007279}
7280
7281template<typename Derived>
7282ExprResult
7283TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7284 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7285 /*NotCopyInit*/false);
7286 if (Result.isInvalid())
7287 return ExprError();
7288
7289 // Always rebuild; we don't know if this needs to be injected into a new
7290 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007291 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7292 E->isImplicit());
7293}
7294
7295template <typename Derived>
7296ExprResult
7297TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7298 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7299 /*NotCopyInit*/ false);
7300 if (OperandResult.isInvalid())
7301 return ExprError();
7302
7303 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7304 E->getOperatorCoawaitLookup());
7305
7306 if (LookupResult.isInvalid())
7307 return ExprError();
7308
7309 // Always rebuild; we don't know if this needs to be injected into a new
7310 // context or if the promise type has changed.
7311 return getDerived().RebuildDependentCoawaitExpr(
7312 E->getKeywordLoc(), OperandResult.get(),
7313 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007314}
7315
7316template<typename Derived>
7317ExprResult
7318TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7319 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7320 /*NotCopyInit*/false);
7321 if (Result.isInvalid())
7322 return ExprError();
7323
7324 // Always rebuild; we don't know if this needs to be injected into a new
7325 // context or if the promise type has changed.
7326 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7327}
7328
7329// Objective-C Statements.
7330
Douglas Gregorebe10102009-08-20 07:17:43 +00007331template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007332StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007333TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007334 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007335 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007336 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007337 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007338
Douglas Gregor96c79492010-04-23 22:50:49 +00007339 // Transform the @catch statements (if present).
7340 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007341 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007342 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007343 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007344 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007345 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007346 if (Catch.get() != S->getCatchStmt(I))
7347 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007348 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007349 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007350
Douglas Gregor306de2f2010-04-22 23:59:56 +00007351 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007352 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007353 if (S->getFinallyStmt()) {
7354 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7355 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007356 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007357 }
7358
7359 // If nothing changed, just retain this statement.
7360 if (!getDerived().AlwaysRebuild() &&
7361 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007362 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007363 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007364 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007365
Douglas Gregor306de2f2010-04-22 23:59:56 +00007366 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007367 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007368 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007369}
Mike Stump11289f42009-09-09 15:08:12 +00007370
Douglas Gregorebe10102009-08-20 07:17:43 +00007371template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007372StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007373TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007374 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007375 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007376 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007377 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007378 if (FromVar->getTypeSourceInfo()) {
7379 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7380 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007381 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007382 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007383
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007384 QualType T;
7385 if (TSInfo)
7386 T = TSInfo->getType();
7387 else {
7388 T = getDerived().TransformType(FromVar->getType());
7389 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007390 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007392
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007393 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7394 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007395 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007397
John McCalldadc5752010-08-24 06:29:42 +00007398 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007399 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007400 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007401
7402 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007403 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007404 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007405}
Mike Stump11289f42009-09-09 15:08:12 +00007406
Douglas Gregorebe10102009-08-20 07:17:43 +00007407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007408StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007409TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007410 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007411 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007412 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007413 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007414
Douglas Gregor306de2f2010-04-22 23:59:56 +00007415 // If nothing changed, just retain this statement.
7416 if (!getDerived().AlwaysRebuild() &&
7417 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007418 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007419
7420 // Build a new statement.
7421 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007422 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007423}
Mike Stump11289f42009-09-09 15:08:12 +00007424
Douglas Gregorebe10102009-08-20 07:17:43 +00007425template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007426StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007427TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007428 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007429 if (S->getThrowExpr()) {
7430 Operand = getDerived().TransformExpr(S->getThrowExpr());
7431 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007432 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007433 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007434
Douglas Gregor2900c162010-04-22 21:44:01 +00007435 if (!getDerived().AlwaysRebuild() &&
7436 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007437 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007438
John McCallb268a282010-08-23 23:25:46 +00007439 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007440}
Mike Stump11289f42009-09-09 15:08:12 +00007441
Douglas Gregorebe10102009-08-20 07:17:43 +00007442template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007443StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007444TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007445 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007446 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007447 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007448 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007449 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007450 Object =
7451 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7452 Object.get());
7453 if (Object.isInvalid())
7454 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007455
Douglas Gregor6148de72010-04-22 22:01:21 +00007456 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007457 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007458 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007459 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007460
Douglas Gregor6148de72010-04-22 22:01:21 +00007461 // If nothing change, just retain the current statement.
7462 if (!getDerived().AlwaysRebuild() &&
7463 Object.get() == S->getSynchExpr() &&
7464 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007465 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007466
7467 // Build a new statement.
7468 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007469 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007470}
7471
7472template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007473StmtResult
John McCall31168b02011-06-15 23:02:42 +00007474TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7475 ObjCAutoreleasePoolStmt *S) {
7476 // Transform the body.
7477 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7478 if (Body.isInvalid())
7479 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007480
John McCall31168b02011-06-15 23:02:42 +00007481 // If nothing changed, just retain this statement.
7482 if (!getDerived().AlwaysRebuild() &&
7483 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007484 return S;
John McCall31168b02011-06-15 23:02:42 +00007485
7486 // Build a new statement.
7487 return getDerived().RebuildObjCAutoreleasePoolStmt(
7488 S->getAtLoc(), Body.get());
7489}
7490
7491template<typename Derived>
7492StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007493TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007494 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007495 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007496 StmtResult Element =
7497 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007498 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007499 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007500
Douglas Gregorf68a5082010-04-22 23:10:45 +00007501 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007502 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007503 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007504 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007505
Douglas Gregorf68a5082010-04-22 23:10:45 +00007506 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007507 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007508 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007509 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007510
Douglas Gregorf68a5082010-04-22 23:10:45 +00007511 // If nothing changed, just retain this statement.
7512 if (!getDerived().AlwaysRebuild() &&
7513 Element.get() == S->getElement() &&
7514 Collection.get() == S->getCollection() &&
7515 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007516 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007517
Douglas Gregorf68a5082010-04-22 23:10:45 +00007518 // Build a new statement.
7519 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007520 Element.get(),
7521 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007522 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007523 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007524}
7525
David Majnemer5f7efef2013-10-15 09:50:08 +00007526template <typename Derived>
7527StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007528 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007529 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007530 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7531 TypeSourceInfo *T =
7532 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007533 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007534 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007535
David Majnemer5f7efef2013-10-15 09:50:08 +00007536 Var = getDerived().RebuildExceptionDecl(
7537 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7538 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007539 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007540 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007541 }
Mike Stump11289f42009-09-09 15:08:12 +00007542
Douglas Gregorebe10102009-08-20 07:17:43 +00007543 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007544 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007545 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007546 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007547
David Majnemer5f7efef2013-10-15 09:50:08 +00007548 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007549 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007550 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007551
David Majnemer5f7efef2013-10-15 09:50:08 +00007552 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007553}
Mike Stump11289f42009-09-09 15:08:12 +00007554
David Majnemer5f7efef2013-10-15 09:50:08 +00007555template <typename Derived>
7556StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007557 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007558 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007559 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007560 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007561
Douglas Gregorebe10102009-08-20 07:17:43 +00007562 // Transform the handlers.
7563 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007564 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007565 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007566 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007567 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007569
Douglas Gregorebe10102009-08-20 07:17:43 +00007570 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007571 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007572 }
Mike Stump11289f42009-09-09 15:08:12 +00007573
David Majnemer5f7efef2013-10-15 09:50:08 +00007574 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007575 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007576 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007577
John McCallb268a282010-08-23 23:25:46 +00007578 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007579 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007580}
Mike Stump11289f42009-09-09 15:08:12 +00007581
Richard Smith02e85f32011-04-14 22:09:26 +00007582template<typename Derived>
7583StmtResult
7584TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007585 StmtResult Init =
7586 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7587 if (Init.isInvalid())
7588 return StmtError();
7589
Richard Smith02e85f32011-04-14 22:09:26 +00007590 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7591 if (Range.isInvalid())
7592 return StmtError();
7593
Richard Smith01694c32016-03-20 10:33:40 +00007594 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7595 if (Begin.isInvalid())
7596 return StmtError();
7597 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7598 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007599 return StmtError();
7600
7601 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7602 if (Cond.isInvalid())
7603 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007604 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007605 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007606 if (Cond.isInvalid())
7607 return StmtError();
7608 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007609 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007610
7611 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7612 if (Inc.isInvalid())
7613 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007614 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007615 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007616
7617 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7618 if (LoopVar.isInvalid())
7619 return StmtError();
7620
7621 StmtResult NewStmt = S;
7622 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007623 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007624 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007625 Begin.get() != S->getBeginStmt() ||
7626 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007627 Cond.get() != S->getCond() ||
7628 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007629 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007630 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007631 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007632 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007633 Begin.get(), End.get(),
7634 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007635 Inc.get(), LoopVar.get(),
7636 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007637 if (NewStmt.isInvalid())
7638 return StmtError();
7639 }
Richard Smith02e85f32011-04-14 22:09:26 +00007640
7641 StmtResult Body = getDerived().TransformStmt(S->getBody());
7642 if (Body.isInvalid())
7643 return StmtError();
7644
7645 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7646 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007647 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007648 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007649 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007650 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007651 Begin.get(), End.get(),
7652 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007653 Inc.get(), LoopVar.get(),
7654 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007655 if (NewStmt.isInvalid())
7656 return StmtError();
7657 }
Richard Smith02e85f32011-04-14 22:09:26 +00007658
7659 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007660 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007661
7662 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7663}
7664
John Wiegley1c0675e2011-04-28 01:08:34 +00007665template<typename Derived>
7666StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007667TreeTransform<Derived>::TransformMSDependentExistsStmt(
7668 MSDependentExistsStmt *S) {
7669 // Transform the nested-name-specifier, if any.
7670 NestedNameSpecifierLoc QualifierLoc;
7671 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007672 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007673 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7674 if (!QualifierLoc)
7675 return StmtError();
7676 }
7677
7678 // Transform the declaration name.
7679 DeclarationNameInfo NameInfo = S->getNameInfo();
7680 if (NameInfo.getName()) {
7681 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7682 if (!NameInfo.getName())
7683 return StmtError();
7684 }
7685
7686 // Check whether anything changed.
7687 if (!getDerived().AlwaysRebuild() &&
7688 QualifierLoc == S->getQualifierLoc() &&
7689 NameInfo.getName() == S->getNameInfo().getName())
7690 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007691
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007692 // Determine whether this name exists, if we can.
7693 CXXScopeSpec SS;
7694 SS.Adopt(QualifierLoc);
7695 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007696 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007697 case Sema::IER_Exists:
7698 if (S->isIfExists())
7699 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007700
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007701 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7702
7703 case Sema::IER_DoesNotExist:
7704 if (S->isIfNotExists())
7705 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007706
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007707 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007708
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007709 case Sema::IER_Dependent:
7710 Dependent = true;
7711 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007712
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007713 case Sema::IER_Error:
7714 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007715 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007716
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007717 // We need to continue with the instantiation, so do so now.
7718 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7719 if (SubStmt.isInvalid())
7720 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007721
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007722 // If we have resolved the name, just transform to the substatement.
7723 if (!Dependent)
7724 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007725
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007726 // The name is still dependent, so build a dependent expression again.
7727 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7728 S->isIfExists(),
7729 QualifierLoc,
7730 NameInfo,
7731 SubStmt.get());
7732}
7733
7734template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007735ExprResult
7736TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7737 NestedNameSpecifierLoc QualifierLoc;
7738 if (E->getQualifierLoc()) {
7739 QualifierLoc
7740 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7741 if (!QualifierLoc)
7742 return ExprError();
7743 }
7744
7745 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7746 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7747 if (!PD)
7748 return ExprError();
7749
7750 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7751 if (Base.isInvalid())
7752 return ExprError();
7753
7754 return new (SemaRef.getASTContext())
7755 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7756 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7757 QualifierLoc, E->getMemberLoc());
7758}
7759
David Majnemerfad8f482013-10-15 09:33:02 +00007760template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007761ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7762 MSPropertySubscriptExpr *E) {
7763 auto BaseRes = getDerived().TransformExpr(E->getBase());
7764 if (BaseRes.isInvalid())
7765 return ExprError();
7766 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7767 if (IdxRes.isInvalid())
7768 return ExprError();
7769
7770 if (!getDerived().AlwaysRebuild() &&
7771 BaseRes.get() == E->getBase() &&
7772 IdxRes.get() == E->getIdx())
7773 return E;
7774
7775 return getDerived().RebuildArraySubscriptExpr(
7776 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7777}
7778
7779template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007780StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007781 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007782 if (TryBlock.isInvalid())
7783 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007784
7785 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007786 if (Handler.isInvalid())
7787 return StmtError();
7788
David Majnemerfad8f482013-10-15 09:33:02 +00007789 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7790 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007791 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007792
Warren Huntf6be4cb2014-07-25 20:52:51 +00007793 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7794 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007795}
7796
David Majnemerfad8f482013-10-15 09:33:02 +00007797template <typename Derived>
7798StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007799 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007800 if (Block.isInvalid())
7801 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007802
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007803 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007804}
7805
David Majnemerfad8f482013-10-15 09:33:02 +00007806template <typename Derived>
7807StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007808 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007809 if (FilterExpr.isInvalid())
7810 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007811
David Majnemer7e755502013-10-15 09:30:14 +00007812 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007813 if (Block.isInvalid())
7814 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007815
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007816 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7817 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007818}
7819
David Majnemerfad8f482013-10-15 09:33:02 +00007820template <typename Derived>
7821StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7822 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007823 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7824 else
7825 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7826}
7827
Nico Weber9b982072014-07-07 00:12:30 +00007828template<typename Derived>
7829StmtResult
7830TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7831 return S;
7832}
7833
Alexander Musman64d33f12014-06-04 07:53:32 +00007834//===----------------------------------------------------------------------===//
7835// OpenMP directive transformation
7836//===----------------------------------------------------------------------===//
7837template <typename Derived>
7838StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7839 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007840
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007841 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007842 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007843 ArrayRef<OMPClause *> Clauses = D->clauses();
7844 TClauses.reserve(Clauses.size());
7845 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7846 I != E; ++I) {
7847 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007848 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007849 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007850 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007851 if (Clause)
7852 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007853 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007854 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007855 }
7856 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007857 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007858 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007859 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7860 /*CurScope=*/nullptr);
7861 StmtResult Body;
7862 {
7863 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007864 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007865 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007866 }
7867 AssociatedStmt =
7868 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007869 if (AssociatedStmt.isInvalid()) {
7870 return StmtError();
7871 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007872 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007873 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007874 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007875 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007876
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007877 // Transform directive name for 'omp critical' directive.
7878 DeclarationNameInfo DirName;
7879 if (D->getDirectiveKind() == OMPD_critical) {
7880 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7881 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7882 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007883 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7884 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7885 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007886 } else if (D->getDirectiveKind() == OMPD_cancel) {
7887 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007888 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007889
Alexander Musman64d33f12014-06-04 07:53:32 +00007890 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007891 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007892 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007893}
7894
Alexander Musman64d33f12014-06-04 07:53:32 +00007895template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007896StmtResult
7897TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7898 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007899 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007900 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007901 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7902 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7903 return Res;
7904}
7905
Alexander Musman64d33f12014-06-04 07:53:32 +00007906template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007907StmtResult
7908TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7909 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007910 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007911 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007912 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7913 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007914 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007915}
7916
Alexey Bataevf29276e2014-06-18 04:14:57 +00007917template <typename Derived>
7918StmtResult
7919TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7920 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007921 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007922 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007923 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7924 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7925 return Res;
7926}
7927
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007928template <typename Derived>
7929StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007930TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7931 DeclarationNameInfo DirName;
7932 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007933 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007934 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7935 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7936 return Res;
7937}
7938
7939template <typename Derived>
7940StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007941TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7942 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007943 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007944 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007945 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7946 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7947 return Res;
7948}
7949
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007950template <typename Derived>
7951StmtResult
7952TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7953 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007954 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007955 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007956 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7957 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7958 return Res;
7959}
7960
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007961template <typename Derived>
7962StmtResult
7963TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7964 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007965 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007966 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007967 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7968 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7969 return Res;
7970}
7971
Alexey Bataev4acb8592014-07-07 13:01:15 +00007972template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007973StmtResult
7974TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7975 DeclarationNameInfo DirName;
7976 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007977 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7980 return Res;
7981}
7982
7983template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007984StmtResult
7985TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7986 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007987 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990 return Res;
7991}
7992
7993template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007994StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7995 OMPParallelForDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007998 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001 return Res;
8002}
8003
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008004template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00008005StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
8006 OMPParallelForSimdDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008009 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00008010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8012 return Res;
8013}
8014
8015template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008016StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
8017 OMPParallelSectionsDirective *D) {
8018 DeclarationNameInfo DirName;
8019 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008020 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00008021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8023 return Res;
8024}
8025
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008026template <typename Derived>
8027StmtResult
8028TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
8029 DeclarationNameInfo DirName;
8030 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008031 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00008032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8034 return Res;
8035}
8036
Alexey Bataev68446b72014-07-18 07:47:19 +00008037template <typename Derived>
8038StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
8039 OMPTaskyieldDirective *D) {
8040 DeclarationNameInfo DirName;
8041 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008042 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00008043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8045 return Res;
8046}
8047
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008048template <typename Derived>
8049StmtResult
8050TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
8051 DeclarationNameInfo DirName;
8052 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008053 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00008054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8056 return Res;
8057}
8058
Alexey Bataev2df347a2014-07-18 10:17:07 +00008059template <typename Derived>
8060StmtResult
8061TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
8062 DeclarationNameInfo DirName;
8063 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008064 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00008065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8067 return Res;
8068}
8069
Alexey Bataev6125da92014-07-21 11:26:11 +00008070template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008071StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
8072 OMPTaskgroupDirective *D) {
8073 DeclarationNameInfo DirName;
8074 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008075 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00008076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8078 return Res;
8079}
8080
8081template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00008082StmtResult
8083TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
8084 DeclarationNameInfo DirName;
8085 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008086 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8089 return Res;
8090}
8091
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008092template <typename Derived>
8093StmtResult
8094TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
8095 DeclarationNameInfo DirName;
8096 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008097 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00008098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8100 return Res;
8101}
8102
Alexey Bataev0162e452014-07-22 10:10:35 +00008103template <typename Derived>
8104StmtResult
8105TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
8106 DeclarationNameInfo DirName;
8107 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008108 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00008109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8111 return Res;
8112}
8113
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008114template <typename Derived>
8115StmtResult
8116TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8117 DeclarationNameInfo DirName;
8118 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008119 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8122 return Res;
8123}
8124
Alexey Bataev13314bf2014-10-09 04:18:56 +00008125template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008126StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8127 OMPTargetDataDirective *D) {
8128 DeclarationNameInfo DirName;
8129 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008130 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8133 return Res;
8134}
8135
8136template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008137StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8138 OMPTargetEnterDataDirective *D) {
8139 DeclarationNameInfo DirName;
8140 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008141 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8144 return Res;
8145}
8146
8147template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008148StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8149 OMPTargetExitDataDirective *D) {
8150 DeclarationNameInfo DirName;
8151 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008152 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8155 return Res;
8156}
8157
8158template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008159StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8160 OMPTargetParallelDirective *D) {
8161 DeclarationNameInfo DirName;
8162 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008163 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008164 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8165 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8166 return Res;
8167}
8168
8169template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008170StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8171 OMPTargetParallelForDirective *D) {
8172 DeclarationNameInfo DirName;
8173 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008174 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8177 return Res;
8178}
8179
8180template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008181StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8182 OMPTargetUpdateDirective *D) {
8183 DeclarationNameInfo DirName;
8184 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008185 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8188 return Res;
8189}
8190
8191template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008192StmtResult
8193TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8194 DeclarationNameInfo DirName;
8195 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008196 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8199 return Res;
8200}
8201
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008202template <typename Derived>
8203StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8204 OMPCancellationPointDirective *D) {
8205 DeclarationNameInfo DirName;
8206 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008207 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8210 return Res;
8211}
8212
Alexey Bataev80909872015-07-02 11:25:17 +00008213template <typename Derived>
8214StmtResult
8215TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8216 DeclarationNameInfo DirName;
8217 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008218 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8221 return Res;
8222}
8223
Alexey Bataev49f6e782015-12-01 04:18:41 +00008224template <typename Derived>
8225StmtResult
8226TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8227 DeclarationNameInfo DirName;
8228 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008229 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8232 return Res;
8233}
8234
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008235template <typename Derived>
8236StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8237 OMPTaskLoopSimdDirective *D) {
8238 DeclarationNameInfo DirName;
8239 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008240 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008241 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8243 return Res;
8244}
8245
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008246template <typename Derived>
8247StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8248 OMPDistributeDirective *D) {
8249 DeclarationNameInfo DirName;
8250 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008251 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008252 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8253 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8254 return Res;
8255}
8256
Carlo Bertolli9925f152016-06-27 14:55:37 +00008257template <typename Derived>
8258StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8259 OMPDistributeParallelForDirective *D) {
8260 DeclarationNameInfo DirName;
8261 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008262 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008263 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8264 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8265 return Res;
8266}
8267
Kelvin Li4a39add2016-07-05 05:00:15 +00008268template <typename Derived>
8269StmtResult
8270TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8271 OMPDistributeParallelForSimdDirective *D) {
8272 DeclarationNameInfo DirName;
8273 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008274 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008275 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8276 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8277 return Res;
8278}
8279
Kelvin Li787f3fc2016-07-06 04:45:38 +00008280template <typename Derived>
8281StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8282 OMPDistributeSimdDirective *D) {
8283 DeclarationNameInfo DirName;
8284 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008285 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008286 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8287 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8288 return Res;
8289}
8290
Kelvin Lia579b912016-07-14 02:54:56 +00008291template <typename Derived>
8292StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8293 OMPTargetParallelForSimdDirective *D) {
8294 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008295 getDerived().getSema().StartOpenMPDSABlock(
8296 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008297 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8298 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8299 return Res;
8300}
8301
Kelvin Li986330c2016-07-20 22:57:10 +00008302template <typename Derived>
8303StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8304 OMPTargetSimdDirective *D) {
8305 DeclarationNameInfo DirName;
8306 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008307 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008308 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8309 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8310 return Res;
8311}
8312
Kelvin Li02532872016-08-05 14:37:37 +00008313template <typename Derived>
8314StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8315 OMPTeamsDistributeDirective *D) {
8316 DeclarationNameInfo DirName;
8317 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008318 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008319 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8320 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8321 return Res;
8322}
8323
Kelvin Li4e325f72016-10-25 12:50:55 +00008324template <typename Derived>
8325StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8326 OMPTeamsDistributeSimdDirective *D) {
8327 DeclarationNameInfo DirName;
8328 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008329 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008330 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8331 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8332 return Res;
8333}
8334
Kelvin Li579e41c2016-11-30 23:51:03 +00008335template <typename Derived>
8336StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8337 OMPTeamsDistributeParallelForSimdDirective *D) {
8338 DeclarationNameInfo DirName;
8339 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008340 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8341 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008342 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8343 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8344 return Res;
8345}
8346
Kelvin Li7ade93f2016-12-09 03:24:30 +00008347template <typename Derived>
8348StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8349 OMPTeamsDistributeParallelForDirective *D) {
8350 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008351 getDerived().getSema().StartOpenMPDSABlock(
8352 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008353 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8354 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8355 return Res;
8356}
8357
Kelvin Libf594a52016-12-17 05:48:59 +00008358template <typename Derived>
8359StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8360 OMPTargetTeamsDirective *D) {
8361 DeclarationNameInfo DirName;
8362 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008363 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008364 auto Res = getDerived().TransformOMPExecutableDirective(D);
8365 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8366 return Res;
8367}
Kelvin Li579e41c2016-11-30 23:51:03 +00008368
Kelvin Li83c451e2016-12-25 04:52:54 +00008369template <typename Derived>
8370StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8371 OMPTargetTeamsDistributeDirective *D) {
8372 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008373 getDerived().getSema().StartOpenMPDSABlock(
8374 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008375 auto Res = getDerived().TransformOMPExecutableDirective(D);
8376 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8377 return Res;
8378}
8379
Kelvin Li80e8f562016-12-29 22:16:30 +00008380template <typename Derived>
8381StmtResult
8382TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8383 OMPTargetTeamsDistributeParallelForDirective *D) {
8384 DeclarationNameInfo DirName;
8385 getDerived().getSema().StartOpenMPDSABlock(
8386 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008387 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008388 auto Res = getDerived().TransformOMPExecutableDirective(D);
8389 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8390 return Res;
8391}
8392
Kelvin Li1851df52017-01-03 05:23:48 +00008393template <typename Derived>
8394StmtResult TreeTransform<Derived>::
8395 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8396 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8397 DeclarationNameInfo DirName;
8398 getDerived().getSema().StartOpenMPDSABlock(
8399 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008400 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008401 auto Res = getDerived().TransformOMPExecutableDirective(D);
8402 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8403 return Res;
8404}
8405
Kelvin Lida681182017-01-10 18:08:18 +00008406template <typename Derived>
8407StmtResult
8408TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8409 OMPTargetTeamsDistributeSimdDirective *D) {
8410 DeclarationNameInfo DirName;
8411 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008412 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008413 auto Res = getDerived().TransformOMPExecutableDirective(D);
8414 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8415 return Res;
8416}
8417
Kelvin Li1851df52017-01-03 05:23:48 +00008418
Alexander Musman64d33f12014-06-04 07:53:32 +00008419//===----------------------------------------------------------------------===//
8420// OpenMP clause transformation
8421//===----------------------------------------------------------------------===//
8422template <typename Derived>
8423OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008424 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8425 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008426 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008427 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008428 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008429 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008430}
8431
Alexander Musman64d33f12014-06-04 07:53:32 +00008432template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008433OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8434 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8435 if (Cond.isInvalid())
8436 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008437 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008438 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008439}
8440
8441template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008442OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008443TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8444 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8445 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008446 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008447 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008448 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008449}
8450
Alexey Bataev62c87d22014-03-21 04:51:18 +00008451template <typename Derived>
8452OMPClause *
8453TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8454 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8455 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008456 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008457 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008458 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008459}
8460
Alexander Musman8bd31e62014-05-27 15:12:19 +00008461template <typename Derived>
8462OMPClause *
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00008463TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
8464 ExprResult E = getDerived().TransformExpr(C->getAllocator());
8465 if (E.isInvalid())
8466 return nullptr;
8467 return getDerived().RebuildOMPAllocatorClause(
8468 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
8469}
8470
8471template <typename Derived>
8472OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008473TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8474 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8475 if (E.isInvalid())
8476 return nullptr;
8477 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008478 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008479}
8480
8481template <typename Derived>
8482OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008483TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8484 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8485 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008486 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008487 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008488 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008489}
8490
Alexander Musman64d33f12014-06-04 07:53:32 +00008491template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008492OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008493TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008494 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008495 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008496 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008497}
8498
Alexander Musman64d33f12014-06-04 07:53:32 +00008499template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008500OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008501TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008502 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008503 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008504 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008505}
8506
Alexander Musman64d33f12014-06-04 07:53:32 +00008507template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008508OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008509TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8510 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8511 if (E.isInvalid())
8512 return nullptr;
8513 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008514 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008515 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008516 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008517 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008518}
8519
8520template <typename Derived>
8521OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008522TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008523 ExprResult E;
8524 if (auto *Num = C->getNumForLoops()) {
8525 E = getDerived().TransformExpr(Num);
8526 if (E.isInvalid())
8527 return nullptr;
8528 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008529 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008530 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008531}
8532
8533template <typename Derived>
8534OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008535TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8536 // No need to rebuild this clause, no template-dependent parameters.
8537 return C;
8538}
8539
8540template <typename Derived>
8541OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008542TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8543 // No need to rebuild this clause, no template-dependent parameters.
8544 return C;
8545}
8546
8547template <typename Derived>
8548OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008549TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8550 // No need to rebuild this clause, no template-dependent parameters.
8551 return C;
8552}
8553
8554template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008555OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8556 // No need to rebuild this clause, no template-dependent parameters.
8557 return C;
8558}
8559
8560template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008561OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8562 // No need to rebuild this clause, no template-dependent parameters.
8563 return C;
8564}
8565
8566template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008567OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008568TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8569 // No need to rebuild this clause, no template-dependent parameters.
8570 return C;
8571}
8572
8573template <typename Derived>
8574OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008575TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8576 // No need to rebuild this clause, no template-dependent parameters.
8577 return C;
8578}
8579
8580template <typename Derived>
8581OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008582TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8583 // No need to rebuild this clause, no template-dependent parameters.
8584 return C;
8585}
8586
8587template <typename Derived>
8588OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008589TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8590 // No need to rebuild this clause, no template-dependent parameters.
8591 return C;
8592}
8593
8594template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008595OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8596 // No need to rebuild this clause, no template-dependent parameters.
8597 return C;
8598}
8599
8600template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008601OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008602TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8603 // No need to rebuild this clause, no template-dependent parameters.
8604 return C;
8605}
8606
8607template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008608OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8609 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008610 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008611}
8612
8613template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008614OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8615 OMPUnifiedSharedMemoryClause *C) {
8616 llvm_unreachable(
8617 "unified_shared_memory clause cannot appear in dependent context");
8618}
8619
8620template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008621OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8622 OMPReverseOffloadClause *C) {
8623 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8624}
8625
8626template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008627OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8628 OMPDynamicAllocatorsClause *C) {
8629 llvm_unreachable(
8630 "dynamic_allocators clause cannot appear in dependent context");
8631}
8632
8633template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008634OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8635 OMPAtomicDefaultMemOrderClause *C) {
8636 llvm_unreachable(
8637 "atomic_default_mem_order clause cannot appear in dependent context");
8638}
8639
8640template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008641OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008642TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008643 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008644 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008645 for (auto *VE : C->varlists()) {
8646 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008647 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008648 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008649 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008650 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008651 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008652 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008653}
8654
Alexander Musman64d33f12014-06-04 07:53:32 +00008655template <typename Derived>
8656OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8657 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008658 llvm::SmallVector<Expr *, 16> Vars;
8659 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008660 for (auto *VE : C->varlists()) {
8661 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008662 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008663 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008664 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008665 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008666 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008667 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008668}
8669
Alexander Musman64d33f12014-06-04 07:53:32 +00008670template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008671OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008672TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8673 llvm::SmallVector<Expr *, 16> Vars;
8674 Vars.reserve(C->varlist_size());
8675 for (auto *VE : C->varlists()) {
8676 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8677 if (EVar.isInvalid())
8678 return nullptr;
8679 Vars.push_back(EVar.get());
8680 }
8681 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008682 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008683}
8684
8685template <typename Derived>
8686OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008687TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8688 llvm::SmallVector<Expr *, 16> Vars;
8689 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008690 for (auto *VE : C->varlists()) {
8691 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008692 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008693 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008694 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008695 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008696 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008697 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008698}
8699
Alexander Musman64d33f12014-06-04 07:53:32 +00008700template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008701OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008702TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8703 llvm::SmallVector<Expr *, 16> Vars;
8704 Vars.reserve(C->varlist_size());
8705 for (auto *VE : C->varlists()) {
8706 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8707 if (EVar.isInvalid())
8708 return nullptr;
8709 Vars.push_back(EVar.get());
8710 }
8711 CXXScopeSpec ReductionIdScopeSpec;
8712 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8713
8714 DeclarationNameInfo NameInfo = C->getNameInfo();
8715 if (NameInfo.getName()) {
8716 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8717 if (!NameInfo.getName())
8718 return nullptr;
8719 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008720 // Build a list of all UDR decls with the same names ranged by the Scopes.
8721 // The Scope boundary is a duplication of the previous decl.
8722 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8723 for (auto *E : C->reduction_ops()) {
8724 // Transform all the decls.
8725 if (E) {
8726 auto *ULE = cast<UnresolvedLookupExpr>(E);
8727 UnresolvedSet<8> Decls;
8728 for (auto *D : ULE->decls()) {
8729 NamedDecl *InstD =
8730 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8731 Decls.addDecl(InstD, InstD->getAccess());
8732 }
8733 UnresolvedReductions.push_back(
8734 UnresolvedLookupExpr::Create(
8735 SemaRef.Context, /*NamingClass=*/nullptr,
8736 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8737 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8738 Decls.begin(), Decls.end()));
8739 } else
8740 UnresolvedReductions.push_back(nullptr);
8741 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008742 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008743 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008744 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008745}
8746
8747template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008748OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8749 OMPTaskReductionClause *C) {
8750 llvm::SmallVector<Expr *, 16> Vars;
8751 Vars.reserve(C->varlist_size());
8752 for (auto *VE : C->varlists()) {
8753 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8754 if (EVar.isInvalid())
8755 return nullptr;
8756 Vars.push_back(EVar.get());
8757 }
8758 CXXScopeSpec ReductionIdScopeSpec;
8759 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8760
8761 DeclarationNameInfo NameInfo = C->getNameInfo();
8762 if (NameInfo.getName()) {
8763 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8764 if (!NameInfo.getName())
8765 return nullptr;
8766 }
8767 // Build a list of all UDR decls with the same names ranged by the Scopes.
8768 // The Scope boundary is a duplication of the previous decl.
8769 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8770 for (auto *E : C->reduction_ops()) {
8771 // Transform all the decls.
8772 if (E) {
8773 auto *ULE = cast<UnresolvedLookupExpr>(E);
8774 UnresolvedSet<8> Decls;
8775 for (auto *D : ULE->decls()) {
8776 NamedDecl *InstD =
8777 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8778 Decls.addDecl(InstD, InstD->getAccess());
8779 }
8780 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8781 SemaRef.Context, /*NamingClass=*/nullptr,
8782 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8783 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8784 } else
8785 UnresolvedReductions.push_back(nullptr);
8786 }
8787 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008788 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008789 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008790}
8791
8792template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008793OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008794TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8795 llvm::SmallVector<Expr *, 16> Vars;
8796 Vars.reserve(C->varlist_size());
8797 for (auto *VE : C->varlists()) {
8798 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8799 if (EVar.isInvalid())
8800 return nullptr;
8801 Vars.push_back(EVar.get());
8802 }
8803 CXXScopeSpec ReductionIdScopeSpec;
8804 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8805
8806 DeclarationNameInfo NameInfo = C->getNameInfo();
8807 if (NameInfo.getName()) {
8808 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8809 if (!NameInfo.getName())
8810 return nullptr;
8811 }
8812 // Build a list of all UDR decls with the same names ranged by the Scopes.
8813 // The Scope boundary is a duplication of the previous decl.
8814 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8815 for (auto *E : C->reduction_ops()) {
8816 // Transform all the decls.
8817 if (E) {
8818 auto *ULE = cast<UnresolvedLookupExpr>(E);
8819 UnresolvedSet<8> Decls;
8820 for (auto *D : ULE->decls()) {
8821 NamedDecl *InstD =
8822 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8823 Decls.addDecl(InstD, InstD->getAccess());
8824 }
8825 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8826 SemaRef.Context, /*NamingClass=*/nullptr,
8827 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8828 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8829 } else
8830 UnresolvedReductions.push_back(nullptr);
8831 }
8832 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008833 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008834 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008835}
8836
8837template <typename Derived>
8838OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008839TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8840 llvm::SmallVector<Expr *, 16> Vars;
8841 Vars.reserve(C->varlist_size());
8842 for (auto *VE : C->varlists()) {
8843 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8844 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008845 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008846 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008847 }
8848 ExprResult Step = getDerived().TransformExpr(C->getStep());
8849 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008850 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008851 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008852 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008853 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008854}
8855
Alexander Musman64d33f12014-06-04 07:53:32 +00008856template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008857OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008858TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8859 llvm::SmallVector<Expr *, 16> Vars;
8860 Vars.reserve(C->varlist_size());
8861 for (auto *VE : C->varlists()) {
8862 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8863 if (EVar.isInvalid())
8864 return nullptr;
8865 Vars.push_back(EVar.get());
8866 }
8867 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8868 if (Alignment.isInvalid())
8869 return nullptr;
8870 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008871 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008872 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008873}
8874
Alexander Musman64d33f12014-06-04 07:53:32 +00008875template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008876OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008877TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8878 llvm::SmallVector<Expr *, 16> Vars;
8879 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008880 for (auto *VE : C->varlists()) {
8881 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008882 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008883 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008884 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008885 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008886 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008887 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008888}
8889
Alexey Bataevbae9a792014-06-27 10:37:06 +00008890template <typename Derived>
8891OMPClause *
8892TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8893 llvm::SmallVector<Expr *, 16> Vars;
8894 Vars.reserve(C->varlist_size());
8895 for (auto *VE : C->varlists()) {
8896 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8897 if (EVar.isInvalid())
8898 return nullptr;
8899 Vars.push_back(EVar.get());
8900 }
8901 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008902 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008903}
8904
Alexey Bataev6125da92014-07-21 11:26:11 +00008905template <typename Derived>
8906OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8907 llvm::SmallVector<Expr *, 16> Vars;
8908 Vars.reserve(C->varlist_size());
8909 for (auto *VE : C->varlists()) {
8910 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8911 if (EVar.isInvalid())
8912 return nullptr;
8913 Vars.push_back(EVar.get());
8914 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008915 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008916 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008917}
8918
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008919template <typename Derived>
8920OMPClause *
8921TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8922 llvm::SmallVector<Expr *, 16> Vars;
8923 Vars.reserve(C->varlist_size());
8924 for (auto *VE : C->varlists()) {
8925 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8926 if (EVar.isInvalid())
8927 return nullptr;
8928 Vars.push_back(EVar.get());
8929 }
8930 return getDerived().RebuildOMPDependClause(
8931 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008932 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008933}
8934
Michael Wonge710d542015-08-07 16:16:36 +00008935template <typename Derived>
8936OMPClause *
8937TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8938 ExprResult E = getDerived().TransformExpr(C->getDevice());
8939 if (E.isInvalid())
8940 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008941 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008942 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008943}
8944
Michael Kruse01f670d2019-02-22 22:29:42 +00008945template <typename Derived, class T>
8946bool transformOMPMappableExprListClause(
8947 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
8948 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
8949 DeclarationNameInfo &MapperIdInfo,
8950 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
8951 // Transform expressions in the list.
Kelvin Li0bff7af2015-11-23 05:32:03 +00008952 Vars.reserve(C->varlist_size());
8953 for (auto *VE : C->varlists()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008954 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
Kelvin Li0bff7af2015-11-23 05:32:03 +00008955 if (EVar.isInvalid())
Michael Kruse01f670d2019-02-22 22:29:42 +00008956 return true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00008957 Vars.push_back(EVar.get());
8958 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008959 // Transform mapper scope specifier and identifier.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008960 NestedNameSpecifierLoc QualifierLoc;
8961 if (C->getMapperQualifierLoc()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008962 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
Michael Kruse4304e9d2019-02-19 16:38:20 +00008963 C->getMapperQualifierLoc());
8964 if (!QualifierLoc)
Michael Kruse01f670d2019-02-22 22:29:42 +00008965 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008966 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00008967 MapperIdScopeSpec.Adopt(QualifierLoc);
Michael Kruse01f670d2019-02-22 22:29:42 +00008968 MapperIdInfo = C->getMapperIdInfo();
Michael Kruse4304e9d2019-02-19 16:38:20 +00008969 if (MapperIdInfo.getName()) {
Michael Kruse01f670d2019-02-22 22:29:42 +00008970 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
Michael Kruse4304e9d2019-02-19 16:38:20 +00008971 if (!MapperIdInfo.getName())
Michael Kruse01f670d2019-02-22 22:29:42 +00008972 return true;
Michael Kruse4304e9d2019-02-19 16:38:20 +00008973 }
8974 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
8975 // the previous user-defined mapper lookup in dependent environment.
Michael Kruse4304e9d2019-02-19 16:38:20 +00008976 for (auto *E : C->mapperlists()) {
8977 // Transform all the decls.
8978 if (E) {
8979 auto *ULE = cast<UnresolvedLookupExpr>(E);
8980 UnresolvedSet<8> Decls;
8981 for (auto *D : ULE->decls()) {
8982 NamedDecl *InstD =
Michael Kruse01f670d2019-02-22 22:29:42 +00008983 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008984 Decls.addDecl(InstD, InstD->getAccess());
8985 }
8986 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
Michael Kruse01f670d2019-02-22 22:29:42 +00008987 TT.getSema().Context, /*NamingClass=*/nullptr,
8988 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
8989 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
8990 Decls.end()));
Michael Kruse4304e9d2019-02-19 16:38:20 +00008991 } else {
8992 UnresolvedMappers.push_back(nullptr);
8993 }
8994 }
Michael Kruse01f670d2019-02-22 22:29:42 +00008995 return false;
8996}
8997
8998template <typename Derived>
8999OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009000 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009001 llvm::SmallVector<Expr *, 16> Vars;
9002 CXXScopeSpec MapperIdScopeSpec;
9003 DeclarationNameInfo MapperIdInfo;
9004 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9005 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
9006 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9007 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00009008 return getDerived().RebuildOMPMapClause(
Michael Kruse4304e9d2019-02-19 16:38:20 +00009009 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
9010 MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
9011 C->getColonLoc(), Vars, Locs, UnresolvedMappers);
Kelvin Li0bff7af2015-11-23 05:32:03 +00009012}
9013
Kelvin Li099bb8c2015-11-24 20:50:12 +00009014template <typename Derived>
9015OMPClause *
Alexey Bataeve04483e2019-03-27 14:14:31 +00009016TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
9017 Expr *Allocator = C->getAllocator();
9018 if (Allocator) {
9019 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
9020 if (AllocatorRes.isInvalid())
9021 return nullptr;
9022 Allocator = AllocatorRes.get();
9023 }
9024 llvm::SmallVector<Expr *, 16> Vars;
9025 Vars.reserve(C->varlist_size());
9026 for (auto *VE : C->varlists()) {
9027 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9028 if (EVar.isInvalid())
9029 return nullptr;
9030 Vars.push_back(EVar.get());
9031 }
9032 return getDerived().RebuildOMPAllocateClause(
9033 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
9034 C->getEndLoc());
9035}
9036
9037template <typename Derived>
9038OMPClause *
Kelvin Li099bb8c2015-11-24 20:50:12 +00009039TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
9040 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
9041 if (E.isInvalid())
9042 return nullptr;
9043 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009044 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00009045}
9046
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009047template <typename Derived>
9048OMPClause *
9049TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
9050 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
9051 if (E.isInvalid())
9052 return nullptr;
9053 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009054 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00009055}
9056
Alexey Bataeva0569352015-12-01 10:17:31 +00009057template <typename Derived>
9058OMPClause *
9059TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
9060 ExprResult E = getDerived().TransformExpr(C->getPriority());
9061 if (E.isInvalid())
9062 return nullptr;
9063 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009064 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00009065}
9066
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009067template <typename Derived>
9068OMPClause *
9069TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
9070 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
9071 if (E.isInvalid())
9072 return nullptr;
9073 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009074 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00009075}
9076
Alexey Bataev382967a2015-12-08 12:06:20 +00009077template <typename Derived>
9078OMPClause *
9079TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
9080 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
9081 if (E.isInvalid())
9082 return nullptr;
9083 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009084 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00009085}
9086
Alexey Bataev28c75412015-12-15 08:19:24 +00009087template <typename Derived>
9088OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
9089 ExprResult E = getDerived().TransformExpr(C->getHint());
9090 if (E.isInvalid())
9091 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009092 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009093 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00009094}
9095
Carlo Bertollib4adf552016-01-15 18:50:31 +00009096template <typename Derived>
9097OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
9098 OMPDistScheduleClause *C) {
9099 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9100 if (E.isInvalid())
9101 return nullptr;
9102 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009103 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009104 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00009105}
9106
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00009107template <typename Derived>
9108OMPClause *
9109TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
9110 return C;
9111}
9112
Samuel Antao661c0902016-05-26 17:39:58 +00009113template <typename Derived>
9114OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009115 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse01f670d2019-02-22 22:29:42 +00009116 llvm::SmallVector<Expr *, 16> Vars;
9117 CXXScopeSpec MapperIdScopeSpec;
9118 DeclarationNameInfo MapperIdInfo;
9119 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9120 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
9121 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9122 return nullptr;
9123 return getDerived().RebuildOMPToClause(Vars, MapperIdScopeSpec, MapperIdInfo,
9124 Locs, UnresolvedMappers);
Samuel Antao661c0902016-05-26 17:39:58 +00009125}
9126
Samuel Antaoec172c62016-05-26 17:49:04 +00009127template <typename Derived>
9128OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
Michael Kruse4304e9d2019-02-19 16:38:20 +00009129 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Michael Kruse0336c752019-02-25 20:34:15 +00009130 llvm::SmallVector<Expr *, 16> Vars;
9131 CXXScopeSpec MapperIdScopeSpec;
9132 DeclarationNameInfo MapperIdInfo;
9133 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
9134 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
9135 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
9136 return nullptr;
9137 return getDerived().RebuildOMPFromClause(
9138 Vars, MapperIdScopeSpec, MapperIdInfo, Locs, UnresolvedMappers);
Samuel Antaoec172c62016-05-26 17:49:04 +00009139}
9140
Carlo Bertolli2404b172016-07-13 15:37:16 +00009141template <typename Derived>
9142OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
9143 OMPUseDevicePtrClause *C) {
9144 llvm::SmallVector<Expr *, 16> Vars;
9145 Vars.reserve(C->varlist_size());
9146 for (auto *VE : C->varlists()) {
9147 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9148 if (EVar.isInvalid())
9149 return nullptr;
9150 Vars.push_back(EVar.get());
9151 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009152 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9153 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
Carlo Bertolli2404b172016-07-13 15:37:16 +00009154}
9155
Carlo Bertolli70594e92016-07-13 17:16:49 +00009156template <typename Derived>
9157OMPClause *
9158TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
9159 llvm::SmallVector<Expr *, 16> Vars;
9160 Vars.reserve(C->varlist_size());
9161 for (auto *VE : C->varlists()) {
9162 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
9163 if (EVar.isInvalid())
9164 return nullptr;
9165 Vars.push_back(EVar.get());
9166 }
Michael Kruse4304e9d2019-02-19 16:38:20 +00009167 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9168 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
Carlo Bertolli70594e92016-07-13 17:16:49 +00009169}
9170
Douglas Gregorebe10102009-08-20 07:17:43 +00009171//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00009172// Expression transformation
9173//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00009174template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009175ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00009176TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
9177 return TransformExpr(E->getSubExpr());
9178}
9179
9180template<typename Derived>
9181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009182TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00009183 if (!E->isTypeDependent())
9184 return E;
9185
9186 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00009187 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00009188}
Mike Stump11289f42009-09-09 15:08:12 +00009189
9190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009192TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009193 NestedNameSpecifierLoc QualifierLoc;
9194 if (E->getQualifierLoc()) {
9195 QualifierLoc
9196 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9197 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009198 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009199 }
John McCallce546572009-12-08 09:08:17 +00009200
9201 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009202 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9203 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009206
John McCall815039a2010-08-17 21:27:17 +00009207 DeclarationNameInfo NameInfo = E->getNameInfo();
9208 if (NameInfo.getName()) {
9209 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9210 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009211 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009212 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009213
9214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009215 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009216 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009217 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009218 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009219
9220 // Mark it referenced in the new context regardless.
9221 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009222 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009223
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009224 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009225 }
John McCallce546572009-12-08 09:08:17 +00009226
Craig Topperc3ec1492014-05-26 06:22:03 +00009227 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009228 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009229 TemplateArgs = &TransArgs;
9230 TransArgs.setLAngleLoc(E->getLAngleLoc());
9231 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009232 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9233 E->getNumTemplateArgs(),
9234 TransArgs))
9235 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009236 }
9237
Chad Rosier1dcde962012-08-08 18:46:20 +00009238 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009239 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009240}
Mike Stump11289f42009-09-09 15:08:12 +00009241
Douglas Gregora16548e2009-08-11 05:31:07 +00009242template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009243ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009244TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009245 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009246}
Mike Stump11289f42009-09-09 15:08:12 +00009247
Leonard Chandb01c3a2018-06-20 17:19:40 +00009248template <typename Derived>
9249ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9250 FixedPointLiteral *E) {
9251 return E;
9252}
9253
Douglas Gregora16548e2009-08-11 05:31:07 +00009254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009256TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009257 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009258}
Mike Stump11289f42009-09-09 15:08:12 +00009259
Douglas Gregora16548e2009-08-11 05:31:07 +00009260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009261ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009262TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009263 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009264}
Mike Stump11289f42009-09-09 15:08:12 +00009265
Douglas Gregora16548e2009-08-11 05:31:07 +00009266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009267ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009268TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009269 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009270}
Mike Stump11289f42009-09-09 15:08:12 +00009271
Douglas Gregora16548e2009-08-11 05:31:07 +00009272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009273ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009274TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009275 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009276}
9277
9278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009280TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009281 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009282 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009283 return SemaRef.MaybeBindToTemporary(E);
9284}
9285
9286template<typename Derived>
9287ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009288TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9289 ExprResult ControllingExpr =
9290 getDerived().TransformExpr(E->getControllingExpr());
9291 if (ControllingExpr.isInvalid())
9292 return ExprError();
9293
Chris Lattner01cf8db2011-07-20 06:58:45 +00009294 SmallVector<Expr *, 4> AssocExprs;
9295 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009296 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9297 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9298 if (TSI) {
9299 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009300 if (!AssocType)
9301 return ExprError();
9302 AssocTypes.push_back(AssocType);
9303 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009304 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009305 }
9306
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009307 ExprResult AssocExpr =
9308 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009309 if (AssocExpr.isInvalid())
9310 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009311 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009312 }
9313
9314 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9315 E->getDefaultLoc(),
9316 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009317 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009318 AssocTypes,
9319 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009320}
9321
9322template<typename Derived>
9323ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009324TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009325 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009326 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009328
Douglas Gregora16548e2009-08-11 05:31:07 +00009329 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009330 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009331
John McCallb268a282010-08-23 23:25:46 +00009332 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009333 E->getRParen());
9334}
9335
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009336/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009337/// allowed to refer to a non-static member of a class even if there's no 'this'
9338/// object available.
9339template<typename Derived>
9340ExprResult
9341TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9342 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009343 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009344 else
9345 return getDerived().TransformExpr(E);
9346}
9347
Mike Stump11289f42009-09-09 15:08:12 +00009348template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009349ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009350TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009351 ExprResult SubExpr;
9352 if (E->getOpcode() == UO_AddrOf)
9353 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9354 else
9355 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009356 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009357 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009358
Douglas Gregora16548e2009-08-11 05:31:07 +00009359 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009360 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009361
Douglas Gregora16548e2009-08-11 05:31:07 +00009362 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9363 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009364 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009365}
Mike Stump11289f42009-09-09 15:08:12 +00009366
Douglas Gregora16548e2009-08-11 05:31:07 +00009367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009368ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009369TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9370 // Transform the type.
9371 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9372 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009373 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009374
Douglas Gregor882211c2010-04-28 22:16:22 +00009375 // Transform all of the components into components similar to what the
9376 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009377 // FIXME: It would be slightly more efficient in the non-dependent case to
9378 // just map FieldDecls, rather than requiring the rebuilder to look for
9379 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009380 // template code that we don't care.
9381 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009382 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009383 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009384 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009385 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009386 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009387 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009388 Comp.LocStart = ON.getSourceRange().getBegin();
9389 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009390 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009391 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009392 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009393 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009394 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009395 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009396
Douglas Gregor882211c2010-04-28 22:16:22 +00009397 ExprChanged = ExprChanged || Index.get() != FromIndex;
9398 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009399 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009400 break;
9401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009402
James Y Knight7281c352015-12-29 22:31:18 +00009403 case OffsetOfNode::Field:
9404 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009405 Comp.isBrackets = false;
9406 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009407 if (!Comp.U.IdentInfo)
9408 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009409
Douglas Gregor882211c2010-04-28 22:16:22 +00009410 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009411
James Y Knight7281c352015-12-29 22:31:18 +00009412 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009413 // Will be recomputed during the rebuild.
9414 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009416
Douglas Gregor882211c2010-04-28 22:16:22 +00009417 Components.push_back(Comp);
9418 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009419
Douglas Gregor882211c2010-04-28 22:16:22 +00009420 // If nothing changed, retain the existing expression.
9421 if (!getDerived().AlwaysRebuild() &&
9422 Type == E->getTypeSourceInfo() &&
9423 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009424 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009425
Douglas Gregor882211c2010-04-28 22:16:22 +00009426 // Build a new offsetof expression.
9427 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009428 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009429}
9430
9431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009432ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009433TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009434 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009435 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009436 return E;
John McCall8d69a212010-11-15 23:31:06 +00009437}
9438
9439template<typename Derived>
9440ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009441TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9442 return E;
9443}
9444
9445template<typename Derived>
9446ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009447TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009448 // Rebuild the syntactic form. The original syntactic form has
9449 // opaque-value expressions in it, so strip those away and rebuild
9450 // the result. This is a really awful way of doing this, but the
9451 // better solution (rebuilding the semantic expressions and
9452 // rebinding OVEs as necessary) doesn't work; we'd need
9453 // TreeTransform to not strip away implicit conversions.
9454 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9455 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009456 if (result.isInvalid()) return ExprError();
9457
9458 // If that gives us a pseudo-object result back, the pseudo-object
9459 // expression must have been an lvalue-to-rvalue conversion which we
9460 // should reapply.
9461 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009462 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009463
9464 return result;
9465}
9466
9467template<typename Derived>
9468ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009469TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9470 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009471 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009472 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009473
John McCallbcd03502009-12-07 02:54:59 +00009474 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009475 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009476 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009477
John McCall4c98fd82009-11-04 07:28:41 +00009478 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009479 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009480
Peter Collingbournee190dee2011-03-11 19:24:49 +00009481 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9482 E->getKind(),
9483 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 }
Mike Stump11289f42009-09-09 15:08:12 +00009485
Eli Friedmane4f22df2012-02-29 04:03:55 +00009486 // C++0x [expr.sizeof]p1:
9487 // The operand is either an expression, which is an unevaluated operand
9488 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009489 EnterExpressionEvaluationContext Unevaluated(
9490 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9491 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009492
Reid Kleckner32506ed2014-06-12 23:03:48 +00009493 // Try to recover if we have something like sizeof(T::X) where X is a type.
9494 // Notably, there must be *exactly* one set of parens if X is a type.
9495 TypeSourceInfo *RecoveryTSI = nullptr;
9496 ExprResult SubExpr;
9497 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9498 if (auto *DRE =
9499 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9500 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9501 PE, DRE, false, &RecoveryTSI);
9502 else
9503 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9504
9505 if (RecoveryTSI) {
9506 return getDerived().RebuildUnaryExprOrTypeTrait(
9507 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9508 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009510
Eli Friedmane4f22df2012-02-29 04:03:55 +00009511 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009512 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009513
Peter Collingbournee190dee2011-03-11 19:24:49 +00009514 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9515 E->getOperatorLoc(),
9516 E->getKind(),
9517 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009518}
Mike Stump11289f42009-09-09 15:08:12 +00009519
Douglas Gregora16548e2009-08-11 05:31:07 +00009520template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009521ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009522TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009523 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009524 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009525 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009526
John McCalldadc5752010-08-24 06:29:42 +00009527 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009528 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009530
9531
Douglas Gregora16548e2009-08-11 05:31:07 +00009532 if (!getDerived().AlwaysRebuild() &&
9533 LHS.get() == E->getLHS() &&
9534 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009535 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009536
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009537 return getDerived().RebuildArraySubscriptExpr(
9538 LHS.get(),
9539 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009540}
Mike Stump11289f42009-09-09 15:08:12 +00009541
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009542template <typename Derived>
9543ExprResult
9544TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9545 ExprResult Base = getDerived().TransformExpr(E->getBase());
9546 if (Base.isInvalid())
9547 return ExprError();
9548
9549 ExprResult LowerBound;
9550 if (E->getLowerBound()) {
9551 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9552 if (LowerBound.isInvalid())
9553 return ExprError();
9554 }
9555
9556 ExprResult Length;
9557 if (E->getLength()) {
9558 Length = getDerived().TransformExpr(E->getLength());
9559 if (Length.isInvalid())
9560 return ExprError();
9561 }
9562
9563 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9564 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9565 return E;
9566
9567 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009568 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009569 Length.get(), E->getRBracketLoc());
9570}
9571
Mike Stump11289f42009-09-09 15:08:12 +00009572template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009573ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009574TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009575 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009576 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009577 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009578 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009579
9580 // Transform arguments.
9581 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009582 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009583 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009584 &ArgChanged))
9585 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009586
Douglas Gregora16548e2009-08-11 05:31:07 +00009587 if (!getDerived().AlwaysRebuild() &&
9588 Callee.get() == E->getCallee() &&
9589 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009590 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009591
Douglas Gregora16548e2009-08-11 05:31:07 +00009592 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009593 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009594 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009595 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009596 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009597 E->getRParenLoc());
9598}
Mike Stump11289f42009-09-09 15:08:12 +00009599
9600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009601ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009602TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009603 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009604 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009605 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009606
Douglas Gregorea972d32011-02-28 21:54:11 +00009607 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009608 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009609 QualifierLoc
9610 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009611
Douglas Gregorea972d32011-02-28 21:54:11 +00009612 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009613 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009614 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009615 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009616
Eli Friedman2cfcef62009-12-04 06:40:45 +00009617 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009618 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9619 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009620 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009621 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009622
John McCall16df1e52010-03-30 21:47:33 +00009623 NamedDecl *FoundDecl = E->getFoundDecl();
9624 if (FoundDecl == E->getMemberDecl()) {
9625 FoundDecl = Member;
9626 } else {
9627 FoundDecl = cast_or_null<NamedDecl>(
9628 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9629 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009630 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009631 }
9632
Douglas Gregora16548e2009-08-11 05:31:07 +00009633 if (!getDerived().AlwaysRebuild() &&
9634 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009635 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009636 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009637 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009638 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009639
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009640 // Mark it referenced in the new context regardless.
9641 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009642 SemaRef.MarkMemberReferenced(E);
9643
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009644 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009645 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009646
John McCall6b51f282009-11-23 01:53:49 +00009647 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009648 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009649 TransArgs.setLAngleLoc(E->getLAngleLoc());
9650 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009651 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9652 E->getNumTemplateArgs(),
9653 TransArgs))
9654 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009655 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009656
Douglas Gregora16548e2009-08-11 05:31:07 +00009657 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009658 SourceLocation FakeOperatorLoc =
9659 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009660
John McCall38836f02010-01-15 08:34:02 +00009661 // FIXME: to do this check properly, we will need to preserve the
9662 // first-qualifier-in-scope here, just in case we had a dependent
9663 // base (and therefore couldn't do the check) and a
9664 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009665 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009666 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9667 if (MemberNameInfo.getName()) {
9668 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9669 if (!MemberNameInfo.getName())
9670 return ExprError();
9671 }
John McCall38836f02010-01-15 08:34:02 +00009672
John McCallb268a282010-08-23 23:25:46 +00009673 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009674 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009675 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009676 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009677 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009678 Member,
John McCall16df1e52010-03-30 21:47:33 +00009679 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009680 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009681 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009682 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009683}
Mike Stump11289f42009-09-09 15:08:12 +00009684
Douglas Gregora16548e2009-08-11 05:31:07 +00009685template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009686ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009687TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009688 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009689 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009690 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009691
John McCalldadc5752010-08-24 06:29:42 +00009692 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009693 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009694 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009695
Douglas Gregora16548e2009-08-11 05:31:07 +00009696 if (!getDerived().AlwaysRebuild() &&
9697 LHS.get() == E->getLHS() &&
9698 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009699 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009700
Lang Hames5de91cc2012-10-02 04:45:10 +00009701 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009702 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009703
Douglas Gregora16548e2009-08-11 05:31:07 +00009704 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009705 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009706}
9707
Mike Stump11289f42009-09-09 15:08:12 +00009708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009709ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009710TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009711 CompoundAssignOperator *E) {
9712 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009713}
Mike Stump11289f42009-09-09 15:08:12 +00009714
Douglas Gregora16548e2009-08-11 05:31:07 +00009715template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009716ExprResult TreeTransform<Derived>::
9717TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9718 // Just rebuild the common and RHS expressions and see whether we
9719 // get any changes.
9720
9721 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9722 if (commonExpr.isInvalid())
9723 return ExprError();
9724
9725 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9726 if (rhs.isInvalid())
9727 return ExprError();
9728
9729 if (!getDerived().AlwaysRebuild() &&
9730 commonExpr.get() == e->getCommon() &&
9731 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009732 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009733
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009734 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009735 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009736 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009737 e->getColonLoc(),
9738 rhs.get());
9739}
9740
9741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009743TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009744 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009745 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009747
John McCalldadc5752010-08-24 06:29:42 +00009748 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009749 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009750 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009751
John McCalldadc5752010-08-24 06:29:42 +00009752 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009754 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009755
Douglas Gregora16548e2009-08-11 05:31:07 +00009756 if (!getDerived().AlwaysRebuild() &&
9757 Cond.get() == E->getCond() &&
9758 LHS.get() == E->getLHS() &&
9759 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009760 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009761
John McCallb268a282010-08-23 23:25:46 +00009762 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009763 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009764 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009765 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009766 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009767}
Mike Stump11289f42009-09-09 15:08:12 +00009768
9769template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009770ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009771TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009772 // Implicit casts are eliminated during transformation, since they
9773 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009774 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009775}
Mike Stump11289f42009-09-09 15:08:12 +00009776
Douglas Gregora16548e2009-08-11 05:31:07 +00009777template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009779TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009780 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9781 if (!Type)
9782 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009783
John McCalldadc5752010-08-24 06:29:42 +00009784 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009785 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009788
Douglas Gregora16548e2009-08-11 05:31:07 +00009789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009790 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009792 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009793
John McCall97513962010-01-15 18:39:57 +00009794 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009795 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009796 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009797 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009798}
Mike Stump11289f42009-09-09 15:08:12 +00009799
Douglas Gregora16548e2009-08-11 05:31:07 +00009800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009802TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009803 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9804 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9805 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009807
John McCalldadc5752010-08-24 06:29:42 +00009808 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009809 if (Init.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() &&
John McCalle15bbff2010-01-18 19:35:47 +00009813 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009814 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009815 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009816
John McCall5d7aa7f2010-01-19 22:33:45 +00009817 // Note: the expression type doesn't necessarily match the
9818 // type-as-written, but that's okay, because it should always be
9819 // derivable from the initializer.
9820
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009821 return getDerived().RebuildCompoundLiteralExpr(
9822 E->getLParenLoc(), NewT,
9823 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009824}
Mike Stump11289f42009-09-09 15:08:12 +00009825
Douglas Gregora16548e2009-08-11 05:31:07 +00009826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009828TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009829 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009831 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009832
Douglas Gregora16548e2009-08-11 05:31:07 +00009833 if (!getDerived().AlwaysRebuild() &&
9834 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009835 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009836
Douglas Gregora16548e2009-08-11 05:31:07 +00009837 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009838 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009839 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009840 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009841 E->getAccessorLoc(),
9842 E->getAccessor());
9843}
Mike Stump11289f42009-09-09 15:08:12 +00009844
Douglas Gregora16548e2009-08-11 05:31:07 +00009845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009847TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009848 if (InitListExpr *Syntactic = E->getSyntacticForm())
9849 E = Syntactic;
9850
Douglas Gregora16548e2009-08-11 05:31:07 +00009851 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009852
Richard Smith12938cf2018-09-26 04:36:55 +00009853 EnterExpressionEvaluationContext Context(
9854 getSema(), EnterExpressionEvaluationContext::InitList);
9855
Benjamin Kramerf0623432012-08-23 22:51:59 +00009856 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009857 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009858 Inits, &InitChanged))
9859 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009860
Richard Smith520449d2015-02-05 06:15:50 +00009861 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9862 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9863 // in some cases. We can't reuse it in general, because the syntactic and
9864 // semantic forms are linked, and we can't know that semantic form will
9865 // match even if the syntactic form does.
9866 }
Mike Stump11289f42009-09-09 15:08:12 +00009867
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009868 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009869 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009870}
Mike Stump11289f42009-09-09 15:08:12 +00009871
Douglas Gregora16548e2009-08-11 05:31:07 +00009872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009873ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009874TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009875 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009876
Douglas Gregorebe10102009-08-20 07:17:43 +00009877 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009878 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009879 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009880 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009881
Douglas Gregorebe10102009-08-20 07:17:43 +00009882 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009883 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009884 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009885 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9886 if (D.isFieldDesignator()) {
9887 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9888 D.getDotLoc(),
9889 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009890 if (D.getField()) {
9891 FieldDecl *Field = cast_or_null<FieldDecl>(
9892 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9893 if (Field != D.getField())
9894 // Rebuild the expression when the transformed FieldDecl is
9895 // different to the already assigned FieldDecl.
9896 ExprChanged = true;
9897 } else {
9898 // Ensure that the designator expression is rebuilt when there isn't
9899 // a resolved FieldDecl in the designator as we don't want to assign
9900 // a FieldDecl to a pattern designator that will be instantiated again.
9901 ExprChanged = true;
9902 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009903 continue;
9904 }
Mike Stump11289f42009-09-09 15:08:12 +00009905
David Majnemerf7e36092016-06-23 00:15:04 +00009906 if (D.isArrayDesignator()) {
9907 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009908 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009909 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009910
David Majnemerf7e36092016-06-23 00:15:04 +00009911 Desig.AddDesignator(
9912 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009913
David Majnemerf7e36092016-06-23 00:15:04 +00009914 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009915 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009916 continue;
9917 }
Mike Stump11289f42009-09-09 15:08:12 +00009918
David Majnemerf7e36092016-06-23 00:15:04 +00009919 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009920 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009921 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009922 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009924
David Majnemerf7e36092016-06-23 00:15:04 +00009925 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009926 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009927 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009928
9929 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009930 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009931 D.getLBracketLoc(),
9932 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009933
David Majnemerf7e36092016-06-23 00:15:04 +00009934 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9935 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009936
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009937 ArrayExprs.push_back(Start.get());
9938 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009939 }
Mike Stump11289f42009-09-09 15:08:12 +00009940
Douglas Gregora16548e2009-08-11 05:31:07 +00009941 if (!getDerived().AlwaysRebuild() &&
9942 Init.get() == E->getInit() &&
9943 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009944 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009945
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009946 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009947 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009948 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009949}
Mike Stump11289f42009-09-09 15:08:12 +00009950
Yunzhong Gaocb779302015-06-10 00:27:52 +00009951// Seems that if TransformInitListExpr() only works on the syntactic form of an
9952// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9953template<typename Derived>
9954ExprResult
9955TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9956 DesignatedInitUpdateExpr *E) {
9957 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9958 "initializer");
9959 return ExprError();
9960}
9961
9962template<typename Derived>
9963ExprResult
9964TreeTransform<Derived>::TransformNoInitExpr(
9965 NoInitExpr *E) {
9966 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9967 return ExprError();
9968}
9969
Douglas Gregora16548e2009-08-11 05:31:07 +00009970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009971ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009972TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9973 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9974 return ExprError();
9975}
9976
9977template<typename Derived>
9978ExprResult
9979TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9980 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9981 return ExprError();
9982}
9983
9984template<typename Derived>
9985ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009986TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009987 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009988 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009989
Douglas Gregor3da3c062009-10-28 00:29:27 +00009990 // FIXME: Will we ever have proper type location here? Will we actually
9991 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009992 QualType T = getDerived().TransformType(E->getType());
9993 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009995
Douglas Gregora16548e2009-08-11 05:31:07 +00009996 if (!getDerived().AlwaysRebuild() &&
9997 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009998 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009999
Douglas Gregora16548e2009-08-11 05:31:07 +000010000 return getDerived().RebuildImplicitValueInitExpr(T);
10001}
Mike Stump11289f42009-09-09 15:08:12 +000010002
Douglas Gregora16548e2009-08-11 05:31:07 +000010003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010004ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010005TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +000010006 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
10007 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010008 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010009
John McCalldadc5752010-08-24 06:29:42 +000010010 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010011 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010013
Douglas Gregora16548e2009-08-11 05:31:07 +000010014 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +000010015 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010016 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010017 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010018
John McCallb268a282010-08-23 23:25:46 +000010019 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +000010020 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010021}
10022
10023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010024ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010025TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010026 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010027 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +000010028 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
10029 &ArgumentChanged))
10030 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010033 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +000010034 E->getRParenLoc());
10035}
Mike Stump11289f42009-09-09 15:08:12 +000010036
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010037/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010038///
10039/// By default, the transformation of an address-of-label expression always
10040/// rebuilds the expression, so that the label identifier can be resolved to
10041/// the corresponding label statement by semantic analysis.
10042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010044TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +000010045 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
10046 E->getLabel());
10047 if (!LD)
10048 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010049
Douglas Gregora16548e2009-08-11 05:31:07 +000010050 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +000010051 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +000010052}
Mike Stump11289f42009-09-09 15:08:12 +000010053
10054template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000010055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010056TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +000010057 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +000010058 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +000010059 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +000010060 if (SubStmt.isInvalid()) {
10061 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +000010062 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +000010063 }
Mike Stump11289f42009-09-09 15:08:12 +000010064
Douglas Gregora16548e2009-08-11 05:31:07 +000010065 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +000010066 SubStmt.get() == E->getSubStmt()) {
10067 // Calling this an 'error' is unintuitive, but it does the right thing.
10068 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010069 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +000010070 }
Mike Stump11289f42009-09-09 15:08:12 +000010071
10072 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010073 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010074 E->getRParenLoc());
10075}
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregora16548e2009-08-11 05:31:07 +000010077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010078ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010079TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010080 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +000010081 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010083
John McCalldadc5752010-08-24 06:29:42 +000010084 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010085 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010086 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010087
John McCalldadc5752010-08-24 06:29:42 +000010088 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +000010089 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010090 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010091
Douglas Gregora16548e2009-08-11 05:31:07 +000010092 if (!getDerived().AlwaysRebuild() &&
10093 Cond.get() == E->getCond() &&
10094 LHS.get() == E->getLHS() &&
10095 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010096 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010097
Douglas Gregora16548e2009-08-11 05:31:07 +000010098 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +000010099 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010100 E->getRParenLoc());
10101}
Mike Stump11289f42009-09-09 15:08:12 +000010102
Douglas Gregora16548e2009-08-11 05:31:07 +000010103template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010104ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010105TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010106 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010107}
10108
10109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010111TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010112 switch (E->getOperator()) {
10113 case OO_New:
10114 case OO_Delete:
10115 case OO_Array_New:
10116 case OO_Array_Delete:
10117 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +000010118
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010119 case OO_Call: {
10120 // This is a call to an object's operator().
10121 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
10122
10123 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +000010124 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010125 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010126 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010127
10128 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +000010129 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010130 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010131
10132 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +000010133 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010134 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +000010135 Args))
10136 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010137
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010138 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
10139 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010140 }
10141
10142#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
10143 case OO_##Name:
10144#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
10145#include "clang/Basic/OperatorKinds.def"
10146 case OO_Subscript:
10147 // Handled below.
10148 break;
10149
10150 case OO_Conditional:
10151 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010152
10153 case OO_None:
10154 case NUM_OVERLOADED_OPERATORS:
10155 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +000010156 }
10157
John McCalldadc5752010-08-24 06:29:42 +000010158 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +000010159 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010160 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010161
Richard Smithdb2630f2012-10-21 03:28:35 +000010162 ExprResult First;
10163 if (E->getOperator() == OO_Amp)
10164 First = getDerived().TransformAddressOfOperand(E->getArg(0));
10165 else
10166 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +000010167 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010168 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010169
John McCalldadc5752010-08-24 06:29:42 +000010170 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +000010171 if (E->getNumArgs() == 2) {
10172 Second = getDerived().TransformExpr(E->getArg(1));
10173 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010174 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010175 }
Mike Stump11289f42009-09-09 15:08:12 +000010176
Douglas Gregora16548e2009-08-11 05:31:07 +000010177 if (!getDerived().AlwaysRebuild() &&
10178 Callee.get() == E->getCallee() &&
10179 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +000010180 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010181 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +000010182
Lang Hames5de91cc2012-10-02 04:45:10 +000010183 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +000010184 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +000010185
Douglas Gregora16548e2009-08-11 05:31:07 +000010186 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
10187 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +000010188 Callee.get(),
10189 First.get(),
10190 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010191}
Mike Stump11289f42009-09-09 15:08:12 +000010192
Douglas Gregora16548e2009-08-11 05:31:07 +000010193template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010194ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010195TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10196 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010197}
Mike Stump11289f42009-09-09 15:08:12 +000010198
Eric Fiselier708afb52019-05-16 21:04:15 +000010199template <typename Derived>
10200ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
10201 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
10202 getSema().CurContext != E->getParentContext();
10203
10204 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
10205 return E;
10206
10207 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
10208 E->getEndLoc(),
10209 getSema().CurContext);
10210}
10211
Douglas Gregora16548e2009-08-11 05:31:07 +000010212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010213ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +000010214TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10215 // Transform the callee.
10216 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10217 if (Callee.isInvalid())
10218 return ExprError();
10219
10220 // Transform exec config.
10221 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10222 if (EC.isInvalid())
10223 return ExprError();
10224
10225 // Transform arguments.
10226 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010227 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010228 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010229 &ArgChanged))
10230 return ExprError();
10231
10232 if (!getDerived().AlwaysRebuild() &&
10233 Callee.get() == E->getCallee() &&
10234 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010235 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010236
10237 // FIXME: Wrong source location information for the '('.
10238 SourceLocation FakeLParenLoc
10239 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10240 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010241 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010242 E->getRParenLoc(), EC.get());
10243}
10244
10245template<typename Derived>
10246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010247TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010248 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10249 if (!Type)
10250 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010251
John McCalldadc5752010-08-24 06:29:42 +000010252 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010253 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010254 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010256
Douglas Gregora16548e2009-08-11 05:31:07 +000010257 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010258 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010259 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010260 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010261 return getDerived().RebuildCXXNamedCastExpr(
10262 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10263 Type, E->getAngleBrackets().getEnd(),
10264 // FIXME. this should be '(' location
10265 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010266}
Mike Stump11289f42009-09-09 15:08:12 +000010267
Douglas Gregora16548e2009-08-11 05:31:07 +000010268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010269ExprResult
Erik Pilkingtoneee944e2019-07-02 18:28:13 +000010270TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) {
10271 TypeSourceInfo *TSI =
10272 getDerived().TransformType(BCE->getTypeInfoAsWritten());
10273 if (!TSI)
10274 return ExprError();
10275
10276 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
10277 if (Sub.isInvalid())
10278 return ExprError();
10279
10280 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
10281 Sub.get(), BCE->getEndLoc());
10282}
10283
10284template<typename Derived>
10285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010286TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10287 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010288}
Mike Stump11289f42009-09-09 15:08:12 +000010289
10290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010292TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10293 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010294}
10295
Douglas Gregora16548e2009-08-11 05:31:07 +000010296template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010297ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010298TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010299 CXXReinterpretCastExpr *E) {
10300 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010301}
Mike Stump11289f42009-09-09 15:08:12 +000010302
Douglas Gregora16548e2009-08-11 05:31:07 +000010303template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010304ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010305TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10306 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010307}
Mike Stump11289f42009-09-09 15:08:12 +000010308
Douglas Gregora16548e2009-08-11 05:31:07 +000010309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010310ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010311TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010312 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010313 TypeSourceInfo *Type =
10314 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010315 if (!Type)
10316 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010317
John McCalldadc5752010-08-24 06:29:42 +000010318 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010319 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010320 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010322
Douglas Gregora16548e2009-08-11 05:31:07 +000010323 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010324 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010325 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010326 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010327
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010328 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010329 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010330 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010331 E->getRParenLoc(),
10332 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010333}
Mike Stump11289f42009-09-09 15:08:12 +000010334
Douglas Gregora16548e2009-08-11 05:31:07 +000010335template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010336ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010337TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010338 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010339 TypeSourceInfo *TInfo
10340 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10341 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010342 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010343
Douglas Gregora16548e2009-08-11 05:31:07 +000010344 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010345 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010346 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010347
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010348 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010349 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010350 }
Mike Stump11289f42009-09-09 15:08:12 +000010351
Eli Friedman456f0182012-01-20 01:26:23 +000010352 // We don't know whether the subexpression is potentially evaluated until
10353 // after we perform semantic analysis. We speculatively assume it is
10354 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010355 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010356 EnterExpressionEvaluationContext Unevaluated(
10357 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10358 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010359
John McCalldadc5752010-08-24 06:29:42 +000010360 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010361 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010362 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010363
Douglas Gregora16548e2009-08-11 05:31:07 +000010364 if (!getDerived().AlwaysRebuild() &&
10365 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010366 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010367
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010368 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010369 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010370}
10371
10372template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010373ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010374TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10375 if (E->isTypeOperand()) {
10376 TypeSourceInfo *TInfo
10377 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10378 if (!TInfo)
10379 return ExprError();
10380
10381 if (!getDerived().AlwaysRebuild() &&
10382 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010383 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010384
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010385 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010386 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010387 }
10388
Faisal Valid143a0c2017-04-01 21:30:49 +000010389 EnterExpressionEvaluationContext Unevaluated(
10390 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010391
10392 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10393 if (SubExpr.isInvalid())
10394 return ExprError();
10395
10396 if (!getDerived().AlwaysRebuild() &&
10397 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010398 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010399
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010400 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010401 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010402}
10403
10404template<typename Derived>
10405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010406TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010407 return E;
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
Douglas Gregora16548e2009-08-11 05:31:07 +000010412TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010413 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010414 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010415}
Mike Stump11289f42009-09-09 15:08:12 +000010416
Douglas Gregora16548e2009-08-11 05:31:07 +000010417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010418ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010419TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010420 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010421
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010422 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
Richard Smith8458c9e2019-05-24 01:35:07 +000010423 // Mark it referenced in the new context regardless.
10424 // FIXME: this is a bit instantiation-specific.
10425 getSema().MarkThisReferenced(E);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010426 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010427 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010428
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010429 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010430}
Mike Stump11289f42009-09-09 15:08:12 +000010431
Douglas Gregora16548e2009-08-11 05:31:07 +000010432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010434TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010435 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010436 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010437 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010438
Douglas Gregora16548e2009-08-11 05:31:07 +000010439 if (!getDerived().AlwaysRebuild() &&
10440 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010441 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010442
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010443 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10444 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010445}
Mike Stump11289f42009-09-09 15:08:12 +000010446
Douglas Gregora16548e2009-08-11 05:31:07 +000010447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010449TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010450 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10451 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010452 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010453 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010454
Eric Fiselier708afb52019-05-16 21:04:15 +000010455 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
10456 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010457 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010458
Douglas Gregor033f6752009-12-23 23:03:06 +000010459 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010460}
Mike Stump11289f42009-09-09 15:08:12 +000010461
Douglas Gregora16548e2009-08-11 05:31:07 +000010462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010463ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010464TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010465 FieldDecl *Field = cast_or_null<FieldDecl>(
10466 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010467 if (!Field)
10468 return ExprError();
10469
Eric Fiselier708afb52019-05-16 21:04:15 +000010470 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
10471 E->getUsedContext() == SemaRef.CurContext)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010472 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010473
10474 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10475}
10476
10477template<typename Derived>
10478ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010479TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10480 CXXScalarValueInitExpr *E) {
10481 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10482 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010483 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010484
Douglas Gregora16548e2009-08-11 05:31:07 +000010485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010486 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010487 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010488
Chad Rosier1dcde962012-08-08 18:46:20 +000010489 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010490 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010491 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010492}
Mike Stump11289f42009-09-09 15:08:12 +000010493
Douglas Gregora16548e2009-08-11 05:31:07 +000010494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010496TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010497 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010498 TypeSourceInfo *AllocTypeInfo =
10499 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010500 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010501 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010502
Douglas Gregora16548e2009-08-11 05:31:07 +000010503 // Transform the size of the array we're allocating (if any).
Richard Smithb9fb1212019-05-06 03:47:15 +000010504 Optional<Expr *> ArraySize;
10505 if (Optional<Expr *> OldArraySize = E->getArraySize()) {
10506 ExprResult NewArraySize;
10507 if (*OldArraySize) {
10508 NewArraySize = getDerived().TransformExpr(*OldArraySize);
10509 if (NewArraySize.isInvalid())
10510 return ExprError();
10511 }
10512 ArraySize = NewArraySize.get();
10513 }
Mike Stump11289f42009-09-09 15:08:12 +000010514
Douglas Gregora16548e2009-08-11 05:31:07 +000010515 // Transform the placement arguments (if any).
10516 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010517 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010518 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010519 E->getNumPlacementArgs(), true,
10520 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010522
Sebastian Redl6047f072012-02-16 12:22:20 +000010523 // Transform the initializer (if any).
10524 Expr *OldInit = E->getInitializer();
10525 ExprResult NewInit;
10526 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010527 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010528 if (NewInit.isInvalid())
10529 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010530
Sebastian Redl6047f072012-02-16 12:22:20 +000010531 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010532 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010533 if (E->getOperatorNew()) {
10534 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010535 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010536 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010537 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010538 }
10539
Craig Topperc3ec1492014-05-26 06:22:03 +000010540 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010541 if (E->getOperatorDelete()) {
10542 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010543 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010544 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010545 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010546 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010547
Douglas Gregora16548e2009-08-11 05:31:07 +000010548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010549 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Richard Smithb9fb1212019-05-06 03:47:15 +000010550 ArraySize == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010551 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010552 OperatorNew == E->getOperatorNew() &&
10553 OperatorDelete == E->getOperatorDelete() &&
10554 !ArgumentChanged) {
10555 // Mark any declarations we need as referenced.
10556 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010557 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010558 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010559 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010560 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010561
Sebastian Redl6047f072012-02-16 12:22:20 +000010562 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010563 QualType ElementType
10564 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10565 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10566 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10567 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010568 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010569 }
10570 }
10571 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010572
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010573 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010574 }
Mike Stump11289f42009-09-09 15:08:12 +000010575
Douglas Gregor0744ef62010-09-07 21:49:58 +000010576 QualType AllocType = AllocTypeInfo->getType();
Richard Smithb9fb1212019-05-06 03:47:15 +000010577 if (!ArraySize) {
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010578 // If no array size was specified, but the new expression was
10579 // instantiated with an array type (e.g., "new T" where T is
10580 // instantiated with "int[4]"), extract the outer bound from the
10581 // array type as our array size. We do this with constant and
10582 // dependently-sized array types.
10583 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10584 if (!ArrayT) {
10585 // Do nothing
10586 } else if (const ConstantArrayType *ConsArrayT
10587 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010588 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10589 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010590 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010591 AllocType = ConsArrayT->getElementType();
10592 } else if (const DependentSizedArrayType *DepArrayT
10593 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10594 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010595 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010596 AllocType = DepArrayT->getElementType();
10597 }
10598 }
10599 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010600
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010601 return getDerived().RebuildCXXNewExpr(
10602 E->getBeginLoc(), E->isGlobalNew(),
10603 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10604 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
Richard Smithb9fb1212019-05-06 03:47:15 +000010605 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010606}
Mike Stump11289f42009-09-09 15:08:12 +000010607
Douglas Gregora16548e2009-08-11 05:31:07 +000010608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010609ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010610TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010611 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010612 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010614
Douglas Gregord2d9da02010-02-26 00:38:10 +000010615 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010616 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010617 if (E->getOperatorDelete()) {
10618 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010619 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010620 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010621 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010622 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
Douglas Gregora16548e2009-08-11 05:31:07 +000010624 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010625 Operand.get() == E->getArgument() &&
10626 OperatorDelete == E->getOperatorDelete()) {
10627 // Mark any declarations we need as referenced.
10628 // FIXME: instantiation-specific.
10629 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010630 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010631
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010632 if (!E->getArgument()->isTypeDependent()) {
10633 QualType Destroyed = SemaRef.Context.getBaseElementType(
10634 E->getDestroyedType());
10635 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10636 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010637 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010638 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010639 }
10640 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010641
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010642 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010643 }
Mike Stump11289f42009-09-09 15:08:12 +000010644
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010645 return getDerived().RebuildCXXDeleteExpr(
10646 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010647}
Mike Stump11289f42009-09-09 15:08:12 +000010648
Douglas Gregora16548e2009-08-11 05:31:07 +000010649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010650ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010651TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010652 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010653 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010654 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010655 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010656
John McCallba7bf592010-08-24 05:47:05 +000010657 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010658 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010659 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010660 E->getOperatorLoc(),
10661 E->isArrow()? tok::arrow : tok::period,
10662 ObjectTypePtr,
10663 MayBePseudoDestructor);
10664 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010665 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010666
John McCallba7bf592010-08-24 05:47:05 +000010667 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010668 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10669 if (QualifierLoc) {
10670 QualifierLoc
10671 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10672 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010673 return ExprError();
10674 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010675 CXXScopeSpec SS;
10676 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010677
Douglas Gregor678f90d2010-02-25 01:56:36 +000010678 PseudoDestructorTypeStorage Destroyed;
10679 if (E->getDestroyedTypeInfo()) {
10680 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010681 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010682 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010683 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010684 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010685 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010686 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010687 // We aren't likely to be able to resolve the identifier down to a type
10688 // now anyway, so just retain the identifier.
10689 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10690 E->getDestroyedTypeLoc());
10691 } else {
10692 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010693 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010694 *E->getDestroyedTypeIdentifier(),
10695 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010696 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010697 SS, ObjectTypePtr,
10698 false);
10699 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010700 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010701
Douglas Gregor678f90d2010-02-25 01:56:36 +000010702 Destroyed
10703 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10704 E->getDestroyedTypeLoc());
10705 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010706
Craig Topperc3ec1492014-05-26 06:22:03 +000010707 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010708 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010709 CXXScopeSpec EmptySS;
10710 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010711 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010712 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010713 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010714 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010715
John McCallb268a282010-08-23 23:25:46 +000010716 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010717 E->getOperatorLoc(),
10718 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010719 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010720 ScopeTypeInfo,
10721 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010722 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010723 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010724}
Mike Stump11289f42009-09-09 15:08:12 +000010725
Richard Smith151c4562016-12-20 21:35:28 +000010726template <typename Derived>
10727bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10728 bool RequiresADL,
10729 LookupResult &R) {
10730 // Transform all the decls.
10731 bool AllEmptyPacks = true;
10732 for (auto *OldD : Old->decls()) {
10733 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10734 if (!InstD) {
10735 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10736 // This can happen because of dependent hiding.
10737 if (isa<UsingShadowDecl>(OldD))
10738 continue;
10739 else {
10740 R.clear();
10741 return true;
10742 }
10743 }
10744
10745 // Expand using pack declarations.
10746 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10747 ArrayRef<NamedDecl*> Decls = SingleDecl;
10748 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10749 Decls = UPD->expansions();
10750
10751 // Expand using declarations.
10752 for (auto *D : Decls) {
10753 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10754 for (auto *SD : UD->shadows())
10755 R.addDecl(SD);
10756 } else {
10757 R.addDecl(D);
10758 }
10759 }
10760
10761 AllEmptyPacks &= Decls.empty();
10762 };
10763
10764 // C++ [temp.res]/8.4.2:
10765 // The program is ill-formed, no diagnostic required, if [...] lookup for
10766 // a name in the template definition found a using-declaration, but the
10767 // lookup in the corresponding scope in the instantiation odoes not find
10768 // any declarations because the using-declaration was a pack expansion and
10769 // the corresponding pack is empty
10770 if (AllEmptyPacks && !RequiresADL) {
10771 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010772 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010773 return true;
10774 }
10775
10776 // Resolve a kind, but don't do any further analysis. If it's
10777 // ambiguous, the callee needs to deal with it.
10778 R.resolveKind();
10779 return false;
10780}
10781
Douglas Gregorad8a3362009-09-04 17:36:40 +000010782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010783ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010784TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010785 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010786 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10787 Sema::LookupOrdinaryName);
10788
Richard Smith151c4562016-12-20 21:35:28 +000010789 // Transform the declaration set.
10790 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10791 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010792
10793 // Rebuild the nested-name qualifier, if present.
10794 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010795 if (Old->getQualifierLoc()) {
10796 NestedNameSpecifierLoc QualifierLoc
10797 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10798 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010799 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010800
Douglas Gregor0da1d432011-02-28 20:01:57 +000010801 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010802 }
10803
Douglas Gregor9262f472010-04-27 18:19:34 +000010804 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010805 CXXRecordDecl *NamingClass
10806 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10807 Old->getNameLoc(),
10808 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010809 if (!NamingClass) {
10810 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010811 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010812 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010813
Douglas Gregorda7be082010-04-27 16:10:10 +000010814 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010815 }
10816
Abramo Bagnara7945c982012-01-27 09:46:47 +000010817 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10818
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010819 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010820 // it's a normal declaration name or member reference.
10821 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10822 NamedDecl *D = R.getAsSingle<NamedDecl>();
10823 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10824 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10825 // give a good diagnostic.
10826 if (D && D->isCXXInstanceMember()) {
10827 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10828 /*TemplateArgs=*/nullptr,
10829 /*Scope=*/nullptr);
10830 }
10831
John McCalle66edc12009-11-24 19:00:30 +000010832 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010833 }
John McCalle66edc12009-11-24 19:00:30 +000010834
10835 // If we have template arguments, rebuild them, then rebuild the
10836 // templateid expression.
10837 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010838 if (Old->hasExplicitTemplateArgs() &&
10839 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010840 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010841 TransArgs)) {
10842 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010843 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010844 }
John McCalle66edc12009-11-24 19:00:30 +000010845
Abramo Bagnara7945c982012-01-27 09:46:47 +000010846 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010847 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010848}
Mike Stump11289f42009-09-09 15:08:12 +000010849
Douglas Gregora16548e2009-08-11 05:31:07 +000010850template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010851ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010852TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10853 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010854 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010855 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10856 TypeSourceInfo *From = E->getArg(I);
10857 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010858 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010859 TypeLocBuilder TLB;
10860 TLB.reserve(FromTL.getFullDataSize());
10861 QualType To = getDerived().TransformType(TLB, FromTL);
10862 if (To.isNull())
10863 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010864
Douglas Gregor29c42f22012-02-24 07:38:34 +000010865 if (To == From->getType())
10866 Args.push_back(From);
10867 else {
10868 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10869 ArgChanged = true;
10870 }
10871 continue;
10872 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010873
Douglas Gregor29c42f22012-02-24 07:38:34 +000010874 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010875
Douglas Gregor29c42f22012-02-24 07:38:34 +000010876 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010877 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010878 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10879 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10880 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010881
Douglas Gregor29c42f22012-02-24 07:38:34 +000010882 // Determine whether the set of unexpanded parameter packs can and should
10883 // be expanded.
10884 bool Expand = true;
10885 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010886 Optional<unsigned> OrigNumExpansions =
10887 ExpansionTL.getTypePtr()->getNumExpansions();
10888 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010889 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10890 PatternTL.getSourceRange(),
10891 Unexpanded,
10892 Expand, RetainExpansion,
10893 NumExpansions))
10894 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010895
Douglas Gregor29c42f22012-02-24 07:38:34 +000010896 if (!Expand) {
10897 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010898 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010899 // expansion.
10900 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010901
Douglas Gregor29c42f22012-02-24 07:38:34 +000010902 TypeLocBuilder TLB;
10903 TLB.reserve(From->getTypeLoc().getFullDataSize());
10904
10905 QualType To = getDerived().TransformType(TLB, PatternTL);
10906 if (To.isNull())
10907 return ExprError();
10908
Chad Rosier1dcde962012-08-08 18:46:20 +000010909 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010910 PatternTL.getSourceRange(),
10911 ExpansionTL.getEllipsisLoc(),
10912 NumExpansions);
10913 if (To.isNull())
10914 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010915
Douglas Gregor29c42f22012-02-24 07:38:34 +000010916 PackExpansionTypeLoc ToExpansionTL
10917 = TLB.push<PackExpansionTypeLoc>(To);
10918 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10919 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10920 continue;
10921 }
10922
10923 // Expand the pack expansion by substituting for each argument in the
10924 // pack(s).
10925 for (unsigned I = 0; I != *NumExpansions; ++I) {
10926 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10927 TypeLocBuilder TLB;
10928 TLB.reserve(PatternTL.getFullDataSize());
10929 QualType To = getDerived().TransformType(TLB, PatternTL);
10930 if (To.isNull())
10931 return ExprError();
10932
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010933 if (To->containsUnexpandedParameterPack()) {
10934 To = getDerived().RebuildPackExpansionType(To,
10935 PatternTL.getSourceRange(),
10936 ExpansionTL.getEllipsisLoc(),
10937 NumExpansions);
10938 if (To.isNull())
10939 return ExprError();
10940
10941 PackExpansionTypeLoc ToExpansionTL
10942 = TLB.push<PackExpansionTypeLoc>(To);
10943 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10944 }
10945
Douglas Gregor29c42f22012-02-24 07:38:34 +000010946 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10947 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010948
Douglas Gregor29c42f22012-02-24 07:38:34 +000010949 if (!RetainExpansion)
10950 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010951
Douglas Gregor29c42f22012-02-24 07:38:34 +000010952 // If we're supposed to retain a pack expansion, do so by temporarily
10953 // forgetting the partially-substituted parameter pack.
10954 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10955
10956 TypeLocBuilder TLB;
10957 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010958
Douglas Gregor29c42f22012-02-24 07:38:34 +000010959 QualType To = getDerived().TransformType(TLB, PatternTL);
10960 if (To.isNull())
10961 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010962
10963 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010964 PatternTL.getSourceRange(),
10965 ExpansionTL.getEllipsisLoc(),
10966 NumExpansions);
10967 if (To.isNull())
10968 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010969
Douglas Gregor29c42f22012-02-24 07:38:34 +000010970 PackExpansionTypeLoc ToExpansionTL
10971 = TLB.push<PackExpansionTypeLoc>(To);
10972 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10973 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10974 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010975
Douglas Gregor29c42f22012-02-24 07:38:34 +000010976 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010977 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010978
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010979 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010980 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010981}
10982
10983template<typename Derived>
10984ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010985TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10986 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10987 if (!T)
10988 return ExprError();
10989
10990 if (!getDerived().AlwaysRebuild() &&
10991 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010992 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010993
10994 ExprResult SubExpr;
10995 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010996 EnterExpressionEvaluationContext Unevaluated(
10997 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010998 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10999 if (SubExpr.isInvalid())
11000 return ExprError();
11001
11002 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011003 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000011004 }
11005
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011006 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011007 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000011008}
11009
11010template<typename Derived>
11011ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000011012TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
11013 ExprResult SubExpr;
11014 {
Faisal Valid143a0c2017-04-01 21:30:49 +000011015 EnterExpressionEvaluationContext Unevaluated(
11016 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000011017 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
11018 if (SubExpr.isInvalid())
11019 return ExprError();
11020
11021 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011022 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000011023 }
11024
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011025 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011026 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000011027}
11028
Reid Kleckner32506ed2014-06-12 23:03:48 +000011029template <typename Derived>
11030ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
11031 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
11032 TypeSourceInfo **RecoveryTSI) {
11033 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
11034 DRE, AddrTaken, RecoveryTSI);
11035
11036 // Propagate both errors and recovered types, which return ExprEmpty.
11037 if (!NewDRE.isUsable())
11038 return NewDRE;
11039
11040 // We got an expr, wrap it up in parens.
11041 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
11042 return PE;
11043 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
11044 PE->getRParen());
11045}
11046
11047template <typename Derived>
11048ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11049 DependentScopeDeclRefExpr *E) {
11050 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
11051 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000011052}
11053
11054template<typename Derived>
11055ExprResult
11056TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
11057 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000011058 bool IsAddressOfOperand,
11059 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000011060 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011061 NestedNameSpecifierLoc QualifierLoc
11062 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11063 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011064 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000011065 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000011066
John McCall31f82722010-11-12 08:19:04 +000011067 // TODO: If this is a conversion-function-id, verify that the
11068 // destination type name (if present) resolves the same way after
11069 // instantiation as it did in the local scope.
11070
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011071 DeclarationNameInfo NameInfo
11072 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
11073 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011075
John McCalle66edc12009-11-24 19:00:30 +000011076 if (!E->hasExplicitTemplateArgs()) {
11077 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000011078 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011079 // Note: it is sufficient to compare the Name component of NameInfo:
11080 // if name has not changed, DNLoc has not changed either.
11081 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011082 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011083
Reid Kleckner32506ed2014-06-12 23:03:48 +000011084 return getDerived().RebuildDependentScopeDeclRefExpr(
11085 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
11086 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000011087 }
John McCall6b51f282009-11-23 01:53:49 +000011088
11089 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011090 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11091 E->getNumTemplateArgs(),
11092 TransArgs))
11093 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011094
Reid Kleckner32506ed2014-06-12 23:03:48 +000011095 return getDerived().RebuildDependentScopeDeclRefExpr(
11096 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
11097 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000011098}
11099
11100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011102TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000011103 // CXXConstructExprs other than for list-initialization and
11104 // CXXTemporaryObjectExpr are always implicit, so when we have
11105 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000011106 if ((E->getNumArgs() == 1 ||
11107 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000011108 (!getDerived().DropCallArgument(E->getArg(0))) &&
11109 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000011110 return getDerived().TransformExpr(E->getArg(0));
11111
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011112 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000011113
11114 QualType T = getDerived().TransformType(E->getType());
11115 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000011116 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000011117
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011118 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11119 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011120 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011122
Douglas Gregora16548e2009-08-11 05:31:07 +000011123 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011124 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000011125 {
11126 EnterExpressionEvaluationContext Context(
11127 getSema(), EnterExpressionEvaluationContext::InitList,
11128 E->isListInitialization());
11129 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11130 &ArgumentChanged))
11131 return ExprError();
11132 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011133
Douglas Gregora16548e2009-08-11 05:31:07 +000011134 if (!getDerived().AlwaysRebuild() &&
11135 T == E->getType() &&
11136 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000011137 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000011138 // Mark the constructor as referenced.
11139 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011140 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011141 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000011142 }
Mike Stump11289f42009-09-09 15:08:12 +000011143
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011144 return getDerived().RebuildCXXConstructExpr(
11145 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
11146 E->hadMultipleCandidates(), E->isListInitialization(),
11147 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
11148 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000011149}
Mike Stump11289f42009-09-09 15:08:12 +000011150
Richard Smith5179eb72016-06-28 19:03:57 +000011151template<typename Derived>
11152ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
11153 CXXInheritedCtorInitExpr *E) {
11154 QualType T = getDerived().TransformType(E->getType());
11155 if (T.isNull())
11156 return ExprError();
11157
11158 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011159 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000011160 if (!Constructor)
11161 return ExprError();
11162
11163 if (!getDerived().AlwaysRebuild() &&
11164 T == E->getType() &&
11165 Constructor == E->getConstructor()) {
11166 // Mark the constructor as referenced.
11167 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011168 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000011169 return E;
11170 }
11171
11172 return getDerived().RebuildCXXInheritedCtorInitExpr(
11173 T, E->getLocation(), Constructor,
11174 E->constructsVBase(), E->inheritedFromVBase());
11175}
11176
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011177/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000011178///
Douglas Gregor363b1512009-12-24 18:51:59 +000011179/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
11180/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011183TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011184 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011185}
Mike Stump11289f42009-09-09 15:08:12 +000011186
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000011187/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000011188/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000011189///
John McCall5d413782010-12-06 08:20:24 +000011190/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000011191/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000011192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011193ExprResult
John McCall5d413782010-12-06 08:20:24 +000011194TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000011195 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000011196}
Mike Stump11289f42009-09-09 15:08:12 +000011197
Douglas Gregora16548e2009-08-11 05:31:07 +000011198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011199ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011200TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000011201 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011202 TypeSourceInfo *T =
11203 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011204 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011206
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011207 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
11208 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000011209 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000011210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011211
Douglas Gregora16548e2009-08-11 05:31:07 +000011212 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011213 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000011214 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000011215 {
11216 EnterExpressionEvaluationContext Context(
11217 getSema(), EnterExpressionEvaluationContext::InitList,
11218 E->isListInitialization());
11219 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11220 &ArgumentChanged))
11221 return ExprError();
11222 }
Mike Stump11289f42009-09-09 15:08:12 +000011223
Douglas Gregora16548e2009-08-11 05:31:07 +000011224 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011225 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011226 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011227 !ArgumentChanged) {
11228 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011229 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000011230 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000011231 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011232
Vedant Kumara14a1f92018-01-17 18:53:51 +000011233 // FIXME: We should just pass E->isListInitialization(), but we're not
11234 // prepared to handle list-initialization without a child InitListExpr.
11235 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11236 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011237 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011238 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011239}
Mike Stump11289f42009-09-09 15:08:12 +000011240
Douglas Gregora16548e2009-08-11 05:31:07 +000011241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011242ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011243TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011244 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011245 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011246 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Richard Smithb2997f52019-05-21 20:10:50 +000011247 struct TransformedInitCapture {
11248 // The location of the ... if the result is retaining a pack expansion.
11249 SourceLocation EllipsisLoc;
11250 // Zero or more expansions of the init-capture.
11251 SmallVector<InitCaptureInfoTy, 4> Expansions;
11252 };
11253 SmallVector<TransformedInitCapture, 4> InitCaptures;
11254 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011255 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011256 CEnd = E->capture_end();
11257 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011258 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011259 continue;
Richard Smith01014ce2014-11-20 23:53:14 +000011260
Richard Smithb2997f52019-05-21 20:10:50 +000011261 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011262 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011263
11264 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
11265 Optional<unsigned> NumExpansions) {
Richard Smithb2997f52019-05-21 20:10:50 +000011266 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11267 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
11268
11269 if (NewExprInitResult.isInvalid()) {
11270 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
11271 return;
11272 }
11273 Expr *NewExprInit = NewExprInitResult.get();
11274
11275 QualType NewInitCaptureType =
11276 getSema().buildLambdaInitCaptureInitialization(
11277 C->getLocation(), OldVD->getType()->isReferenceType(),
11278 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
11279 C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
11280 NewExprInit);
11281 Result.Expansions.push_back(
11282 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
11283 };
11284
11285 // If this is an init-capture pack, consider expanding the pack now.
11286 if (OldVD->isParameterPack()) {
11287 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
11288 ->getTypeLoc()
11289 .castAs<PackExpansionTypeLoc>();
11290 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11291 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
11292
11293 // Determine whether the set of unexpanded parameter packs can and should
11294 // be expanded.
11295 bool Expand = true;
11296 bool RetainExpansion = false;
11297 Optional<unsigned> OrigNumExpansions =
11298 ExpansionTL.getTypePtr()->getNumExpansions();
11299 Optional<unsigned> NumExpansions = OrigNumExpansions;
11300 if (getDerived().TryExpandParameterPacks(
11301 ExpansionTL.getEllipsisLoc(),
11302 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
11303 RetainExpansion, NumExpansions))
11304 return ExprError();
11305 if (Expand) {
11306 for (unsigned I = 0; I != *NumExpansions; ++I) {
11307 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11308 SubstInitCapture(SourceLocation(), None);
11309 }
11310 }
11311 if (!Expand || RetainExpansion) {
11312 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11313 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
11314 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
11315 }
11316 } else {
11317 SubstInitCapture(SourceLocation(), None);
11318 }
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011319 }
11320
Faisal Vali2cba1332013-10-23 06:44:28 +000011321 // Transform the template parameters, and add them to the current
11322 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011323 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011324 E->getTemplateParameterList());
11325
Richard Smith01014ce2014-11-20 23:53:14 +000011326 // Transform the type of the original lambda's call operator.
11327 // The transformation MUST be done in the CurrentInstantiationScope since
11328 // it introduces a mapping of the original to the newly created
11329 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011330 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011331 {
11332 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011333 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011334 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011335
11336 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011337 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011338 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011339 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011340 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011341 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11342 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11343 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011344 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011345 if (NewCallOpType.isNull())
11346 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011347 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11348 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011349 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011350
Richard Smithc38498f2015-04-27 21:27:54 +000011351 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11352 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11353 LSI->GLTemplateParameterList = TPL;
11354
Eli Friedmand564afb2012-09-19 01:18:11 +000011355 // Create the local class that will describe the lambda.
Richard Smith87346a12019-06-02 18:53:44 +000011356 CXXRecordDecl *OldClass = E->getLambdaClass();
Eli Friedmand564afb2012-09-19 01:18:11 +000011357 CXXRecordDecl *Class
11358 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011359 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011360 /*KnownDependent=*/false,
11361 E->getCaptureDefault());
Richard Smith87346a12019-06-02 18:53:44 +000011362 getDerived().transformedLocalDecl(OldClass, {Class});
11363
11364 Optional<std::pair<unsigned, Decl*>> Mangling;
11365 if (getDerived().ReplacingOriginal())
11366 Mangling = std::make_pair(OldClass->getLambdaManglingNumber(),
11367 OldClass->getLambdaContextDecl());
Eli Friedmand564afb2012-09-19 01:18:11 +000011368
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011369 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011370 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11371 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011372 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011373 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
Gauthier Harnisch796ed032019-06-14 08:56:20 +000011374 E->getCallOperator()->getConstexprKind(), Mangling);
Faisal Valia734ab92016-03-26 16:11:37 +000011375
Faisal Vali2cba1332013-10-23 06:44:28 +000011376 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011377
Akira Hatanaka402818462016-12-16 21:16:57 +000011378 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11379 I != NumParams; ++I) {
11380 auto *P = NewCallOperator->getParamDecl(I);
11381 if (P->hasUninstantiatedDefaultArg()) {
11382 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011383 getSema(),
11384 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011385 ExprResult R = getDerived().TransformExpr(
11386 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11387 P->setDefaultArg(R.get());
11388 }
11389 }
11390
Faisal Vali2cba1332013-10-23 06:44:28 +000011391 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithb2997f52019-05-21 20:10:50 +000011392 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
Richard Smithba71c082013-05-16 06:20:58 +000011393
Douglas Gregorb4328232012-02-14 00:00:48 +000011394 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011395 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011396 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011397
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011398 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011399 getSema().buildLambdaScope(LSI, NewCallOperator,
11400 E->getIntroducerRange(),
11401 E->getCaptureDefault(),
11402 E->getCaptureDefaultLoc(),
11403 E->hasExplicitParameters(),
11404 E->hasExplicitResultType(),
11405 E->isMutable());
11406
11407 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011408
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011409 // Transform captures.
Chad Rosier1dcde962012-08-08 18:46:20 +000011410 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011411 CEnd = E->capture_end();
11412 C != CEnd; ++C) {
11413 // When we hit the first implicit capture, tell Sema that we've finished
11414 // the list of explicit captures.
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011415 if (C->isImplicit())
11416 break;
Chad Rosier1dcde962012-08-08 18:46:20 +000011417
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011418 // Capturing 'this' is trivial.
11419 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011420 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11421 /*BuildAndDiagnose*/ true, nullptr,
11422 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011423 continue;
11424 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011425 // Captured expression will be recaptured during captured variables
11426 // rebuilding.
11427 if (C->capturesVLAType())
11428 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011429
Richard Smithba71c082013-05-16 06:20:58 +000011430 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011431 if (E->isInitCapture(C)) {
Richard Smithb2997f52019-05-21 20:10:50 +000011432 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
11433
Richard Smithbb13c9a2013-09-28 04:02:39 +000011434 VarDecl *OldVD = C->getCapturedVar();
Richard Smithb2997f52019-05-21 20:10:50 +000011435 llvm::SmallVector<Decl*, 4> NewVDs;
11436
11437 for (InitCaptureInfoTy &Info : NewC.Expansions) {
11438 ExprResult Init = Info.first;
11439 QualType InitQualType = Info.second;
11440 if (Init.isInvalid() || InitQualType.isNull()) {
11441 Invalid = true;
11442 break;
11443 }
11444 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
11445 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
11446 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
11447 if (!NewVD) {
11448 Invalid = true;
11449 break;
11450 }
11451 NewVDs.push_back(NewVD);
Richard Smith30116532019-05-28 23:09:46 +000011452 getSema().addInitCapture(LSI, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011453 }
Richard Smithb2997f52019-05-21 20:10:50 +000011454
11455 if (Invalid)
11456 break;
11457
11458 getDerived().transformedLocalDecl(OldVD, NewVDs);
Richard Smithba71c082013-05-16 06:20:58 +000011459 continue;
11460 }
11461
11462 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11463
Douglas Gregor3e308b12012-02-14 19:27:52 +000011464 // Determine the capture kind for Sema.
11465 Sema::TryCaptureKind Kind
11466 = C->isImplicit()? Sema::TryCapture_Implicit
11467 : C->getCaptureKind() == LCK_ByCopy
11468 ? Sema::TryCapture_ExplicitByVal
11469 : Sema::TryCapture_ExplicitByRef;
11470 SourceLocation EllipsisLoc;
11471 if (C->isPackExpansion()) {
11472 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11473 bool ShouldExpand = false;
11474 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011475 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011476 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11477 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011478 Unexpanded,
11479 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011480 NumExpansions)) {
11481 Invalid = true;
11482 continue;
11483 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011484
Douglas Gregor3e308b12012-02-14 19:27:52 +000011485 if (ShouldExpand) {
11486 // The transform has determined that we should perform an expansion;
11487 // transform and capture each of the arguments.
11488 // expansion of the pattern. Do so.
11489 VarDecl *Pack = C->getCapturedVar();
11490 for (unsigned I = 0; I != *NumExpansions; ++I) {
11491 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11492 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011493 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011494 Pack));
11495 if (!CapturedVar) {
11496 Invalid = true;
11497 continue;
11498 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011499
Douglas Gregor3e308b12012-02-14 19:27:52 +000011500 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011501 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11502 }
Richard Smith9467be42014-06-06 17:33:35 +000011503
11504 // FIXME: Retain a pack expansion if RetainExpansion is true.
11505
Douglas Gregor3e308b12012-02-14 19:27:52 +000011506 continue;
11507 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011508
Douglas Gregor3e308b12012-02-14 19:27:52 +000011509 EllipsisLoc = C->getEllipsisLoc();
11510 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011511
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011512 // Transform the captured variable.
11513 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011514 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011515 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011516 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011517 Invalid = true;
11518 continue;
11519 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011520
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011521 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011522 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11523 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011524 }
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011525 getSema().finishLambdaExplicitCaptures(LSI);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011526
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011527 // FIXME: Sema's lambda-building mechanism expects us to push an expression
11528 // evaluation context even if we're not transforming the function body.
Faisal Valid143a0c2017-04-01 21:30:49 +000011529 getSema().PushExpressionEvaluationContext(
11530 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011531
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011532 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011533 StmtResult Body =
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011534 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
Richard Smithc38498f2015-04-27 21:27:54 +000011535
11536 // ActOnLambda* will pop the function scope for us.
11537 FuncScopeCleanup.disable();
11538
Douglas Gregorb4328232012-02-14 00:00:48 +000011539 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011540 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011541 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011542 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011543 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011544 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011545
Richard Smithc38498f2015-04-27 21:27:54 +000011546 // Copy the LSI before ActOnFinishFunctionBody removes it.
11547 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11548 // the call operator.
11549 auto LSICopy = *LSI;
11550 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11551 /*IsInstantiation*/ true);
11552 SavedContext.pop();
11553
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011554 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011555 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011556}
11557
11558template<typename Derived>
Richard Smith87346a12019-06-02 18:53:44 +000011559StmtResult
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011560TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
Richard Smith87346a12019-06-02 18:53:44 +000011561 return TransformStmt(S);
11562}
11563
11564template<typename Derived>
Richard Smith7bf8f6f2019-06-04 17:17:20 +000011565StmtResult
11566TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) {
11567 // Transform captures.
11568 for (LambdaExpr::capture_iterator C = E->capture_begin(),
11569 CEnd = E->capture_end();
11570 C != CEnd; ++C) {
11571 // When we hit the first implicit capture, tell Sema that we've finished
11572 // the list of explicit captures.
11573 if (!C->isImplicit())
11574 continue;
11575
11576 // Capturing 'this' is trivial.
11577 if (C->capturesThis()) {
11578 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11579 /*BuildAndDiagnose*/ true, nullptr,
11580 C->getCaptureKind() == LCK_StarThis);
11581 continue;
11582 }
11583 // Captured expression will be recaptured during captured variables
11584 // rebuilding.
11585 if (C->capturesVLAType())
11586 continue;
11587
11588 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11589 assert(!E->isInitCapture(C) && "implicit init-capture?");
11590
11591 // Transform the captured variable.
11592 VarDecl *CapturedVar = cast_or_null<VarDecl>(
11593 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
11594 if (!CapturedVar || CapturedVar->isInvalidDecl())
11595 return StmtError();
11596
11597 // Capture the transformed variable.
11598 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
11599 }
11600
11601 return S;
11602}
11603
11604template<typename Derived>
Douglas Gregore31e6062012-02-07 10:09:13 +000011605ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011606TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011607 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011608 TypeSourceInfo *T =
11609 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011610 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011612
Douglas Gregora16548e2009-08-11 05:31:07 +000011613 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011614 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011615 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011616 {
11617 EnterExpressionEvaluationContext Context(
11618 getSema(), EnterExpressionEvaluationContext::InitList,
11619 E->isListInitialization());
11620 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11621 &ArgumentChanged))
11622 return ExprError();
11623 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011624
Douglas Gregora16548e2009-08-11 05:31:07 +000011625 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011626 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011627 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011628 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011629
Douglas Gregora16548e2009-08-11 05:31:07 +000011630 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011631 return getDerived().RebuildCXXUnresolvedConstructExpr(
11632 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011633}
Mike Stump11289f42009-09-09 15:08:12 +000011634
Douglas Gregora16548e2009-08-11 05:31:07 +000011635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011636ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011637TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011638 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011639 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011640 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011641 Expr *OldBase;
11642 QualType BaseType;
11643 QualType ObjectType;
11644 if (!E->isImplicitAccess()) {
11645 OldBase = E->getBase();
11646 Base = getDerived().TransformExpr(OldBase);
11647 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011649
John McCall2d74de92009-12-01 22:10:20 +000011650 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011651 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011652 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011653 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011654 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011655 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011656 ObjectTy,
11657 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011658 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011659 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011660
John McCallba7bf592010-08-24 05:47:05 +000011661 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011662 BaseType = ((Expr*) Base.get())->getType();
11663 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011664 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011665 BaseType = getDerived().TransformType(E->getBaseType());
11666 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11667 }
Mike Stump11289f42009-09-09 15:08:12 +000011668
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011669 // Transform the first part of the nested-name-specifier that qualifies
11670 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011671 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011672 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011673 E->getFirstQualifierFoundInScope(),
11674 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011675
Douglas Gregore16af532011-02-28 18:50:33 +000011676 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011677 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011678 QualifierLoc
11679 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11680 ObjectType,
11681 FirstQualifierInScope);
11682 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011683 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011684 }
Mike Stump11289f42009-09-09 15:08:12 +000011685
Abramo Bagnara7945c982012-01-27 09:46:47 +000011686 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11687
John McCall31f82722010-11-12 08:19:04 +000011688 // TODO: If this is a conversion-function-id, verify that the
11689 // destination type name (if present) resolves the same way after
11690 // instantiation as it did in the local scope.
11691
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011692 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011693 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011694 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011696
John McCall2d74de92009-12-01 22:10:20 +000011697 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011698 // This is a reference to a member without an explicitly-specified
11699 // template argument list. Optimize for this common case.
11700 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011701 Base.get() == OldBase &&
11702 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011703 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011704 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011705 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011706 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011707
John McCallb268a282010-08-23 23:25:46 +000011708 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011709 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011710 E->isArrow(),
11711 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011712 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011713 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011714 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011715 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011716 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011717 }
11718
John McCall6b51f282009-11-23 01:53:49 +000011719 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011720 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11721 E->getNumTemplateArgs(),
11722 TransArgs))
11723 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011724
John McCallb268a282010-08-23 23:25:46 +000011725 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011726 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011727 E->isArrow(),
11728 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011729 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011730 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011731 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011732 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011733 &TransArgs);
11734}
11735
11736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011738TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011739 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011740 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011741 QualType BaseType;
11742 if (!Old->isImplicitAccess()) {
11743 Base = getDerived().TransformExpr(Old->getBase());
11744 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011745 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011746 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011747 Old->isArrow());
11748 if (Base.isInvalid())
11749 return ExprError();
11750 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011751 } else {
11752 BaseType = getDerived().TransformType(Old->getBaseType());
11753 }
John McCall10eae182009-11-30 22:42:35 +000011754
Douglas Gregor0da1d432011-02-28 20:01:57 +000011755 NestedNameSpecifierLoc QualifierLoc;
11756 if (Old->getQualifierLoc()) {
11757 QualifierLoc
11758 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11759 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011760 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011761 }
11762
Abramo Bagnara7945c982012-01-27 09:46:47 +000011763 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11764
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011765 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011766 Sema::LookupOrdinaryName);
11767
Richard Smith151c4562016-12-20 21:35:28 +000011768 // Transform the declaration set.
11769 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11770 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011771
Douglas Gregor9262f472010-04-27 18:19:34 +000011772 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011773 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011774 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011775 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011776 Old->getMemberLoc(),
11777 Old->getNamingClass()));
11778 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011779 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011780
Douglas Gregorda7be082010-04-27 16:10:10 +000011781 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011782 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011783
John McCall10eae182009-11-30 22:42:35 +000011784 TemplateArgumentListInfo TransArgs;
11785 if (Old->hasExplicitTemplateArgs()) {
11786 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11787 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011788 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11789 Old->getNumTemplateArgs(),
11790 TransArgs))
11791 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011792 }
John McCall38836f02010-01-15 08:34:02 +000011793
11794 // FIXME: to do this check properly, we will need to preserve the
11795 // first-qualifier-in-scope here, just in case we had a dependent
11796 // base (and therefore couldn't do the check) and a
11797 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011798 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011799
John McCallb268a282010-08-23 23:25:46 +000011800 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011801 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011802 Old->getOperatorLoc(),
11803 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011804 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011805 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011806 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011807 R,
11808 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011809 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011810}
11811
11812template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011813ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011814TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011815 EnterExpressionEvaluationContext Unevaluated(
11816 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011817 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11818 if (SubExpr.isInvalid())
11819 return ExprError();
11820
11821 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011822 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011823
11824 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11825}
11826
11827template<typename Derived>
11828ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011829TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011830 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11831 if (Pattern.isInvalid())
11832 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011833
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011834 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011835 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011836
Douglas Gregorb8840002011-01-14 21:20:45 +000011837 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11838 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011839}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011840
11841template<typename Derived>
11842ExprResult
11843TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11844 // If E is not value-dependent, then nothing will change when we transform it.
11845 // Note: This is an instantiation-centric view.
11846 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011847 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011848
Faisal Valid143a0c2017-04-01 21:30:49 +000011849 EnterExpressionEvaluationContext Unevaluated(
11850 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011851
Richard Smithd784e682015-09-23 21:41:42 +000011852 ArrayRef<TemplateArgument> PackArgs;
11853 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011854
Richard Smithd784e682015-09-23 21:41:42 +000011855 // Find the argument list to transform.
11856 if (E->isPartiallySubstituted()) {
11857 PackArgs = E->getPartialArguments();
11858 } else if (E->isValueDependent()) {
11859 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11860 bool ShouldExpand = false;
11861 bool RetainExpansion = false;
11862 Optional<unsigned> NumExpansions;
11863 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11864 Unexpanded,
11865 ShouldExpand, RetainExpansion,
11866 NumExpansions))
11867 return ExprError();
11868
11869 // If we need to expand the pack, build a template argument from it and
11870 // expand that.
11871 if (ShouldExpand) {
11872 auto *Pack = E->getPack();
11873 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11874 ArgStorage = getSema().Context.getPackExpansionType(
11875 getSema().Context.getTypeDeclType(TTPD), None);
11876 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11877 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11878 } else {
11879 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011880 ExprResult DRE = getSema().BuildDeclRefExpr(
11881 VD, VD->getType().getNonLValueExprType(getSema().Context),
11882 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11883 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011884 if (DRE.isInvalid())
11885 return ExprError();
11886 ArgStorage = new (getSema().Context) PackExpansionExpr(
11887 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11888 }
11889 PackArgs = ArgStorage;
11890 }
11891 }
11892
11893 // If we're not expanding the pack, just transform the decl.
11894 if (!PackArgs.size()) {
11895 auto *Pack = cast_or_null<NamedDecl>(
11896 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011897 if (!Pack)
11898 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011899 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11900 E->getPackLoc(),
11901 E->getRParenLoc(), None, None);
11902 }
11903
Richard Smithc5452ed2016-10-19 22:18:42 +000011904 // Try to compute the result without performing a partial substitution.
11905 Optional<unsigned> Result = 0;
11906 for (const TemplateArgument &Arg : PackArgs) {
11907 if (!Arg.isPackExpansion()) {
11908 Result = *Result + 1;
11909 continue;
11910 }
11911
11912 TemplateArgumentLoc ArgLoc;
11913 InventTemplateArgumentLoc(Arg, ArgLoc);
11914
11915 // Find the pattern of the pack expansion.
11916 SourceLocation Ellipsis;
11917 Optional<unsigned> OrigNumExpansions;
11918 TemplateArgumentLoc Pattern =
11919 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11920 OrigNumExpansions);
11921
11922 // Substitute under the pack expansion. Do not expand the pack (yet).
11923 TemplateArgumentLoc OutPattern;
11924 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11925 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11926 /*Uneval*/ true))
11927 return true;
11928
11929 // See if we can determine the number of arguments from the result.
11930 Optional<unsigned> NumExpansions =
11931 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11932 if (!NumExpansions) {
11933 // No: we must be in an alias template expansion, and we're going to need
11934 // to actually expand the packs.
11935 Result = None;
11936 break;
11937 }
11938
11939 Result = *Result + *NumExpansions;
11940 }
11941
11942 // Common case: we could determine the number of expansions without
11943 // substituting.
11944 if (Result)
11945 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11946 E->getPackLoc(),
11947 E->getRParenLoc(), *Result, None);
11948
Richard Smithd784e682015-09-23 21:41:42 +000011949 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11950 E->getPackLoc());
11951 {
11952 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11953 typedef TemplateArgumentLocInventIterator<
11954 Derived, const TemplateArgument*> PackLocIterator;
11955 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11956 PackLocIterator(*this, PackArgs.end()),
11957 TransformedPackArgs, /*Uneval*/true))
11958 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011959 }
11960
Richard Smithc5452ed2016-10-19 22:18:42 +000011961 // Check whether we managed to fully-expand the pack.
11962 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011963 SmallVector<TemplateArgument, 8> Args;
11964 bool PartialSubstitution = false;
11965 for (auto &Loc : TransformedPackArgs.arguments()) {
11966 Args.push_back(Loc.getArgument());
11967 if (Loc.getArgument().isPackExpansion())
11968 PartialSubstitution = true;
11969 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011970
Richard Smithd784e682015-09-23 21:41:42 +000011971 if (PartialSubstitution)
11972 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11973 E->getPackLoc(),
11974 E->getRParenLoc(), None, Args);
11975
11976 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011977 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011978 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011979}
11980
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011981template<typename Derived>
11982ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011983TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11984 SubstNonTypeTemplateParmPackExpr *E) {
11985 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011986 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011987}
11988
11989template<typename Derived>
11990ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011991TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11992 SubstNonTypeTemplateParmExpr *E) {
11993 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011994 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011995}
11996
11997template<typename Derived>
11998ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011999TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
12000 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012001 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000012002}
12003
12004template<typename Derived>
12005ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000012006TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
12007 MaterializeTemporaryExpr *E) {
12008 return getDerived().TransformExpr(E->GetTemporaryExpr());
12009}
Chad Rosier1dcde962012-08-08 18:46:20 +000012010
Douglas Gregorfe314812011-06-21 17:03:29 +000012011template<typename Derived>
12012ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000012013TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
12014 Expr *Pattern = E->getPattern();
12015
12016 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
12018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12019
12020 // Determine whether the set of unexpanded parameter packs can and should
12021 // be expanded.
12022 bool Expand = true;
12023 bool RetainExpansion = false;
Richard Smithc7214f62019-05-13 08:31:14 +000012024 Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
12025 NumExpansions = OrigNumExpansions;
Richard Smith0f0af192014-11-08 05:07:16 +000012026 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
12027 Pattern->getSourceRange(),
12028 Unexpanded,
12029 Expand, RetainExpansion,
12030 NumExpansions))
12031 return true;
12032
12033 if (!Expand) {
12034 // Do not expand any packs here, just transform and rebuild a fold
12035 // expression.
12036 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12037
12038 ExprResult LHS =
12039 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
12040 if (LHS.isInvalid())
12041 return true;
12042
12043 ExprResult RHS =
12044 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
12045 if (RHS.isInvalid())
12046 return true;
12047
12048 if (!getDerived().AlwaysRebuild() &&
12049 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
12050 return E;
12051
12052 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012053 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012054 RHS.get(), E->getEndLoc(), NumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012055 }
12056
12057 // The transform has determined that we should perform an elementwise
12058 // expansion of the pattern. Do so.
12059 ExprResult Result = getDerived().TransformExpr(E->getInit());
12060 if (Result.isInvalid())
12061 return true;
12062 bool LeftFold = E->isLeftFold();
12063
12064 // If we're retaining an expansion for a right fold, it is the innermost
12065 // component and takes the init (if any).
12066 if (!LeftFold && RetainExpansion) {
12067 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12068
12069 ExprResult Out = getDerived().TransformExpr(Pattern);
12070 if (Out.isInvalid())
12071 return true;
12072
12073 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012074 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012075 Result.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012076 if (Result.isInvalid())
12077 return true;
12078 }
12079
12080 for (unsigned I = 0; I != *NumExpansions; ++I) {
12081 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
12082 getSema(), LeftFold ? I : *NumExpansions - I - 1);
12083 ExprResult Out = getDerived().TransformExpr(Pattern);
12084 if (Out.isInvalid())
12085 return true;
12086
12087 if (Out.get()->containsUnexpandedParameterPack()) {
12088 // We still have a pack; retain a pack expansion for this slice.
12089 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012090 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000012091 E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012092 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
12093 OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012094 } else if (Result.isUsable()) {
12095 // We've got down to a single element; build a binary operator.
12096 Result = getDerived().RebuildBinaryOperator(
12097 E->getEllipsisLoc(), E->getOperator(),
12098 LeftFold ? Result.get() : Out.get(),
12099 LeftFold ? Out.get() : Result.get());
12100 } else
12101 Result = Out;
12102
12103 if (Result.isInvalid())
12104 return true;
12105 }
12106
12107 // If we're retaining an expansion for a left fold, it is the outermost
12108 // component and takes the complete expansion so far as its init (if any).
12109 if (LeftFold && RetainExpansion) {
12110 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
12111
12112 ExprResult Out = getDerived().TransformExpr(Pattern);
12113 if (Out.isInvalid())
12114 return true;
12115
12116 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012117 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Richard Smithc7214f62019-05-13 08:31:14 +000012118 Out.get(), E->getEndLoc(), OrigNumExpansions);
Richard Smith0f0af192014-11-08 05:07:16 +000012119 if (Result.isInvalid())
12120 return true;
12121 }
12122
12123 // If we had no init and an empty pack, and we're not retaining an expansion,
12124 // then produce a fallback value or error.
12125 if (Result.isUnset())
12126 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
12127 E->getOperator());
12128
12129 return Result;
12130}
12131
12132template<typename Derived>
12133ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000012134TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
12135 CXXStdInitializerListExpr *E) {
12136 return getDerived().TransformExpr(E->getSubExpr());
12137}
12138
12139template<typename Derived>
12140ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012141TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012142 return SemaRef.MaybeBindToTemporary(E);
12143}
12144
12145template<typename Derived>
12146ExprResult
12147TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012148 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012149}
12150
12151template<typename Derived>
12152ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000012153TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
12154 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12155 if (SubExpr.isInvalid())
12156 return ExprError();
12157
12158 if (!getDerived().AlwaysRebuild() &&
12159 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012160 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000012161
12162 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000012163}
12164
12165template<typename Derived>
12166ExprResult
12167TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
12168 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012169 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012170 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000012171 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012172 /*IsCall=*/false, Elements, &ArgChanged))
12173 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012174
Ted Kremeneke65b0862012-03-06 20:05:56 +000012175 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12176 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012177
Ted Kremeneke65b0862012-03-06 20:05:56 +000012178 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
12179 Elements.data(),
12180 Elements.size());
12181}
12182
12183template<typename Derived>
12184ExprResult
12185TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000012186 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012187 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000012188 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012189 bool ArgChanged = false;
12190 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
12191 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000012192
Ted Kremeneke65b0862012-03-06 20:05:56 +000012193 if (OrigElement.isPackExpansion()) {
12194 // This key/value element is a pack expansion.
12195 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
12196 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
12197 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
12198 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
12199
12200 // Determine whether the set of unexpanded parameter packs can
12201 // and should be expanded.
12202 bool Expand = true;
12203 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000012204 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
12205 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012206 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000012207 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012208 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
12209 PatternRange, Unexpanded, Expand,
12210 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000012211 return ExprError();
12212
12213 if (!Expand) {
12214 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000012215 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000012216 // expansion.
12217 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
12218 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12219 if (Key.isInvalid())
12220 return ExprError();
12221
12222 if (Key.get() != OrigElement.Key)
12223 ArgChanged = true;
12224
12225 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12226 if (Value.isInvalid())
12227 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012228
Ted Kremeneke65b0862012-03-06 20:05:56 +000012229 if (Value.get() != OrigElement.Value)
12230 ArgChanged = true;
12231
Chad Rosier1dcde962012-08-08 18:46:20 +000012232 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012233 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
12234 };
12235 Elements.push_back(Expansion);
12236 continue;
12237 }
12238
12239 // Record right away that the argument was changed. This needs
12240 // to happen even if the array expands to nothing.
12241 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012242
Ted Kremeneke65b0862012-03-06 20:05:56 +000012243 // The transform has determined that we should perform an elementwise
12244 // expansion of the pattern. Do so.
12245 for (unsigned I = 0; I != *NumExpansions; ++I) {
12246 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
12247 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12248 if (Key.isInvalid())
12249 return ExprError();
12250
12251 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
12252 if (Value.isInvalid())
12253 return ExprError();
12254
Chad Rosier1dcde962012-08-08 18:46:20 +000012255 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000012256 Key.get(), Value.get(), SourceLocation(), NumExpansions
12257 };
12258
12259 // If any unexpanded parameter packs remain, we still have a
12260 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000012261 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000012262 if (Key.get()->containsUnexpandedParameterPack() ||
12263 Value.get()->containsUnexpandedParameterPack())
12264 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000012265
Ted Kremeneke65b0862012-03-06 20:05:56 +000012266 Elements.push_back(Element);
12267 }
12268
Richard Smith9467be42014-06-06 17:33:35 +000012269 // FIXME: Retain a pack expansion if RetainExpansion is true.
12270
Ted Kremeneke65b0862012-03-06 20:05:56 +000012271 // We've finished with this pack expansion.
12272 continue;
12273 }
12274
12275 // Transform and check key.
12276 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
12277 if (Key.isInvalid())
12278 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012279
Ted Kremeneke65b0862012-03-06 20:05:56 +000012280 if (Key.get() != OrigElement.Key)
12281 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012282
Ted Kremeneke65b0862012-03-06 20:05:56 +000012283 // Transform and check value.
12284 ExprResult Value
12285 = getDerived().TransformExpr(OrigElement.Value);
12286 if (Value.isInvalid())
12287 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012288
Ted Kremeneke65b0862012-03-06 20:05:56 +000012289 if (Value.get() != OrigElement.Value)
12290 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000012291
12292 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000012293 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000012294 };
12295 Elements.push_back(Element);
12296 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012297
Ted Kremeneke65b0862012-03-06 20:05:56 +000012298 if (!getDerived().AlwaysRebuild() && !ArgChanged)
12299 return SemaRef.MaybeBindToTemporary(E);
12300
12301 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000012302 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000012303}
12304
Mike Stump11289f42009-09-09 15:08:12 +000012305template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012306ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012307TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000012308 TypeSourceInfo *EncodedTypeInfo
12309 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
12310 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012312
Douglas Gregora16548e2009-08-11 05:31:07 +000012313 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000012314 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012315 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012316
12317 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000012318 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000012319 E->getRParenLoc());
12320}
Mike Stump11289f42009-09-09 15:08:12 +000012321
Douglas Gregora16548e2009-08-11 05:31:07 +000012322template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000012323ExprResult TreeTransform<Derived>::
12324TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000012325 // This is a kind of implicit conversion, and it needs to get dropped
12326 // and recomputed for the same general reasons that ImplicitCastExprs
12327 // do, as well a more specific one: this expression is only valid when
12328 // it appears *immediately* as an argument expression.
12329 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000012330}
12331
12332template<typename Derived>
12333ExprResult TreeTransform<Derived>::
12334TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000012335 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000012336 = getDerived().TransformType(E->getTypeInfoAsWritten());
12337 if (!TSInfo)
12338 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012339
John McCall31168b02011-06-15 23:02:42 +000012340 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012341 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012342 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012343
John McCall31168b02011-06-15 23:02:42 +000012344 if (!getDerived().AlwaysRebuild() &&
12345 TSInfo == E->getTypeInfoAsWritten() &&
12346 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012347 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012348
John McCall31168b02011-06-15 23:02:42 +000012349 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012350 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012351 Result.get());
12352}
12353
Erik Pilkington29099de2016-07-16 00:35:23 +000012354template <typename Derived>
12355ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12356 ObjCAvailabilityCheckExpr *E) {
12357 return E;
12358}
12359
John McCall31168b02011-06-15 23:02:42 +000012360template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012361ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012362TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012363 // Transform arguments.
12364 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012365 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012366 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012367 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012368 &ArgChanged))
12369 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012370
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012371 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12372 // Class message: transform the receiver type.
12373 TypeSourceInfo *ReceiverTypeInfo
12374 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12375 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012376 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012377
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012378 // If nothing changed, just retain the existing message send.
12379 if (!getDerived().AlwaysRebuild() &&
12380 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012381 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012382
12383 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012384 SmallVector<SourceLocation, 16> SelLocs;
12385 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012386 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12387 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012388 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012389 E->getMethodDecl(),
12390 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012391 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012392 E->getRightLoc());
12393 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012394 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12395 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012396 if (!E->getMethodDecl())
12397 return ExprError();
12398
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012399 // Build a new class message send to 'super'.
12400 SmallVector<SourceLocation, 16> SelLocs;
12401 E->getSelectorLocs(SelLocs);
12402 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12403 E->getSelector(),
12404 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012405 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012406 E->getMethodDecl(),
12407 E->getLeftLoc(),
12408 Args,
12409 E->getRightLoc());
12410 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012411
12412 // Instance message: transform the receiver
12413 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12414 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012415 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012416 = getDerived().TransformExpr(E->getInstanceReceiver());
12417 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012418 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012419
12420 // If nothing changed, just retain the existing message send.
12421 if (!getDerived().AlwaysRebuild() &&
12422 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012423 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012424
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012425 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012426 SmallVector<SourceLocation, 16> SelLocs;
12427 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012428 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012429 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012430 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012431 E->getMethodDecl(),
12432 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012433 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012434 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012435}
12436
Mike Stump11289f42009-09-09 15:08:12 +000012437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012438ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012439TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012440 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012441}
12442
Mike Stump11289f42009-09-09 15:08:12 +000012443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012444ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012445TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012446 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012447}
12448
Mike Stump11289f42009-09-09 15:08:12 +000012449template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012450ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012451TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012452 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012453 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012454 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012455 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012456
12457 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012458
Douglas Gregord51d90d2010-04-26 20:11:03 +000012459 // If nothing changed, just retain the existing expression.
12460 if (!getDerived().AlwaysRebuild() &&
12461 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012462 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012463
John McCallb268a282010-08-23 23:25:46 +000012464 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012465 E->getLocation(),
12466 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012467}
12468
Mike Stump11289f42009-09-09 15:08:12 +000012469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012470ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012471TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012472 // 'super' and types never change. Property never changes. Just
12473 // retain the existing expression.
12474 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012475 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012476
Douglas Gregor9faee212010-04-26 20:47:02 +000012477 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012478 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012479 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012480 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012481
Douglas Gregor9faee212010-04-26 20:47:02 +000012482 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012483
Douglas Gregor9faee212010-04-26 20:47:02 +000012484 // If nothing changed, just retain the existing expression.
12485 if (!getDerived().AlwaysRebuild() &&
12486 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012487 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012488
John McCallb7bd14f2010-12-02 01:19:52 +000012489 if (E->isExplicitProperty())
12490 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12491 E->getExplicitProperty(),
12492 E->getLocation());
12493
12494 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012495 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012496 E->getImplicitPropertyGetter(),
12497 E->getImplicitPropertySetter(),
12498 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012499}
12500
Mike Stump11289f42009-09-09 15:08:12 +000012501template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012502ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012503TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12504 // Transform the base expression.
12505 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12506 if (Base.isInvalid())
12507 return ExprError();
12508
12509 // Transform the key expression.
12510 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12511 if (Key.isInvalid())
12512 return ExprError();
12513
12514 // If nothing changed, just retain the existing expression.
12515 if (!getDerived().AlwaysRebuild() &&
12516 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012517 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012518
Chad Rosier1dcde962012-08-08 18:46:20 +000012519 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012520 Base.get(), Key.get(),
12521 E->getAtIndexMethodDecl(),
12522 E->setAtIndexMethodDecl());
12523}
12524
12525template<typename Derived>
12526ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012527TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012528 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012529 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012530 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012531 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012532
Douglas Gregord51d90d2010-04-26 20:11:03 +000012533 // If nothing changed, just retain the existing expression.
12534 if (!getDerived().AlwaysRebuild() &&
12535 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012536 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012537
John McCallb268a282010-08-23 23:25:46 +000012538 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012539 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012540 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012541}
12542
Mike Stump11289f42009-09-09 15:08:12 +000012543template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012544ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012545TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012546 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012547 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012548 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012549 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012550 SubExprs, &ArgumentChanged))
12551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012552
Douglas Gregora16548e2009-08-11 05:31:07 +000012553 if (!getDerived().AlwaysRebuild() &&
12554 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012555 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012556
Douglas Gregora16548e2009-08-11 05:31:07 +000012557 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012558 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012559 E->getRParenLoc());
12560}
12561
Mike Stump11289f42009-09-09 15:08:12 +000012562template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012563ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012564TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12565 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12566 if (SrcExpr.isInvalid())
12567 return ExprError();
12568
12569 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12570 if (!Type)
12571 return ExprError();
12572
12573 if (!getDerived().AlwaysRebuild() &&
12574 Type == E->getTypeSourceInfo() &&
12575 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012576 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012577
12578 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12579 SrcExpr.get(), Type,
12580 E->getRParenLoc());
12581}
12582
12583template<typename Derived>
12584ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012585TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012586 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012587
Craig Topperc3ec1492014-05-26 06:22:03 +000012588 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012589 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12590
12591 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012592 blockScope->TheDecl->setBlockMissingReturnType(
12593 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012594
Chris Lattner01cf8db2011-07-20 06:58:45 +000012595 SmallVector<ParmVarDecl*, 4> params;
12596 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012597
John McCallc8e321d2016-03-01 02:09:25 +000012598 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12599
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012600 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012601 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012602 if (getDerived().TransformFunctionTypeParams(
12603 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12604 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12605 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012606 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012607 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012608 }
John McCall490112f2011-02-04 18:33:18 +000012609
Eli Friedman34b49062012-01-26 03:00:14 +000012610 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012611 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012612
John McCallc8e321d2016-03-01 02:09:25 +000012613 auto epi = exprFunctionType->getExtProtoInfo();
12614 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12615
Jordan Rose5c382722013-03-08 21:51:21 +000012616 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012617 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012618 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012619
12620 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012621 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012622 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012623
12624 if (!oldBlock->blockMissingReturnType()) {
12625 blockScope->HasImplicitReturnType = false;
12626 blockScope->ReturnType = exprResultType;
12627 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012628
John McCall3882ace2011-01-05 12:14:39 +000012629 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012630 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012631 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012632 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012633 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012634 }
John McCall3882ace2011-01-05 12:14:39 +000012635
John McCall490112f2011-02-04 18:33:18 +000012636#ifndef NDEBUG
12637 // In builds with assertions, make sure that we captured everything we
12638 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012639 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012640 for (const auto &I : oldBlock->captures()) {
12641 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012642
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012643 // Ignore parameter packs.
Richard Smithb2997f52019-05-21 20:10:50 +000012644 if (oldCapture->isParameterPack())
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012645 continue;
John McCall490112f2011-02-04 18:33:18 +000012646
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012647 VarDecl *newCapture =
12648 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12649 oldCapture));
12650 assert(blockScope->CaptureMap.count(newCapture));
12651 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012652 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012653 }
12654#endif
12655
12656 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012657 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012658}
12659
Mike Stump11289f42009-09-09 15:08:12 +000012660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012661ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012662TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012663 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012664}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012665
12666template<typename Derived>
12667ExprResult
12668TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012669 QualType RetTy = getDerived().TransformType(E->getType());
12670 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012671 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012672 SubExprs.reserve(E->getNumSubExprs());
12673 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12674 SubExprs, &ArgumentChanged))
12675 return ExprError();
12676
12677 if (!getDerived().AlwaysRebuild() &&
12678 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012679 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012680
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012681 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012682 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012683}
Chad Rosier1dcde962012-08-08 18:46:20 +000012684
Douglas Gregora16548e2009-08-11 05:31:07 +000012685//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012686// Type reconstruction
12687//===----------------------------------------------------------------------===//
12688
Mike Stump11289f42009-09-09 15:08:12 +000012689template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012690QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12691 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012692 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012693 getDerived().getBaseEntity());
12694}
12695
Mike Stump11289f42009-09-09 15:08:12 +000012696template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012697QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12698 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012699 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012700 getDerived().getBaseEntity());
12701}
12702
Mike Stump11289f42009-09-09 15:08:12 +000012703template<typename Derived>
12704QualType
John McCall70dd5f62009-10-30 00:06:24 +000012705TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12706 bool WrittenAsLValue,
12707 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012708 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012709 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012710}
12711
12712template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012713QualType
John McCall70dd5f62009-10-30 00:06:24 +000012714TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12715 QualType ClassType,
12716 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012717 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12718 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012719}
12720
12721template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012722QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12723 const ObjCTypeParamDecl *Decl,
12724 SourceLocation ProtocolLAngleLoc,
12725 ArrayRef<ObjCProtocolDecl *> Protocols,
12726 ArrayRef<SourceLocation> ProtocolLocs,
12727 SourceLocation ProtocolRAngleLoc) {
12728 return SemaRef.BuildObjCTypeParamType(Decl,
12729 ProtocolLAngleLoc, Protocols,
12730 ProtocolLocs, ProtocolRAngleLoc,
12731 /*FailOnError=*/true);
12732}
12733
12734template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012735QualType TreeTransform<Derived>::RebuildObjCObjectType(
12736 QualType BaseType,
12737 SourceLocation Loc,
12738 SourceLocation TypeArgsLAngleLoc,
12739 ArrayRef<TypeSourceInfo *> TypeArgs,
12740 SourceLocation TypeArgsRAngleLoc,
12741 SourceLocation ProtocolLAngleLoc,
12742 ArrayRef<ObjCProtocolDecl *> Protocols,
12743 ArrayRef<SourceLocation> ProtocolLocs,
12744 SourceLocation ProtocolRAngleLoc) {
12745 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12746 TypeArgs, TypeArgsRAngleLoc,
12747 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12748 ProtocolRAngleLoc,
12749 /*FailOnError=*/true);
12750}
12751
12752template<typename Derived>
12753QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12754 QualType PointeeType,
12755 SourceLocation Star) {
12756 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12757}
12758
12759template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012760QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012761TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12762 ArrayType::ArraySizeModifier SizeMod,
12763 const llvm::APInt *Size,
12764 Expr *SizeExpr,
12765 unsigned IndexTypeQuals,
12766 SourceRange BracketsRange) {
12767 if (SizeExpr || !Size)
12768 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12769 IndexTypeQuals, BracketsRange,
12770 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012771
12772 QualType Types[] = {
12773 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12774 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12775 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012776 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012777 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012778 QualType SizeType;
12779 for (unsigned I = 0; I != NumTypes; ++I)
12780 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12781 SizeType = Types[I];
12782 break;
12783 }
Mike Stump11289f42009-09-09 15:08:12 +000012784
Eli Friedman9562f392012-01-25 23:20:27 +000012785 // Note that we can return a VariableArrayType here in the case where
12786 // the element type was a dependent VariableArrayType.
12787 IntegerLiteral *ArraySize
12788 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12789 /*FIXME*/BracketsRange.getBegin());
12790 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012791 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012792 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012793}
Mike Stump11289f42009-09-09 15:08:12 +000012794
Douglas Gregord6ff3322009-08-04 16:50:30 +000012795template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012796QualType
12797TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012798 ArrayType::ArraySizeModifier SizeMod,
12799 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012800 unsigned IndexTypeQuals,
12801 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012802 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012803 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012804}
12805
12806template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012807QualType
Mike Stump11289f42009-09-09 15:08:12 +000012808TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012809 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012810 unsigned IndexTypeQuals,
12811 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012812 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012813 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012814}
Mike Stump11289f42009-09-09 15:08:12 +000012815
Douglas Gregord6ff3322009-08-04 16:50:30 +000012816template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012817QualType
12818TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012819 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012820 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012821 unsigned IndexTypeQuals,
12822 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012823 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012824 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012825 IndexTypeQuals, BracketsRange);
12826}
12827
12828template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012829QualType
12830TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012831 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012832 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012833 unsigned IndexTypeQuals,
12834 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012835 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012836 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012837 IndexTypeQuals, BracketsRange);
12838}
12839
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012840template <typename Derived>
12841QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12842 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12843 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12844 AttributeLoc);
12845}
12846
12847template <typename Derived>
12848QualType
12849TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12850 unsigned NumElements,
12851 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012852 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012853 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012854}
Mike Stump11289f42009-09-09 15:08:12 +000012855
Erich Keanef702b022018-07-13 19:46:04 +000012856template <typename Derived>
12857QualType TreeTransform<Derived>::RebuildDependentVectorType(
12858 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12859 VectorType::VectorKind VecKind) {
12860 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12861}
12862
Douglas Gregord6ff3322009-08-04 16:50:30 +000012863template<typename Derived>
12864QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12865 unsigned NumElements,
12866 SourceLocation AttributeLoc) {
12867 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12868 NumElements, true);
12869 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012870 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12871 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012872 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012873}
Mike Stump11289f42009-09-09 15:08:12 +000012874
Douglas Gregord6ff3322009-08-04 16:50:30 +000012875template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012876QualType
12877TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012878 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012879 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012880 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012881}
Mike Stump11289f42009-09-09 15:08:12 +000012882
Douglas Gregord6ff3322009-08-04 16:50:30 +000012883template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012884QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12885 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012886 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012887 const FunctionProtoType::ExtProtoInfo &EPI) {
12888 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012889 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012890 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012891 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012892}
Mike Stump11289f42009-09-09 15:08:12 +000012893
Douglas Gregord6ff3322009-08-04 16:50:30 +000012894template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012895QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12896 return SemaRef.Context.getFunctionNoProtoType(T);
12897}
12898
12899template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012900QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12901 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012902 assert(D && "no decl found");
12903 if (D->isInvalidDecl()) return QualType();
12904
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012905 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012906 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012907 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12908 // A valid resolved using typename pack expansion decl can have multiple
12909 // UsingDecls, but they must each have exactly one type, and it must be
12910 // the same type in every case. But we must have at least one expansion!
12911 if (UPD->expansions().empty()) {
12912 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12913 << UPD->isCXXClassMember() << UPD;
12914 return QualType();
12915 }
12916
12917 // We might still have some unresolved types. Try to pick a resolved type
12918 // if we can. The final instantiation will check that the remaining
12919 // unresolved types instantiate to the type we pick.
12920 QualType FallbackT;
12921 QualType T;
12922 for (auto *E : UPD->expansions()) {
12923 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12924 if (ThisT.isNull())
12925 continue;
12926 else if (ThisT->getAs<UnresolvedUsingType>())
12927 FallbackT = ThisT;
12928 else if (T.isNull())
12929 T = ThisT;
12930 else
12931 assert(getSema().Context.hasSameType(ThisT, T) &&
12932 "mismatched resolved types in using pack expansion");
12933 }
12934 return T.isNull() ? FallbackT : T;
12935 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012936 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012937 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12938
12939 // A valid resolved using typename decl points to exactly one type decl.
12940 assert(++Using->shadow_begin() == Using->shadow_end());
12941 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012942 } else {
12943 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12944 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12945 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12946 }
12947
12948 return SemaRef.Context.getTypeDeclType(Ty);
12949}
12950
12951template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012952QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12953 SourceLocation Loc) {
12954 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012955}
12956
12957template<typename Derived>
12958QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12959 return SemaRef.Context.getTypeOfType(Underlying);
12960}
12961
12962template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012963QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12964 SourceLocation Loc) {
12965 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012966}
12967
12968template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012969QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12970 UnaryTransformType::UTTKind UKind,
12971 SourceLocation Loc) {
12972 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12973}
12974
12975template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012976QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012977 TemplateName Template,
12978 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012979 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012980 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012981}
Mike Stump11289f42009-09-09 15:08:12 +000012982
Douglas Gregor1135c352009-08-06 05:28:30 +000012983template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012984QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12985 SourceLocation KWLoc) {
12986 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12987}
12988
12989template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012990QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012991 SourceLocation KWLoc,
12992 bool isReadPipe) {
12993 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12994 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012995}
12996
12997template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012998TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012999TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000013000 bool TemplateKW,
13001 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000013002 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000013003 Template);
13004}
13005
13006template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000013007TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000013008TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000013009 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000013010 const IdentifierInfo &Name,
13011 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000013012 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000013013 NamedDecl *FirstQualifierInScope,
13014 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000013015 UnqualifiedId TemplateName;
13016 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000013017 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000013018 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013019 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000013020 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000013021 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000013022 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000013023 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000013024}
Mike Stump11289f42009-09-09 15:08:12 +000013025
Douglas Gregora16548e2009-08-11 05:31:07 +000013026template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000013027TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000013028TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000013029 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000013030 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000013031 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000013032 QualType ObjectType,
13033 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000013034 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000013035 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000013036 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000013037 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000013038 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000013039 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013040 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000013041 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000013042 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000013043 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000013044 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000013045}
Chad Rosier1dcde962012-08-08 18:46:20 +000013046
Douglas Gregor71395fa2009-11-04 00:56:37 +000013047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000013048ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000013049TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
13050 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000013051 Expr *OrigCallee,
13052 Expr *First,
13053 Expr *Second) {
13054 Expr *Callee = OrigCallee->IgnoreParenCasts();
13055 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000013056
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000013057 if (First->getObjectKind() == OK_ObjCProperty) {
13058 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
13059 if (BinaryOperator::isAssignmentOp(Opc))
13060 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
13061 First, Second);
13062 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
13063 if (Result.isInvalid())
13064 return ExprError();
13065 First = Result.get();
13066 }
13067
13068 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
13069 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
13070 if (Result.isInvalid())
13071 return ExprError();
13072 Second = Result.get();
13073 }
13074
Douglas Gregora16548e2009-08-11 05:31:07 +000013075 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000013076 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000013077 if (!First->getType()->isOverloadableType() &&
13078 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013079 return getSema().CreateBuiltinArraySubscriptExpr(
13080 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000013081 } else if (Op == OO_Arrow) {
13082 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000013083 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
13084 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000013085 if (!First->getType()->isOverloadableType() ||
13086 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
13087 // The argument is not of overloadable type, or this is an expression
13088 // of the form &Class::member, so try to create a built-in unary
13089 // operation.
John McCalle3027922010-08-25 11:45:40 +000013090 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013091 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000013092
John McCallb268a282010-08-23 23:25:46 +000013093 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000013094 }
13095 } else {
John McCallb268a282010-08-23 23:25:46 +000013096 if (!First->getType()->isOverloadableType() &&
13097 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000013098 // Neither of the arguments is an overloadable type, so try to
13099 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000013100 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000013101 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000013102 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000013103 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013104 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013105
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013106 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013107 }
13108 }
Mike Stump11289f42009-09-09 15:08:12 +000013109
13110 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000013111 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000013112 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000013113 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000013114
John McCallb268a282010-08-23 23:25:46 +000013115 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000013116 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000013117 // If the overload could not be resolved in the template definition
13118 // (because we had a dependent argument), ADL is performed as part of
13119 // template instantiation.
13120 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000013121 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000013122 // If we've resolved this to a particular non-member function, just call
13123 // that function. If we resolved it to a member function,
13124 // CreateOverloaded* will find that function for us.
13125 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
13126 if (!isa<CXXMethodDecl>(ND))
13127 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000013128 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000013129 }
Mike Stump11289f42009-09-09 15:08:12 +000013130
Douglas Gregora16548e2009-08-11 05:31:07 +000013131 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000013132 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000013133 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000013134
Douglas Gregora16548e2009-08-11 05:31:07 +000013135 // Create the overloaded operator invocation for unary operators.
13136 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000013137 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000013138 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000013139 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
13140 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013141 }
Mike Stump11289f42009-09-09 15:08:12 +000013142
Douglas Gregore9d62932011-07-15 16:25:15 +000013143 if (Op == OO_Subscript) {
13144 SourceLocation LBrace;
13145 SourceLocation RBrace;
13146
13147 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000013148 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000013149 LBrace = SourceLocation::getFromRawEncoding(
13150 NameLoc.CXXOperatorName.BeginOpNameLoc);
13151 RBrace = SourceLocation::getFromRawEncoding(
13152 NameLoc.CXXOperatorName.EndOpNameLoc);
13153 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013154 LBrace = Callee->getBeginLoc();
13155 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000013156 }
13157
13158 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
13159 First, Second);
13160 }
Sebastian Redladba46e2009-10-29 20:17:01 +000013161
Douglas Gregora16548e2009-08-11 05:31:07 +000013162 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000013163 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000013164 ExprResult Result = SemaRef.CreateOverloadedBinOp(
13165 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000013166 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000013167 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000013168
Benjamin Kramer62b95d82012-08-23 21:35:17 +000013169 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000013170}
Mike Stump11289f42009-09-09 15:08:12 +000013171
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013172template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000013173ExprResult
John McCallb268a282010-08-23 23:25:46 +000013174TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013175 SourceLocation OperatorLoc,
13176 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000013177 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013178 TypeSourceInfo *ScopeType,
13179 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000013180 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000013181 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000013182 QualType BaseType = Base->getType();
13183 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013184 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000013185 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000013186 !BaseType->getAs<PointerType>()->getPointeeType()
13187 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013188 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000013189 return SemaRef.BuildPseudoDestructorExpr(
13190 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
13191 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013192 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013193
Douglas Gregor678f90d2010-02-25 01:56:36 +000013194 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013195 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
13196 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
13197 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
13198 NameInfo.setNamedTypeInfo(DestroyedType);
13199
Richard Smith8e4a3862012-05-15 06:15:11 +000013200 // The scope type is now known to be a valid nested name specifier
13201 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000013202 if (ScopeType) {
13203 if (!ScopeType->getType()->getAs<TagType>()) {
13204 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
13205 diag::err_expected_class_or_namespace)
13206 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
13207 return ExprError();
13208 }
13209 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
13210 CCLoc);
13211 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013212
Abramo Bagnara7945c982012-01-27 09:46:47 +000013213 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000013214 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013215 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000013216 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000013217 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000013218 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000013219 /*TemplateArgs*/ nullptr,
13220 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000013221}
13222
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013223template<typename Derived>
13224StmtResult
13225TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000013226 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000013227 CapturedDecl *CD = S->getCapturedDecl();
13228 unsigned NumParams = CD->getNumParams();
13229 unsigned ContextParamPos = CD->getContextParamPosition();
13230 SmallVector<Sema::CapturedParamNameType, 4> Params;
13231 for (unsigned I = 0; I < NumParams; ++I) {
13232 if (I != ContextParamPos) {
13233 Params.push_back(
13234 std::make_pair(
13235 CD->getParam(I)->getName(),
13236 getDerived().TransformType(CD->getParam(I)->getType())));
13237 } else {
13238 Params.push_back(std::make_pair(StringRef(), QualType()));
13239 }
13240 }
Craig Topperc3ec1492014-05-26 06:22:03 +000013241 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000013242 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000013243 StmtResult Body;
13244 {
13245 Sema::CompoundScopeRAII CompoundScope(getSema());
13246 Body = getDerived().TransformStmt(S->getCapturedStmt());
13247 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000013248
13249 if (Body.isInvalid()) {
13250 getSema().ActOnCapturedRegionError();
13251 return StmtError();
13252 }
13253
Nikola Smiljanic01a75982014-05-29 10:55:11 +000013254 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000013255}
13256
Douglas Gregord6ff3322009-08-04 16:50:30 +000013257} // end namespace clang
13258
Hans Wennborg59dbe862015-09-29 20:56:43 +000013259#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H