blob: ff33028ebbc969074d21e72053bde4c35dd64c05 [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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000151 /// Returns the location of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000159 /// Returns the name of the entity being transformed, if that
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000166 /// Sets the "base" location and entity when that
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000173 /// RAII object that temporarily sets the base location and entity
Douglas Gregora16548e2009-08-11 05:31:07 +0000174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000195 /// Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000206 /// Determine whether the given call argument should be dropped, e.g.,
Douglas Gregord196a582009-12-14 19:27:10 +0000207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000216 /// Determine whether we should expand a pack expansion with the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000263 /// "Forget" about the partially-substituted pack template argument,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000272 /// "Remember" the partially-substituted pack template argument
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000279 /// Note to the derived class when a function parameter pack is
Douglas Gregorf3010112011-01-07 16:43:16 +0000280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000283 /// Transforms the given type into another type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000294 /// Transforms the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000304 /// Transform the given type-with-location into a new
John McCall550e0c22009-10-21 00:40:46 +0000305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000310 /// Transform a type that is permitted to produce a
Richard Smithee579842017-01-30 20:39:26 +0000311 /// DeducedTemplateSpecializationType.
312 ///
313 /// This is used in the (relatively rare) contexts where it is acceptable
314 /// for transformation to produce a class template type with deduced
315 /// template arguments.
316 /// @{
317 QualType TransformTypeWithDeducedTST(QualType T);
318 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
319 /// @}
320
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000321 /// The reason why the value of a statement is not discarded, if any.
322 enum StmtDiscardKind {
323 SDK_Discarded,
324 SDK_NotDiscarded,
325 SDK_StmtExprResult,
326 };
327
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000328 /// Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000329 ///
Mike Stump11289f42009-09-09 15:08:12 +0000330 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000331 /// appropriate TransformXXXStmt function to transform a specific kind of
332 /// statement or the TransformExpr() function to transform an expression.
333 /// Subclasses may override this function to transform statements using some
334 /// other mechanism.
335 ///
336 /// \returns the transformed statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000337 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
Mike Stump11289f42009-09-09 15:08:12 +0000338
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000339 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000340 ///
341 /// By default, this routine transforms a statement by delegating to the
342 /// appropriate TransformOMPXXXClause function to transform a specific kind
343 /// of clause. Subclasses may override this function to transform statements
344 /// using some other mechanism.
345 ///
346 /// \returns the transformed OpenMP clause.
347 OMPClause *TransformOMPClause(OMPClause *S);
348
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000349 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000350 ///
351 /// By default, this routine transforms a statement by delegating to the
352 /// appropriate TransformXXXAttr function to transform a specific kind
353 /// of attribute. Subclasses may override this function to transform
354 /// attributed statements using some other mechanism.
355 ///
356 /// \returns the transformed attribute
357 const Attr *TransformAttr(const Attr *S);
358
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000359/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000360///
361/// Subclasses should override the transformation of attributes with a pragma
362/// spelling to transform expressions stored within the attribute.
363///
364/// \returns the transformed attribute.
365#define ATTR(X)
366#define PRAGMA_SPELLING_ATTR(X) \
367 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
368#include "clang/Basic/AttrList.inc"
369
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000370 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000371 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000372 /// By default, this routine transforms an expression by delegating to the
373 /// appropriate TransformXXXExpr function to build a new expression.
374 /// Subclasses may override this function to transform expressions using some
375 /// other mechanism.
376 ///
377 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000378 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000379
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000380 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000381 ///
382 /// By default, this routine transforms an initializer by stripping off the
383 /// semantic nodes added by initialization, then passing the result to
384 /// TransformExpr or TransformExprs.
385 ///
386 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000387 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000388
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000389 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000390 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000391 /// This routine transforms a list of expressions by invoking
392 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000393 /// support for variadic templates by expanding any pack expansions (if the
394 /// derived class permits such expansion) along the way. When pack expansions
395 /// are present, the number of outputs may not equal the number of inputs.
396 ///
397 /// \param Inputs The set of expressions to be transformed.
398 ///
399 /// \param NumInputs The number of expressions in \c Inputs.
400 ///
401 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000402 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000403 /// be.
404 ///
405 /// \param Outputs The transformed input expressions will be added to this
406 /// vector.
407 ///
408 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
409 /// due to transformation.
410 ///
411 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000412 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000413 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000414 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000415
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000416 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// or expression.
418 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000419 /// By default, acts as the identity function on declarations, unless the
420 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000421 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000422 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 llvm::DenseMap<Decl *, Decl *>::iterator Known
424 = TransformedLocalDecls.find(D);
425 if (Known != TransformedLocalDecls.end())
426 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000427
428 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000429 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000430
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000431 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000432 ///
433 /// By default, this transforms the variable and expression and rebuilds
434 /// the condition.
435 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
436 Expr *Expr,
437 Sema::ConditionKind Kind);
438
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000439 /// Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000440 /// place them on the new declaration.
441 ///
442 /// By default, this operation does nothing. Subclasses may override this
443 /// behavior to transform attributes.
444 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000445
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000446 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000447 /// transformer.
448 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000449 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000450 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
451 /// the transformer itself has to transform the declarations. This routine
452 /// can be overridden by a subclass that keeps track of such mappings.
453 void transformedLocalDecl(Decl *Old, Decl *New) {
454 TransformedLocalDecls[Old] = New;
455 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000456
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000457 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000458 ///
Mike Stump11289f42009-09-09 15:08:12 +0000459 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000460 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000461 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
462 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000463 }
Mike Stump11289f42009-09-09 15:08:12 +0000464
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000465 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000466 /// nested-name-specifier in a member access expression.
467 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000469 /// identifier in a nested-name-specifier of a member access expression, e.g.,
470 /// the \c T in \c x->T::member
471 ///
472 /// By default, invokes TransformDecl() to transform the declaration.
473 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000474 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
475 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000476 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000477
Richard Smith151c4562016-12-20 21:35:28 +0000478 /// Transform the set of declarations in an OverloadExpr.
479 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
480 LookupResult &R);
481
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000482 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000483 /// information.
484 ///
485 /// By default, transforms all of the types and declarations within the
486 /// nested-name-specifier. Subclasses may override this function to provide
487 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000488 NestedNameSpecifierLoc
489 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
490 QualType ObjectType = QualType(),
491 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000492
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000493 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000494 ///
495 /// By default, transforms the types of conversion function, constructor,
496 /// and destructor names and then (if needed) rebuilds the declaration name.
497 /// Identifiers and selectors are returned unmodified. Sublcasses may
498 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000499 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000500 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000501
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000502 /// Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000503 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000504 /// \param SS The nested-name-specifier that qualifies the template
505 /// name. This nested-name-specifier must already have been transformed.
506 ///
507 /// \param Name The template name to transform.
508 ///
509 /// \param NameLoc The source location of the template name.
510 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000511 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000512 /// access expression, this is the type of the object whose member template
513 /// is being referenced.
514 ///
515 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
516 /// also refers to a name within the current (lexical) scope, this is the
517 /// declaration it refers to.
518 ///
519 /// By default, transforms the template name by transforming the declarations
520 /// and nested-name-specifiers that occur within the template name.
521 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000522 TemplateName
523 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
524 SourceLocation NameLoc,
525 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000526 NamedDecl *FirstQualifierInScope = nullptr,
527 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000528
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000529 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 ///
Mike Stump11289f42009-09-09 15:08:12 +0000531 /// By default, this operation transforms the type, expression, or
532 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000533 /// new template argument from the transformed result. Subclasses may
534 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000535 ///
536 /// Returns true if there was an error.
537 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000538 TemplateArgumentLoc &Output,
539 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000540
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000541 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000542 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000543 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000544 /// in the input set using \c TransformTemplateArgument(), and appends
545 /// the transformed arguments to the output list.
546 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000547 /// Note that this overload of \c TransformTemplateArguments() is merely
548 /// a convenience function. Subclasses that wish to override this behavior
549 /// should override the iterator-based member template version.
550 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000551 /// \param Inputs The set of template arguments to be transformed.
552 ///
553 /// \param NumInputs The number of template arguments in \p Inputs.
554 ///
555 /// \param Outputs The set of transformed template arguments output by this
556 /// routine.
557 ///
558 /// Returns true if an error occurred.
559 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
560 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000561 TemplateArgumentListInfo &Outputs,
562 bool Uneval = false) {
563 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
564 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000565 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000566
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000567 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000568 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000569 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000570 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000571 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000572 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000573 /// \param First An iterator to the first template argument.
574 ///
575 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000576 ///
577 /// \param Outputs The set of transformed template arguments output by this
578 /// routine.
579 ///
580 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000581 template<typename InputIterator>
582 bool TransformTemplateArguments(InputIterator First,
583 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000584 TemplateArgumentListInfo &Outputs,
585 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000586
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000587 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000588 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
589 TemplateArgumentLoc &ArgLoc);
590
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000591 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000592 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
593 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000594 getDerived().getBaseLocation());
595 }
Mike Stump11289f42009-09-09 15:08:12 +0000596
John McCall550e0c22009-10-21 00:40:46 +0000597#define ABSTRACT_TYPELOC(CLASS, PARENT)
598#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000599 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000600#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601
Richard Smith2e321552014-11-12 02:00:47 +0000602 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000603 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
604 FunctionProtoTypeLoc TL,
605 CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +0000606 Qualifiers ThisTypeQuals,
Richard Smith2e321552014-11-12 02:00:47 +0000607 Fn TransformExceptionSpec);
608
609 bool TransformExceptionSpec(SourceLocation Loc,
610 FunctionProtoType::ExceptionSpecInfo &ESI,
611 SmallVectorImpl<QualType> &Exceptions,
612 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000613
David Majnemerfad8f482013-10-15 09:33:02 +0000614 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000615
Chad Rosier1dcde962012-08-08 18:46:20 +0000616 QualType
John McCall31f82722010-11-12 08:19:04 +0000617 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
618 TemplateSpecializationTypeLoc TL,
619 TemplateName Template);
620
Chad Rosier1dcde962012-08-08 18:46:20 +0000621 QualType
John McCall31f82722010-11-12 08:19:04 +0000622 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
623 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000624 TemplateName Template,
625 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000626
Nico Weberc153d242014-07-28 00:02:09 +0000627 QualType TransformDependentTemplateSpecializationType(
628 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
629 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000630
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000631 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000632 /// given vectors.
633 ///
634 /// The result vectors should be kept in sync; null entries in the
635 /// variables vector are acceptable.
636 ///
637 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000638 bool TransformFunctionTypeParams(
639 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
640 const QualType *ParamTypes,
641 const FunctionProtoType::ExtParameterInfo *ParamInfos,
642 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
643 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000644
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000645 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000646 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000647 ///
648 /// \param indexAdjustment - A number to add to the parameter's
649 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000650 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000651 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000652 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000653 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000654
John McCall31f82722010-11-12 08:19:04 +0000655 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000656
John McCalldadc5752010-08-24 06:29:42 +0000657 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
658 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000659
Faisal Vali2cba1332013-10-23 06:44:28 +0000660 TemplateParameterList *TransformTemplateParameterList(
661 TemplateParameterList *TPL) {
662 return TPL;
663 }
664
Richard Smithdb2630f2012-10-21 03:28:35 +0000665 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000666
Richard Smithdb2630f2012-10-21 03:28:35 +0000667 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000668 bool IsAddressOfOperand,
669 TypeSourceInfo **RecoveryTSI);
670
671 ExprResult TransformParenDependentScopeDeclRefExpr(
672 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
673 TypeSourceInfo **RecoveryTSI);
674
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000675 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000676
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000677// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
678// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000679#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000680 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000681 StmtResult Transform##Node(Node *S);
Richard Smitha6e8d5e2019-02-15 00:27:53 +0000682#define VALUESTMT(Node, Parent) \
683 LLVM_ATTRIBUTE_NOINLINE \
684 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
Douglas Gregora16548e2009-08-11 05:31:07 +0000685#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000686 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000687 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000688#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000689#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000690
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000691#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000692 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000693 OMPClause *Transform ## Class(Class *S);
Roman Lebedev23019f92019-01-28 17:04:11 +0000694 OPENMP_CLAUSE(flush, OMPFlushClause)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000695#include "clang/Basic/OpenMPKinds.def"
696
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000697 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000698 ///
699 /// By default, this routine adds type qualifiers only to types that can
700 /// have qualifiers, and silently suppresses those qualifiers that are not
701 /// permitted. Subclasses may override this routine to provide different
702 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000703 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000704
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000705 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 ///
707 /// By default, performs semantic analysis when building the pointer type.
708 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000709 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000711 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ///
Mike Stump11289f42009-09-09 15:08:12 +0000713 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000715 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000716
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000717 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000718 ///
John McCall70dd5f62009-10-30 00:06:24 +0000719 /// By default, performs semantic analysis when building the
720 /// reference type. Subclasses may override this routine to provide
721 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000722 ///
John McCall70dd5f62009-10-30 00:06:24 +0000723 /// \param LValue whether the type was written with an lvalue sigil
724 /// or an rvalue sigil.
725 QualType RebuildReferenceType(QualType ReferentType,
726 bool LValue,
727 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000728
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000729 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 /// class type it refers into.
731 ///
732 /// By default, performs semantic analysis when building the member pointer
733 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000734 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
735 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000736
Manman Rene6be26c2016-09-13 17:25:08 +0000737 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
738 SourceLocation ProtocolLAngleLoc,
739 ArrayRef<ObjCProtocolDecl *> Protocols,
740 ArrayRef<SourceLocation> ProtocolLocs,
741 SourceLocation ProtocolRAngleLoc);
742
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000743 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000744 ///
745 /// By default, performs semantic analysis when building the object type.
746 /// Subclasses may override this routine to provide different behavior.
747 QualType RebuildObjCObjectType(QualType BaseType,
748 SourceLocation Loc,
749 SourceLocation TypeArgsLAngleLoc,
750 ArrayRef<TypeSourceInfo *> TypeArgs,
751 SourceLocation TypeArgsRAngleLoc,
752 SourceLocation ProtocolLAngleLoc,
753 ArrayRef<ObjCProtocolDecl *> Protocols,
754 ArrayRef<SourceLocation> ProtocolLocs,
755 SourceLocation ProtocolRAngleLoc);
756
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000757 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000758 ///
759 /// By default, directly builds the pointer type, with no additional semantic
760 /// analysis.
761 QualType RebuildObjCObjectPointerType(QualType PointeeType,
762 SourceLocation Star);
763
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000764 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// modifier, size of the array (if known), size expression, and index type
766 /// qualifiers.
767 ///
768 /// By default, performs semantic analysis when building the array type.
769 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000770 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000771 QualType RebuildArrayType(QualType ElementType,
772 ArrayType::ArraySizeModifier SizeMod,
773 const llvm::APInt *Size,
774 Expr *SizeExpr,
775 unsigned IndexTypeQuals,
776 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000777
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000778 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// modifier, (known) size of the array, and index type qualifiers.
780 ///
781 /// By default, performs semantic analysis when building the array type.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000783 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000784 ArrayType::ArraySizeModifier SizeMod,
785 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000786 unsigned IndexTypeQuals,
787 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000789 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// modifier, and index type qualifiers.
791 ///
792 /// By default, performs semantic analysis when building the array type.
793 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000794 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000796 unsigned IndexTypeQuals,
797 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000798
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000799 /// Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// size modifier, size expression, and index type qualifiers.
801 ///
802 /// By default, performs semantic analysis when building the array type.
803 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000804 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000805 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000806 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 unsigned IndexTypeQuals,
808 SourceRange BracketsRange);
809
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000810 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// size modifier, size expression, and index type qualifiers.
812 ///
813 /// By default, performs semantic analysis when building the array type.
814 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000815 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000816 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000817 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000818 unsigned IndexTypeQuals,
819 SourceRange BracketsRange);
820
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000821 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000822 /// number of elements.
823 ///
824 /// By default, performs semantic analysis when building the vector type.
825 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000826 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000827 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000828
Erich Keanef702b022018-07-13 19:46:04 +0000829 /// Build a new potentially dependently-sized extended vector type
830 /// given the element type and number of elements.
831 ///
832 /// By default, performs semantic analysis when building the vector type.
833 /// Subclasses may override this routine to provide different behavior.
834 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
835 SourceLocation AttributeLoc,
836 VectorType::VectorKind);
837
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000838 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000839 /// number of elements.
840 ///
841 /// By default, performs semantic analysis when building the vector type.
842 /// Subclasses may override this routine to provide different behavior.
843 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
844 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000845
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000846 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000847 /// given the element type and number of elements.
848 ///
849 /// By default, performs semantic analysis when building the vector type.
850 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000851 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000852 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000853 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000854
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000855 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000856 /// type variable with the correct address space (retrieved from
857 /// AddrSpaceExpr) applied to it. The former will be returned in cases
858 /// where the address space remains dependent.
859 ///
860 /// By default, performs semantic analysis when building the type with address
861 /// space applied. Subclasses may override this routine to provide different
862 /// behavior.
863 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
864 Expr *AddrSpaceExpr,
865 SourceLocation AttributeLoc);
866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000867 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000868 ///
869 /// By default, performs semantic analysis when building the function type.
870 /// Subclasses may override this routine to provide different behavior.
871 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000872 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000873 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000874
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000875 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000876 QualType RebuildFunctionNoProtoType(QualType ResultType);
877
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000878 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000879 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000880 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000881
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000882 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000883 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000884 return SemaRef.Context.getTypeDeclType(Typedef);
885 }
886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000888 QualType RebuildRecordType(RecordDecl *Record) {
889 return SemaRef.Context.getTypeDeclType(Record);
890 }
891
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000892 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000893 QualType RebuildEnumType(EnumDecl *Enum) {
894 return SemaRef.Context.getTypeDeclType(Enum);
895 }
John McCallfcc33b02009-09-05 00:15:47 +0000896
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000897 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000898 ///
899 /// By default, performs semantic analysis when building the typeof type.
900 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000901 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000902
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000903 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000904 ///
905 /// By default, builds a new TypeOfType with the given underlying type.
906 QualType RebuildTypeOfType(QualType Underlying);
907
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000908 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000909 QualType RebuildUnaryTransformType(QualType BaseType,
910 UnaryTransformType::UTTKind UKind,
911 SourceLocation Loc);
912
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000913 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000914 ///
915 /// By default, performs semantic analysis when building the decltype type.
916 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000917 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000918
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000919 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000920 ///
921 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000922 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000923 // Note, IsDependent is always false here: we implicitly convert an 'auto'
924 // which has been deduced to a dependent type into an undeduced 'auto', so
925 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000926 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000927 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000928 }
929
Richard Smith600b5262017-01-26 20:40:47 +0000930 /// By default, builds a new DeducedTemplateSpecializationType with the given
931 /// deduced type.
932 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
933 QualType Deduced) {
934 return SemaRef.Context.getDeducedTemplateSpecializationType(
935 Template, Deduced, /*IsDependent*/ false);
936 }
937
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000938 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000939 ///
940 /// By default, performs semantic analysis when building the template
941 /// specialization type. Subclasses may override this routine to provide
942 /// different behavior.
943 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000944 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000945 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000946
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000947 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000948 ///
949 /// By default, builds a new ParenType type from the inner type.
950 /// Subclasses may override this routine to provide different behavior.
951 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000952 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000953 }
954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000955 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000956 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957 /// By default, builds a new ElaboratedType type from the keyword,
958 /// the nested-name-specifier and the named type.
959 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000960 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
961 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000962 NestedNameSpecifierLoc QualifierLoc,
963 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000964 return SemaRef.Context.getElaboratedType(Keyword,
965 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000966 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000967 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000968
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000969 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000970 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000971 /// By default, builds a new DependentNameType type from the
972 /// nested-name-specifier and the given type. Subclasses may override
973 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000974 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000975 ElaboratedTypeKeyword Keyword,
976 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000977 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000978 const IdentifierInfo *Name,
979 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000980 TemplateArgumentListInfo &Args,
981 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000982 // Rebuild the template name.
983 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000984 CXXScopeSpec SS;
985 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +0000986 TemplateName InstName = getDerived().RebuildTemplateName(
987 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
988 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000989
Douglas Gregora7a795b2011-03-01 20:11:18 +0000990 if (InstName.isNull())
991 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000992
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 // If it's still dependent, make a dependent specialization.
994 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000995 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
996 QualifierLoc.getNestedNameSpecifier(),
997 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000998 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000999
Douglas Gregora7a795b2011-03-01 20:11:18 +00001000 // Otherwise, make an elaborated type wrapping a non-dependent
1001 // specialization.
1002 QualType T =
1003 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1004 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00001005
Craig Topperc3ec1492014-05-26 06:22:03 +00001006 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +00001007 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +00001008
1009 return SemaRef.Context.getElaboratedType(Keyword,
1010 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001011 T);
1012 }
1013
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001014 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001015 ///
1016 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001017 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001018 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001020 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001021 NestedNameSpecifierLoc QualifierLoc,
1022 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001023 SourceLocation IdLoc,
1024 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001025 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001026 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001027
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 // If the name is still dependent, just build a new dependent name type.
1030 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001031 return SemaRef.Context.getDependentNameType(Keyword,
1032 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001033 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001034 }
1035
Richard Smithee579842017-01-30 20:39:26 +00001036 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1037 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1038 *Id, IdLoc);
1039 // If a dependent name resolves to a deduced template specialization type,
1040 // check that we're in one of the syntactic contexts permitting it.
1041 if (!DeducedTSTContext) {
1042 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1043 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1044 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1045 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1046 Deduced->getTemplateName())
1047 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1048 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1049 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1050 return QualType();
1051 }
1052 }
1053 return T;
1054 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001055
1056 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1057
Abramo Bagnarad7548482010-05-19 21:37:53 +00001058 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001059 // into a non-dependent elaborated-type-specifier. Find the tag we're
1060 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001061 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001062 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1063 if (!DC)
1064 return QualType();
1065
John McCallbf8c5192010-05-27 06:40:31 +00001066 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1067 return QualType();
1068
Craig Topperc3ec1492014-05-26 06:22:03 +00001069 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001070 SemaRef.LookupQualifiedName(Result, DC);
1071 switch (Result.getResultKind()) {
1072 case LookupResult::NotFound:
1073 case LookupResult::NotFoundInCurrentInstantiation:
1074 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001075
Douglas Gregore677daf2010-03-31 22:19:08 +00001076 case LookupResult::Found:
1077 Tag = Result.getAsSingle<TagDecl>();
1078 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001079
Douglas Gregore677daf2010-03-31 22:19:08 +00001080 case LookupResult::FoundOverloaded:
1081 case LookupResult::FoundUnresolvedValue:
1082 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001083
Douglas Gregore677daf2010-03-31 22:19:08 +00001084 case LookupResult::Ambiguous:
1085 // Let the LookupResult structure handle ambiguities.
1086 return QualType();
1087 }
1088
1089 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001090 // Check where the name exists but isn't a tag type and use that to emit
1091 // better diagnostics.
1092 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1093 SemaRef.LookupQualifiedName(Result, DC);
1094 switch (Result.getResultKind()) {
1095 case LookupResult::Found:
1096 case LookupResult::FoundOverloaded:
1097 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001098 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001099 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1100 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1101 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001102 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1103 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001104 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001105 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001106 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001107 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001108 break;
1109 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001110 return QualType();
1111 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001112
Richard Trieucaa33d32011-06-10 03:11:26 +00001113 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001114 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001115 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001116 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1117 return QualType();
1118 }
1119
1120 // Build the elaborated-type-specifier type.
1121 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001122 return SemaRef.Context.getElaboratedType(Keyword,
1123 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001124 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001125 }
Mike Stump11289f42009-09-09 15:08:12 +00001126
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001127 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001128 ///
1129 /// By default, builds a new PackExpansionType type from the given pattern.
1130 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001131 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001132 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001133 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001134 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001135 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1136 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001137 }
1138
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001139 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001140 ///
1141 /// By default, performs semantic analysis when building the atomic type.
1142 /// Subclasses may override this routine to provide different behavior.
1143 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1144
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001145 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001146 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1147 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001148
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001149 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001150 /// indicating whether the "template" keyword was provided, and the template
1151 /// that the template name refers to.
1152 ///
1153 /// By default, builds the new template name directly. Subclasses may override
1154 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001155 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001156 bool TemplateKW,
1157 TemplateDecl *Template);
1158
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001159 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001160 /// name that is referred to as a template.
1161 ///
1162 /// By default, performs semantic analysis to determine whether the name can
1163 /// be resolved to a specific template, then builds the appropriate kind of
1164 /// template name. Subclasses may override this routine to provide different
1165 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001166 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001167 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001168 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001169 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001170 NamedDecl *FirstQualifierInScope,
1171 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001172
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001173 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001174 /// overloaded operator name that is referred to as a template.
1175 ///
1176 /// By default, performs semantic analysis to determine whether the name can
1177 /// be resolved to a specific template, then builds the appropriate kind of
1178 /// template name. Subclasses may override this routine to provide different
1179 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001180 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001181 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001182 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001183 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001184 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001185
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001186 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001187 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001188 ///
1189 /// By default, performs semantic analysis to determine whether the name can
1190 /// be resolved to a specific template, then builds the appropriate kind of
1191 /// template name. Subclasses may override this routine to provide different
1192 /// behavior.
1193 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1194 const TemplateArgument &ArgPack) {
1195 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1196 }
1197
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001198 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 MultiStmtArg Statements,
1204 SourceLocation RBraceLoc,
1205 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001206 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 IsStmtExpr);
1208 }
1209
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001210 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001214 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001215 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001216 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001217 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001218 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001219 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 ColonLoc);
1221 }
Mike Stump11289f42009-09-09 15:08:12 +00001222
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001223 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001224 ///
1225 /// By default, performs semantic analysis to build the new statement.
1226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001227 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001228 getSema().ActOnCaseStmtBody(S, Body);
1229 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001230 }
Mike Stump11289f42009-09-09 15:08:12 +00001231
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001232 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001236 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001237 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001238 Stmt *SubStmt) {
1239 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001240 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001243 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001247 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1248 SourceLocation ColonLoc, Stmt *SubStmt) {
1249 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001252 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001256 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1257 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001258 Stmt *SubStmt) {
1259 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1260 }
1261
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001262 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001266 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001267 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001268 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001269 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001270 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001273 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001277 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001278 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001279 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001280 }
Mike Stump11289f42009-09-09 15:08:12 +00001281
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001282 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001283 ///
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001287 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001288 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001289 }
1290
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001291 /// Build a new while 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 Smith03a4aa32016-06-23 19:02:52 +00001295 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1296 Sema::ConditionResult Cond, Stmt *Body) {
1297 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001300 /// Build a new do-while 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 RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001305 SourceLocation WhileLoc, SourceLocation LParenLoc,
1306 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001307 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1308 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001309 }
1310
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001311 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001312 ///
1313 /// By default, performs semantic analysis to build the new statement.
1314 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001315 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001316 Stmt *Init, Sema::ConditionResult Cond,
1317 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1318 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001319 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001320 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001321 }
Mike Stump11289f42009-09-09 15:08:12 +00001322
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001323 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001324 ///
1325 /// By default, performs semantic analysis to build the new statement.
1326 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001327 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1328 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001329 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 }
1331
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001332 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001336 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001337 SourceLocation StarLoc,
1338 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001339 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001342 /// Build a new return statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001346 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001347 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001348 }
Mike Stump11289f42009-09-09 15:08:12 +00001349
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001350 /// Build a new declaration 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.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001354 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001355 SourceLocation StartLoc, SourceLocation EndLoc) {
1356 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001357 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
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 inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001361 ///
1362 /// By default, performs semantic analysis to build the new statement.
1363 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001364 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1365 bool IsVolatile, unsigned NumOutputs,
1366 unsigned NumInputs, IdentifierInfo **Names,
1367 MultiExprArg Constraints, MultiExprArg Exprs,
1368 Expr *AsmString, MultiExprArg Clobbers,
1369 SourceLocation RParenLoc) {
1370 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1371 NumInputs, Names, Constraints, Exprs,
1372 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001373 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001374
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001375 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001376 ///
1377 /// By default, performs semantic analysis to build the new statement.
1378 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001379 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001380 ArrayRef<Token> AsmToks,
1381 StringRef AsmString,
1382 unsigned NumOutputs, unsigned NumInputs,
1383 ArrayRef<StringRef> Constraints,
1384 ArrayRef<StringRef> Clobbers,
1385 ArrayRef<Expr*> Exprs,
1386 SourceLocation EndLoc) {
1387 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1388 NumOutputs, NumInputs,
1389 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001390 }
1391
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001392 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001393 ///
1394 /// By default, performs semantic analysis to build the new statement.
1395 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001396 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1397 bool IsImplicit) {
1398 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001399 }
1400
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001401 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001402 ///
1403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001405 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1406 bool IsImplicit) {
1407 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1408 }
1409
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001410 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001411 ///
1412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
1414 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1415 Expr *Result,
1416 UnresolvedLookupExpr *Lookup) {
1417 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001418 }
1419
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001420 /// Build a new co_yield 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.
1424 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1425 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1426 }
1427
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001428 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1429 return getSema().BuildCoroutineBodyStmt(Args);
1430 }
1431
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001432 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001433 ///
1434 /// By default, performs semantic analysis to build the new statement.
1435 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001436 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001437 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001438 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001439 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001440 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001441 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001442 }
1443
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001444 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001445 ///
1446 /// By default, performs semantic analysis to build the new declaration.
1447 /// Subclasses may override this routine to provide different behavior.
1448 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1449 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001450 return getSema().BuildObjCExceptionDecl(TInfo, T,
1451 ExceptionDecl->getInnerLocStart(),
1452 ExceptionDecl->getLocation(),
1453 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001455
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001456 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001460 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001461 SourceLocation RParenLoc,
1462 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001463 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001464 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001465 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001467
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001468 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001469 ///
1470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001473 Stmt *Body) {
1474 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001475 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001476
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001477 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001481 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001482 Expr *Operand) {
1483 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001485
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001486 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001490 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001491 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001492 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001493 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001494 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001495 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001496 return getSema().ActOnOpenMPExecutableDirective(
1497 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001498 }
1499
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001500 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001501 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001502 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001503 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001504 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1505 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001506 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001507 SourceLocation NameModifierLoc,
1508 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001509 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001510 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1511 LParenLoc, NameModifierLoc, ColonLoc,
1512 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001513 }
1514
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001515 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001516 ///
1517 /// By default, performs semantic analysis to build the new OpenMP clause.
1518 /// Subclasses may override this routine to provide different behavior.
1519 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001526 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001527 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001528 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation EndLoc) {
1534 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1535 LParenLoc, EndLoc);
1536 }
1537
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001538 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001539 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001540 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001541 /// Subclasses may override this routine to provide different behavior.
1542 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1546 }
1547
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001548 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001549 ///
1550 /// By default, performs semantic analysis to build the new OpenMP clause.
1551 /// Subclasses may override this routine to provide different behavior.
1552 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1553 SourceLocation LParenLoc,
1554 SourceLocation EndLoc) {
1555 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1556 }
1557
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001558 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1563 SourceLocation LParenLoc,
1564 SourceLocation EndLoc) {
1565 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1566 EndLoc);
1567 }
1568
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001569 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001570 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001571 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001572 /// Subclasses may override this routine to provide different behavior.
1573 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1574 SourceLocation KindKwLoc,
1575 SourceLocation StartLoc,
1576 SourceLocation LParenLoc,
1577 SourceLocation EndLoc) {
1578 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1579 StartLoc, LParenLoc, EndLoc);
1580 }
1581
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001582 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001583 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001584 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001585 /// Subclasses may override this routine to provide different behavior.
1586 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1587 SourceLocation KindKwLoc,
1588 SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1592 StartLoc, LParenLoc, EndLoc);
1593 }
1594
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001595 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001596 ///
1597 /// By default, performs semantic analysis to build the new OpenMP clause.
1598 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001599 OMPClause *RebuildOMPScheduleClause(
1600 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1601 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1602 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1603 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001604 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001605 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1606 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001607 }
1608
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001609 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001610 ///
1611 /// By default, performs semantic analysis to build the new OpenMP clause.
1612 /// Subclasses may override this routine to provide different behavior.
1613 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1614 SourceLocation EndLoc,
1615 SourceLocation LParenLoc, Expr *Num) {
1616 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1617 }
1618
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001619 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001620 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001621 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001622 /// Subclasses may override this routine to provide different behavior.
1623 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1624 SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001631 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001632 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001633 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001634 /// Subclasses may override this routine to provide different behavior.
1635 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1636 SourceLocation StartLoc,
1637 SourceLocation LParenLoc,
1638 SourceLocation EndLoc) {
1639 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1640 EndLoc);
1641 }
1642
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001643 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001644 ///
1645 /// By default, performs semantic analysis to build the new OpenMP clause.
1646 /// Subclasses may override this routine to provide different behavior.
1647 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1648 SourceLocation StartLoc,
1649 SourceLocation LParenLoc,
1650 SourceLocation EndLoc) {
1651 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1652 EndLoc);
1653 }
1654
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001655 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001656 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001657 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001658 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001659 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1660 SourceLocation StartLoc,
1661 SourceLocation LParenLoc,
1662 SourceLocation EndLoc) {
1663 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1664 EndLoc);
1665 }
1666
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001667 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001668 ///
1669 /// By default, performs semantic analysis to build the new statement.
1670 /// Subclasses may override this routine to provide different behavior.
1671 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1672 SourceLocation StartLoc,
1673 SourceLocation LParenLoc,
1674 SourceLocation ColonLoc,
1675 SourceLocation EndLoc,
1676 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001677 const DeclarationNameInfo &ReductionId,
1678 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001679 return getSema().ActOnOpenMPReductionClause(
1680 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001681 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001682 }
1683
Alexey Bataev169d96a2017-07-18 20:17:46 +00001684 /// Build a new OpenMP 'task_reduction' clause.
1685 ///
1686 /// By default, performs semantic analysis to build the new statement.
1687 /// Subclasses may override this routine to provide different behavior.
1688 OMPClause *RebuildOMPTaskReductionClause(
1689 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1690 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1691 CXXScopeSpec &ReductionIdScopeSpec,
1692 const DeclarationNameInfo &ReductionId,
1693 ArrayRef<Expr *> UnresolvedReductions) {
1694 return getSema().ActOnOpenMPTaskReductionClause(
1695 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1696 ReductionId, UnresolvedReductions);
1697 }
1698
Alexey Bataevfa312f32017-07-21 18:48:21 +00001699 /// Build a new OpenMP 'in_reduction' clause.
1700 ///
1701 /// By default, performs semantic analysis to build the new statement.
1702 /// Subclasses may override this routine to provide different behavior.
1703 OMPClause *
1704 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1705 SourceLocation LParenLoc, SourceLocation ColonLoc,
1706 SourceLocation EndLoc,
1707 CXXScopeSpec &ReductionIdScopeSpec,
1708 const DeclarationNameInfo &ReductionId,
1709 ArrayRef<Expr *> UnresolvedReductions) {
1710 return getSema().ActOnOpenMPInReductionClause(
1711 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1712 ReductionId, UnresolvedReductions);
1713 }
1714
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001715 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001716 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001717 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001718 /// Subclasses may override this routine to provide different behavior.
1719 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1720 SourceLocation StartLoc,
1721 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001722 OpenMPLinearClauseKind Modifier,
1723 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001724 SourceLocation ColonLoc,
1725 SourceLocation EndLoc) {
1726 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001727 Modifier, ModifierLoc, ColonLoc,
1728 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001729 }
1730
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001731 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001732 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001733 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001734 /// Subclasses may override this routine to provide different behavior.
1735 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1736 SourceLocation StartLoc,
1737 SourceLocation LParenLoc,
1738 SourceLocation ColonLoc,
1739 SourceLocation EndLoc) {
1740 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1741 LParenLoc, ColonLoc, EndLoc);
1742 }
1743
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001744 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001745 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001746 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001747 /// Subclasses may override this routine to provide different behavior.
1748 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1749 SourceLocation StartLoc,
1750 SourceLocation LParenLoc,
1751 SourceLocation EndLoc) {
1752 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1753 EndLoc);
1754 }
1755
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001756 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001757 ///
1758 /// By default, performs semantic analysis to build the new OpenMP clause.
1759 /// Subclasses may override this routine to provide different behavior.
1760 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1761 SourceLocation StartLoc,
1762 SourceLocation LParenLoc,
1763 SourceLocation EndLoc) {
1764 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1765 EndLoc);
1766 }
1767
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001768 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001769 ///
1770 /// By default, performs semantic analysis to build the new OpenMP clause.
1771 /// Subclasses may override this routine to provide different behavior.
1772 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1773 SourceLocation StartLoc,
1774 SourceLocation LParenLoc,
1775 SourceLocation EndLoc) {
1776 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1777 EndLoc);
1778 }
1779
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001780 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001781 ///
1782 /// By default, performs semantic analysis to build the new OpenMP clause.
1783 /// Subclasses may override this routine to provide different behavior.
1784 OMPClause *
1785 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1786 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1787 SourceLocation StartLoc, SourceLocation LParenLoc,
1788 SourceLocation EndLoc) {
1789 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1790 StartLoc, LParenLoc, EndLoc);
1791 }
1792
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001793 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001794 ///
1795 /// By default, performs semantic analysis to build the new statement.
1796 /// Subclasses may override this routine to provide different behavior.
1797 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1798 SourceLocation LParenLoc,
1799 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001800 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001801 EndLoc);
1802 }
1803
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001804 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001805 ///
1806 /// By default, performs semantic analysis to build the new OpenMP clause.
1807 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001808 OMPClause *
Kelvin Lief579432018-12-18 22:18:41 +00001809 RebuildOMPMapClause(ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1810 ArrayRef<SourceLocation> MapTypeModifiersLoc,
Samuel Antao23abd722016-01-19 20:40:49 +00001811 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1812 SourceLocation MapLoc, SourceLocation ColonLoc,
1813 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1814 SourceLocation LParenLoc, SourceLocation EndLoc) {
Kelvin Lief579432018-12-18 22:18:41 +00001815 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
1816 MapType, IsMapTypeImplicit, MapLoc,
1817 ColonLoc, VarList, StartLoc,
1818 LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001819 }
1820
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001821 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001822 ///
1823 /// By default, performs semantic analysis to build the new statement.
1824 /// Subclasses may override this routine to provide different behavior.
1825 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1826 SourceLocation LParenLoc,
1827 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001828 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001829 EndLoc);
1830 }
1831
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001832 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001833 ///
1834 /// By default, performs semantic analysis to build the new statement.
1835 /// Subclasses may override this routine to provide different behavior.
1836 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1837 SourceLocation StartLoc,
1838 SourceLocation LParenLoc,
1839 SourceLocation EndLoc) {
1840 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1841 LParenLoc, EndLoc);
1842 }
1843
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001844 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001845 ///
1846 /// By default, performs semantic analysis to build the new statement.
1847 /// Subclasses may override this routine to provide different behavior.
1848 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1849 SourceLocation LParenLoc,
1850 SourceLocation EndLoc) {
1851 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1852 EndLoc);
1853 }
1854
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001855 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001856 ///
1857 /// By default, performs semantic analysis to build the new statement.
1858 /// Subclasses may override this routine to provide different behavior.
1859 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1860 SourceLocation LParenLoc,
1861 SourceLocation EndLoc) {
1862 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1863 EndLoc);
1864 }
1865
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001866 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001867 ///
1868 /// By default, performs semantic analysis to build the new statement.
1869 /// Subclasses may override this routine to provide different behavior.
1870 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1871 SourceLocation LParenLoc,
1872 SourceLocation EndLoc) {
1873 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1874 EndLoc);
1875 }
1876
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001877 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001878 ///
1879 /// By default, performs semantic analysis to build the new statement.
1880 /// Subclasses may override this routine to provide different behavior.
1881 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1882 SourceLocation LParenLoc,
1883 SourceLocation EndLoc) {
1884 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1885 }
1886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001887 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001888 ///
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1891 OMPClause *
1892 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1893 Expr *ChunkSize, SourceLocation StartLoc,
1894 SourceLocation LParenLoc, SourceLocation KindLoc,
1895 SourceLocation CommaLoc, SourceLocation EndLoc) {
1896 return getSema().ActOnOpenMPDistScheduleClause(
1897 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1898 }
1899
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001900 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001901 ///
1902 /// By default, performs semantic analysis to build the new statement.
1903 /// Subclasses may override this routine to provide different behavior.
1904 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1905 SourceLocation StartLoc,
1906 SourceLocation LParenLoc,
1907 SourceLocation EndLoc) {
1908 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1909 }
1910
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001911 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001912 ///
1913 /// By default, performs semantic analysis to build the new statement.
1914 /// Subclasses may override this routine to provide different behavior.
1915 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1916 SourceLocation StartLoc,
1917 SourceLocation LParenLoc,
1918 SourceLocation EndLoc) {
1919 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1920 EndLoc);
1921 }
1922
Carlo Bertolli2404b172016-07-13 15:37:16 +00001923 /// Build a new OpenMP 'use_device_ptr' clause.
1924 ///
1925 /// By default, performs semantic analysis to build the new OpenMP clause.
1926 /// Subclasses may override this routine to provide different behavior.
1927 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1928 SourceLocation StartLoc,
1929 SourceLocation LParenLoc,
1930 SourceLocation EndLoc) {
1931 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1932 EndLoc);
1933 }
1934
Carlo Bertolli70594e92016-07-13 17:16:49 +00001935 /// Build a new OpenMP 'is_device_ptr' clause.
1936 ///
1937 /// By default, performs semantic analysis to build the new OpenMP clause.
1938 /// Subclasses may override this routine to provide different behavior.
1939 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1940 SourceLocation StartLoc,
1941 SourceLocation LParenLoc,
1942 SourceLocation EndLoc) {
1943 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1944 EndLoc);
1945 }
1946
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001947 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001948 ///
1949 /// By default, performs semantic analysis to build the new statement.
1950 /// Subclasses may override this routine to provide different behavior.
1951 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1952 Expr *object) {
1953 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1954 }
1955
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001956 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001957 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001958 /// By default, performs semantic analysis to build the new statement.
1959 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001960 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001961 Expr *Object, Stmt *Body) {
1962 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001963 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001964
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001965 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001966 ///
1967 /// By default, performs semantic analysis to build the new statement.
1968 /// Subclasses may override this routine to provide different behavior.
1969 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1970 Stmt *Body) {
1971 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1972 }
John McCall53848232011-07-27 01:07:15 +00001973
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001974 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00001975 ///
1976 /// By default, performs semantic analysis to build the new statement.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001979 Stmt *Element,
1980 Expr *Collection,
1981 SourceLocation RParenLoc,
1982 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001983 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001984 Element,
John McCallb268a282010-08-23 23:25:46 +00001985 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001986 RParenLoc);
1987 if (ForEachStmt.isInvalid())
1988 return StmtError();
1989
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001990 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001991 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001992
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001993 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00001994 ///
1995 /// By default, performs semantic analysis to build the new decaration.
1996 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001997 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001998 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001999 SourceLocation StartLoc,
2000 SourceLocation IdLoc,
2001 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002002 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00002003 StartLoc, IdLoc, Id);
2004 if (Var)
2005 getSema().CurContext->addDecl(Var);
2006 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00002007 }
2008
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002009 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002010 ///
2011 /// By default, performs semantic analysis to build the new statement.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002014 VarDecl *ExceptionDecl,
2015 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002016 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2017 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002020 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002021 ///
2022 /// By default, performs semantic analysis to build the new statement.
2023 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002024 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2025 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002026 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002029 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002030 ///
2031 /// By default, performs semantic analysis to build the new statement.
2032 /// Subclasses may override this routine to provide different behavior.
2033 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002034 SourceLocation CoawaitLoc, Stmt *Init,
2035 SourceLocation ColonLoc, Stmt *Range,
2036 Stmt *Begin, Stmt *End, Expr *Cond,
2037 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002038 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002039 // If we've just learned that the range is actually an Objective-C
2040 // collection, treat this as an Objective-C fast enumeration loop.
2041 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2042 if (RangeStmt->isSingleDecl()) {
2043 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002044 if (RangeVar->isInvalidDecl())
2045 return StmtError();
2046
Douglas Gregorf7106af2013-04-08 18:40:13 +00002047 Expr *RangeExpr = RangeVar->getInit();
2048 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002049 RangeExpr->getType()->isObjCObjectPointerType()) {
2050 // FIXME: Support init-statements in Objective-C++20 ranged for
2051 // statement.
2052 if (Init) {
2053 return SemaRef.Diag(Init->getBeginLoc(),
2054 diag::err_objc_for_range_init_stmt)
2055 << Init->getSourceRange();
2056 }
2057 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2058 RangeExpr, RParenLoc);
2059 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002060 }
2061 }
2062 }
2063
Richard Smith8baa5002018-09-28 18:44:09 +00002064 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2065 Range, Begin, End, Cond, Inc, LoopVar,
2066 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002067 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002068
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002069 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002070 ///
2071 /// By default, performs semantic analysis to build the new statement.
2072 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002073 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002074 bool IsIfExists,
2075 NestedNameSpecifierLoc QualifierLoc,
2076 DeclarationNameInfo NameInfo,
2077 Stmt *Nested) {
2078 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2079 QualifierLoc, NameInfo, Nested);
2080 }
2081
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002082 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002083 ///
2084 /// By default, performs semantic analysis to finish the new statement.
2085 /// Subclasses may override this routine to provide different behavior.
2086 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2087 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2088 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002089
David Majnemerfad8f482013-10-15 09:33:02 +00002090 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002091 Stmt *TryBlock, Stmt *Handler) {
2092 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002093 }
2094
David Majnemerfad8f482013-10-15 09:33:02 +00002095 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002096 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002097 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002098 }
2099
David Majnemerfad8f482013-10-15 09:33:02 +00002100 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002101 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002102 }
2103
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002104 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
2108 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002109 PredefinedExpr::IdentKind IK) {
2110 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002111 }
2112
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002113 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 ///
2115 /// By default, performs semantic analysis to build the new expression.
2116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002117 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002118 LookupResult &R,
2119 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002120 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2121 }
2122
2123
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002124 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002125 ///
2126 /// By default, performs semantic analysis to build the new expression.
2127 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002128 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002129 ValueDecl *VD,
2130 const DeclarationNameInfo &NameInfo,
2131 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002132 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002133 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002134
2135 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002136
2137 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 }
Mike Stump11289f42009-09-09 15:08:12 +00002139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002140 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002141 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002142 /// By default, performs semantic analysis to build the new expression.
2143 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002144 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002146 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 }
2148
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002149 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002150 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002154 SourceLocation OperatorLoc,
2155 bool isArrow,
2156 CXXScopeSpec &SS,
2157 TypeSourceInfo *ScopeType,
2158 SourceLocation CCLoc,
2159 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002160 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002161
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002162 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002163 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// By default, performs semantic analysis to build the new expression.
2165 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002166 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002167 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002168 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002169 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 }
Mike Stump11289f42009-09-09 15:08:12 +00002171
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002172 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002173 ///
2174 /// By default, performs semantic analysis to build the new expression.
2175 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002176 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002177 TypeSourceInfo *Type,
2178 ArrayRef<Sema::OffsetOfComponent> Components,
2179 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002180 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002181 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002182 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002183
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002184 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002185 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002186 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 /// By default, performs semantic analysis to build the new expression.
2188 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002189 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2190 SourceLocation OpLoc,
2191 UnaryExprOrTypeTrait ExprKind,
2192 SourceRange R) {
2193 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 }
2195
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002196 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002197 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002198 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002199 /// By default, performs semantic analysis to build the new expression.
2200 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002201 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2202 UnaryExprOrTypeTrait ExprKind,
2203 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002204 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002205 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002207 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002208
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002209 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 }
Mike Stump11289f42009-09-09 15:08:12 +00002211
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002212 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002213 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 /// By default, performs semantic analysis to build the new expression.
2215 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002216 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002218 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002220 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002221 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002222 RBracketLoc);
2223 }
2224
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002225 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002226 ///
2227 /// By default, performs semantic analysis to build the new expression.
2228 /// Subclasses may override this routine to provide different behavior.
2229 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2230 Expr *LowerBound,
2231 SourceLocation ColonLoc, Expr *Length,
2232 SourceLocation RBracketLoc) {
2233 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2234 ColonLoc, Length, RBracketLoc);
2235 }
2236
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002237 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002238 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002239 /// By default, performs semantic analysis to build the new expression.
2240 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002241 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002243 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002244 Expr *ExecConfig = nullptr) {
2245 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002246 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002247 }
2248
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002249 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002250 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002253 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002254 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002255 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002256 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002257 const DeclarationNameInfo &MemberNameInfo,
2258 ValueDecl *Member,
2259 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002260 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002261 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002262 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2263 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002264 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002265 // We have a reference to an unnamed field. This is always the
2266 // base of an anonymous struct/union member access, i.e. the
2267 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002268 assert(Member->getType()->isRecordType() &&
2269 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002270
Richard Smithcab9a7d2011-10-26 19:06:56 +00002271 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002272 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002273 QualifierLoc.getNestedNameSpecifier(),
2274 FoundDecl, Member);
2275 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002276 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002277 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002278
2279 CXXScopeSpec EmptySS;
2280 return getSema().BuildFieldReferenceExpr(
2281 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2282 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002285 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002286 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002287
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002288 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002289 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002290
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002291 if (isArrow && !BaseType->isPointerType())
2292 return ExprError();
2293
John McCall16df1e52010-03-30 21:47:33 +00002294 // FIXME: this involves duplicating earlier analysis in a lot of
2295 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002296 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002297 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002298 R.resolveKind();
2299
John McCallb268a282010-08-23 23:25:46 +00002300 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002301 SS, TemplateKWLoc,
2302 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002303 R, ExplicitTemplateArgs,
2304 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 }
Mike Stump11289f42009-09-09 15:08:12 +00002306
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002307 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002308 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 /// By default, performs semantic analysis to build the new expression.
2310 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002311 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002312 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002313 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002314 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 }
2316
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002317 /// Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002318 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 /// By default, performs semantic analysis to build the new expression.
2320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002322 SourceLocation QuestionLoc,
2323 Expr *LHS,
2324 SourceLocation ColonLoc,
2325 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002326 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2327 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 }
2329
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002330 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002331 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002332 /// By default, performs semantic analysis to build the new expression.
2333 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002334 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002335 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002336 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002337 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002338 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002339 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 }
Mike Stump11289f42009-09-09 15:08:12 +00002341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002342 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 /// By default, performs semantic analysis to build the new expression.
2345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002346 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002347 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002349 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002350 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002351 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002354 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002355 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002356 /// By default, performs semantic analysis to build the new expression.
2357 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002358 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 SourceLocation OpLoc,
2360 SourceLocation AccessorLoc,
2361 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002362
John McCall10eae182009-11-30 22:42:35 +00002363 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002364 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002365 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002366 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002367 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002368 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002369 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002370 /* TemplateArgs */ nullptr,
2371 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 }
Mike Stump11289f42009-09-09 15:08:12 +00002373
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002374 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002375 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002376 /// By default, performs semantic analysis to build the new expression.
2377 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002378 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002379 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002380 SourceLocation RBraceLoc) {
2381 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002384 /// Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002385 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 /// By default, performs semantic analysis to build the new expression.
2387 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002388 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 MultiExprArg ArrayExprs,
2390 SourceLocation EqualOrColonLoc,
2391 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002392 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002393 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002395 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002398
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002399 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 }
Mike Stump11289f42009-09-09 15:08:12 +00002401
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002402 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002403 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002404 /// By default, builds the implicit value initialization without performing
2405 /// any semantic analysis. Subclasses may override this routine to provide
2406 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002407 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002408 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002409 }
Mike Stump11289f42009-09-09 15:08:12 +00002410
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002411 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002412 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002413 /// By default, performs semantic analysis to build the new expression.
2414 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002415 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002416 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002417 SourceLocation RParenLoc) {
2418 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002419 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002420 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
2422
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002423 /// Build a new expression list in parentheses.
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 RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002428 MultiExprArg SubExprs,
2429 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002430 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002431 }
Mike Stump11289f42009-09-09 15:08:12 +00002432
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002433 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002434 ///
2435 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 /// rather than attempting to map the label statement itself.
2437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002438 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002439 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002440 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002441 }
Mike Stump11289f42009-09-09 15:08:12 +00002442
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002443 /// Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002444 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 /// By default, performs semantic analysis to build the new expression.
2446 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002447 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002448 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002450 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 }
Mike Stump11289f42009-09-09 15:08:12 +00002452
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002453 /// Build a new __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 ///
2455 /// By default, performs semantic analysis to build the new expression.
2456 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002457 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002458 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002459 SourceLocation RParenLoc) {
2460 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002461 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002462 RParenLoc);
2463 }
Mike Stump11289f42009-09-09 15:08:12 +00002464
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002465 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002466 ///
2467 /// By default, performs semantic analysis to build the new expression.
2468 /// Subclasses may override this routine to provide different behavior.
2469 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2470 SourceLocation DefaultLoc,
2471 SourceLocation RParenLoc,
2472 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002473 ArrayRef<TypeSourceInfo *> Types,
2474 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002475 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002476 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002477 }
2478
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002479 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 ///
2481 /// By default, performs semantic analysis to build the new expression.
2482 /// The semantic analysis provides the behavior of template instantiation,
2483 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002484 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 /// argument-dependent lookup, etc. Subclasses may override this routine to
2486 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002487 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002489 Expr *Callee,
2490 Expr *First,
2491 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002492
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002493 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 /// reinterpret_cast.
2495 ///
2496 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002497 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002499 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 Stmt::StmtClass Class,
2501 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002502 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002503 SourceLocation RAngleLoc,
2504 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002505 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 SourceLocation RParenLoc) {
2507 switch (Class) {
2508 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002509 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002510 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002511 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002512
2513 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002514 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002515 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002516 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002517
Douglas Gregora16548e2009-08-11 05:31:07 +00002518 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002519 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002520 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002521 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002523
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002525 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002526 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002527 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002528
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002530 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 }
Mike Stump11289f42009-09-09 15:08:12 +00002533
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002534 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 ///
2536 /// By default, performs semantic analysis to build the new expression.
2537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002538 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002540 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 SourceLocation RAngleLoc,
2542 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002543 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002544 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002545 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002546 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002547 SourceRange(LAngleLoc, RAngleLoc),
2548 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 }
2550
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002551 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 ///
2553 /// By default, performs semantic analysis to build the new expression.
2554 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002555 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002557 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 SourceLocation RAngleLoc,
2559 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002560 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002562 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002563 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002564 SourceRange(LAngleLoc, RAngleLoc),
2565 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002566 }
2567
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002568 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002569 ///
2570 /// By default, performs semantic analysis to build the new expression.
2571 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002572 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002574 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 SourceLocation RAngleLoc,
2576 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002577 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002578 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002579 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002580 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002581 SourceRange(LAngleLoc, RAngleLoc),
2582 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002583 }
2584
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002585 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002586 ///
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002589 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002591 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 SourceLocation RAngleLoc,
2593 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002594 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002595 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002596 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002597 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002598 SourceRange(LAngleLoc, RAngleLoc),
2599 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002600 }
Mike Stump11289f42009-09-09 15:08:12 +00002601
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002602 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002603 ///
2604 /// By default, performs semantic analysis to build the new expression.
2605 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002606 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2607 SourceLocation LParenLoc,
2608 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002609 SourceLocation RParenLoc,
2610 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002611 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002612 MultiExprArg(&Sub, 1), RParenLoc,
2613 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002614 }
Mike Stump11289f42009-09-09 15:08:12 +00002615
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002616 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002620 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002621 SourceLocation TypeidLoc,
2622 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002623 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002624 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002625 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002626 }
Mike Stump11289f42009-09-09 15:08:12 +00002627
Francois Pichet9f4f2072010-09-08 12:20:18 +00002628
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002629 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002630 ///
2631 /// By default, performs semantic analysis to build the new expression.
2632 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002633 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002634 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002635 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002636 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002637 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002638 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002639 }
2640
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002641 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002642 ///
2643 /// By default, performs semantic analysis to build the new expression.
2644 /// Subclasses may override this routine to provide different behavior.
2645 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2646 SourceLocation TypeidLoc,
2647 TypeSourceInfo *Operand,
2648 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002649 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002650 RParenLoc);
2651 }
2652
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002653 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002654 ///
2655 /// By default, performs semantic analysis to build the new expression.
2656 /// Subclasses may override this routine to provide different behavior.
2657 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2658 SourceLocation TypeidLoc,
2659 Expr *Operand,
2660 SourceLocation RParenLoc) {
2661 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2662 RParenLoc);
2663 }
2664
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002665 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002666 ///
2667 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002668 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002670 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002671 QualType ThisType,
2672 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002673 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002674 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002675 }
2676
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002677 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002678 ///
2679 /// By default, performs semantic analysis to build the new expression.
2680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002681 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2682 bool IsThrownVariableInScope) {
2683 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002684 }
2685
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002686 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 ///
2688 /// By default, builds a new default-argument expression, which does not
2689 /// require any semantic analysis. Subclasses may override this routine to
2690 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002691 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002692 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002693 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002694 }
2695
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002696 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002697 ///
2698 /// By default, builds a new default field initialization expression, which
2699 /// does not require any semantic analysis. Subclasses may override this
2700 /// routine to provide different behavior.
2701 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2702 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002703 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002704 }
2705
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002706 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002707 ///
2708 /// By default, performs semantic analysis to build the new expression.
2709 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002710 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2711 SourceLocation LParenLoc,
2712 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002713 return getSema().BuildCXXTypeConstructExpr(
2714 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002715 }
Mike Stump11289f42009-09-09 15:08:12 +00002716
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002717 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002718 ///
2719 /// By default, performs semantic analysis to build the new expression.
2720 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002721 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002722 bool UseGlobal,
2723 SourceLocation PlacementLParen,
2724 MultiExprArg PlacementArgs,
2725 SourceLocation PlacementRParen,
2726 SourceRange TypeIdParens,
2727 QualType AllocatedType,
2728 TypeSourceInfo *AllocatedTypeInfo,
2729 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002730 SourceRange DirectInitRange,
2731 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002732 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002733 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002734 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002735 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002736 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002737 AllocatedType,
2738 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002739 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002740 DirectInitRange,
2741 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 }
Mike Stump11289f42009-09-09 15:08:12 +00002743
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002744 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002745 ///
2746 /// By default, performs semantic analysis to build the new expression.
2747 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002748 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002749 bool IsGlobalDelete,
2750 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002751 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002752 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002753 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002754 }
Mike Stump11289f42009-09-09 15:08:12 +00002755
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002756 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002757 ///
2758 /// By default, performs semantic analysis to build the new expression.
2759 /// Subclasses may override this routine to provide different behavior.
2760 ExprResult RebuildTypeTrait(TypeTrait Trait,
2761 SourceLocation StartLoc,
2762 ArrayRef<TypeSourceInfo *> Args,
2763 SourceLocation RParenLoc) {
2764 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002766
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002767 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002768 ///
2769 /// By default, performs semantic analysis to build the new expression.
2770 /// Subclasses may override this routine to provide different behavior.
2771 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2772 SourceLocation StartLoc,
2773 TypeSourceInfo *TSInfo,
2774 Expr *DimExpr,
2775 SourceLocation RParenLoc) {
2776 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2777 }
2778
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002779 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002780 ///
2781 /// By default, performs semantic analysis to build the new expression.
2782 /// Subclasses may override this routine to provide different behavior.
2783 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2784 SourceLocation StartLoc,
2785 Expr *Queried,
2786 SourceLocation RParenLoc) {
2787 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2788 }
2789
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002790 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002791 /// expression.
2792 ///
2793 /// By default, performs semantic analysis to build the new expression.
2794 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002795 ExprResult RebuildDependentScopeDeclRefExpr(
2796 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002797 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002798 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002799 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002800 bool IsAddressOfOperand,
2801 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002802 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002803 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002804
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002805 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002806 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2807 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002808
Reid Kleckner32506ed2014-06-12 23:03:48 +00002809 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002810 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002811 }
2812
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002813 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002814 ///
2815 /// By default, performs semantic analysis to build the new expression.
2816 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002817 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002818 SourceLocation TemplateKWLoc,
2819 LookupResult &R,
2820 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002821 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002822 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2823 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002824 }
2825
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002826 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 ///
2828 /// By default, performs semantic analysis to build the new expression.
2829 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002830 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002831 SourceLocation Loc,
2832 CXXConstructorDecl *Constructor,
2833 bool IsElidable,
2834 MultiExprArg Args,
2835 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002836 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002837 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002838 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002839 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002840 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002841 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002842 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002843 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002844 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002845
Richard Smithc83bf822016-06-10 00:58:19 +00002846 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002847 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002848 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002849 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002850 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002851 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002852 RequiresZeroInit, ConstructKind,
2853 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002854 }
2855
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002856 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002857 /// expression.
2858 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2859 CXXConstructorDecl *Constructor,
2860 bool ConstructsVBase,
2861 bool InheritedFromVBase) {
2862 return new (getSema().Context) CXXInheritedCtorInitExpr(
2863 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2864 }
2865
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002866 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002867 ///
2868 /// By default, performs semantic analysis to build the new expression.
2869 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002870 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002871 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002872 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002873 SourceLocation RParenOrBraceLoc,
2874 bool ListInitialization) {
2875 return getSema().BuildCXXTypeConstructExpr(
2876 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002877 }
2878
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002879 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002880 ///
2881 /// By default, performs semantic analysis to build the new expression.
2882 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002883 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2884 SourceLocation LParenLoc,
2885 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002886 SourceLocation RParenLoc,
2887 bool ListInitialization) {
2888 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2889 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002890 }
Mike Stump11289f42009-09-09 15:08:12 +00002891
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002892 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002893 ///
2894 /// By default, performs semantic analysis to build the new expression.
2895 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002896 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002897 QualType BaseType,
2898 bool IsArrow,
2899 SourceLocation OperatorLoc,
2900 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002901 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002902 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002903 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002904 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002905 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002906 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002907
John McCallb268a282010-08-23 23:25:46 +00002908 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002909 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002910 SS, TemplateKWLoc,
2911 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002912 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002913 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002914 }
2915
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002916 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002917 ///
2918 /// By default, performs semantic analysis to build the new expression.
2919 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002920 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2921 SourceLocation OperatorLoc,
2922 bool IsArrow,
2923 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002924 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002925 NamedDecl *FirstQualifierInScope,
2926 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002927 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002928 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002929 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002930
John McCallb268a282010-08-23 23:25:46 +00002931 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002932 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002933 SS, TemplateKWLoc,
2934 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002935 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002936 }
Mike Stump11289f42009-09-09 15:08:12 +00002937
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002938 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002939 ///
2940 /// By default, performs semantic analysis to build the new expression.
2941 /// Subclasses may override this routine to provide different behavior.
2942 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2943 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2944 }
2945
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002946 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002947 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2948 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002949 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002950 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002951 Optional<unsigned> Length,
2952 ArrayRef<TemplateArgument> PartialArgs) {
2953 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2954 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002955 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002956
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002957 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00002958 ///
2959 /// By default, performs semantic analysis to build the new expression.
2960 /// Subclasses may override this routine to provide different behavior.
2961 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2962 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002964
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002965 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002966 ///
2967 /// By default, performs semantic analysis to build the new expression.
2968 /// Subclasses may override this routine to provide different behavior.
2969 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2970 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002971 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002972 MultiExprArg(Elements, NumElements));
2973 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002974
2975 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002976 Expr *Base, Expr *Key,
2977 ObjCMethodDecl *getterMethod,
2978 ObjCMethodDecl *setterMethod) {
2979 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2980 getterMethod, setterMethod);
2981 }
2982
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002983 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002984 ///
2985 /// By default, performs semantic analysis to build the new expression.
2986 /// Subclasses may override this routine to provide different behavior.
2987 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002988 MutableArrayRef<ObjCDictionaryElement> Elements) {
2989 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002990 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002991
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002992 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002993 ///
2994 /// By default, performs semantic analysis to build the new expression.
2995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002996 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002997 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002998 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002999 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003000 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003001
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003002 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00003003 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003004 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003005 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003006 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003007 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003008 MultiExprArg Args,
3009 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003010 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3011 ReceiverTypeInfo->getType(),
3012 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003013 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003014 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003015 }
3016
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003017 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003018 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003019 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003020 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003021 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003022 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003023 MultiExprArg Args,
3024 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003025 return SemaRef.BuildInstanceMessage(Receiver,
3026 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003027 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003028 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003029 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003030 }
3031
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003032 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003033 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3034 Selector Sel,
3035 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003036 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003037 ObjCMethodDecl *Method,
3038 SourceLocation LBracLoc,
3039 MultiExprArg Args,
3040 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003041 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003042 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003043 SuperLoc,
3044 Sel, Method, LBracLoc, SelectorLocs,
3045 RBracLoc, Args)
3046 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003047 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003048 SuperLoc,
3049 Sel, Method, LBracLoc, SelectorLocs,
3050 RBracLoc, Args);
3051
Fangrui Song6907ce22018-07-30 19:24:48 +00003052
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003053 }
3054
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003055 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003056 ///
3057 /// By default, performs semantic analysis to build the new expression.
3058 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003059 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003060 SourceLocation IvarLoc,
3061 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003062 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003063 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003064 ExprResult Result = getSema().BuildMemberReferenceExpr(
3065 BaseArg, BaseArg->getType(),
3066 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3067 /*FirstQualifierInScope=*/nullptr, NameInfo,
3068 /*TemplateArgs=*/nullptr,
3069 /*S=*/nullptr);
3070 if (IsFreeIvar && Result.isUsable())
3071 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3072 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003073 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003074
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003075 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003076 ///
3077 /// By default, performs semantic analysis to build the new expression.
3078 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003079 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003080 ObjCPropertyDecl *Property,
3081 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003082 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003083 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3084 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3085 /*FIXME:*/PropertyLoc,
3086 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003087 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003088 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003089 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003090 /*TemplateArgs=*/nullptr,
3091 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003092 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003093
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003094 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003095 ///
3096 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003097 /// Subclasses may override this routine to provide different behavior.
3098 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3099 ObjCMethodDecl *Getter,
3100 ObjCMethodDecl *Setter,
3101 SourceLocation PropertyLoc) {
3102 // Since these expressions can only be value-dependent, we do not
3103 // need to perform semantic analysis again.
3104 return Owned(
3105 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3106 VK_LValue, OK_ObjCProperty,
3107 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003108 }
3109
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003110 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003111 ///
3112 /// By default, performs semantic analysis to build the new expression.
3113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003114 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003115 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003116 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003117 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3118 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003119 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003120 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003121 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003122 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003123 /*TemplateArgs=*/nullptr,
3124 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003126
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003127 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003128 ///
3129 /// By default, performs semantic analysis to build the new expression.
3130 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003131 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003132 MultiExprArg SubExprs,
3133 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003134 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003135 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003136 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3137 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3138 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003139 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003140
Douglas Gregora16548e2009-08-11 05:31:07 +00003141 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003142 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003143 Expr *Callee = new (SemaRef.Context)
3144 DeclRefExpr(SemaRef.Context, Builtin, false,
3145 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003146 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3147 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003148 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003149
3150 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003151 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003152 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003153 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregora16548e2009-08-11 05:31:07 +00003155 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003156 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003157 }
John McCall31f82722010-11-12 08:19:04 +00003158
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003159 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003160 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3161 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3162 SourceLocation RParenLoc) {
3163 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3164 BuiltinLoc, RParenLoc);
3165 }
3166
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003167 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003168 ///
3169 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003170 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003171 /// different behavior.
3172 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003173 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003174 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003175 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003176 case TemplateArgument::Expression: {
3177 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003178 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3179 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003180 if (Result.isInvalid())
3181 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003182
Douglas Gregor98318c22011-01-03 21:37:45 +00003183 return TemplateArgumentLoc(Result.get(), Result.get());
3184 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003185
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003186 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003187 return TemplateArgumentLoc(TemplateArgument(
3188 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003189 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003190 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003191 Pattern.getTemplateNameLoc(),
3192 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003193
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003194 case TemplateArgument::Null:
3195 case TemplateArgument::Integral:
3196 case TemplateArgument::Declaration:
3197 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003198 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003199 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003200 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003201
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003202 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003203 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003204 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003205 EllipsisLoc,
3206 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003207 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3208 Expansion);
3209 break;
3210 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003211
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003212 return TemplateArgumentLoc();
3213 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003214
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003215 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003216 ///
3217 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003218 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003219 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003220 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003221 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003222 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003223 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003224
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003225 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003226 ///
3227 /// By default, performs semantic analysis in order to build a new fold
3228 /// expression.
3229 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3230 BinaryOperatorKind Operator,
3231 SourceLocation EllipsisLoc, Expr *RHS,
3232 SourceLocation RParenLoc) {
3233 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3234 RHS, RParenLoc);
3235 }
3236
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003237 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003238 ///
3239 /// By default, produces the fallback value for the fold-expression, or
3240 /// produce an error if there is no fallback value.
3241 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3242 BinaryOperatorKind Operator) {
3243 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3244 }
3245
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003246 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003247 ///
3248 /// By default, performs semantic analysis to build the new expression.
3249 /// Subclasses may override this routine to provide different behavior.
3250 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3251 MultiExprArg SubExprs,
3252 QualType RetTy,
3253 AtomicExpr::AtomicOp Op,
3254 SourceLocation RParenLoc) {
3255 // Just create the expression; there is not any interesting semantic
3256 // analysis here because we can't actually build an AtomicExpr until
3257 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003258 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003259 RParenLoc);
3260 }
3261
John McCall31f82722010-11-12 08:19:04 +00003262private:
Douglas Gregor14454802011-02-25 02:25:35 +00003263 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3264 QualType ObjectType,
3265 NamedDecl *FirstQualifierInScope,
3266 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003267
3268 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3269 QualType ObjectType,
3270 NamedDecl *FirstQualifierInScope,
3271 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003272
3273 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3274 NamedDecl *FirstQualifierInScope,
3275 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003276
3277 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3278 DependentNameTypeLoc TL,
3279 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003280};
Douglas Gregora16548e2009-08-11 05:31:07 +00003281
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003282template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003283StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003285 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 switch (S->getStmtClass()) {
3288 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003289
Douglas Gregorebe10102009-08-20 07:17:43 +00003290 // Transform individual statement nodes
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003291 // Pass SDK into statements that can produce a value
Douglas Gregorebe10102009-08-20 07:17:43 +00003292#define STMT(Node, Parent) \
3293 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003294#define VALUESTMT(Node, Parent) \
3295 case Stmt::Node##Class: \
3296 return getDerived().Transform##Node(cast<Node>(S), SDK);
John McCallbd066782011-02-09 08:16:59 +00003297#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003298#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003299#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 // Transform expressions by calling TransformExpr.
3302#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003303#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003304#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003305#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003306 {
John McCalldadc5752010-08-24 06:29:42 +00003307 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Mike Stump11289f42009-09-09 15:08:12 +00003308
Richard Smitha6e8d5e2019-02-15 00:27:53 +00003309 if (SDK == SDK_StmtExprResult)
3310 E = getSema().ActOnStmtExprResult(E);
3311 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
Douglas Gregorebe10102009-08-20 07:17:43 +00003312 }
Mike Stump11289f42009-09-09 15:08:12 +00003313 }
3314
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003315 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003316}
Mike Stump11289f42009-09-09 15:08:12 +00003317
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003318template<typename Derived>
3319OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3320 if (!S)
3321 return S;
3322
3323 switch (S->getClauseKind()) {
3324 default: break;
3325 // Transform individual clause nodes
3326#define OPENMP_CLAUSE(Name, Class) \
3327 case OMPC_ ## Name : \
3328 return getDerived().Transform ## Class(cast<Class>(S));
Roman Lebedev23019f92019-01-28 17:04:11 +00003329 OPENMP_CLAUSE(flush, OMPFlushClause)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003330#include "clang/Basic/OpenMPKinds.def"
3331 }
3332
3333 return S;
3334}
3335
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregore922c772009-08-04 22:27:00 +00003337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003338ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003339 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003340 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003341
3342 switch (E->getStmtClass()) {
3343 case Stmt::NoStmtClass: break;
3344#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003345#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003346#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003347 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003348#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003349 }
3350
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003351 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003352}
3353
3354template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003355ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003356 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003357 // Initializers are instantiated like expressions, except that various outer
3358 // layers are stripped.
3359 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003360 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003361
Bill Wendling7c44da22018-10-31 03:48:47 +00003362 if (auto *FE = dyn_cast<FullExpr>(Init))
3363 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003364
Richard Smith410306b2016-12-12 02:53:20 +00003365 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3366 Init = AIL->getCommonExpr();
3367
Richard Smithe6ca4752013-05-30 22:40:16 +00003368 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3369 Init = MTE->GetTemporaryExpr();
3370
Richard Smithd59b8322012-12-19 01:39:02 +00003371 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3372 Init = Binder->getSubExpr();
3373
3374 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3375 Init = ICE->getSubExprAsWritten();
3376
Richard Smithcc1b96d2013-06-12 22:31:48 +00003377 if (CXXStdInitializerListExpr *ILE =
3378 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003379 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003380
Richard Smithc6abd962014-07-25 01:12:44 +00003381 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003382 // InitListExprs. Other forms of copy-initialization will be a no-op if
3383 // the initializer is already the right type.
3384 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003385 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003386 return getDerived().TransformExpr(Init);
3387
3388 // Revert value-initialization back to empty parens.
3389 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3390 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003391 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003392 Parens.getEnd());
3393 }
3394
3395 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3396 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003397 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003398 SourceLocation());
3399
3400 // Revert initialization by constructor back to a parenthesized or braced list
3401 // of expressions. Any other form of initializer can just be reused directly.
3402 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003403 return getDerived().TransformExpr(Init);
3404
Richard Smithf8adcdc2014-07-17 05:12:35 +00003405 // If the initialization implicitly converted an initializer list to a
3406 // std::initializer_list object, unwrap the std::initializer_list too.
3407 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003408 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003409
Richard Smith12938cf2018-09-26 04:36:55 +00003410 // Enter a list-init context if this was list initialization.
3411 EnterExpressionEvaluationContext Context(
3412 getSema(), EnterExpressionEvaluationContext::InitList,
3413 Construct->isListInitialization());
3414
Richard Smithd59b8322012-12-19 01:39:02 +00003415 SmallVector<Expr*, 8> NewArgs;
3416 bool ArgChanged = false;
3417 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003418 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003419 return ExprError();
3420
Richard Smithd1036122018-01-12 22:21:33 +00003421 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003422 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003423 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003424 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003425
Richard Smithd59b8322012-12-19 01:39:02 +00003426 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003427 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003428 if (Parens.isInvalid()) {
3429 // This was a variable declaration's initialization for which no initializer
3430 // was specified.
3431 assert(NewArgs.empty() &&
3432 "no parens or braces but have direct init with arguments?");
3433 return ExprEmpty();
3434 }
Richard Smithd59b8322012-12-19 01:39:02 +00003435 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3436 Parens.getEnd());
3437}
3438
3439template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003440bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003441 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003442 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003443 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003444 bool *ArgChanged) {
3445 for (unsigned I = 0; I != NumInputs; ++I) {
3446 // If requested, drop call arguments that need to be dropped.
3447 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3448 if (ArgChanged)
3449 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003450
Douglas Gregora3efea12011-01-03 19:04:46 +00003451 break;
3452 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor968f23a2011-01-03 19:31:53 +00003454 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3455 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Chris Lattner01cf8db2011-07-20 06:58:45 +00003457 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003458 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3459 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003460
Douglas Gregor968f23a2011-01-03 19:31:53 +00003461 // Determine whether the set of unexpanded parameter packs can and should
3462 // be expanded.
3463 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003464 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003465 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3466 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003467 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3468 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003469 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003470 Expand, RetainExpansion,
3471 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003472 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregor968f23a2011-01-03 19:31:53 +00003474 if (!Expand) {
3475 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003476 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003477 // expansion.
3478 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3479 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3480 if (OutPattern.isInvalid())
3481 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003482
3483 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003484 Expansion->getEllipsisLoc(),
3485 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003486 if (Out.isInvalid())
3487 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003488
Douglas Gregor968f23a2011-01-03 19:31:53 +00003489 if (ArgChanged)
3490 *ArgChanged = true;
3491 Outputs.push_back(Out.get());
3492 continue;
3493 }
John McCall542e7c62011-07-06 07:30:07 +00003494
3495 // Record right away that the argument was changed. This needs
3496 // to happen even if the array expands to nothing.
3497 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003498
Douglas Gregor968f23a2011-01-03 19:31:53 +00003499 // The transform has determined that we should perform an elementwise
3500 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003501 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3503 ExprResult Out = getDerived().TransformExpr(Pattern);
3504 if (Out.isInvalid())
3505 return true;
3506
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003507 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003508 Out = getDerived().RebuildPackExpansion(
3509 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003510 if (Out.isInvalid())
3511 return true;
3512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregor968f23a2011-01-03 19:31:53 +00003514 Outputs.push_back(Out.get());
3515 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003516
Richard Smith9467be42014-06-06 17:33:35 +00003517 // If we're supposed to retain a pack expansion, do so by temporarily
3518 // forgetting the partially-substituted parameter pack.
3519 if (RetainExpansion) {
3520 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3521
3522 ExprResult Out = getDerived().TransformExpr(Pattern);
3523 if (Out.isInvalid())
3524 return true;
3525
3526 Out = getDerived().RebuildPackExpansion(
3527 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3528 if (Out.isInvalid())
3529 return true;
3530
3531 Outputs.push_back(Out.get());
3532 }
3533
Douglas Gregor968f23a2011-01-03 19:31:53 +00003534 continue;
3535 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003536
Richard Smithd59b8322012-12-19 01:39:02 +00003537 ExprResult Result =
3538 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3539 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003540 if (Result.isInvalid())
3541 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregora3efea12011-01-03 19:04:46 +00003543 if (Result.get() != Inputs[I] && ArgChanged)
3544 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003545
3546 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003547 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003548
Douglas Gregora3efea12011-01-03 19:04:46 +00003549 return false;
3550}
3551
Richard Smith03a4aa32016-06-23 19:02:52 +00003552template <typename Derived>
3553Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3554 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3555 if (Var) {
3556 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3557 getDerived().TransformDefinition(Var->getLocation(), Var));
3558
3559 if (!ConditionVar)
3560 return Sema::ConditionError();
3561
3562 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3563 }
3564
3565 if (Expr) {
3566 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3567
3568 if (CondExpr.isInvalid())
3569 return Sema::ConditionError();
3570
3571 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3572 }
3573
3574 return Sema::ConditionResult();
3575}
3576
Douglas Gregora3efea12011-01-03 19:04:46 +00003577template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003578NestedNameSpecifierLoc
3579TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3580 NestedNameSpecifierLoc NNS,
3581 QualType ObjectType,
3582 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003583 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003584 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003585 Qualifier = Qualifier.getPrefix())
3586 Qualifiers.push_back(Qualifier);
3587
3588 CXXScopeSpec SS;
3589 while (!Qualifiers.empty()) {
3590 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3591 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregor14454802011-02-25 02:25:35 +00003593 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003594 case NestedNameSpecifier::Identifier: {
3595 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3596 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3597 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3598 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003599 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003600 }
Douglas Gregor14454802011-02-25 02:25:35 +00003601 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
Douglas Gregor14454802011-02-25 02:25:35 +00003603 case NestedNameSpecifier::Namespace: {
3604 NamespaceDecl *NS
3605 = cast_or_null<NamespaceDecl>(
3606 getDerived().TransformDecl(
3607 Q.getLocalBeginLoc(),
3608 QNNS->getAsNamespace()));
3609 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3610 break;
3611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Douglas Gregor14454802011-02-25 02:25:35 +00003613 case NestedNameSpecifier::NamespaceAlias: {
3614 NamespaceAliasDecl *Alias
3615 = cast_or_null<NamespaceAliasDecl>(
3616 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3617 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003618 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003619 Q.getLocalEndLoc());
3620 break;
3621 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003622
Douglas Gregor14454802011-02-25 02:25:35 +00003623 case NestedNameSpecifier::Global:
3624 // There is no meaningful transformation that one could perform on the
3625 // global scope.
3626 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3627 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003628
Nikola Smiljanic67860242014-09-26 00:28:20 +00003629 case NestedNameSpecifier::Super: {
3630 CXXRecordDecl *RD =
3631 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3632 SourceLocation(), QNNS->getAsRecordDecl()));
3633 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3634 break;
3635 }
3636
Douglas Gregor14454802011-02-25 02:25:35 +00003637 case NestedNameSpecifier::TypeSpecWithTemplate:
3638 case NestedNameSpecifier::TypeSpec: {
3639 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3640 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003641
Douglas Gregor14454802011-02-25 02:25:35 +00003642 if (!TL)
3643 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003644
Douglas Gregor14454802011-02-25 02:25:35 +00003645 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003646 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003647 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003648 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003649 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003650 if (TL.getType()->isEnumeralType())
3651 SemaRef.Diag(TL.getBeginLoc(),
3652 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003653 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3654 Q.getLocalEndLoc());
3655 break;
3656 }
Richard Trieude756fb2011-05-07 01:36:37 +00003657 // If the nested-name-specifier is an invalid type def, don't emit an
3658 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003659 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3660 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003661 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003662 << TL.getType() << SS.getRange();
3663 }
Douglas Gregor14454802011-02-25 02:25:35 +00003664 return NestedNameSpecifierLoc();
3665 }
Douglas Gregore16af532011-02-28 18:50:33 +00003666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Douglas Gregore16af532011-02-28 18:50:33 +00003668 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003669 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003670 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003671 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003672
Douglas Gregor14454802011-02-25 02:25:35 +00003673 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003674 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003675 !getDerived().AlwaysRebuild())
3676 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003677
3678 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003679 // nested-name-specifier, do so.
3680 if (SS.location_size() == NNS.getDataLength() &&
3681 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3682 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3683
3684 // Allocate new nested-name-specifier location information.
3685 return SS.getWithLocInContext(SemaRef.Context);
3686}
3687
3688template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003689DeclarationNameInfo
3690TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003691::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003692 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003693 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003694 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003695
3696 switch (Name.getNameKind()) {
3697 case DeclarationName::Identifier:
3698 case DeclarationName::ObjCZeroArgSelector:
3699 case DeclarationName::ObjCOneArgSelector:
3700 case DeclarationName::ObjCMultiArgSelector:
3701 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003702 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003703 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003704 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003705
Richard Smith35845152017-02-07 01:37:30 +00003706 case DeclarationName::CXXDeductionGuideName: {
3707 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3708 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3709 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3710 if (!NewTemplate)
3711 return DeclarationNameInfo();
3712
3713 DeclarationNameInfo NewNameInfo(NameInfo);
3714 NewNameInfo.setName(
3715 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3716 return NewNameInfo;
3717 }
3718
Douglas Gregorf816bd72009-09-03 22:13:48 +00003719 case DeclarationName::CXXConstructorName:
3720 case DeclarationName::CXXDestructorName:
3721 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003722 TypeSourceInfo *NewTInfo;
3723 CanQualType NewCanTy;
3724 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003725 NewTInfo = getDerived().TransformType(OldTInfo);
3726 if (!NewTInfo)
3727 return DeclarationNameInfo();
3728 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003729 }
3730 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003731 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003732 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003733 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003734 if (NewT.isNull())
3735 return DeclarationNameInfo();
3736 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3737 }
Mike Stump11289f42009-09-09 15:08:12 +00003738
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003739 DeclarationName NewName
3740 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3741 NewCanTy);
3742 DeclarationNameInfo NewNameInfo(NameInfo);
3743 NewNameInfo.setName(NewName);
3744 NewNameInfo.setNamedTypeInfo(NewTInfo);
3745 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747 }
3748
David Blaikie83d382b2011-09-23 05:06:16 +00003749 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003750}
3751
3752template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003753TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003754TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3755 TemplateName Name,
3756 SourceLocation NameLoc,
3757 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003758 NamedDecl *FirstQualifierInScope,
3759 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003760 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3761 TemplateDecl *Template = QTN->getTemplateDecl();
3762 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003763
Douglas Gregor9db53502011-03-02 18:07:45 +00003764 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003765 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003766 Template));
3767 if (!TransTemplate)
3768 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003769
Douglas Gregor9db53502011-03-02 18:07:45 +00003770 if (!getDerived().AlwaysRebuild() &&
3771 SS.getScopeRep() == QTN->getQualifier() &&
3772 TransTemplate == Template)
3773 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregor9db53502011-03-02 18:07:45 +00003775 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3776 TransTemplate);
3777 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
Douglas Gregor9db53502011-03-02 18:07:45 +00003779 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3780 if (SS.getScopeRep()) {
3781 // These apply to the scope specifier, not the template.
3782 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003783 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003784 }
3785
Douglas Gregor9db53502011-03-02 18:07:45 +00003786 if (!getDerived().AlwaysRebuild() &&
3787 SS.getScopeRep() == DTN->getQualifier() &&
3788 ObjectType.isNull())
3789 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003790
Richard Smith79810042018-05-11 02:43:08 +00003791 // FIXME: Preserve the location of the "template" keyword.
3792 SourceLocation TemplateKWLoc = NameLoc;
3793
Douglas Gregor9db53502011-03-02 18:07:45 +00003794 if (DTN->isIdentifier()) {
3795 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003796 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003797 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003798 NameLoc,
3799 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003800 FirstQualifierInScope,
3801 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003802 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003803
Richard Smith79810042018-05-11 02:43:08 +00003804 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3805 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003806 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003808
Douglas Gregor9db53502011-03-02 18:07:45 +00003809 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3810 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003811 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003812 Template));
3813 if (!TransTemplate)
3814 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003815
Douglas Gregor9db53502011-03-02 18:07:45 +00003816 if (!getDerived().AlwaysRebuild() &&
3817 TransTemplate == Template)
3818 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003819
Douglas Gregor9db53502011-03-02 18:07:45 +00003820 return TemplateName(TransTemplate);
3821 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003822
Douglas Gregor9db53502011-03-02 18:07:45 +00003823 if (SubstTemplateTemplateParmPackStorage *SubstPack
3824 = Name.getAsSubstTemplateTemplateParmPack()) {
3825 TemplateTemplateParmDecl *TransParam
3826 = cast_or_null<TemplateTemplateParmDecl>(
3827 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3828 if (!TransParam)
3829 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003830
Douglas Gregor9db53502011-03-02 18:07:45 +00003831 if (!getDerived().AlwaysRebuild() &&
3832 TransParam == SubstPack->getParameterPack())
3833 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003834
3835 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003836 SubstPack->getArgumentPack());
3837 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003838
Douglas Gregor9db53502011-03-02 18:07:45 +00003839 // These should be getting filtered out before they reach the AST.
3840 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003841}
3842
3843template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003844void TreeTransform<Derived>::InventTemplateArgumentLoc(
3845 const TemplateArgument &Arg,
3846 TemplateArgumentLoc &Output) {
3847 SourceLocation Loc = getDerived().getBaseLocation();
3848 switch (Arg.getKind()) {
3849 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003850 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003851 break;
3852
3853 case TemplateArgument::Type:
3854 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003855 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003856
John McCall0ad16662009-10-29 08:12:44 +00003857 break;
3858
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003859 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003860 case TemplateArgument::TemplateExpansion: {
3861 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003862 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003863 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3864 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3865 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3866 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
Douglas Gregor9d802122011-03-02 17:09:35 +00003868 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003869 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003870 Builder.getWithLocInContext(SemaRef.Context),
3871 Loc);
3872 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003873 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003874 Builder.getWithLocInContext(SemaRef.Context),
3875 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003876
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003877 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003878 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003879
John McCall0ad16662009-10-29 08:12:44 +00003880 case TemplateArgument::Expression:
3881 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3882 break;
3883
3884 case TemplateArgument::Declaration:
3885 case TemplateArgument::Integral:
3886 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003887 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003888 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003889 break;
3890 }
3891}
3892
3893template<typename Derived>
3894bool TreeTransform<Derived>::TransformTemplateArgument(
3895 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003896 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003897 EnterExpressionEvaluationContext EEEC(
3898 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3899 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3900 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003901 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003902 switch (Arg.getKind()) {
3903 case TemplateArgument::Null:
3904 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003905 case TemplateArgument::Pack:
3906 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003907 case TemplateArgument::NullPtr:
3908 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003909
Douglas Gregore922c772009-08-04 22:27:00 +00003910 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003911 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003912 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003913 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003914
3915 DI = getDerived().TransformType(DI);
3916 if (!DI) return true;
3917
3918 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3919 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003920 }
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003922 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003923 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3924 if (QualifierLoc) {
3925 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3926 if (!QualifierLoc)
3927 return true;
3928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregordf846d12011-03-02 18:46:51 +00003930 CXXScopeSpec SS;
3931 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003932 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003933 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3934 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003935 if (Template.isNull())
3936 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003937
Douglas Gregor9d802122011-03-02 17:09:35 +00003938 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003939 Input.getTemplateNameLoc());
3940 return false;
3941 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003942
3943 case TemplateArgument::TemplateExpansion:
3944 llvm_unreachable("Caller should expand pack expansions");
3945
Douglas Gregore922c772009-08-04 22:27:00 +00003946 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003947 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003948 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003949 getSema(), Uneval
3950 ? Sema::ExpressionEvaluationContext::Unevaluated
3951 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003952
John McCall0ad16662009-10-29 08:12:44 +00003953 Expr *InputExpr = Input.getSourceExpression();
3954 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3955
Chris Lattnercdb591a2011-04-25 20:37:58 +00003956 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003957 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003958 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003959 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003960 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003961 }
Douglas Gregore922c772009-08-04 22:27:00 +00003962 }
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregore922c772009-08-04 22:27:00 +00003964 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003965 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003966}
3967
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003968/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00003969/// for each of the template arguments in its underlying iterator.
3970template<typename Derived, typename InputIterator>
3971class TemplateArgumentLocInventIterator {
3972 TreeTransform<Derived> &Self;
3973 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003974
Douglas Gregorfe921a72010-12-20 23:36:19 +00003975public:
3976 typedef TemplateArgumentLoc value_type;
3977 typedef TemplateArgumentLoc reference;
3978 typedef typename std::iterator_traits<InputIterator>::difference_type
3979 difference_type;
3980 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003981
Douglas Gregorfe921a72010-12-20 23:36:19 +00003982 class pointer {
3983 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003984
Douglas Gregorfe921a72010-12-20 23:36:19 +00003985 public:
3986 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003987
Douglas Gregorfe921a72010-12-20 23:36:19 +00003988 const TemplateArgumentLoc *operator->() const { return &Arg; }
3989 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003990
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003991 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003992
Douglas Gregorfe921a72010-12-20 23:36:19 +00003993 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3994 InputIterator Iter)
3995 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003996
Douglas Gregorfe921a72010-12-20 23:36:19 +00003997 TemplateArgumentLocInventIterator &operator++() {
3998 ++Iter;
3999 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00004000 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004001
Douglas Gregorfe921a72010-12-20 23:36:19 +00004002 TemplateArgumentLocInventIterator operator++(int) {
4003 TemplateArgumentLocInventIterator Old(*this);
4004 ++(*this);
4005 return Old;
4006 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004007
Douglas Gregorfe921a72010-12-20 23:36:19 +00004008 reference operator*() const {
4009 TemplateArgumentLoc Result;
4010 Self.InventTemplateArgumentLoc(*Iter, Result);
4011 return Result;
4012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004013
Douglas Gregorfe921a72010-12-20 23:36:19 +00004014 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004015
Douglas Gregorfe921a72010-12-20 23:36:19 +00004016 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4017 const TemplateArgumentLocInventIterator &Y) {
4018 return X.Iter == Y.Iter;
4019 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004020
Douglas Gregorfe921a72010-12-20 23:36:19 +00004021 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4022 const TemplateArgumentLocInventIterator &Y) {
4023 return X.Iter != Y.Iter;
4024 }
4025};
Chad Rosier1dcde962012-08-08 18:46:20 +00004026
Douglas Gregor42cafa82010-12-20 17:42:22 +00004027template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004028template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004029bool TreeTransform<Derived>::TransformTemplateArguments(
4030 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4031 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004032 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004033 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004034 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004036 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4037 // Unpack argument packs, which we translate them into separate
4038 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004039 // FIXME: We could do much better if we could guarantee that the
4040 // TemplateArgumentLocInfo for the pack expansion would be usable for
4041 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004042 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004043 TemplateArgument::pack_iterator>
4044 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004045 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004046 In.getArgument().pack_begin()),
4047 PackLocIterator(*this,
4048 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004049 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004050 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004051
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004052 continue;
4053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004054
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004055 if (In.getArgument().isPackExpansion()) {
4056 // We have a pack expansion, for which we will be substituting into
4057 // the pattern.
4058 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004059 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004060 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004061 = getSema().getTemplateArgumentPackExpansionPattern(
4062 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004063
Chris Lattner01cf8db2011-07-20 06:58:45 +00004064 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004065 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4066 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004067
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004068 // Determine whether the set of unexpanded parameter packs can and should
4069 // be expanded.
4070 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004071 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004072 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004073 if (getDerived().TryExpandParameterPacks(Ellipsis,
4074 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004075 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004076 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004077 RetainExpansion,
4078 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004079 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004081 if (!Expand) {
4082 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004083 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004084 // expansion.
4085 TemplateArgumentLoc OutPattern;
4086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004087 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004088 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004089
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004090 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4091 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004092 if (Out.getArgument().isNull())
4093 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004094
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004095 Outputs.addArgument(Out);
4096 continue;
4097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004098
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004099 // The transform has determined that we should perform an elementwise
4100 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004101 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004102 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4103
Richard Smithd784e682015-09-23 21:41:42 +00004104 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004105 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004106
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004107 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004108 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4109 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004110 if (Out.getArgument().isNull())
4111 return true;
4112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004113
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004114 Outputs.addArgument(Out);
4115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
Douglas Gregor48d24112011-01-10 20:53:55 +00004117 // If we're supposed to retain a pack expansion, do so by temporarily
4118 // forgetting the partially-substituted parameter pack.
4119 if (RetainExpansion) {
4120 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004121
Richard Smithd784e682015-09-23 21:41:42 +00004122 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004123 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004124
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004125 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4126 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004127 if (Out.getArgument().isNull())
4128 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004129
Douglas Gregor48d24112011-01-10 20:53:55 +00004130 Outputs.addArgument(Out);
4131 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004132
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004133 continue;
4134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004135
4136 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004137 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004138 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004139
Douglas Gregor42cafa82010-12-20 17:42:22 +00004140 Outputs.addArgument(Out);
4141 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004142
Douglas Gregor42cafa82010-12-20 17:42:22 +00004143 return false;
4144
4145}
4146
Douglas Gregord6ff3322009-08-04 16:50:30 +00004147//===----------------------------------------------------------------------===//
4148// Type transformation
4149//===----------------------------------------------------------------------===//
4150
4151template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004152QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004153 if (getDerived().AlreadyTransformed(T))
4154 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004155
John McCall550e0c22009-10-21 00:40:46 +00004156 // Temporary workaround. All of these transformations should
4157 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004158 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4159 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004160
John McCall31f82722010-11-12 08:19:04 +00004161 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004162
John McCall550e0c22009-10-21 00:40:46 +00004163 if (!NewDI)
4164 return QualType();
4165
4166 return NewDI->getType();
4167}
4168
4169template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004170TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004171 // Refine the base location to the type's location.
4172 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4173 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004174 if (getDerived().AlreadyTransformed(DI->getType()))
4175 return DI;
4176
4177 TypeLocBuilder TLB;
4178
4179 TypeLoc TL = DI->getTypeLoc();
4180 TLB.reserve(TL.getFullDataSize());
4181
John McCall31f82722010-11-12 08:19:04 +00004182 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004183 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004184 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004185
John McCallbcd03502009-12-07 02:54:59 +00004186 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004187}
4188
4189template<typename Derived>
4190QualType
John McCall31f82722010-11-12 08:19:04 +00004191TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004192 switch (T.getTypeLocClass()) {
4193#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004194#define TYPELOC(CLASS, PARENT) \
4195 case TypeLoc::CLASS: \
4196 return getDerived().Transform##CLASS##Type(TLB, \
4197 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004198#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004199 }
Mike Stump11289f42009-09-09 15:08:12 +00004200
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004201 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004202}
4203
Richard Smithee579842017-01-30 20:39:26 +00004204template<typename Derived>
4205QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4206 if (!isa<DependentNameType>(T))
4207 return TransformType(T);
4208
4209 if (getDerived().AlreadyTransformed(T))
4210 return T;
4211 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4212 getDerived().getBaseLocation());
4213 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4214 return NewDI ? NewDI->getType() : QualType();
4215}
4216
4217template<typename Derived>
4218TypeSourceInfo *
4219TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4220 if (!isa<DependentNameType>(DI->getType()))
4221 return TransformType(DI);
4222
4223 // Refine the base location to the type's location.
4224 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4225 getDerived().getBaseEntity());
4226 if (getDerived().AlreadyTransformed(DI->getType()))
4227 return DI;
4228
4229 TypeLocBuilder TLB;
4230
4231 TypeLoc TL = DI->getTypeLoc();
4232 TLB.reserve(TL.getFullDataSize());
4233
Richard Smithee579842017-01-30 20:39:26 +00004234 auto QTL = TL.getAs<QualifiedTypeLoc>();
4235 if (QTL)
4236 TL = QTL.getUnqualifiedLoc();
4237
4238 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4239
4240 QualType Result = getDerived().TransformDependentNameType(
4241 TLB, DNTL, /*DeducedTSTContext*/true);
4242 if (Result.isNull())
4243 return nullptr;
4244
4245 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004246 Result = getDerived().RebuildQualifiedType(Result, QTL);
4247 if (Result.isNull())
4248 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004249 TLB.TypeWasModifiedSafely(Result);
4250 }
4251
4252 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4253}
4254
John McCall550e0c22009-10-21 00:40:46 +00004255template<typename Derived>
4256QualType
4257TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004258 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004259 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004260 if (Result.isNull())
4261 return QualType();
4262
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004263 Result = getDerived().RebuildQualifiedType(Result, T);
4264
4265 if (Result.isNull())
4266 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004267
4268 // RebuildQualifiedType might have updated the type, but not in a way
4269 // that invalidates the TypeLoc. (There's no location information for
4270 // qualifiers.)
4271 TLB.TypeWasModifiedSafely(Result);
4272
4273 return Result;
4274}
4275
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004276template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004277QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004278 QualifiedTypeLoc TL) {
4279
4280 SourceLocation Loc = TL.getBeginLoc();
4281 Qualifiers Quals = TL.getType().getLocalQualifiers();
4282
4283 if (((T.getAddressSpace() != LangAS::Default &&
4284 Quals.getAddressSpace() != LangAS::Default)) &&
4285 T.getAddressSpace() != Quals.getAddressSpace()) {
4286 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4287 << TL.getType() << T;
4288 return QualType();
4289 }
4290
Richard Smithee579842017-01-30 20:39:26 +00004291 // C++ [dcl.fct]p7:
4292 // [When] adding cv-qualifications on top of the function type [...] the
4293 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004294 if (T->isFunctionType()) {
4295 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4296 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004297 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004298 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004299
Richard Smithee579842017-01-30 20:39:26 +00004300 // C++ [dcl.ref]p1:
4301 // when the cv-qualifiers are introduced through the use of a typedef-name
4302 // or decltype-specifier [...] the cv-qualifiers are ignored.
4303 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4304 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004305 if (T->isReferenceType()) {
4306 // The only qualifier that applies to a reference type is restrict.
4307 if (!Quals.hasRestrict())
4308 return T;
4309 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4310 }
Mike Stump11289f42009-09-09 15:08:12 +00004311
John McCall31168b02011-06-15 23:02:42 +00004312 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004313 // resulting type.
4314 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004315 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004316 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004317 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004318 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004319 // A lifetime qualifier applied to a substituted template parameter
4320 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004321 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004322 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004323 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004324 QualType Replacement = SubstTypeParam->getReplacementType();
4325 Qualifiers Qs = Replacement.getQualifiers();
4326 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004327 Replacement = SemaRef.Context.getQualifiedType(
4328 Replacement.getUnqualifiedType(), Qs);
4329 T = SemaRef.Context.getSubstTemplateTypeParmType(
4330 SubstTypeParam->getReplacedParameter(), Replacement);
4331 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004332 // 'auto' types behave the same way as template parameters.
4333 QualType Deduced = AutoTy->getDeducedType();
4334 Qualifiers Qs = Deduced.getQualifiers();
4335 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004336 Deduced =
4337 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4338 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4339 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004340 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004341 // Otherwise, complain about the addition of a qualifier to an
4342 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004343 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4344 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004345 Quals.removeObjCLifetime();
4346 }
4347 }
4348 }
John McCall550e0c22009-10-21 00:40:46 +00004349
Richard Smithee579842017-01-30 20:39:26 +00004350 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004351}
4352
Douglas Gregor14454802011-02-25 02:25:35 +00004353template<typename Derived>
4354TypeLoc
4355TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4356 QualType ObjectType,
4357 NamedDecl *UnqualLookup,
4358 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004359 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004360 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004361
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004362 TypeSourceInfo *TSI =
4363 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4364 if (TSI)
4365 return TSI->getTypeLoc();
4366 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004367}
4368
Douglas Gregor579c15f2011-03-02 18:32:08 +00004369template<typename Derived>
4370TypeSourceInfo *
4371TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4372 QualType ObjectType,
4373 NamedDecl *UnqualLookup,
4374 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004375 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004376 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004378 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4379 UnqualLookup, SS);
4380}
4381
4382template <typename Derived>
4383TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4384 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4385 CXXScopeSpec &SS) {
4386 QualType T = TL.getType();
4387 assert(!getDerived().AlreadyTransformed(T));
4388
Douglas Gregor579c15f2011-03-02 18:32:08 +00004389 TypeLocBuilder TLB;
4390 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004391
Douglas Gregor579c15f2011-03-02 18:32:08 +00004392 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004393 TemplateSpecializationTypeLoc SpecTL =
4394 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004395
Richard Smithfd3dae02017-01-20 00:20:39 +00004396 TemplateName Template = getDerived().TransformTemplateName(
4397 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4398 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004399 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004400 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
4402 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004403 Template);
4404 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004405 DependentTemplateSpecializationTypeLoc SpecTL =
4406 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
Douglas Gregor579c15f2011-03-02 18:32:08 +00004408 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004409 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004410 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004411 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004412 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004413 ObjectType, UnqualLookup,
4414 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004415 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004416 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004417
4418 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004419 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004420 Template,
4421 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004422 } else {
4423 // Nothing special needs to be done for these.
4424 Result = getDerived().TransformType(TLB, TL);
4425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004426
4427 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004428 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004429
Douglas Gregor579c15f2011-03-02 18:32:08 +00004430 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4431}
4432
John McCall550e0c22009-10-21 00:40:46 +00004433template <class TyLoc> static inline
4434QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4435 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4436 NewT.setNameLoc(T.getNameLoc());
4437 return T.getType();
4438}
4439
John McCall550e0c22009-10-21 00:40:46 +00004440template<typename Derived>
4441QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004442 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004443 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4444 NewT.setBuiltinLoc(T.getBuiltinLoc());
4445 if (T.needsExtraLocalData())
4446 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4447 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004448}
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregord6ff3322009-08-04 16:50:30 +00004450template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004451QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004452 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004453 // FIXME: recurse?
4454 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004455}
Mike Stump11289f42009-09-09 15:08:12 +00004456
Reid Kleckner0503a872013-12-05 01:23:43 +00004457template <typename Derived>
4458QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4459 AdjustedTypeLoc TL) {
4460 // Adjustments applied during transformation are handled elsewhere.
4461 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4462}
4463
Douglas Gregord6ff3322009-08-04 16:50:30 +00004464template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004465QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4466 DecayedTypeLoc TL) {
4467 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4468 if (OriginalType.isNull())
4469 return QualType();
4470
4471 QualType Result = TL.getType();
4472 if (getDerived().AlwaysRebuild() ||
4473 OriginalType != TL.getOriginalLoc().getType())
4474 Result = SemaRef.Context.getDecayedType(OriginalType);
4475 TLB.push<DecayedTypeLoc>(Result);
4476 // Nothing to set for DecayedTypeLoc.
4477 return Result;
4478}
4479
4480template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004481QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004482 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004483 QualType PointeeType
4484 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004485 if (PointeeType.isNull())
4486 return QualType();
4487
4488 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004489 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004490 // A dependent pointer type 'T *' has is being transformed such
4491 // that an Objective-C class type is being replaced for 'T'. The
4492 // resulting pointer type is an ObjCObjectPointerType, not a
4493 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004494 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004495
John McCall8b07ec22010-05-15 11:32:37 +00004496 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4497 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004498 return Result;
4499 }
John McCall31f82722010-11-12 08:19:04 +00004500
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004501 if (getDerived().AlwaysRebuild() ||
4502 PointeeType != TL.getPointeeLoc().getType()) {
4503 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4504 if (Result.isNull())
4505 return QualType();
4506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004507
John McCall31168b02011-06-15 23:02:42 +00004508 // Objective-C ARC can add lifetime qualifiers to the type that we're
4509 // pointing to.
4510 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004511
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004512 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4513 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004514 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004515}
Mike Stump11289f42009-09-09 15:08:12 +00004516
4517template<typename Derived>
4518QualType
John McCall550e0c22009-10-21 00:40:46 +00004519TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004520 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004521 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004522 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4523 if (PointeeType.isNull())
4524 return QualType();
4525
4526 QualType Result = TL.getType();
4527 if (getDerived().AlwaysRebuild() ||
4528 PointeeType != TL.getPointeeLoc().getType()) {
4529 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004530 TL.getSigilLoc());
4531 if (Result.isNull())
4532 return QualType();
4533 }
4534
Douglas Gregor049211a2010-04-22 16:50:51 +00004535 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004536 NewT.setSigilLoc(TL.getSigilLoc());
4537 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004538}
4539
John McCall70dd5f62009-10-30 00:06:24 +00004540/// Transforms a reference type. Note that somewhat paradoxically we
4541/// don't care whether the type itself is an l-value type or an r-value
4542/// type; we only care if the type was *written* as an l-value type
4543/// or an r-value type.
4544template<typename Derived>
4545QualType
4546TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004547 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004548 const ReferenceType *T = TL.getTypePtr();
4549
4550 // Note that this works with the pointee-as-written.
4551 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4552 if (PointeeType.isNull())
4553 return QualType();
4554
4555 QualType Result = TL.getType();
4556 if (getDerived().AlwaysRebuild() ||
4557 PointeeType != T->getPointeeTypeAsWritten()) {
4558 Result = getDerived().RebuildReferenceType(PointeeType,
4559 T->isSpelledAsLValue(),
4560 TL.getSigilLoc());
4561 if (Result.isNull())
4562 return QualType();
4563 }
4564
John McCall31168b02011-06-15 23:02:42 +00004565 // Objective-C ARC can add lifetime qualifiers to the type that we're
4566 // referring to.
4567 TLB.TypeWasModifiedSafely(
4568 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4569
John McCall70dd5f62009-10-30 00:06:24 +00004570 // r-value references can be rebuilt as l-value references.
4571 ReferenceTypeLoc NewTL;
4572 if (isa<LValueReferenceType>(Result))
4573 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4574 else
4575 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4576 NewTL.setSigilLoc(TL.getSigilLoc());
4577
4578 return Result;
4579}
4580
Mike Stump11289f42009-09-09 15:08:12 +00004581template<typename Derived>
4582QualType
John McCall550e0c22009-10-21 00:40:46 +00004583TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004584 LValueReferenceTypeLoc TL) {
4585 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586}
4587
Mike Stump11289f42009-09-09 15:08:12 +00004588template<typename Derived>
4589QualType
John McCall550e0c22009-10-21 00:40:46 +00004590TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004591 RValueReferenceTypeLoc TL) {
4592 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregord6ff3322009-08-04 16:50:30 +00004595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004596QualType
John McCall550e0c22009-10-21 00:40:46 +00004597TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004598 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004599 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004600 if (PointeeType.isNull())
4601 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004602
Abramo Bagnara509357842011-03-05 14:42:21 +00004603 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004604 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004605 if (OldClsTInfo) {
4606 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4607 if (!NewClsTInfo)
4608 return QualType();
4609 }
4610
4611 const MemberPointerType *T = TL.getTypePtr();
4612 QualType OldClsType = QualType(T->getClass(), 0);
4613 QualType NewClsType;
4614 if (NewClsTInfo)
4615 NewClsType = NewClsTInfo->getType();
4616 else {
4617 NewClsType = getDerived().TransformType(OldClsType);
4618 if (NewClsType.isNull())
4619 return QualType();
4620 }
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCall550e0c22009-10-21 00:40:46 +00004622 QualType Result = TL.getType();
4623 if (getDerived().AlwaysRebuild() ||
4624 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004625 NewClsType != OldClsType) {
4626 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004627 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004628 if (Result.isNull())
4629 return QualType();
4630 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631
Reid Kleckner0503a872013-12-05 01:23:43 +00004632 // If we had to adjust the pointee type when building a member pointer, make
4633 // sure to push TypeLoc info for it.
4634 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4635 if (MPT && PointeeType != MPT->getPointeeType()) {
4636 assert(isa<AdjustedType>(MPT->getPointeeType()));
4637 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4638 }
4639
John McCall550e0c22009-10-21 00:40:46 +00004640 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4641 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004642 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004643
4644 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004645}
4646
Mike Stump11289f42009-09-09 15:08:12 +00004647template<typename Derived>
4648QualType
John McCall550e0c22009-10-21 00:40:46 +00004649TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004650 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004651 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004652 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004653 if (ElementType.isNull())
4654 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004655
John McCall550e0c22009-10-21 00:40:46 +00004656 QualType Result = TL.getType();
4657 if (getDerived().AlwaysRebuild() ||
4658 ElementType != T->getElementType()) {
4659 Result = getDerived().RebuildConstantArrayType(ElementType,
4660 T->getSizeModifier(),
4661 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004662 T->getIndexTypeCVRQualifiers(),
4663 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004664 if (Result.isNull())
4665 return QualType();
4666 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004667
4668 // We might have either a ConstantArrayType or a VariableArrayType now:
4669 // a ConstantArrayType is allowed to have an element type which is a
4670 // VariableArrayType if the type is dependent. Fortunately, all array
4671 // types have the same location layout.
4672 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004673 NewTL.setLBracketLoc(TL.getLBracketLoc());
4674 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004675
John McCall550e0c22009-10-21 00:40:46 +00004676 Expr *Size = TL.getSizeExpr();
4677 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004678 EnterExpressionEvaluationContext Unevaluated(
4679 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004680 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4681 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004682 }
4683 NewTL.setSizeExpr(Size);
4684
4685 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004686}
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregord6ff3322009-08-04 16:50:30 +00004688template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004689QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004690 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004691 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004692 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004693 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004694 if (ElementType.isNull())
4695 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004696
John McCall550e0c22009-10-21 00:40:46 +00004697 QualType Result = TL.getType();
4698 if (getDerived().AlwaysRebuild() ||
4699 ElementType != T->getElementType()) {
4700 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004701 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004702 T->getIndexTypeCVRQualifiers(),
4703 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004704 if (Result.isNull())
4705 return QualType();
4706 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004707
John McCall550e0c22009-10-21 00:40:46 +00004708 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4709 NewTL.setLBracketLoc(TL.getLBracketLoc());
4710 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004711 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004712
4713 return Result;
4714}
4715
4716template<typename Derived>
4717QualType
4718TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004719 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004720 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004721 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4722 if (ElementType.isNull())
4723 return QualType();
4724
Tim Shenb34d0ef2017-02-14 23:46:37 +00004725 ExprResult SizeResult;
4726 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004727 EnterExpressionEvaluationContext Context(
4728 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004729 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4730 }
4731 if (SizeResult.isInvalid())
4732 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004733 SizeResult =
4734 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004735 if (SizeResult.isInvalid())
4736 return QualType();
4737
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004738 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004739
4740 QualType Result = TL.getType();
4741 if (getDerived().AlwaysRebuild() ||
4742 ElementType != T->getElementType() ||
4743 Size != T->getSizeExpr()) {
4744 Result = getDerived().RebuildVariableArrayType(ElementType,
4745 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004746 Size,
John McCall550e0c22009-10-21 00:40:46 +00004747 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004748 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004749 if (Result.isNull())
4750 return QualType();
4751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004752
Serge Pavlov774c6d02014-02-06 03:49:11 +00004753 // We might have constant size array now, but fortunately it has the same
4754 // location layout.
4755 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004756 NewTL.setLBracketLoc(TL.getLBracketLoc());
4757 NewTL.setRBracketLoc(TL.getRBracketLoc());
4758 NewTL.setSizeExpr(Size);
4759
4760 return Result;
4761}
4762
4763template<typename Derived>
4764QualType
4765TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004766 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004767 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004768 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4769 if (ElementType.isNull())
4770 return QualType();
4771
Richard Smith764d2fe2011-12-20 02:08:33 +00004772 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004773 EnterExpressionEvaluationContext Unevaluated(
4774 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004775
John McCall33ddac02011-01-19 10:06:00 +00004776 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4777 Expr *origSize = TL.getSizeExpr();
4778 if (!origSize) origSize = T->getSizeExpr();
4779
4780 ExprResult sizeResult
4781 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004782 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004783 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004784 return QualType();
4785
John McCall33ddac02011-01-19 10:06:00 +00004786 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004787
4788 QualType Result = TL.getType();
4789 if (getDerived().AlwaysRebuild() ||
4790 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004791 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004792 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4793 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004794 size,
John McCall550e0c22009-10-21 00:40:46 +00004795 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004796 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004797 if (Result.isNull())
4798 return QualType();
4799 }
John McCall550e0c22009-10-21 00:40:46 +00004800
4801 // We might have any sort of array type now, but fortunately they
4802 // all have the same location layout.
4803 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4804 NewTL.setLBracketLoc(TL.getLBracketLoc());
4805 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004806 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004807
4808 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004809}
Mike Stump11289f42009-09-09 15:08:12 +00004810
Erich Keanef702b022018-07-13 19:46:04 +00004811template <typename Derived>
4812QualType TreeTransform<Derived>::TransformDependentVectorType(
4813 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4814 const DependentVectorType *T = TL.getTypePtr();
4815 QualType ElementType = getDerived().TransformType(T->getElementType());
4816 if (ElementType.isNull())
4817 return QualType();
4818
4819 EnterExpressionEvaluationContext Unevaluated(
4820 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4821
4822 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4823 Size = SemaRef.ActOnConstantExpression(Size);
4824 if (Size.isInvalid())
4825 return QualType();
4826
4827 QualType Result = TL.getType();
4828 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4829 Size.get() != T->getSizeExpr()) {
4830 Result = getDerived().RebuildDependentVectorType(
4831 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4832 if (Result.isNull())
4833 return QualType();
4834 }
4835
4836 // Result might be dependent or not.
4837 if (isa<DependentVectorType>(Result)) {
4838 DependentVectorTypeLoc NewTL =
4839 TLB.push<DependentVectorTypeLoc>(Result);
4840 NewTL.setNameLoc(TL.getNameLoc());
4841 } else {
4842 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4843 NewTL.setNameLoc(TL.getNameLoc());
4844 }
4845
4846 return Result;
4847}
4848
Mike Stump11289f42009-09-09 15:08:12 +00004849template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004850QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004851 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004852 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004853 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004854
4855 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004856 QualType ElementType = getDerived().TransformType(T->getElementType());
4857 if (ElementType.isNull())
4858 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004859
Richard Smith764d2fe2011-12-20 02:08:33 +00004860 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004861 EnterExpressionEvaluationContext Unevaluated(
4862 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004863
John McCalldadc5752010-08-24 06:29:42 +00004864 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004865 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004866 if (Size.isInvalid())
4867 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004868
John McCall550e0c22009-10-21 00:40:46 +00004869 QualType Result = TL.getType();
4870 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004871 ElementType != T->getElementType() ||
4872 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004873 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004874 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004875 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004876 if (Result.isNull())
4877 return QualType();
4878 }
John McCall550e0c22009-10-21 00:40:46 +00004879
4880 // Result might be dependent or not.
4881 if (isa<DependentSizedExtVectorType>(Result)) {
4882 DependentSizedExtVectorTypeLoc NewTL
4883 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4884 NewTL.setNameLoc(TL.getNameLoc());
4885 } else {
4886 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4887 NewTL.setNameLoc(TL.getNameLoc());
4888 }
4889
4890 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004891}
Mike Stump11289f42009-09-09 15:08:12 +00004892
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004893template <typename Derived>
4894QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4895 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4896 const DependentAddressSpaceType *T = TL.getTypePtr();
4897
4898 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4899
4900 if (pointeeType.isNull())
4901 return QualType();
4902
4903 // Address spaces are constant expressions.
4904 EnterExpressionEvaluationContext Unevaluated(
4905 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4906
4907 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4908 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4909 if (AddrSpace.isInvalid())
4910 return QualType();
4911
4912 QualType Result = TL.getType();
4913 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4914 AddrSpace.get() != T->getAddrSpaceExpr()) {
4915 Result = getDerived().RebuildDependentAddressSpaceType(
4916 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4917 if (Result.isNull())
4918 return QualType();
4919 }
4920
4921 // Result might be dependent or not.
4922 if (isa<DependentAddressSpaceType>(Result)) {
4923 DependentAddressSpaceTypeLoc NewTL =
4924 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4925
4926 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4927 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4928 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4929
4930 } else {
4931 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4932 Result, getDerived().getBaseLocation());
4933 TransformType(TLB, DI->getTypeLoc());
4934 }
4935
4936 return Result;
4937}
4938
4939template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004940QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004941 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004942 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943 QualType ElementType = getDerived().TransformType(T->getElementType());
4944 if (ElementType.isNull())
4945 return QualType();
4946
John McCall550e0c22009-10-21 00:40:46 +00004947 QualType Result = TL.getType();
4948 if (getDerived().AlwaysRebuild() ||
4949 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004950 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004951 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004952 if (Result.isNull())
4953 return QualType();
4954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004955
John McCall550e0c22009-10-21 00:40:46 +00004956 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4957 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004958
John McCall550e0c22009-10-21 00:40:46 +00004959 return Result;
4960}
4961
4962template<typename Derived>
4963QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004964 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004965 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004966 QualType ElementType = getDerived().TransformType(T->getElementType());
4967 if (ElementType.isNull())
4968 return QualType();
4969
4970 QualType Result = TL.getType();
4971 if (getDerived().AlwaysRebuild() ||
4972 ElementType != T->getElementType()) {
4973 Result = getDerived().RebuildExtVectorType(ElementType,
4974 T->getNumElements(),
4975 /*FIXME*/ SourceLocation());
4976 if (Result.isNull())
4977 return QualType();
4978 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004979
John McCall550e0c22009-10-21 00:40:46 +00004980 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4981 NewTL.setNameLoc(TL.getNameLoc());
4982
4983 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004984}
Mike Stump11289f42009-09-09 15:08:12 +00004985
David Blaikie05785d12013-02-20 22:23:23 +00004986template <typename Derived>
4987ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4988 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4989 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004990 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004991 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004992
Douglas Gregor715e4612011-01-14 22:40:04 +00004993 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004994 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004995 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004996 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004997 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004998
Douglas Gregor715e4612011-01-14 22:40:04 +00004999 TypeLocBuilder TLB;
5000 TypeLoc NewTL = OldDI->getTypeLoc();
5001 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
5003 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00005004 OldExpansionTL.getPatternLoc());
5005 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005006 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005007
5008 Result = RebuildPackExpansionType(Result,
5009 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00005010 OldExpansionTL.getEllipsisLoc(),
5011 NumExpansions);
5012 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00005013 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005014
Douglas Gregor715e4612011-01-14 22:40:04 +00005015 PackExpansionTypeLoc NewExpansionTL
5016 = TLB.push<PackExpansionTypeLoc>(Result);
5017 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5018 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5019 } else
5020 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005021 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005022 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005023
John McCall8fb0d9d2011-05-01 22:35:37 +00005024 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005025 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005026
5027 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5028 OldParm->getDeclContext(),
5029 OldParm->getInnerLocStart(),
5030 OldParm->getLocation(),
5031 OldParm->getIdentifier(),
5032 NewDI->getType(),
5033 NewDI,
5034 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005035 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005036 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5037 OldParm->getFunctionScopeIndex() + indexAdjustment);
5038 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005039}
5040
David Majnemer59f77922016-06-24 04:05:48 +00005041template <typename Derived>
5042bool TreeTransform<Derived>::TransformFunctionTypeParams(
5043 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5044 const QualType *ParamTypes,
5045 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5046 SmallVectorImpl<QualType> &OutParamTypes,
5047 SmallVectorImpl<ParmVarDecl *> *PVars,
5048 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005049 int indexAdjustment = 0;
5050
David Majnemer59f77922016-06-24 04:05:48 +00005051 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005052 for (unsigned i = 0; i != NumParams; ++i) {
5053 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005054 assert(OldParm->getFunctionScopeIndex() == i);
5055
David Blaikie05785d12013-02-20 22:23:23 +00005056 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005057 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005058 if (OldParm->isParameterPack()) {
5059 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005060 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005061
Douglas Gregor5499af42011-01-05 23:12:31 +00005062 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005063 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005064 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005065 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5066 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005067 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5068
Douglas Gregor5499af42011-01-05 23:12:31 +00005069 // Determine whether we should expand the parameter packs.
5070 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005071 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005072 Optional<unsigned> OrigNumExpansions =
5073 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005074 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005075 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5076 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005077 Unexpanded,
5078 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005079 RetainExpansion,
5080 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005081 return true;
5082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005083
Douglas Gregor5499af42011-01-05 23:12:31 +00005084 if (ShouldExpand) {
5085 // Expand the function parameter pack into multiple, separate
5086 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005087 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005088 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005089 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005090 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005091 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005092 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005093 OrigNumExpansions,
5094 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005095 if (!NewParm)
5096 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005097
John McCallc8e321d2016-03-01 02:09:25 +00005098 if (ParamInfos)
5099 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005100 OutParamTypes.push_back(NewParm->getType());
5101 if (PVars)
5102 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005103 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005104
5105 // If we're supposed to retain a pack expansion, do so by temporarily
5106 // forgetting the partially-substituted parameter pack.
5107 if (RetainExpansion) {
5108 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005109 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005110 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005111 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005112 OrigNumExpansions,
5113 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005114 if (!NewParm)
5115 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005116
John McCallc8e321d2016-03-01 02:09:25 +00005117 if (ParamInfos)
5118 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005119 OutParamTypes.push_back(NewParm->getType());
5120 if (PVars)
5121 PVars->push_back(NewParm);
5122 }
5123
John McCall8fb0d9d2011-05-01 22:35:37 +00005124 // The next parameter should have the same adjustment as the
5125 // last thing we pushed, but we post-incremented indexAdjustment
5126 // on every push. Also, if we push nothing, the adjustment should
5127 // go down by one.
5128 indexAdjustment--;
5129
Douglas Gregor5499af42011-01-05 23:12:31 +00005130 // We're done with the pack expansion.
5131 continue;
5132 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005133
5134 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005135 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5137 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005138 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005139 NumExpansions,
5140 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005141 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005142 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005143 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005144 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005145
John McCall58f10c32010-03-11 09:03:00 +00005146 if (!NewParm)
5147 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005148
John McCallc8e321d2016-03-01 02:09:25 +00005149 if (ParamInfos)
5150 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005151 OutParamTypes.push_back(NewParm->getType());
5152 if (PVars)
5153 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005154 continue;
5155 }
John McCall58f10c32010-03-11 09:03:00 +00005156
5157 // Deal with the possibility that we don't have a parameter
5158 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005159 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005160 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005161 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005162 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005163 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005164 = dyn_cast<PackExpansionType>(OldType)) {
5165 // We have a function parameter pack that may need to be expanded.
5166 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005167 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005168 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005169
Douglas Gregor5499af42011-01-05 23:12:31 +00005170 // Determine whether we should expand the parameter packs.
5171 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005172 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005173 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005174 Unexpanded,
5175 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005176 RetainExpansion,
5177 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005178 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005179 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005180
Douglas Gregor5499af42011-01-05 23:12:31 +00005181 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005182 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005183 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005184 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005185 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5186 QualType NewType = getDerived().TransformType(Pattern);
5187 if (NewType.isNull())
5188 return true;
John McCall58f10c32010-03-11 09:03:00 +00005189
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005190 if (NewType->containsUnexpandedParameterPack()) {
5191 NewType =
5192 getSema().getASTContext().getPackExpansionType(NewType, None);
5193
5194 if (NewType.isNull())
5195 return true;
5196 }
5197
John McCallc8e321d2016-03-01 02:09:25 +00005198 if (ParamInfos)
5199 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005200 OutParamTypes.push_back(NewType);
5201 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005202 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005204
Douglas Gregor5499af42011-01-05 23:12:31 +00005205 // We're done with the pack expansion.
5206 continue;
5207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005208
Douglas Gregor48d24112011-01-10 20:53:55 +00005209 // If we're supposed to retain a pack expansion, do so by temporarily
5210 // forgetting the partially-substituted parameter pack.
5211 if (RetainExpansion) {
5212 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5213 QualType NewType = getDerived().TransformType(Pattern);
5214 if (NewType.isNull())
5215 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005216
John McCallc8e321d2016-03-01 02:09:25 +00005217 if (ParamInfos)
5218 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005219 OutParamTypes.push_back(NewType);
5220 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005221 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005222 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005223
Chad Rosier1dcde962012-08-08 18:46:20 +00005224 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005225 // expansion.
5226 OldType = Expansion->getPattern();
5227 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005228 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5229 NewType = getDerived().TransformType(OldType);
5230 } else {
5231 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005232 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005233
Douglas Gregor5499af42011-01-05 23:12:31 +00005234 if (NewType.isNull())
5235 return true;
5236
5237 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005238 NewType = getSema().Context.getPackExpansionType(NewType,
5239 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005240
John McCallc8e321d2016-03-01 02:09:25 +00005241 if (ParamInfos)
5242 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005243 OutParamTypes.push_back(NewType);
5244 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005245 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005246 }
5247
John McCall8fb0d9d2011-05-01 22:35:37 +00005248#ifndef NDEBUG
5249 if (PVars) {
5250 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5251 if (ParmVarDecl *parm = (*PVars)[i])
5252 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005253 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005254#endif
5255
5256 return false;
5257}
John McCall58f10c32010-03-11 09:03:00 +00005258
5259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005260QualType
John McCall550e0c22009-10-21 00:40:46 +00005261TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005262 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005263 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005264 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005265 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005266 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005267 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5268 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5269 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005270 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005271}
5272
Richard Smith2e321552014-11-12 02:00:47 +00005273template<typename Derived> template<typename Fn>
5274QualType TreeTransform<Derived>::TransformFunctionProtoType(
5275 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005276 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005277
Douglas Gregor4afc2362010-08-31 00:26:14 +00005278 // Transform the parameters and return type.
5279 //
Richard Smithf623c962012-04-17 00:58:00 +00005280 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005281 // When the function has a trailing return type, we instantiate the
5282 // parameters before the return type, since the return type can then refer
5283 // to the parameters themselves (via decltype, sizeof, etc.).
5284 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005285 SmallVector<QualType, 4> ParamTypes;
5286 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005287 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005288 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005289
Douglas Gregor7fb25412010-10-01 18:44:50 +00005290 QualType ResultType;
5291
Richard Smith1226c602012-08-14 22:51:13 +00005292 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005293 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005294 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005295 TL.getTypePtr()->param_type_begin(),
5296 T->getExtParameterInfosOrNull(),
5297 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005298 return QualType();
5299
Douglas Gregor3024f072012-04-16 07:05:22 +00005300 {
5301 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005302 // If a declaration declares a member function or member function
5303 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005304 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005305 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005306 // declarator.
5307 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005308
Alp Toker42a16a62014-01-25 23:51:36 +00005309 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005310 if (ResultType.isNull())
5311 return QualType();
5312 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005313 }
5314 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005315 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005316 if (ResultType.isNull())
5317 return QualType();
5318
Anastasia Stulova6a4c3462018-11-29 14:11:15 +00005319 // Return type can not be qualified with an address space.
5320 if (ResultType.getAddressSpace() != LangAS::Default) {
5321 SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5322 diag::err_attribute_address_function_type);
5323 return QualType();
5324 }
5325
Alp Toker9cacbab2014-01-20 20:26:09 +00005326 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005327 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005328 TL.getTypePtr()->param_type_begin(),
5329 T->getExtParameterInfosOrNull(),
5330 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005331 return QualType();
5332 }
5333
Richard Smith2e321552014-11-12 02:00:47 +00005334 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5335
5336 bool EPIChanged = false;
5337 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5338 return QualType();
5339
John McCallc8e321d2016-03-01 02:09:25 +00005340 // Handle extended parameter information.
5341 if (auto NewExtParamInfos =
5342 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5343 if (!EPI.ExtParameterInfos ||
5344 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5345 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5346 EPIChanged = true;
5347 }
5348 EPI.ExtParameterInfos = NewExtParamInfos;
5349 } else if (EPI.ExtParameterInfos) {
5350 EPIChanged = true;
5351 EPI.ExtParameterInfos = nullptr;
5352 }
Richard Smithf623c962012-04-17 00:58:00 +00005353
John McCall550e0c22009-10-21 00:40:46 +00005354 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005355 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005356 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005357 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005358 if (Result.isNull())
5359 return QualType();
5360 }
Mike Stump11289f42009-09-09 15:08:12 +00005361
John McCall550e0c22009-10-21 00:40:46 +00005362 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005363 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005364 NewTL.setLParenLoc(TL.getLParenLoc());
5365 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005366 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005367 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005368 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5369 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005370
5371 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005372}
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregord6ff3322009-08-04 16:50:30 +00005374template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005375bool TreeTransform<Derived>::TransformExceptionSpec(
5376 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5377 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5378 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5379
5380 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005381 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005382 EnterExpressionEvaluationContext Unevaluated(
5383 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005384 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5385 if (NoexceptExpr.isInvalid())
5386 return true;
5387
Richard Smitheaf11ad2018-05-03 03:58:32 +00005388 ExceptionSpecificationType EST = ESI.Type;
5389 NoexceptExpr =
5390 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005391 if (NoexceptExpr.isInvalid())
5392 return true;
5393
Richard Smitheaf11ad2018-05-03 03:58:32 +00005394 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005395 Changed = true;
5396 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005397 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005398 }
5399
5400 if (ESI.Type != EST_Dynamic)
5401 return false;
5402
5403 // Instantiate a dynamic exception specification's type.
5404 for (QualType T : ESI.Exceptions) {
5405 if (const PackExpansionType *PackExpansion =
5406 T->getAs<PackExpansionType>()) {
5407 Changed = true;
5408
5409 // We have a pack expansion. Instantiate it.
5410 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5411 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5412 Unexpanded);
5413 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5414
5415 // Determine whether the set of unexpanded parameter packs can and
5416 // should
5417 // be expanded.
5418 bool Expand = false;
5419 bool RetainExpansion = false;
5420 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5421 // FIXME: Track the location of the ellipsis (and track source location
5422 // information for the types in the exception specification in general).
5423 if (getDerived().TryExpandParameterPacks(
5424 Loc, SourceRange(), Unexpanded, Expand,
5425 RetainExpansion, NumExpansions))
5426 return true;
5427
5428 if (!Expand) {
5429 // We can't expand this pack expansion into separate arguments yet;
5430 // just substitute into the pattern and create a new pack expansion
5431 // type.
5432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5433 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5434 if (U.isNull())
5435 return true;
5436
5437 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5438 Exceptions.push_back(U);
5439 continue;
5440 }
5441
5442 // Substitute into the pack expansion pattern for each slice of the
5443 // pack.
5444 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5445 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5446
5447 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5448 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5449 return true;
5450
5451 Exceptions.push_back(U);
5452 }
5453 } else {
5454 QualType U = getDerived().TransformType(T);
5455 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5456 return true;
5457 if (T != U)
5458 Changed = true;
5459
5460 Exceptions.push_back(U);
5461 }
5462 }
5463
5464 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005465 if (ESI.Exceptions.empty())
5466 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005467 return false;
5468}
5469
5470template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005471QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005472 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005473 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005474 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005475 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005476 if (ResultType.isNull())
5477 return QualType();
5478
5479 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005480 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005481 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5482
5483 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005484 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005485 NewTL.setLParenLoc(TL.getLParenLoc());
5486 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005487 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005488
5489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005490}
Mike Stump11289f42009-09-09 15:08:12 +00005491
John McCallb96ec562009-12-04 22:46:56 +00005492template<typename Derived> QualType
5493TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005494 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005495 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005496 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005497 if (!D)
5498 return QualType();
5499
5500 QualType Result = TL.getType();
5501 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005502 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005503 if (Result.isNull())
5504 return QualType();
5505 }
5506
5507 // We might get an arbitrary type spec type back. We should at
5508 // least always get a type spec type, though.
5509 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5510 NewTL.setNameLoc(TL.getNameLoc());
5511
5512 return Result;
5513}
5514
Douglas Gregord6ff3322009-08-04 16:50:30 +00005515template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005516QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005517 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005518 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005519 TypedefNameDecl *Typedef
5520 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5521 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005522 if (!Typedef)
5523 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005524
John McCall550e0c22009-10-21 00:40:46 +00005525 QualType Result = TL.getType();
5526 if (getDerived().AlwaysRebuild() ||
5527 Typedef != T->getDecl()) {
5528 Result = getDerived().RebuildTypedefType(Typedef);
5529 if (Result.isNull())
5530 return QualType();
5531 }
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCall550e0c22009-10-21 00:40:46 +00005533 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5534 NewTL.setNameLoc(TL.getNameLoc());
5535
5536 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005537}
Mike Stump11289f42009-09-09 15:08:12 +00005538
Douglas Gregord6ff3322009-08-04 16:50:30 +00005539template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005540QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005541 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005542 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005543 EnterExpressionEvaluationContext Unevaluated(
5544 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5545 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005546
John McCalldadc5752010-08-24 06:29:42 +00005547 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005548 if (E.isInvalid())
5549 return QualType();
5550
Eli Friedmane4f22df2012-02-29 04:03:55 +00005551 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5552 if (E.isInvalid())
5553 return QualType();
5554
John McCall550e0c22009-10-21 00:40:46 +00005555 QualType Result = TL.getType();
5556 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005557 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005558 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005559 if (Result.isNull())
5560 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005561 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005562 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005563
John McCall550e0c22009-10-21 00:40:46 +00005564 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005565 NewTL.setTypeofLoc(TL.getTypeofLoc());
5566 NewTL.setLParenLoc(TL.getLParenLoc());
5567 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005568
5569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570}
Mike Stump11289f42009-09-09 15:08:12 +00005571
5572template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005573QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005574 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005575 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5576 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5577 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005578 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005579
John McCall550e0c22009-10-21 00:40:46 +00005580 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005581 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5582 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005583 if (Result.isNull())
5584 return QualType();
5585 }
Mike Stump11289f42009-09-09 15:08:12 +00005586
John McCall550e0c22009-10-21 00:40:46 +00005587 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005588 NewTL.setTypeofLoc(TL.getTypeofLoc());
5589 NewTL.setLParenLoc(TL.getLParenLoc());
5590 NewTL.setRParenLoc(TL.getRParenLoc());
5591 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005592
5593 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005594}
Mike Stump11289f42009-09-09 15:08:12 +00005595
5596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005597QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005598 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005599 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005600
Douglas Gregore922c772009-08-04 22:27:00 +00005601 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005602 EnterExpressionEvaluationContext Unevaluated(
5603 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005604 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005605
John McCalldadc5752010-08-24 06:29:42 +00005606 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005607 if (E.isInvalid())
5608 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005609
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005610 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005611 if (E.isInvalid())
5612 return QualType();
5613
John McCall550e0c22009-10-21 00:40:46 +00005614 QualType Result = TL.getType();
5615 if (getDerived().AlwaysRebuild() ||
5616 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005617 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005618 if (Result.isNull())
5619 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005620 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005621 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005622
John McCall550e0c22009-10-21 00:40:46 +00005623 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5624 NewTL.setNameLoc(TL.getNameLoc());
5625
5626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005627}
5628
5629template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005630QualType TreeTransform<Derived>::TransformUnaryTransformType(
5631 TypeLocBuilder &TLB,
5632 UnaryTransformTypeLoc TL) {
5633 QualType Result = TL.getType();
5634 if (Result->isDependentType()) {
5635 const UnaryTransformType *T = TL.getTypePtr();
5636 QualType NewBase =
5637 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5638 Result = getDerived().RebuildUnaryTransformType(NewBase,
5639 T->getUTTKind(),
5640 TL.getKWLoc());
5641 if (Result.isNull())
5642 return QualType();
5643 }
5644
5645 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5646 NewTL.setKWLoc(TL.getKWLoc());
5647 NewTL.setParensRange(TL.getParensRange());
5648 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5649 return Result;
5650}
5651
5652template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005653QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5654 AutoTypeLoc TL) {
5655 const AutoType *T = TL.getTypePtr();
5656 QualType OldDeduced = T->getDeducedType();
5657 QualType NewDeduced;
5658 if (!OldDeduced.isNull()) {
5659 NewDeduced = getDerived().TransformType(OldDeduced);
5660 if (NewDeduced.isNull())
5661 return QualType();
5662 }
5663
5664 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005665 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5666 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005667 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005668 if (Result.isNull())
5669 return QualType();
5670 }
5671
5672 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5673 NewTL.setNameLoc(TL.getNameLoc());
5674
5675 return Result;
5676}
5677
5678template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005679QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5680 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5681 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5682
5683 CXXScopeSpec SS;
5684 TemplateName TemplateName = getDerived().TransformTemplateName(
5685 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5686 if (TemplateName.isNull())
5687 return QualType();
5688
5689 QualType OldDeduced = T->getDeducedType();
5690 QualType NewDeduced;
5691 if (!OldDeduced.isNull()) {
5692 NewDeduced = getDerived().TransformType(OldDeduced);
5693 if (NewDeduced.isNull())
5694 return QualType();
5695 }
5696
5697 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5698 TemplateName, NewDeduced);
5699 if (Result.isNull())
5700 return QualType();
5701
5702 DeducedTemplateSpecializationTypeLoc NewTL =
5703 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5704 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5705
5706 return Result;
5707}
5708
5709template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005710QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005711 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005712 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005713 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005714 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5715 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005716 if (!Record)
5717 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005718
John McCall550e0c22009-10-21 00:40:46 +00005719 QualType Result = TL.getType();
5720 if (getDerived().AlwaysRebuild() ||
5721 Record != T->getDecl()) {
5722 Result = getDerived().RebuildRecordType(Record);
5723 if (Result.isNull())
5724 return QualType();
5725 }
Mike Stump11289f42009-09-09 15:08:12 +00005726
John McCall550e0c22009-10-21 00:40:46 +00005727 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5728 NewTL.setNameLoc(TL.getNameLoc());
5729
5730 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005731}
Mike Stump11289f42009-09-09 15:08:12 +00005732
5733template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005734QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005735 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005736 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005737 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005738 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5739 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005740 if (!Enum)
5741 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005742
John McCall550e0c22009-10-21 00:40:46 +00005743 QualType Result = TL.getType();
5744 if (getDerived().AlwaysRebuild() ||
5745 Enum != T->getDecl()) {
5746 Result = getDerived().RebuildEnumType(Enum);
5747 if (Result.isNull())
5748 return QualType();
5749 }
Mike Stump11289f42009-09-09 15:08:12 +00005750
John McCall550e0c22009-10-21 00:40:46 +00005751 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5752 NewTL.setNameLoc(TL.getNameLoc());
5753
5754 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005755}
John McCallfcc33b02009-09-05 00:15:47 +00005756
John McCalle78aac42010-03-10 03:28:59 +00005757template<typename Derived>
5758QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5759 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005760 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005761 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5762 TL.getTypePtr()->getDecl());
5763 if (!D) return QualType();
5764
5765 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5766 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5767 return T;
5768}
5769
Douglas Gregord6ff3322009-08-04 16:50:30 +00005770template<typename Derived>
5771QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005772 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005773 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005774 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005775}
5776
Mike Stump11289f42009-09-09 15:08:12 +00005777template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005778QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005779 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005780 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005781 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005783 // Substitute into the replacement type, which itself might involve something
5784 // that needs to be transformed. This only tends to occur with default
5785 // template arguments of template template parameters.
5786 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5787 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5788 if (Replacement.isNull())
5789 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005791 // Always canonicalize the replacement type.
5792 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5793 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005794 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005795 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005796
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005797 // Propagate type-source information.
5798 SubstTemplateTypeParmTypeLoc NewTL
5799 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5800 NewTL.setNameLoc(TL.getNameLoc());
5801 return Result;
5802
John McCallcebee162009-10-18 09:09:24 +00005803}
5804
5805template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005806QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5807 TypeLocBuilder &TLB,
5808 SubstTemplateTypeParmPackTypeLoc TL) {
5809 return TransformTypeSpecType(TLB, TL);
5810}
5811
5812template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005813QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005814 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005815 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005816 const TemplateSpecializationType *T = TL.getTypePtr();
5817
Douglas Gregordf846d12011-03-02 18:46:51 +00005818 // The nested-name-specifier never matters in a TemplateSpecializationType,
5819 // because we can't have a dependent nested-name-specifier anyway.
5820 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005821 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005822 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5823 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005824 if (Template.isNull())
5825 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005826
John McCall31f82722010-11-12 08:19:04 +00005827 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5828}
5829
Eli Friedman0dfb8892011-10-06 23:00:33 +00005830template<typename Derived>
5831QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5832 AtomicTypeLoc TL) {
5833 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5834 if (ValueType.isNull())
5835 return QualType();
5836
5837 QualType Result = TL.getType();
5838 if (getDerived().AlwaysRebuild() ||
5839 ValueType != TL.getValueLoc().getType()) {
5840 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5841 if (Result.isNull())
5842 return QualType();
5843 }
5844
5845 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5846 NewTL.setKWLoc(TL.getKWLoc());
5847 NewTL.setLParenLoc(TL.getLParenLoc());
5848 NewTL.setRParenLoc(TL.getRParenLoc());
5849
5850 return Result;
5851}
5852
Xiuli Pan9c14e282016-01-09 12:53:17 +00005853template <typename Derived>
5854QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5855 PipeTypeLoc TL) {
5856 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5857 if (ValueType.isNull())
5858 return QualType();
5859
5860 QualType Result = TL.getType();
5861 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005862 const PipeType *PT = Result->getAs<PipeType>();
5863 bool isReadPipe = PT->isReadOnly();
5864 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005865 if (Result.isNull())
5866 return QualType();
5867 }
5868
5869 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5870 NewTL.setKWLoc(TL.getKWLoc());
5871
5872 return Result;
5873}
5874
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005875 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005876 /// container that provides a \c getArgLoc() member function.
5877 ///
5878 /// This iterator is intended to be used with the iterator form of
5879 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5880 template<typename ArgLocContainer>
5881 class TemplateArgumentLocContainerIterator {
5882 ArgLocContainer *Container;
5883 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005884
Douglas Gregorfe921a72010-12-20 23:36:19 +00005885 public:
5886 typedef TemplateArgumentLoc value_type;
5887 typedef TemplateArgumentLoc reference;
5888 typedef int difference_type;
5889 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005890
Douglas Gregorfe921a72010-12-20 23:36:19 +00005891 class pointer {
5892 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005893
Douglas Gregorfe921a72010-12-20 23:36:19 +00005894 public:
5895 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005896
Douglas Gregorfe921a72010-12-20 23:36:19 +00005897 const TemplateArgumentLoc *operator->() const {
5898 return &Arg;
5899 }
5900 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005901
5902
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005903 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005904
Douglas Gregorfe921a72010-12-20 23:36:19 +00005905 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5906 unsigned Index)
5907 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005908
Douglas Gregorfe921a72010-12-20 23:36:19 +00005909 TemplateArgumentLocContainerIterator &operator++() {
5910 ++Index;
5911 return *this;
5912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005913
Douglas Gregorfe921a72010-12-20 23:36:19 +00005914 TemplateArgumentLocContainerIterator operator++(int) {
5915 TemplateArgumentLocContainerIterator Old(*this);
5916 ++(*this);
5917 return Old;
5918 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005919
Douglas Gregorfe921a72010-12-20 23:36:19 +00005920 TemplateArgumentLoc operator*() const {
5921 return Container->getArgLoc(Index);
5922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005923
Douglas Gregorfe921a72010-12-20 23:36:19 +00005924 pointer operator->() const {
5925 return pointer(Container->getArgLoc(Index));
5926 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005927
Douglas Gregorfe921a72010-12-20 23:36:19 +00005928 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005929 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005930 return X.Container == Y.Container && X.Index == Y.Index;
5931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005932
Douglas Gregorfe921a72010-12-20 23:36:19 +00005933 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005934 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005935 return !(X == Y);
5936 }
5937 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005938
5939
John McCall31f82722010-11-12 08:19:04 +00005940template <typename Derived>
5941QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5942 TypeLocBuilder &TLB,
5943 TemplateSpecializationTypeLoc TL,
5944 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005945 TemplateArgumentListInfo NewTemplateArgs;
5946 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5947 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005948 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5949 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005950 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005951 ArgIterator(TL, TL.getNumArgs()),
5952 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005953 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005954
John McCall0ad16662009-10-29 08:12:44 +00005955 // FIXME: maybe don't rebuild if all the template arguments are the same.
5956
5957 QualType Result =
5958 getDerived().RebuildTemplateSpecializationType(Template,
5959 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005960 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005961
5962 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005963 // Specializations of template template parameters are represented as
5964 // TemplateSpecializationTypes, and substitution of type alias templates
5965 // within a dependent context can transform them into
5966 // DependentTemplateSpecializationTypes.
5967 if (isa<DependentTemplateSpecializationType>(Result)) {
5968 DependentTemplateSpecializationTypeLoc NewTL
5969 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005970 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005971 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005972 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005973 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005974 NewTL.setLAngleLoc(TL.getLAngleLoc());
5975 NewTL.setRAngleLoc(TL.getRAngleLoc());
5976 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5977 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5978 return Result;
5979 }
5980
John McCall0ad16662009-10-29 08:12:44 +00005981 TemplateSpecializationTypeLoc NewTL
5982 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005983 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005984 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5985 NewTL.setLAngleLoc(TL.getLAngleLoc());
5986 NewTL.setRAngleLoc(TL.getRAngleLoc());
5987 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5988 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005989 }
Mike Stump11289f42009-09-09 15:08:12 +00005990
John McCall0ad16662009-10-29 08:12:44 +00005991 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005992}
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregor5a064722011-02-28 17:23:35 +00005994template <typename Derived>
5995QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5996 TypeLocBuilder &TLB,
5997 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005998 TemplateName Template,
5999 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00006000 TemplateArgumentListInfo NewTemplateArgs;
6001 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6002 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6003 typedef TemplateArgumentLocContainerIterator<
6004 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00006005 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00006006 ArgIterator(TL, TL.getNumArgs()),
6007 NewTemplateArgs))
6008 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006009
Douglas Gregor5a064722011-02-28 17:23:35 +00006010 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00006011
Douglas Gregor5a064722011-02-28 17:23:35 +00006012 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
6013 QualType Result
6014 = getSema().Context.getDependentTemplateSpecializationType(
6015 TL.getTypePtr()->getKeyword(),
6016 DTN->getQualifier(),
6017 DTN->getIdentifier(),
6018 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Douglas Gregor5a064722011-02-28 17:23:35 +00006020 DependentTemplateSpecializationTypeLoc NewTL
6021 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006022 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006023 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006024 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006025 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006026 NewTL.setLAngleLoc(TL.getLAngleLoc());
6027 NewTL.setRAngleLoc(TL.getRAngleLoc());
6028 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6029 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6030 return Result;
6031 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006032
6033 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006034 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006035 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006036 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006037
Douglas Gregor5a064722011-02-28 17:23:35 +00006038 if (!Result.isNull()) {
6039 /// FIXME: Wrap this in an elaborated-type-specifier?
6040 TemplateSpecializationTypeLoc NewTL
6041 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006042 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006043 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006044 NewTL.setLAngleLoc(TL.getLAngleLoc());
6045 NewTL.setRAngleLoc(TL.getRAngleLoc());
6046 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6047 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6048 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006049
Douglas Gregor5a064722011-02-28 17:23:35 +00006050 return Result;
6051}
6052
Mike Stump11289f42009-09-09 15:08:12 +00006053template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006054QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006055TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006056 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006057 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006058
Douglas Gregor844cb502011-03-01 18:12:44 +00006059 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006060 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006061 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006062 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006063 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6064 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006065 return QualType();
6066 }
Mike Stump11289f42009-09-09 15:08:12 +00006067
John McCall31f82722010-11-12 08:19:04 +00006068 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6069 if (NamedT.isNull())
6070 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006071
Richard Smith3f1b5d02011-05-05 21:57:07 +00006072 // C++0x [dcl.type.elab]p2:
6073 // If the identifier resolves to a typedef-name or the simple-template-id
6074 // resolves to an alias template specialization, the
6075 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006076 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6077 if (const TemplateSpecializationType *TST =
6078 NamedT->getAs<TemplateSpecializationType>()) {
6079 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006080 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6081 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006082 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006083 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006084 << TAT << Sema::NTK_TypeAliasTemplate
6085 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006086 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6087 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006088 }
6089 }
6090
John McCall550e0c22009-10-21 00:40:46 +00006091 QualType Result = TL.getType();
6092 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006093 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006094 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006095 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006096 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006097 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006098 if (Result.isNull())
6099 return QualType();
6100 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006101
Abramo Bagnara6150c882010-05-11 21:36:43 +00006102 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006103 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006104 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006105 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006106}
Mike Stump11289f42009-09-09 15:08:12 +00006107
6108template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006109QualType TreeTransform<Derived>::TransformAttributedType(
6110 TypeLocBuilder &TLB,
6111 AttributedTypeLoc TL) {
6112 const AttributedType *oldType = TL.getTypePtr();
6113 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6114 if (modifiedType.isNull())
6115 return QualType();
6116
Richard Smithe43e2b32018-08-20 21:47:29 +00006117 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6118 const Attr *oldAttr = TL.getAttr();
6119 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6120 if (oldAttr && !newAttr)
6121 return QualType();
6122
John McCall81904512011-01-06 01:58:22 +00006123 QualType result = TL.getType();
6124
6125 // FIXME: dependent operand expressions?
6126 if (getDerived().AlwaysRebuild() ||
6127 modifiedType != oldType->getModifiedType()) {
6128 // TODO: this is really lame; we should really be rebuilding the
6129 // equivalent type from first principles.
6130 QualType equivalentType
6131 = getDerived().TransformType(oldType->getEquivalentType());
6132 if (equivalentType.isNull())
6133 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006134
6135 // Check whether we can add nullability; it is only represented as
6136 // type sugar, and therefore cannot be diagnosed in any other way.
6137 if (auto nullability = oldType->getImmediateNullability()) {
6138 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006139 SemaRef.Diag(TL.getAttr()->getLocation(),
6140 diag::err_nullability_nonpointer)
6141 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006142 return QualType();
6143 }
6144 }
6145
Richard Smithe43e2b32018-08-20 21:47:29 +00006146 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006147 modifiedType,
6148 equivalentType);
6149 }
6150
6151 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006152 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006153 return result;
6154}
6155
6156template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006157QualType
6158TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6159 ParenTypeLoc TL) {
6160 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6161 if (Inner.isNull())
6162 return QualType();
6163
6164 QualType Result = TL.getType();
6165 if (getDerived().AlwaysRebuild() ||
6166 Inner != TL.getInnerLoc().getType()) {
6167 Result = getDerived().RebuildParenType(Inner);
6168 if (Result.isNull())
6169 return QualType();
6170 }
6171
6172 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6173 NewTL.setLParenLoc(TL.getLParenLoc());
6174 NewTL.setRParenLoc(TL.getRParenLoc());
6175 return Result;
6176}
6177
6178template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006179QualType TreeTransform<Derived>::TransformDependentNameType(
6180 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6181 return TransformDependentNameType(TLB, TL, false);
6182}
6183
6184template<typename Derived>
6185QualType TreeTransform<Derived>::TransformDependentNameType(
6186 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006187 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006188
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006189 NestedNameSpecifierLoc QualifierLoc
6190 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6191 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006192 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006193
John McCallc392f372010-06-11 00:33:02 +00006194 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006195 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006196 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006197 QualifierLoc,
6198 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006199 TL.getNameLoc(),
6200 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006201 if (Result.isNull())
6202 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006203
Abramo Bagnarad7548482010-05-19 21:37:53 +00006204 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6205 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006206 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6207
Abramo Bagnarad7548482010-05-19 21:37:53 +00006208 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006209 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006210 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006211 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006212 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006213 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006214 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006215 NewTL.setNameLoc(TL.getNameLoc());
6216 }
John McCall550e0c22009-10-21 00:40:46 +00006217 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006218}
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregord6ff3322009-08-04 16:50:30 +00006220template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006221QualType TreeTransform<Derived>::
6222 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006223 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006224 NestedNameSpecifierLoc QualifierLoc;
6225 if (TL.getQualifierLoc()) {
6226 QualifierLoc
6227 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6228 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006229 return QualType();
6230 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006231
John McCall31f82722010-11-12 08:19:04 +00006232 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006233 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006234}
6235
6236template<typename Derived>
6237QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006238TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6239 DependentTemplateSpecializationTypeLoc TL,
6240 NestedNameSpecifierLoc QualifierLoc) {
6241 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006242
Douglas Gregora7a795b2011-03-01 20:11:18 +00006243 TemplateArgumentListInfo NewTemplateArgs;
6244 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6245 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006246
Douglas Gregora7a795b2011-03-01 20:11:18 +00006247 typedef TemplateArgumentLocContainerIterator<
6248 DependentTemplateSpecializationTypeLoc> ArgIterator;
6249 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6250 ArgIterator(TL, TL.getNumArgs()),
6251 NewTemplateArgs))
6252 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006253
Richard Smithfd3dae02017-01-20 00:20:39 +00006254 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006255 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6256 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006257 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006258 if (Result.isNull())
6259 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006260
Douglas Gregora7a795b2011-03-01 20:11:18 +00006261 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6262 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006263
Douglas Gregora7a795b2011-03-01 20:11:18 +00006264 // Copy information relevant to the template specialization.
6265 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006266 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006267 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006268 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006269 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6270 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006271 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006272 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006273
Douglas Gregora7a795b2011-03-01 20:11:18 +00006274 // Copy information relevant to the elaborated type.
6275 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006276 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006277 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006278 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6279 DependentTemplateSpecializationTypeLoc SpecTL
6280 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006281 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006282 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006283 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006284 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006285 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6286 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006287 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006288 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006289 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006290 TemplateSpecializationTypeLoc SpecTL
6291 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006292 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006293 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006294 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6295 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006296 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006297 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006298 }
6299 return Result;
6300}
6301
6302template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006303QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6304 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006305 QualType Pattern
6306 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006307 if (Pattern.isNull())
6308 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006309
6310 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006311 if (getDerived().AlwaysRebuild() ||
6312 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006313 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006314 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006315 TL.getEllipsisLoc(),
6316 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006317 if (Result.isNull())
6318 return QualType();
6319 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006320
Douglas Gregor822d0302011-01-12 17:07:58 +00006321 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6322 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6323 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006324}
6325
6326template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006327QualType
6328TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006329 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006330 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006331 TLB.pushFullCopy(TL);
6332 return TL.getType();
6333}
6334
6335template<typename Derived>
6336QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006337TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6338 ObjCTypeParamTypeLoc TL) {
6339 const ObjCTypeParamType *T = TL.getTypePtr();
6340 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6341 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6342 if (!OTP)
6343 return QualType();
6344
6345 QualType Result = TL.getType();
6346 if (getDerived().AlwaysRebuild() ||
6347 OTP != T->getDecl()) {
6348 Result = getDerived().RebuildObjCTypeParamType(OTP,
6349 TL.getProtocolLAngleLoc(),
6350 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6351 TL.getNumProtocols()),
6352 TL.getProtocolLocs(),
6353 TL.getProtocolRAngleLoc());
6354 if (Result.isNull())
6355 return QualType();
6356 }
6357
6358 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6359 if (TL.getNumProtocols()) {
6360 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6361 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6362 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6363 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6364 }
6365 return Result;
6366}
6367
6368template<typename Derived>
6369QualType
John McCall8b07ec22010-05-15 11:32:37 +00006370TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006371 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006372 // Transform base type.
6373 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6374 if (BaseType.isNull())
6375 return QualType();
6376
6377 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6378
6379 // Transform type arguments.
6380 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6381 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6382 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6383 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6384 QualType TypeArg = TypeArgInfo->getType();
6385 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6386 AnyChanged = true;
6387
6388 // We have a pack expansion. Instantiate it.
6389 const auto *PackExpansion = PackExpansionLoc.getType()
6390 ->castAs<PackExpansionType>();
6391 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6392 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6393 Unexpanded);
6394 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6395
6396 // Determine whether the set of unexpanded parameter packs can
6397 // and should be expanded.
6398 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6399 bool Expand = false;
6400 bool RetainExpansion = false;
6401 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6402 if (getDerived().TryExpandParameterPacks(
6403 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6404 Unexpanded, Expand, RetainExpansion, NumExpansions))
6405 return QualType();
6406
6407 if (!Expand) {
6408 // We can't expand this pack expansion into separate arguments yet;
6409 // just substitute into the pattern and create a new pack expansion
6410 // type.
6411 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6412
6413 TypeLocBuilder TypeArgBuilder;
6414 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006415 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006416 PatternLoc);
6417 if (NewPatternType.isNull())
6418 return QualType();
6419
6420 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6421 NewPatternType, NumExpansions);
6422 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6423 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6424 NewTypeArgInfos.push_back(
6425 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6426 continue;
6427 }
6428
6429 // Substitute into the pack expansion pattern for each slice of the
6430 // pack.
6431 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6433
6434 TypeLocBuilder TypeArgBuilder;
6435 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6436
6437 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6438 PatternLoc);
6439 if (NewTypeArg.isNull())
6440 return QualType();
6441
6442 NewTypeArgInfos.push_back(
6443 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6444 }
6445
6446 continue;
6447 }
6448
6449 TypeLocBuilder TypeArgBuilder;
6450 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6451 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6452 if (NewTypeArg.isNull())
6453 return QualType();
6454
6455 // If nothing changed, just keep the old TypeSourceInfo.
6456 if (NewTypeArg == TypeArg) {
6457 NewTypeArgInfos.push_back(TypeArgInfo);
6458 continue;
6459 }
6460
6461 NewTypeArgInfos.push_back(
6462 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6463 AnyChanged = true;
6464 }
6465
6466 QualType Result = TL.getType();
6467 if (getDerived().AlwaysRebuild() || AnyChanged) {
6468 // Rebuild the type.
6469 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006470 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6471 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6472 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6473 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006474
6475 if (Result.isNull())
6476 return QualType();
6477 }
6478
6479 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006480 NewT.setHasBaseTypeAsWritten(true);
6481 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6482 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6483 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6484 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6485 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6486 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6487 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6488 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6489 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006490}
Mike Stump11289f42009-09-09 15:08:12 +00006491
6492template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006493QualType
6494TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006495 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006496 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6497 if (PointeeType.isNull())
6498 return QualType();
6499
6500 QualType Result = TL.getType();
6501 if (getDerived().AlwaysRebuild() ||
6502 PointeeType != TL.getPointeeLoc().getType()) {
6503 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6504 TL.getStarLoc());
6505 if (Result.isNull())
6506 return QualType();
6507 }
6508
6509 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6510 NewT.setStarLoc(TL.getStarLoc());
6511 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006512}
6513
Douglas Gregord6ff3322009-08-04 16:50:30 +00006514//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006515// Statement transformation
6516//===----------------------------------------------------------------------===//
6517template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006518StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006519TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006520 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006521}
6522
6523template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006524StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006525TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6526 return getDerived().TransformCompoundStmt(S, false);
6527}
6528
6529template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006530StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006531TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006532 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006533 Sema::CompoundScopeRAII CompoundScope(getSema());
6534
John McCall1ababa62010-08-27 19:56:05 +00006535 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006536 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006537 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006538 for (auto *B : S->body()) {
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006539 StmtResult Result = getDerived().TransformStmt(
6540 B,
6541 IsStmtExpr && B == S->body_back() ? SDK_StmtExprResult : SDK_Discarded);
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006542
John McCall1ababa62010-08-27 19:56:05 +00006543 if (Result.isInvalid()) {
6544 // Immediately fail if this was a DeclStmt, since it's very
6545 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006546 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006547 return StmtError();
6548
6549 // Otherwise, just keep processing substatements and fail later.
6550 SubStmtInvalid = true;
6551 continue;
6552 }
Mike Stump11289f42009-09-09 15:08:12 +00006553
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006554 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006555 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006556 }
Mike Stump11289f42009-09-09 15:08:12 +00006557
John McCall1ababa62010-08-27 19:56:05 +00006558 if (SubStmtInvalid)
6559 return StmtError();
6560
Douglas Gregorebe10102009-08-20 07:17:43 +00006561 if (!getDerived().AlwaysRebuild() &&
6562 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006563 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006564
6565 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006566 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006567 S->getRBracLoc(),
6568 IsStmtExpr);
6569}
Mike Stump11289f42009-09-09 15:08:12 +00006570
Douglas Gregorebe10102009-08-20 07:17:43 +00006571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006573TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006574 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006575 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006576 EnterExpressionEvaluationContext Unevaluated(
6577 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006578
Eli Friedman06577382009-11-19 03:14:00 +00006579 // Transform the left-hand case value.
6580 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006581 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006582 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006583 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006584
Eli Friedman06577382009-11-19 03:14:00 +00006585 // Transform the right-hand case value (for the GNU case-range extension).
6586 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006587 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006588 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006589 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006590 }
Mike Stump11289f42009-09-09 15:08:12 +00006591
Douglas Gregorebe10102009-08-20 07:17:43 +00006592 // Build the case statement.
6593 // Case statements are always rebuilt so that they will attached to their
6594 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006595 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006596 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006597 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006598 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006599 S->getColonLoc());
6600 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006601 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006602
Douglas Gregorebe10102009-08-20 07:17:43 +00006603 // Transform the statement following the case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006604 StmtResult SubStmt =
6605 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006606 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006608
Douglas Gregorebe10102009-08-20 07:17:43 +00006609 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006610 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006611}
6612
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006613template <typename Derived>
6614StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006615 // Transform the statement following the default case
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006616 StmtResult SubStmt =
6617 getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006618 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006620
Douglas Gregorebe10102009-08-20 07:17:43 +00006621 // Default statements are always rebuilt
6622 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006623 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006624}
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregorebe10102009-08-20 07:17:43 +00006626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006627StmtResult
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006628TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
6629 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006631 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006632
Chris Lattnercab02a62011-02-17 20:34:02 +00006633 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6634 S->getDecl());
6635 if (!LD)
6636 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006637
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006638 // If we're transforming "in-place" (we're not creating new local
6639 // declarations), assume we're replacing the old label statement
6640 // and clear out the reference to it.
6641 if (LD == S->getDecl())
6642 S->getDecl()->setStmt(nullptr);
Richard Smithc202b282012-04-14 00:33:13 +00006643
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006645 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006646 cast<LabelDecl>(LD), SourceLocation(),
6647 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006648}
Mike Stump11289f42009-09-09 15:08:12 +00006649
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006650template <typename Derived>
6651const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6652 if (!R)
6653 return R;
6654
6655 switch (R->getKind()) {
6656// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6657#define ATTR(X)
6658#define PRAGMA_SPELLING_ATTR(X) \
6659 case attr::X: \
6660 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6661#include "clang/Basic/AttrList.inc"
6662 default:
6663 return R;
6664 }
6665}
6666
6667template <typename Derived>
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006668StmtResult
6669TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
6670 StmtDiscardKind SDK) {
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006671 bool AttrsChanged = false;
6672 SmallVector<const Attr *, 1> Attrs;
6673
6674 // Visit attributes and keep track if any are transformed.
6675 for (const auto *I : S->getAttrs()) {
6676 const Attr *R = getDerived().TransformAttr(I);
6677 AttrsChanged |= (I != R);
6678 Attrs.push_back(R);
6679 }
6680
Richard Smitha6e8d5e2019-02-15 00:27:53 +00006681 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
Richard Smithc202b282012-04-14 00:33:13 +00006682 if (SubStmt.isInvalid())
6683 return StmtError();
6684
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006685 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006686 return S;
6687
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006688 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006689 SubStmt.get());
6690}
6691
6692template<typename Derived>
6693StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006694TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006695 // Transform the initialization statement
6696 StmtResult Init = getDerived().TransformStmt(S->getInit());
6697 if (Init.isInvalid())
6698 return StmtError();
6699
Douglas Gregorebe10102009-08-20 07:17:43 +00006700 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006701 Sema::ConditionResult Cond = getDerived().TransformCondition(
6702 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006703 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6704 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006705 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006706 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006707
Richard Smithb130fe72016-06-23 19:16:49 +00006708 // If this is a constexpr if, determine which arm we should instantiate.
6709 llvm::Optional<bool> ConstexprConditionValue;
6710 if (S->isConstexpr())
6711 ConstexprConditionValue = Cond.getKnownValue();
6712
Douglas Gregorebe10102009-08-20 07:17:43 +00006713 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006714 StmtResult Then;
6715 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6716 Then = getDerived().TransformStmt(S->getThen());
6717 if (Then.isInvalid())
6718 return StmtError();
6719 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006720 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006721 }
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregorebe10102009-08-20 07:17:43 +00006723 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006724 StmtResult Else;
6725 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6726 Else = getDerived().TransformStmt(S->getElse());
6727 if (Else.isInvalid())
6728 return StmtError();
6729 }
Mike Stump11289f42009-09-09 15:08:12 +00006730
Douglas Gregorebe10102009-08-20 07:17:43 +00006731 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006732 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006733 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006734 Then.get() == S->getThen() &&
6735 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006736 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006737
Richard Smithb130fe72016-06-23 19:16:49 +00006738 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006739 Init.get(), Then.get(), S->getElseLoc(),
6740 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006741}
6742
6743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006744StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006745TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006746 // Transform the initialization statement
6747 StmtResult Init = getDerived().TransformStmt(S->getInit());
6748 if (Init.isInvalid())
6749 return StmtError();
6750
Douglas Gregorebe10102009-08-20 07:17:43 +00006751 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006752 Sema::ConditionResult Cond = getDerived().TransformCondition(
6753 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6754 Sema::ConditionKind::Switch);
6755 if (Cond.isInvalid())
6756 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006757
Douglas Gregorebe10102009-08-20 07:17:43 +00006758 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006759 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006760 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006761 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006762 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006763
Douglas Gregorebe10102009-08-20 07:17:43 +00006764 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006765 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006766 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006767 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006768
Douglas Gregorebe10102009-08-20 07:17:43 +00006769 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006770 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6771 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006772}
Mike Stump11289f42009-09-09 15:08:12 +00006773
Douglas Gregorebe10102009-08-20 07:17:43 +00006774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006775StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006776TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006777 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006778 Sema::ConditionResult Cond = getDerived().TransformCondition(
6779 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6780 Sema::ConditionKind::Boolean);
6781 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006782 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006783
Douglas Gregorebe10102009-08-20 07:17:43 +00006784 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006785 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006786 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006787 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006788
Douglas Gregorebe10102009-08-20 07:17:43 +00006789 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006790 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006791 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006792 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006793
Richard Smith03a4aa32016-06-23 19:02:52 +00006794 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006795}
Mike Stump11289f42009-09-09 15:08:12 +00006796
Douglas Gregorebe10102009-08-20 07:17:43 +00006797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006798StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006799TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006800 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006801 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006802 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006803 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006804
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006805 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006806 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006807 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006808 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006809
Douglas Gregorebe10102009-08-20 07:17:43 +00006810 if (!getDerived().AlwaysRebuild() &&
6811 Cond.get() == S->getCond() &&
6812 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006813 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006814
John McCallb268a282010-08-23 23:25:46 +00006815 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6816 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006817 S->getRParenLoc());
6818}
Mike Stump11289f42009-09-09 15:08:12 +00006819
Douglas Gregorebe10102009-08-20 07:17:43 +00006820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006821StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006822TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006823 if (getSema().getLangOpts().OpenMP)
6824 getSema().startOpenMPLoop();
6825
Douglas Gregorebe10102009-08-20 07:17:43 +00006826 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006827 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006828 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006829 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006830
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006831 // In OpenMP loop region loop control variable must be captured and be
6832 // private. Perform analysis of first part (if any).
6833 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6834 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6835
Douglas Gregorebe10102009-08-20 07:17:43 +00006836 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006837 Sema::ConditionResult Cond = getDerived().TransformCondition(
6838 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6839 Sema::ConditionKind::Boolean);
6840 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006841 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006842
Douglas Gregorebe10102009-08-20 07:17:43 +00006843 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006844 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006845 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006846 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006847
Richard Smith945f8d32013-01-14 22:39:08 +00006848 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006849 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006850 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006851
Douglas Gregorebe10102009-08-20 07:17:43 +00006852 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006853 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006856
Douglas Gregorebe10102009-08-20 07:17:43 +00006857 if (!getDerived().AlwaysRebuild() &&
6858 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006859 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006860 Inc.get() == S->getInc() &&
6861 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006862 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006863
Douglas Gregorebe10102009-08-20 07:17:43 +00006864 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006865 Init.get(), Cond, FullInc,
6866 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006867}
6868
6869template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006870StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006871TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006872 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6873 S->getLabel());
6874 if (!LD)
6875 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006876
Douglas Gregorebe10102009-08-20 07:17:43 +00006877 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006878 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006879 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006880}
6881
6882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006883StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006884TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006885 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006886 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006887 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006888 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006889
Douglas Gregorebe10102009-08-20 07:17:43 +00006890 if (!getDerived().AlwaysRebuild() &&
6891 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006892 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006893
6894 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006895 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006896}
6897
6898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006899StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006900TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006901 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006902}
Mike Stump11289f42009-09-09 15:08:12 +00006903
Douglas Gregorebe10102009-08-20 07:17:43 +00006904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006905StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006906TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006907 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006908}
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>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006913 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6914 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006915 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006916 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006917
Mike Stump11289f42009-09-09 15:08:12 +00006918 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006919 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006920 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006921}
Mike Stump11289f42009-09-09 15:08:12 +00006922
Douglas Gregorebe10102009-08-20 07:17:43 +00006923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006924StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006925TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006926 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006927 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006928 for (auto *D : S->decls()) {
6929 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006930 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006931 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006932
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006933 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006934 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006935
Douglas Gregorebe10102009-08-20 07:17:43 +00006936 Decls.push_back(Transformed);
6937 }
Mike Stump11289f42009-09-09 15:08:12 +00006938
Douglas Gregorebe10102009-08-20 07:17:43 +00006939 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006940 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006941
Stephen Kellya6e43582018-08-09 21:05:56 +00006942 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006943}
Mike Stump11289f42009-09-09 15:08:12 +00006944
Douglas Gregorebe10102009-08-20 07:17:43 +00006945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006946StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006947TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006948
Benjamin Kramerf0623432012-08-23 22:51:59 +00006949 SmallVector<Expr*, 8> Constraints;
6950 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006951 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006952
John McCalldadc5752010-08-24 06:29:42 +00006953 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006954 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006955
6956 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006957
Anders Carlssonaaeef072010-01-24 05:50:09 +00006958 // Go through the outputs.
6959 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006960 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006961
Anders Carlssonaaeef072010-01-24 05:50:09 +00006962 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006963 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006964
Anders Carlssonaaeef072010-01-24 05:50:09 +00006965 // Transform the output expr.
6966 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006967 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006968 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006969 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006970
Anders Carlssonaaeef072010-01-24 05:50:09 +00006971 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006972
John McCallb268a282010-08-23 23:25:46 +00006973 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006975
Anders Carlssonaaeef072010-01-24 05:50:09 +00006976 // Go through the inputs.
6977 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006978 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006979
Anders Carlssonaaeef072010-01-24 05:50:09 +00006980 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006981 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006982
Anders Carlssonaaeef072010-01-24 05:50:09 +00006983 // Transform the input expr.
6984 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006985 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006986 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006987 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006988
Anders Carlssonaaeef072010-01-24 05:50:09 +00006989 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006990
John McCallb268a282010-08-23 23:25:46 +00006991 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006993
Anders Carlssonaaeef072010-01-24 05:50:09 +00006994 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006995 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006996
6997 // Go through the clobbers.
6998 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006999 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00007000
7001 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007002 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00007003 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
7004 S->isVolatile(), S->getNumOutputs(),
7005 S->getNumInputs(), Names.data(),
7006 Constraints, Exprs, AsmString.get(),
7007 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00007008}
7009
Chad Rosier32503022012-06-11 20:47:18 +00007010template<typename Derived>
7011StmtResult
7012TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00007013 ArrayRef<Token> AsmToks =
7014 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00007015
John McCallf413f5e2013-05-03 00:10:13 +00007016 bool HadError = false, HadChange = false;
7017
7018 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
7019 SmallVector<Expr*, 8> TransformedExprs;
7020 TransformedExprs.reserve(SrcExprs.size());
7021 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
7022 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7023 if (!Result.isUsable()) {
7024 HadError = true;
7025 } else {
7026 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007027 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007028 }
7029 }
7030
7031 if (HadError) return StmtError();
7032 if (!HadChange && !getDerived().AlwaysRebuild())
7033 return Owned(S);
7034
Chad Rosierb6f46c12012-08-15 16:53:30 +00007035 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007036 AsmToks, S->getAsmString(),
7037 S->getNumOutputs(), S->getNumInputs(),
7038 S->getAllConstraints(), S->getClobbers(),
7039 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007040}
Douglas Gregorebe10102009-08-20 07:17:43 +00007041
Richard Smith9f690bd2015-10-27 06:02:45 +00007042// C++ Coroutines TS
7043
7044template<typename Derived>
7045StmtResult
7046TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007047 auto *ScopeInfo = SemaRef.getCurFunction();
7048 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007049 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007050 ScopeInfo->NeedsCoroutineSuspends &&
7051 ScopeInfo->CoroutineSuspends.first == nullptr &&
7052 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007053 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007054
7055 // Set that we have (possibly-invalid) suspend points before we do anything
7056 // that may fail.
7057 ScopeInfo->setNeedsCoroutineSuspends(false);
7058
7059 // The new CoroutinePromise object needs to be built and put into the current
7060 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007061 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7062 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007063 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7064 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007065 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007066 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
7067 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007068
7069 // Transform the implicit coroutine statements we built during the initial
7070 // parse.
7071 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7072 if (InitSuspend.isInvalid())
7073 return StmtError();
7074 StmtResult FinalSuspend =
7075 getDerived().TransformStmt(S->getFinalSuspendStmt());
7076 if (FinalSuspend.isInvalid())
7077 return StmtError();
7078 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7079 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007080
7081 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7082 if (BodyRes.isInvalid())
7083 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007084
Eric Fiselierbee782b2017-04-03 19:21:00 +00007085 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7086 if (Builder.isInvalid())
7087 return StmtError();
7088
7089 Expr *ReturnObject = S->getReturnValueInit();
7090 assert(ReturnObject && "the return object is expected to be valid");
7091 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7092 /*NoCopyInit*/ false);
7093 if (Res.isInvalid())
7094 return StmtError();
7095 Builder.ReturnValue = Res.get();
7096
7097 if (S->hasDependentPromiseType()) {
7098 assert(!Promise->getType()->isDependentType() &&
7099 "the promise type must no longer be dependent");
7100 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7101 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7102 "these nodes should not have been built yet");
7103 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007104 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007105 } else {
7106 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7107 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7108 if (Res.isInvalid())
7109 return StmtError();
7110 Builder.OnFallthrough = Res.get();
7111 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007112
Eric Fiselierbee782b2017-04-03 19:21:00 +00007113 if (auto *OnException = S->getExceptionHandler()) {
7114 StmtResult Res = getDerived().TransformStmt(OnException);
7115 if (Res.isInvalid())
7116 return StmtError();
7117 Builder.OnException = Res.get();
7118 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007119
Eric Fiselierbee782b2017-04-03 19:21:00 +00007120 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7121 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7122 if (Res.isInvalid())
7123 return StmtError();
7124 Builder.ReturnStmtOnAllocFailure = Res.get();
7125 }
7126
7127 // Transform any additional statements we may have already built
7128 assert(S->getAllocate() && S->getDeallocate() &&
7129 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007130 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7131 if (AllocRes.isInvalid())
7132 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007133 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007134
7135 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7136 if (DeallocRes.isInvalid())
7137 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007138 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007139
7140 assert(S->getResultDecl() && "ResultDecl must already be built");
7141 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7142 if (ResultDecl.isInvalid())
7143 return StmtError();
7144 Builder.ResultDecl = ResultDecl.get();
7145
7146 if (auto *ReturnStmt = S->getReturnStmt()) {
7147 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7148 if (Res.isInvalid())
7149 return StmtError();
7150 Builder.ReturnStmt = Res.get();
7151 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007152 }
7153
Eric Fiselierbee782b2017-04-03 19:21:00 +00007154 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007155}
7156
7157template<typename Derived>
7158StmtResult
7159TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7160 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7161 /*NotCopyInit*/false);
7162 if (Result.isInvalid())
7163 return StmtError();
7164
7165 // Always rebuild; we don't know if this needs to be injected into a new
7166 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007167 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7168 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007169}
7170
7171template<typename Derived>
7172ExprResult
7173TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7174 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7175 /*NotCopyInit*/false);
7176 if (Result.isInvalid())
7177 return ExprError();
7178
7179 // Always rebuild; we don't know if this needs to be injected into a new
7180 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007181 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7182 E->isImplicit());
7183}
7184
7185template <typename Derived>
7186ExprResult
7187TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7188 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7189 /*NotCopyInit*/ false);
7190 if (OperandResult.isInvalid())
7191 return ExprError();
7192
7193 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7194 E->getOperatorCoawaitLookup());
7195
7196 if (LookupResult.isInvalid())
7197 return ExprError();
7198
7199 // Always rebuild; we don't know if this needs to be injected into a new
7200 // context or if the promise type has changed.
7201 return getDerived().RebuildDependentCoawaitExpr(
7202 E->getKeywordLoc(), OperandResult.get(),
7203 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007204}
7205
7206template<typename Derived>
7207ExprResult
7208TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7209 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7210 /*NotCopyInit*/false);
7211 if (Result.isInvalid())
7212 return ExprError();
7213
7214 // Always rebuild; we don't know if this needs to be injected into a new
7215 // context or if the promise type has changed.
7216 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7217}
7218
7219// Objective-C Statements.
7220
Douglas Gregorebe10102009-08-20 07:17:43 +00007221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007222StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007223TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007224 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007225 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007226 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007227 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007228
Douglas Gregor96c79492010-04-23 22:50:49 +00007229 // Transform the @catch statements (if present).
7230 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007231 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007232 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007233 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007234 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007236 if (Catch.get() != S->getCatchStmt(I))
7237 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007238 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007239 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007240
Douglas Gregor306de2f2010-04-22 23:59:56 +00007241 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007242 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007243 if (S->getFinallyStmt()) {
7244 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7245 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007246 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007247 }
7248
7249 // If nothing changed, just retain this statement.
7250 if (!getDerived().AlwaysRebuild() &&
7251 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007252 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007253 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007254 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007255
Douglas Gregor306de2f2010-04-22 23:59:56 +00007256 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007257 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007258 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007259}
Mike Stump11289f42009-09-09 15:08:12 +00007260
Douglas Gregorebe10102009-08-20 07:17:43 +00007261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007262StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007263TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007264 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007265 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007266 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007267 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007268 if (FromVar->getTypeSourceInfo()) {
7269 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7270 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007271 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007272 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007273
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007274 QualType T;
7275 if (TSInfo)
7276 T = TSInfo->getType();
7277 else {
7278 T = getDerived().TransformType(FromVar->getType());
7279 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007280 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007282
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007283 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7284 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007285 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007286 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007287
John McCalldadc5752010-08-24 06:29:42 +00007288 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007289 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007290 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007291
7292 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007293 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007294 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007295}
Mike Stump11289f42009-09-09 15:08:12 +00007296
Douglas Gregorebe10102009-08-20 07:17:43 +00007297template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007298StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007299TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007300 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007301 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007302 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007303 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007304
Douglas Gregor306de2f2010-04-22 23:59:56 +00007305 // If nothing changed, just retain this statement.
7306 if (!getDerived().AlwaysRebuild() &&
7307 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007308 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007309
7310 // Build a new statement.
7311 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007312 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007313}
Mike Stump11289f42009-09-09 15:08:12 +00007314
Douglas Gregorebe10102009-08-20 07:17:43 +00007315template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007316StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007317TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007318 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007319 if (S->getThrowExpr()) {
7320 Operand = getDerived().TransformExpr(S->getThrowExpr());
7321 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007322 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007323 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007324
Douglas Gregor2900c162010-04-22 21:44:01 +00007325 if (!getDerived().AlwaysRebuild() &&
7326 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007327 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007328
John McCallb268a282010-08-23 23:25:46 +00007329 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007330}
Mike Stump11289f42009-09-09 15:08:12 +00007331
Douglas Gregorebe10102009-08-20 07:17:43 +00007332template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007333StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007334TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007335 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007336 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007337 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007338 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007339 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007340 Object =
7341 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7342 Object.get());
7343 if (Object.isInvalid())
7344 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007345
Douglas Gregor6148de72010-04-22 22:01:21 +00007346 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007347 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007348 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007349 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007350
Douglas Gregor6148de72010-04-22 22:01:21 +00007351 // If nothing change, just retain the current statement.
7352 if (!getDerived().AlwaysRebuild() &&
7353 Object.get() == S->getSynchExpr() &&
7354 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007355 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007356
7357 // Build a new statement.
7358 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007359 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007360}
7361
7362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007363StmtResult
John McCall31168b02011-06-15 23:02:42 +00007364TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7365 ObjCAutoreleasePoolStmt *S) {
7366 // Transform the body.
7367 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7368 if (Body.isInvalid())
7369 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007370
John McCall31168b02011-06-15 23:02:42 +00007371 // If nothing changed, just retain this statement.
7372 if (!getDerived().AlwaysRebuild() &&
7373 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007374 return S;
John McCall31168b02011-06-15 23:02:42 +00007375
7376 // Build a new statement.
7377 return getDerived().RebuildObjCAutoreleasePoolStmt(
7378 S->getAtLoc(), Body.get());
7379}
7380
7381template<typename Derived>
7382StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007383TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007384 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007385 // Transform the element statement.
Richard Smitha6e8d5e2019-02-15 00:27:53 +00007386 StmtResult Element =
7387 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
Douglas Gregorf68a5082010-04-22 23:10:45 +00007388 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007389 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007390
Douglas Gregorf68a5082010-04-22 23:10:45 +00007391 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007392 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007393 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007394 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007395
Douglas Gregorf68a5082010-04-22 23:10:45 +00007396 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007397 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007398 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007399 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007400
Douglas Gregorf68a5082010-04-22 23:10:45 +00007401 // If nothing changed, just retain this statement.
7402 if (!getDerived().AlwaysRebuild() &&
7403 Element.get() == S->getElement() &&
7404 Collection.get() == S->getCollection() &&
7405 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007406 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007407
Douglas Gregorf68a5082010-04-22 23:10:45 +00007408 // Build a new statement.
7409 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007410 Element.get(),
7411 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007412 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007413 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007414}
7415
David Majnemer5f7efef2013-10-15 09:50:08 +00007416template <typename Derived>
7417StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007418 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007419 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007420 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7421 TypeSourceInfo *T =
7422 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007423 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007424 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007425
David Majnemer5f7efef2013-10-15 09:50:08 +00007426 Var = getDerived().RebuildExceptionDecl(
7427 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7428 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007429 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007430 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007431 }
Mike Stump11289f42009-09-09 15:08:12 +00007432
Douglas Gregorebe10102009-08-20 07:17:43 +00007433 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007434 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007435 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007436 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007437
David Majnemer5f7efef2013-10-15 09:50:08 +00007438 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007439 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007440 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007441
David Majnemer5f7efef2013-10-15 09:50:08 +00007442 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007443}
Mike Stump11289f42009-09-09 15:08:12 +00007444
David Majnemer5f7efef2013-10-15 09:50:08 +00007445template <typename Derived>
7446StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007447 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007448 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007449 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007450 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007451
Douglas Gregorebe10102009-08-20 07:17:43 +00007452 // Transform the handlers.
7453 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007454 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007455 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007456 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007457 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007458 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregorebe10102009-08-20 07:17:43 +00007460 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007461 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007462 }
Mike Stump11289f42009-09-09 15:08:12 +00007463
David Majnemer5f7efef2013-10-15 09:50:08 +00007464 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007465 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007466 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007467
John McCallb268a282010-08-23 23:25:46 +00007468 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007469 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007470}
Mike Stump11289f42009-09-09 15:08:12 +00007471
Richard Smith02e85f32011-04-14 22:09:26 +00007472template<typename Derived>
7473StmtResult
7474TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007475 StmtResult Init =
7476 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7477 if (Init.isInvalid())
7478 return StmtError();
7479
Richard Smith02e85f32011-04-14 22:09:26 +00007480 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7481 if (Range.isInvalid())
7482 return StmtError();
7483
Richard Smith01694c32016-03-20 10:33:40 +00007484 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7485 if (Begin.isInvalid())
7486 return StmtError();
7487 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7488 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007489 return StmtError();
7490
7491 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7492 if (Cond.isInvalid())
7493 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007494 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007495 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007496 if (Cond.isInvalid())
7497 return StmtError();
7498 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007499 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007500
7501 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7502 if (Inc.isInvalid())
7503 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007504 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007505 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007506
7507 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7508 if (LoopVar.isInvalid())
7509 return StmtError();
7510
7511 StmtResult NewStmt = S;
7512 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007513 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007514 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007515 Begin.get() != S->getBeginStmt() ||
7516 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007517 Cond.get() != S->getCond() ||
7518 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007519 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007520 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007521 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007522 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007523 Begin.get(), End.get(),
7524 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007525 Inc.get(), LoopVar.get(),
7526 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007527 if (NewStmt.isInvalid())
7528 return StmtError();
7529 }
Richard Smith02e85f32011-04-14 22:09:26 +00007530
7531 StmtResult Body = getDerived().TransformStmt(S->getBody());
7532 if (Body.isInvalid())
7533 return StmtError();
7534
7535 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7536 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007537 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007538 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007539 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007540 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007541 Begin.get(), End.get(),
7542 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007543 Inc.get(), LoopVar.get(),
7544 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007545 if (NewStmt.isInvalid())
7546 return StmtError();
7547 }
Richard Smith02e85f32011-04-14 22:09:26 +00007548
7549 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007550 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007551
7552 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7553}
7554
John Wiegley1c0675e2011-04-28 01:08:34 +00007555template<typename Derived>
7556StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007557TreeTransform<Derived>::TransformMSDependentExistsStmt(
7558 MSDependentExistsStmt *S) {
7559 // Transform the nested-name-specifier, if any.
7560 NestedNameSpecifierLoc QualifierLoc;
7561 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007562 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007563 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7564 if (!QualifierLoc)
7565 return StmtError();
7566 }
7567
7568 // Transform the declaration name.
7569 DeclarationNameInfo NameInfo = S->getNameInfo();
7570 if (NameInfo.getName()) {
7571 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7572 if (!NameInfo.getName())
7573 return StmtError();
7574 }
7575
7576 // Check whether anything changed.
7577 if (!getDerived().AlwaysRebuild() &&
7578 QualifierLoc == S->getQualifierLoc() &&
7579 NameInfo.getName() == S->getNameInfo().getName())
7580 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007581
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007582 // Determine whether this name exists, if we can.
7583 CXXScopeSpec SS;
7584 SS.Adopt(QualifierLoc);
7585 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007586 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007587 case Sema::IER_Exists:
7588 if (S->isIfExists())
7589 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007590
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007591 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7592
7593 case Sema::IER_DoesNotExist:
7594 if (S->isIfNotExists())
7595 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007596
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007597 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007598
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007599 case Sema::IER_Dependent:
7600 Dependent = true;
7601 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007602
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007603 case Sema::IER_Error:
7604 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007605 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007606
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007607 // We need to continue with the instantiation, so do so now.
7608 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7609 if (SubStmt.isInvalid())
7610 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007611
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007612 // If we have resolved the name, just transform to the substatement.
7613 if (!Dependent)
7614 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007615
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007616 // The name is still dependent, so build a dependent expression again.
7617 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7618 S->isIfExists(),
7619 QualifierLoc,
7620 NameInfo,
7621 SubStmt.get());
7622}
7623
7624template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007625ExprResult
7626TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7627 NestedNameSpecifierLoc QualifierLoc;
7628 if (E->getQualifierLoc()) {
7629 QualifierLoc
7630 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7631 if (!QualifierLoc)
7632 return ExprError();
7633 }
7634
7635 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7636 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7637 if (!PD)
7638 return ExprError();
7639
7640 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7641 if (Base.isInvalid())
7642 return ExprError();
7643
7644 return new (SemaRef.getASTContext())
7645 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7646 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7647 QualifierLoc, E->getMemberLoc());
7648}
7649
David Majnemerfad8f482013-10-15 09:33:02 +00007650template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007651ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7652 MSPropertySubscriptExpr *E) {
7653 auto BaseRes = getDerived().TransformExpr(E->getBase());
7654 if (BaseRes.isInvalid())
7655 return ExprError();
7656 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7657 if (IdxRes.isInvalid())
7658 return ExprError();
7659
7660 if (!getDerived().AlwaysRebuild() &&
7661 BaseRes.get() == E->getBase() &&
7662 IdxRes.get() == E->getIdx())
7663 return E;
7664
7665 return getDerived().RebuildArraySubscriptExpr(
7666 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7667}
7668
7669template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007670StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007671 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007672 if (TryBlock.isInvalid())
7673 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007674
7675 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007676 if (Handler.isInvalid())
7677 return StmtError();
7678
David Majnemerfad8f482013-10-15 09:33:02 +00007679 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7680 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007681 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007682
Warren Huntf6be4cb2014-07-25 20:52:51 +00007683 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7684 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007685}
7686
David Majnemerfad8f482013-10-15 09:33:02 +00007687template <typename Derived>
7688StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007689 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007690 if (Block.isInvalid())
7691 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007692
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007693 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007694}
7695
David Majnemerfad8f482013-10-15 09:33:02 +00007696template <typename Derived>
7697StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007698 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007699 if (FilterExpr.isInvalid())
7700 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007701
David Majnemer7e755502013-10-15 09:30:14 +00007702 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007703 if (Block.isInvalid())
7704 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007705
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007706 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7707 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007708}
7709
David Majnemerfad8f482013-10-15 09:33:02 +00007710template <typename Derived>
7711StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7712 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007713 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7714 else
7715 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7716}
7717
Nico Weber9b982072014-07-07 00:12:30 +00007718template<typename Derived>
7719StmtResult
7720TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7721 return S;
7722}
7723
Alexander Musman64d33f12014-06-04 07:53:32 +00007724//===----------------------------------------------------------------------===//
7725// OpenMP directive transformation
7726//===----------------------------------------------------------------------===//
7727template <typename Derived>
7728StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7729 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007730
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007731 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007732 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007733 ArrayRef<OMPClause *> Clauses = D->clauses();
7734 TClauses.reserve(Clauses.size());
7735 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7736 I != E; ++I) {
7737 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007738 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007739 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007740 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007741 if (Clause)
7742 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007743 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007744 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007745 }
7746 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007747 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007748 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007749 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7750 /*CurScope=*/nullptr);
7751 StmtResult Body;
7752 {
7753 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007754 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007755 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007756 }
7757 AssociatedStmt =
7758 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007759 if (AssociatedStmt.isInvalid()) {
7760 return StmtError();
7761 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007762 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007763 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007764 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007765 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007766
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007767 // Transform directive name for 'omp critical' directive.
7768 DeclarationNameInfo DirName;
7769 if (D->getDirectiveKind() == OMPD_critical) {
7770 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7771 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7772 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007773 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7774 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7775 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007776 } else if (D->getDirectiveKind() == OMPD_cancel) {
7777 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007778 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007779
Alexander Musman64d33f12014-06-04 07:53:32 +00007780 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007781 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007782 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007783}
7784
Alexander Musman64d33f12014-06-04 07:53:32 +00007785template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007786StmtResult
7787TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7788 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007789 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007790 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007791 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7792 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7793 return Res;
7794}
7795
Alexander Musman64d33f12014-06-04 07:53:32 +00007796template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007797StmtResult
7798TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7799 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007800 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007801 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007802 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7803 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007804 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007805}
7806
Alexey Bataevf29276e2014-06-18 04:14:57 +00007807template <typename Derived>
7808StmtResult
7809TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7810 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007811 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007812 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007813 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7814 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7815 return Res;
7816}
7817
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007818template <typename Derived>
7819StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007820TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7821 DeclarationNameInfo DirName;
7822 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007823 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007824 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7825 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7826 return Res;
7827}
7828
7829template <typename Derived>
7830StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007831TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7832 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007833 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007834 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007835 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7836 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7837 return Res;
7838}
7839
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007840template <typename Derived>
7841StmtResult
7842TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7843 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007844 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007845 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007846 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7847 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7848 return Res;
7849}
7850
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007851template <typename Derived>
7852StmtResult
7853TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7854 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007855 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007856 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007857 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7858 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7859 return Res;
7860}
7861
Alexey Bataev4acb8592014-07-07 13:01:15 +00007862template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007863StmtResult
7864TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7865 DeclarationNameInfo DirName;
7866 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007867 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007868 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7869 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7870 return Res;
7871}
7872
7873template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007874StmtResult
7875TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7876 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007877 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007878 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7879 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7880 return Res;
7881}
7882
7883template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007884StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7885 OMPParallelForDirective *D) {
7886 DeclarationNameInfo DirName;
7887 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007888 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007889 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7890 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7891 return Res;
7892}
7893
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007894template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007895StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7896 OMPParallelForSimdDirective *D) {
7897 DeclarationNameInfo DirName;
7898 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007899 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007900 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7901 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7902 return Res;
7903}
7904
7905template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007906StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7907 OMPParallelSectionsDirective *D) {
7908 DeclarationNameInfo DirName;
7909 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007910 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007911 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7912 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7913 return Res;
7914}
7915
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007916template <typename Derived>
7917StmtResult
7918TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7919 DeclarationNameInfo DirName;
7920 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007921 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007922 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7923 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7924 return Res;
7925}
7926
Alexey Bataev68446b72014-07-18 07:47:19 +00007927template <typename Derived>
7928StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7929 OMPTaskyieldDirective *D) {
7930 DeclarationNameInfo DirName;
7931 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007932 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00007933 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7934 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7935 return Res;
7936}
7937
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007938template <typename Derived>
7939StmtResult
7940TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7941 DeclarationNameInfo DirName;
7942 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007943 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007944 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7945 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7946 return Res;
7947}
7948
Alexey Bataev2df347a2014-07-18 10:17:07 +00007949template <typename Derived>
7950StmtResult
7951TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7952 DeclarationNameInfo DirName;
7953 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007954 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00007955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7956 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7957 return Res;
7958}
7959
Alexey Bataev6125da92014-07-21 11:26:11 +00007960template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007961StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7962 OMPTaskgroupDirective *D) {
7963 DeclarationNameInfo DirName;
7964 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007965 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7967 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7968 return Res;
7969}
7970
7971template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007972StmtResult
7973TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7974 DeclarationNameInfo DirName;
7975 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007976 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00007977 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7978 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7979 return Res;
7980}
7981
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007982template <typename Derived>
7983StmtResult
7984TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7985 DeclarationNameInfo DirName;
7986 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007987 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990 return Res;
7991}
7992
Alexey Bataev0162e452014-07-22 10:10:35 +00007993template <typename Derived>
7994StmtResult
7995TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007998 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00007999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001 return Res;
8002}
8003
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008004template <typename Derived>
8005StmtResult
8006TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008009 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00008010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8012 return Res;
8013}
8014
Alexey Bataev13314bf2014-10-09 04:18:56 +00008015template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00008016StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
8017 OMPTargetDataDirective *D) {
8018 DeclarationNameInfo DirName;
8019 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008020 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00008021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8023 return Res;
8024}
8025
8026template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008027StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8028 OMPTargetEnterDataDirective *D) {
8029 DeclarationNameInfo DirName;
8030 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008031 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8034 return Res;
8035}
8036
8037template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008038StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8039 OMPTargetExitDataDirective *D) {
8040 DeclarationNameInfo DirName;
8041 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008042 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008043 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8044 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8045 return Res;
8046}
8047
8048template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008049StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8050 OMPTargetParallelDirective *D) {
8051 DeclarationNameInfo DirName;
8052 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008053 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008054 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8055 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8056 return Res;
8057}
8058
8059template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008060StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8061 OMPTargetParallelForDirective *D) {
8062 DeclarationNameInfo DirName;
8063 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008064 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008065 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8066 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8067 return Res;
8068}
8069
8070template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008071StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8072 OMPTargetUpdateDirective *D) {
8073 DeclarationNameInfo DirName;
8074 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008075 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008076 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8077 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8078 return Res;
8079}
8080
8081template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008082StmtResult
8083TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8084 DeclarationNameInfo DirName;
8085 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008086 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008087 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8088 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8089 return Res;
8090}
8091
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008092template <typename Derived>
8093StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8094 OMPCancellationPointDirective *D) {
8095 DeclarationNameInfo DirName;
8096 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008097 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008098 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8099 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8100 return Res;
8101}
8102
Alexey Bataev80909872015-07-02 11:25:17 +00008103template <typename Derived>
8104StmtResult
8105TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8106 DeclarationNameInfo DirName;
8107 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008108 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008109 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8110 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8111 return Res;
8112}
8113
Alexey Bataev49f6e782015-12-01 04:18:41 +00008114template <typename Derived>
8115StmtResult
8116TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8117 DeclarationNameInfo DirName;
8118 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008119 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008120 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8121 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8122 return Res;
8123}
8124
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008125template <typename Derived>
8126StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8127 OMPTaskLoopSimdDirective *D) {
8128 DeclarationNameInfo DirName;
8129 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008130 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8132 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8133 return Res;
8134}
8135
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008136template <typename Derived>
8137StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8138 OMPDistributeDirective *D) {
8139 DeclarationNameInfo DirName;
8140 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008141 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8143 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8144 return Res;
8145}
8146
Carlo Bertolli9925f152016-06-27 14:55:37 +00008147template <typename Derived>
8148StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8149 OMPDistributeParallelForDirective *D) {
8150 DeclarationNameInfo DirName;
8151 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008152 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008153 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8154 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8155 return Res;
8156}
8157
Kelvin Li4a39add2016-07-05 05:00:15 +00008158template <typename Derived>
8159StmtResult
8160TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8161 OMPDistributeParallelForSimdDirective *D) {
8162 DeclarationNameInfo DirName;
8163 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008164 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8167 return Res;
8168}
8169
Kelvin Li787f3fc2016-07-06 04:45:38 +00008170template <typename Derived>
8171StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8172 OMPDistributeSimdDirective *D) {
8173 DeclarationNameInfo DirName;
8174 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008175 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8177 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8178 return Res;
8179}
8180
Kelvin Lia579b912016-07-14 02:54:56 +00008181template <typename Derived>
8182StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8183 OMPTargetParallelForSimdDirective *D) {
8184 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008185 getDerived().getSema().StartOpenMPDSABlock(
8186 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008187 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8188 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8189 return Res;
8190}
8191
Kelvin Li986330c2016-07-20 22:57:10 +00008192template <typename Derived>
8193StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8194 OMPTargetSimdDirective *D) {
8195 DeclarationNameInfo DirName;
8196 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008197 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008198 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8199 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8200 return Res;
8201}
8202
Kelvin Li02532872016-08-05 14:37:37 +00008203template <typename Derived>
8204StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8205 OMPTeamsDistributeDirective *D) {
8206 DeclarationNameInfo DirName;
8207 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008208 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008209 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8210 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8211 return Res;
8212}
8213
Kelvin Li4e325f72016-10-25 12:50:55 +00008214template <typename Derived>
8215StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8216 OMPTeamsDistributeSimdDirective *D) {
8217 DeclarationNameInfo DirName;
8218 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008219 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8221 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8222 return Res;
8223}
8224
Kelvin Li579e41c2016-11-30 23:51:03 +00008225template <typename Derived>
8226StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8227 OMPTeamsDistributeParallelForSimdDirective *D) {
8228 DeclarationNameInfo DirName;
8229 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008230 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8231 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008232 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8233 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8234 return Res;
8235}
8236
Kelvin Li7ade93f2016-12-09 03:24:30 +00008237template <typename Derived>
8238StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8239 OMPTeamsDistributeParallelForDirective *D) {
8240 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008241 getDerived().getSema().StartOpenMPDSABlock(
8242 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008243 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8244 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8245 return Res;
8246}
8247
Kelvin Libf594a52016-12-17 05:48:59 +00008248template <typename Derived>
8249StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8250 OMPTargetTeamsDirective *D) {
8251 DeclarationNameInfo DirName;
8252 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008253 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008254 auto Res = getDerived().TransformOMPExecutableDirective(D);
8255 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8256 return Res;
8257}
Kelvin Li579e41c2016-11-30 23:51:03 +00008258
Kelvin Li83c451e2016-12-25 04:52:54 +00008259template <typename Derived>
8260StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8261 OMPTargetTeamsDistributeDirective *D) {
8262 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008263 getDerived().getSema().StartOpenMPDSABlock(
8264 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008265 auto Res = getDerived().TransformOMPExecutableDirective(D);
8266 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8267 return Res;
8268}
8269
Kelvin Li80e8f562016-12-29 22:16:30 +00008270template <typename Derived>
8271StmtResult
8272TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8273 OMPTargetTeamsDistributeParallelForDirective *D) {
8274 DeclarationNameInfo DirName;
8275 getDerived().getSema().StartOpenMPDSABlock(
8276 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008277 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008278 auto Res = getDerived().TransformOMPExecutableDirective(D);
8279 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8280 return Res;
8281}
8282
Kelvin Li1851df52017-01-03 05:23:48 +00008283template <typename Derived>
8284StmtResult TreeTransform<Derived>::
8285 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8286 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8287 DeclarationNameInfo DirName;
8288 getDerived().getSema().StartOpenMPDSABlock(
8289 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008290 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008291 auto Res = getDerived().TransformOMPExecutableDirective(D);
8292 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8293 return Res;
8294}
8295
Kelvin Lida681182017-01-10 18:08:18 +00008296template <typename Derived>
8297StmtResult
8298TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8299 OMPTargetTeamsDistributeSimdDirective *D) {
8300 DeclarationNameInfo DirName;
8301 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008302 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008303 auto Res = getDerived().TransformOMPExecutableDirective(D);
8304 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8305 return Res;
8306}
8307
Kelvin Li1851df52017-01-03 05:23:48 +00008308
Alexander Musman64d33f12014-06-04 07:53:32 +00008309//===----------------------------------------------------------------------===//
8310// OpenMP clause transformation
8311//===----------------------------------------------------------------------===//
8312template <typename Derived>
8313OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008314 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8315 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008316 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008317 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008318 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008319 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008320}
8321
Alexander Musman64d33f12014-06-04 07:53:32 +00008322template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008323OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8324 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8325 if (Cond.isInvalid())
8326 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008327 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008328 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008329}
8330
8331template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008332OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008333TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8334 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8335 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008336 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008337 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008338 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008339}
8340
Alexey Bataev62c87d22014-03-21 04:51:18 +00008341template <typename Derived>
8342OMPClause *
8343TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8344 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8345 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008346 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008347 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008348 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008349}
8350
Alexander Musman8bd31e62014-05-27 15:12:19 +00008351template <typename Derived>
8352OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008353TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8354 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8355 if (E.isInvalid())
8356 return nullptr;
8357 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008358 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008359}
8360
8361template <typename Derived>
8362OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008363TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8364 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8365 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008366 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008367 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008368 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008369}
8370
Alexander Musman64d33f12014-06-04 07:53:32 +00008371template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008372OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008373TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008374 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008375 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008376 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008377}
8378
Alexander Musman64d33f12014-06-04 07:53:32 +00008379template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008380OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008381TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008382 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008383 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008384 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008385}
8386
Alexander Musman64d33f12014-06-04 07:53:32 +00008387template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008388OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008389TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8390 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8391 if (E.isInvalid())
8392 return nullptr;
8393 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008394 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008395 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008396 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008397 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008398}
8399
8400template <typename Derived>
8401OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008402TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008403 ExprResult E;
8404 if (auto *Num = C->getNumForLoops()) {
8405 E = getDerived().TransformExpr(Num);
8406 if (E.isInvalid())
8407 return nullptr;
8408 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008409 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008410 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008411}
8412
8413template <typename Derived>
8414OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008415TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8416 // No need to rebuild this clause, no template-dependent parameters.
8417 return C;
8418}
8419
8420template <typename Derived>
8421OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008422TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8423 // No need to rebuild this clause, no template-dependent parameters.
8424 return C;
8425}
8426
8427template <typename Derived>
8428OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008429TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8430 // No need to rebuild this clause, no template-dependent parameters.
8431 return C;
8432}
8433
8434template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008435OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8436 // No need to rebuild this clause, no template-dependent parameters.
8437 return C;
8438}
8439
8440template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008441OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8442 // No need to rebuild this clause, no template-dependent parameters.
8443 return C;
8444}
8445
8446template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008447OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008448TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8449 // No need to rebuild this clause, no template-dependent parameters.
8450 return C;
8451}
8452
8453template <typename Derived>
8454OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008455TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8456 // No need to rebuild this clause, no template-dependent parameters.
8457 return C;
8458}
8459
8460template <typename Derived>
8461OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008462TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8463 // No need to rebuild this clause, no template-dependent parameters.
8464 return C;
8465}
8466
8467template <typename Derived>
8468OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008469TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8470 // No need to rebuild this clause, no template-dependent parameters.
8471 return C;
8472}
8473
8474template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008475OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8476 // No need to rebuild this clause, no template-dependent parameters.
8477 return C;
8478}
8479
8480template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008481OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008482TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8483 // No need to rebuild this clause, no template-dependent parameters.
8484 return C;
8485}
8486
8487template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008488OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8489 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008490 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008491}
8492
8493template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008494OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8495 OMPUnifiedSharedMemoryClause *C) {
8496 llvm_unreachable(
8497 "unified_shared_memory clause cannot appear in dependent context");
8498}
8499
8500template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008501OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8502 OMPReverseOffloadClause *C) {
8503 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8504}
8505
8506template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008507OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8508 OMPDynamicAllocatorsClause *C) {
8509 llvm_unreachable(
8510 "dynamic_allocators clause cannot appear in dependent context");
8511}
8512
8513template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008514OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8515 OMPAtomicDefaultMemOrderClause *C) {
8516 llvm_unreachable(
8517 "atomic_default_mem_order clause cannot appear in dependent context");
8518}
8519
8520template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008521OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008522TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008523 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008524 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008525 for (auto *VE : C->varlists()) {
8526 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008527 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008528 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008529 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008530 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008531 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008532 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008533}
8534
Alexander Musman64d33f12014-06-04 07:53:32 +00008535template <typename Derived>
8536OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8537 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008538 llvm::SmallVector<Expr *, 16> Vars;
8539 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008540 for (auto *VE : C->varlists()) {
8541 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008542 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008543 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008544 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008545 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008546 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008547 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008548}
8549
Alexander Musman64d33f12014-06-04 07:53:32 +00008550template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008551OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008552TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8553 llvm::SmallVector<Expr *, 16> Vars;
8554 Vars.reserve(C->varlist_size());
8555 for (auto *VE : C->varlists()) {
8556 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8557 if (EVar.isInvalid())
8558 return nullptr;
8559 Vars.push_back(EVar.get());
8560 }
8561 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008562 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008563}
8564
8565template <typename Derived>
8566OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008567TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8568 llvm::SmallVector<Expr *, 16> Vars;
8569 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008570 for (auto *VE : C->varlists()) {
8571 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008572 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008573 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008574 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008575 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008576 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008577 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008578}
8579
Alexander Musman64d33f12014-06-04 07:53:32 +00008580template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008581OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008582TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8583 llvm::SmallVector<Expr *, 16> Vars;
8584 Vars.reserve(C->varlist_size());
8585 for (auto *VE : C->varlists()) {
8586 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8587 if (EVar.isInvalid())
8588 return nullptr;
8589 Vars.push_back(EVar.get());
8590 }
8591 CXXScopeSpec ReductionIdScopeSpec;
8592 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8593
8594 DeclarationNameInfo NameInfo = C->getNameInfo();
8595 if (NameInfo.getName()) {
8596 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8597 if (!NameInfo.getName())
8598 return nullptr;
8599 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008600 // Build a list of all UDR decls with the same names ranged by the Scopes.
8601 // The Scope boundary is a duplication of the previous decl.
8602 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8603 for (auto *E : C->reduction_ops()) {
8604 // Transform all the decls.
8605 if (E) {
8606 auto *ULE = cast<UnresolvedLookupExpr>(E);
8607 UnresolvedSet<8> Decls;
8608 for (auto *D : ULE->decls()) {
8609 NamedDecl *InstD =
8610 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8611 Decls.addDecl(InstD, InstD->getAccess());
8612 }
8613 UnresolvedReductions.push_back(
8614 UnresolvedLookupExpr::Create(
8615 SemaRef.Context, /*NamingClass=*/nullptr,
8616 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8617 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8618 Decls.begin(), Decls.end()));
8619 } else
8620 UnresolvedReductions.push_back(nullptr);
8621 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008622 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008623 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008624 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008625}
8626
8627template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008628OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8629 OMPTaskReductionClause *C) {
8630 llvm::SmallVector<Expr *, 16> Vars;
8631 Vars.reserve(C->varlist_size());
8632 for (auto *VE : C->varlists()) {
8633 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8634 if (EVar.isInvalid())
8635 return nullptr;
8636 Vars.push_back(EVar.get());
8637 }
8638 CXXScopeSpec ReductionIdScopeSpec;
8639 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8640
8641 DeclarationNameInfo NameInfo = C->getNameInfo();
8642 if (NameInfo.getName()) {
8643 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8644 if (!NameInfo.getName())
8645 return nullptr;
8646 }
8647 // Build a list of all UDR decls with the same names ranged by the Scopes.
8648 // The Scope boundary is a duplication of the previous decl.
8649 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8650 for (auto *E : C->reduction_ops()) {
8651 // Transform all the decls.
8652 if (E) {
8653 auto *ULE = cast<UnresolvedLookupExpr>(E);
8654 UnresolvedSet<8> Decls;
8655 for (auto *D : ULE->decls()) {
8656 NamedDecl *InstD =
8657 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8658 Decls.addDecl(InstD, InstD->getAccess());
8659 }
8660 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8661 SemaRef.Context, /*NamingClass=*/nullptr,
8662 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8663 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8664 } else
8665 UnresolvedReductions.push_back(nullptr);
8666 }
8667 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008668 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008669 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008670}
8671
8672template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008673OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008674TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8675 llvm::SmallVector<Expr *, 16> Vars;
8676 Vars.reserve(C->varlist_size());
8677 for (auto *VE : C->varlists()) {
8678 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8679 if (EVar.isInvalid())
8680 return nullptr;
8681 Vars.push_back(EVar.get());
8682 }
8683 CXXScopeSpec ReductionIdScopeSpec;
8684 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8685
8686 DeclarationNameInfo NameInfo = C->getNameInfo();
8687 if (NameInfo.getName()) {
8688 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8689 if (!NameInfo.getName())
8690 return nullptr;
8691 }
8692 // Build a list of all UDR decls with the same names ranged by the Scopes.
8693 // The Scope boundary is a duplication of the previous decl.
8694 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8695 for (auto *E : C->reduction_ops()) {
8696 // Transform all the decls.
8697 if (E) {
8698 auto *ULE = cast<UnresolvedLookupExpr>(E);
8699 UnresolvedSet<8> Decls;
8700 for (auto *D : ULE->decls()) {
8701 NamedDecl *InstD =
8702 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8703 Decls.addDecl(InstD, InstD->getAccess());
8704 }
8705 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8706 SemaRef.Context, /*NamingClass=*/nullptr,
8707 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8708 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8709 } else
8710 UnresolvedReductions.push_back(nullptr);
8711 }
8712 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008713 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008714 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008715}
8716
8717template <typename Derived>
8718OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008719TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8720 llvm::SmallVector<Expr *, 16> Vars;
8721 Vars.reserve(C->varlist_size());
8722 for (auto *VE : C->varlists()) {
8723 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8724 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008725 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008726 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008727 }
8728 ExprResult Step = getDerived().TransformExpr(C->getStep());
8729 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008730 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008731 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008732 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008733 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008734}
8735
Alexander Musman64d33f12014-06-04 07:53:32 +00008736template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008737OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008738TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8739 llvm::SmallVector<Expr *, 16> Vars;
8740 Vars.reserve(C->varlist_size());
8741 for (auto *VE : C->varlists()) {
8742 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8743 if (EVar.isInvalid())
8744 return nullptr;
8745 Vars.push_back(EVar.get());
8746 }
8747 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8748 if (Alignment.isInvalid())
8749 return nullptr;
8750 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008751 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008752 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008753}
8754
Alexander Musman64d33f12014-06-04 07:53:32 +00008755template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008756OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008757TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8758 llvm::SmallVector<Expr *, 16> Vars;
8759 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008760 for (auto *VE : C->varlists()) {
8761 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008762 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008763 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008764 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008765 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008766 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008767 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008768}
8769
Alexey Bataevbae9a792014-06-27 10:37:06 +00008770template <typename Derived>
8771OMPClause *
8772TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8773 llvm::SmallVector<Expr *, 16> Vars;
8774 Vars.reserve(C->varlist_size());
8775 for (auto *VE : C->varlists()) {
8776 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8777 if (EVar.isInvalid())
8778 return nullptr;
8779 Vars.push_back(EVar.get());
8780 }
8781 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008782 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008783}
8784
Alexey Bataev6125da92014-07-21 11:26:11 +00008785template <typename Derived>
8786OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8787 llvm::SmallVector<Expr *, 16> Vars;
8788 Vars.reserve(C->varlist_size());
8789 for (auto *VE : C->varlists()) {
8790 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8791 if (EVar.isInvalid())
8792 return nullptr;
8793 Vars.push_back(EVar.get());
8794 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008795 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008796 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008797}
8798
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008799template <typename Derived>
8800OMPClause *
8801TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8802 llvm::SmallVector<Expr *, 16> Vars;
8803 Vars.reserve(C->varlist_size());
8804 for (auto *VE : C->varlists()) {
8805 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8806 if (EVar.isInvalid())
8807 return nullptr;
8808 Vars.push_back(EVar.get());
8809 }
8810 return getDerived().RebuildOMPDependClause(
8811 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008812 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008813}
8814
Michael Wonge710d542015-08-07 16:16:36 +00008815template <typename Derived>
8816OMPClause *
8817TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8818 ExprResult E = getDerived().TransformExpr(C->getDevice());
8819 if (E.isInvalid())
8820 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008821 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008822 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008823}
8824
Kelvin Li0bff7af2015-11-23 05:32:03 +00008825template <typename Derived>
8826OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8827 llvm::SmallVector<Expr *, 16> Vars;
8828 Vars.reserve(C->varlist_size());
8829 for (auto *VE : C->varlists()) {
8830 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8831 if (EVar.isInvalid())
8832 return nullptr;
8833 Vars.push_back(EVar.get());
8834 }
8835 return getDerived().RebuildOMPMapClause(
Kelvin Lief579432018-12-18 22:18:41 +00008836 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), C->getMapType(),
8837 C->isImplicitMapType(), C->getMapLoc(), C->getColonLoc(), Vars,
8838 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008839}
8840
Kelvin Li099bb8c2015-11-24 20:50:12 +00008841template <typename Derived>
8842OMPClause *
8843TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8844 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8845 if (E.isInvalid())
8846 return nullptr;
8847 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008848 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00008849}
8850
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008851template <typename Derived>
8852OMPClause *
8853TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8854 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8855 if (E.isInvalid())
8856 return nullptr;
8857 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008858 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008859}
8860
Alexey Bataeva0569352015-12-01 10:17:31 +00008861template <typename Derived>
8862OMPClause *
8863TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8864 ExprResult E = getDerived().TransformExpr(C->getPriority());
8865 if (E.isInvalid())
8866 return nullptr;
8867 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008868 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00008869}
8870
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008871template <typename Derived>
8872OMPClause *
8873TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8874 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8875 if (E.isInvalid())
8876 return nullptr;
8877 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008878 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008879}
8880
Alexey Bataev382967a2015-12-08 12:06:20 +00008881template <typename Derived>
8882OMPClause *
8883TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8884 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8885 if (E.isInvalid())
8886 return nullptr;
8887 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008888 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00008889}
8890
Alexey Bataev28c75412015-12-15 08:19:24 +00008891template <typename Derived>
8892OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8893 ExprResult E = getDerived().TransformExpr(C->getHint());
8894 if (E.isInvalid())
8895 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008896 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008897 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00008898}
8899
Carlo Bertollib4adf552016-01-15 18:50:31 +00008900template <typename Derived>
8901OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8902 OMPDistScheduleClause *C) {
8903 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8904 if (E.isInvalid())
8905 return nullptr;
8906 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008907 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008908 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00008909}
8910
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008911template <typename Derived>
8912OMPClause *
8913TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8914 return C;
8915}
8916
Samuel Antao661c0902016-05-26 17:39:58 +00008917template <typename Derived>
8918OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8919 llvm::SmallVector<Expr *, 16> Vars;
8920 Vars.reserve(C->varlist_size());
8921 for (auto *VE : C->varlists()) {
8922 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8923 if (EVar.isInvalid())
8924 return 0;
8925 Vars.push_back(EVar.get());
8926 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008927 return getDerived().RebuildOMPToClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008928 C->getLParenLoc(), C->getEndLoc());
Samuel Antao661c0902016-05-26 17:39:58 +00008929}
8930
Samuel Antaoec172c62016-05-26 17:49:04 +00008931template <typename Derived>
8932OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8933 llvm::SmallVector<Expr *, 16> Vars;
8934 Vars.reserve(C->varlist_size());
8935 for (auto *VE : C->varlists()) {
8936 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8937 if (EVar.isInvalid())
8938 return 0;
8939 Vars.push_back(EVar.get());
8940 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008941 return getDerived().RebuildOMPFromClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008942 C->getLParenLoc(), C->getEndLoc());
Samuel Antaoec172c62016-05-26 17:49:04 +00008943}
8944
Carlo Bertolli2404b172016-07-13 15:37:16 +00008945template <typename Derived>
8946OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8947 OMPUseDevicePtrClause *C) {
8948 llvm::SmallVector<Expr *, 16> Vars;
8949 Vars.reserve(C->varlist_size());
8950 for (auto *VE : C->varlists()) {
8951 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8952 if (EVar.isInvalid())
8953 return nullptr;
8954 Vars.push_back(EVar.get());
8955 }
8956 return getDerived().RebuildOMPUseDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008957 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli2404b172016-07-13 15:37:16 +00008958}
8959
Carlo Bertolli70594e92016-07-13 17:16:49 +00008960template <typename Derived>
8961OMPClause *
8962TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8963 llvm::SmallVector<Expr *, 16> Vars;
8964 Vars.reserve(C->varlist_size());
8965 for (auto *VE : C->varlists()) {
8966 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8967 if (EVar.isInvalid())
8968 return nullptr;
8969 Vars.push_back(EVar.get());
8970 }
8971 return getDerived().RebuildOMPIsDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008972 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli70594e92016-07-13 17:16:49 +00008973}
8974
Douglas Gregorebe10102009-08-20 07:17:43 +00008975//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008976// Expression transformation
8977//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008979ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00008980TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
8981 return TransformExpr(E->getSubExpr());
8982}
8983
8984template<typename Derived>
8985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008986TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008987 if (!E->isTypeDependent())
8988 return E;
8989
8990 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00008991 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00008992}
Mike Stump11289f42009-09-09 15:08:12 +00008993
8994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008995ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008996TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008997 NestedNameSpecifierLoc QualifierLoc;
8998 if (E->getQualifierLoc()) {
8999 QualifierLoc
9000 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9001 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009002 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009003 }
John McCallce546572009-12-08 09:08:17 +00009004
9005 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009006 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
9007 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009008 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00009009 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009010
John McCall815039a2010-08-17 21:27:17 +00009011 DeclarationNameInfo NameInfo = E->getNameInfo();
9012 if (NameInfo.getName()) {
9013 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9014 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009015 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00009016 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009017
9018 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009019 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009020 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009021 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00009022 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009023
9024 // Mark it referenced in the new context regardless.
9025 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009026 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009027
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009028 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009029 }
John McCallce546572009-12-08 09:08:17 +00009030
Craig Topperc3ec1492014-05-26 06:22:03 +00009031 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009032 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009033 TemplateArgs = &TransArgs;
9034 TransArgs.setLAngleLoc(E->getLAngleLoc());
9035 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009036 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9037 E->getNumTemplateArgs(),
9038 TransArgs))
9039 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009040 }
9041
Chad Rosier1dcde962012-08-08 18:46:20 +00009042 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009043 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009044}
Mike Stump11289f42009-09-09 15:08:12 +00009045
Douglas Gregora16548e2009-08-11 05:31:07 +00009046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009048TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009049 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009050}
Mike Stump11289f42009-09-09 15:08:12 +00009051
Leonard Chandb01c3a2018-06-20 17:19:40 +00009052template <typename Derived>
9053ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9054 FixedPointLiteral *E) {
9055 return E;
9056}
9057
Douglas Gregora16548e2009-08-11 05:31:07 +00009058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009059ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009060TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009061 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009062}
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregora16548e2009-08-11 05:31:07 +00009064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009066TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009067 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009068}
Mike Stump11289f42009-09-09 15:08:12 +00009069
Douglas Gregora16548e2009-08-11 05:31:07 +00009070template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009071ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009072TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009073 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009074}
Mike Stump11289f42009-09-09 15:08:12 +00009075
Douglas Gregora16548e2009-08-11 05:31:07 +00009076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009077ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009078TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009079 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009080}
9081
9082template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009083ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009084TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009085 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009086 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009087 return SemaRef.MaybeBindToTemporary(E);
9088}
9089
9090template<typename Derived>
9091ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009092TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9093 ExprResult ControllingExpr =
9094 getDerived().TransformExpr(E->getControllingExpr());
9095 if (ControllingExpr.isInvalid())
9096 return ExprError();
9097
Chris Lattner01cf8db2011-07-20 06:58:45 +00009098 SmallVector<Expr *, 4> AssocExprs;
9099 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009100 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9101 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9102 if (TSI) {
9103 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009104 if (!AssocType)
9105 return ExprError();
9106 AssocTypes.push_back(AssocType);
9107 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009108 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009109 }
9110
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009111 ExprResult AssocExpr =
9112 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009113 if (AssocExpr.isInvalid())
9114 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009115 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009116 }
9117
9118 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9119 E->getDefaultLoc(),
9120 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009121 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009122 AssocTypes,
9123 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009124}
9125
9126template<typename Derived>
9127ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009128TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009129 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009130 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009132
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009134 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009135
John McCallb268a282010-08-23 23:25:46 +00009136 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009137 E->getRParen());
9138}
9139
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009140/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009141/// allowed to refer to a non-static member of a class even if there's no 'this'
9142/// object available.
9143template<typename Derived>
9144ExprResult
9145TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9146 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009147 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009148 else
9149 return getDerived().TransformExpr(E);
9150}
9151
Mike Stump11289f42009-09-09 15:08:12 +00009152template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009153ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009154TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009155 ExprResult SubExpr;
9156 if (E->getOpcode() == UO_AddrOf)
9157 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9158 else
9159 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009160 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009162
Douglas Gregora16548e2009-08-11 05:31:07 +00009163 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009164 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009165
Douglas Gregora16548e2009-08-11 05:31:07 +00009166 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9167 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009168 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009169}
Mike Stump11289f42009-09-09 15:08:12 +00009170
Douglas Gregora16548e2009-08-11 05:31:07 +00009171template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009172ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009173TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9174 // Transform the type.
9175 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9176 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009177 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009178
Douglas Gregor882211c2010-04-28 22:16:22 +00009179 // Transform all of the components into components similar to what the
9180 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009181 // FIXME: It would be slightly more efficient in the non-dependent case to
9182 // just map FieldDecls, rather than requiring the rebuilder to look for
9183 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009184 // template code that we don't care.
9185 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009186 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009187 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009188 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009189 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009190 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009191 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009192 Comp.LocStart = ON.getSourceRange().getBegin();
9193 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009194 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009195 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009196 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009197 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009198 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009199 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009200
Douglas Gregor882211c2010-04-28 22:16:22 +00009201 ExprChanged = ExprChanged || Index.get() != FromIndex;
9202 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009203 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009204 break;
9205 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009206
James Y Knight7281c352015-12-29 22:31:18 +00009207 case OffsetOfNode::Field:
9208 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009209 Comp.isBrackets = false;
9210 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009211 if (!Comp.U.IdentInfo)
9212 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009213
Douglas Gregor882211c2010-04-28 22:16:22 +00009214 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009215
James Y Knight7281c352015-12-29 22:31:18 +00009216 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009217 // Will be recomputed during the rebuild.
9218 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009219 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009220
Douglas Gregor882211c2010-04-28 22:16:22 +00009221 Components.push_back(Comp);
9222 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009223
Douglas Gregor882211c2010-04-28 22:16:22 +00009224 // If nothing changed, retain the existing expression.
9225 if (!getDerived().AlwaysRebuild() &&
9226 Type == E->getTypeSourceInfo() &&
9227 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009228 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009229
Douglas Gregor882211c2010-04-28 22:16:22 +00009230 // Build a new offsetof expression.
9231 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009232 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009233}
9234
9235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009236ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009237TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009238 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009239 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009240 return E;
John McCall8d69a212010-11-15 23:31:06 +00009241}
9242
9243template<typename Derived>
9244ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009245TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9246 return E;
9247}
9248
9249template<typename Derived>
9250ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009251TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009252 // Rebuild the syntactic form. The original syntactic form has
9253 // opaque-value expressions in it, so strip those away and rebuild
9254 // the result. This is a really awful way of doing this, but the
9255 // better solution (rebuilding the semantic expressions and
9256 // rebinding OVEs as necessary) doesn't work; we'd need
9257 // TreeTransform to not strip away implicit conversions.
9258 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9259 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009260 if (result.isInvalid()) return ExprError();
9261
9262 // If that gives us a pseudo-object result back, the pseudo-object
9263 // expression must have been an lvalue-to-rvalue conversion which we
9264 // should reapply.
9265 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009266 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009267
9268 return result;
9269}
9270
9271template<typename Derived>
9272ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009273TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9274 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009275 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009276 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009277
John McCallbcd03502009-12-07 02:54:59 +00009278 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009279 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009280 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009281
John McCall4c98fd82009-11-04 07:28:41 +00009282 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009283 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009284
Peter Collingbournee190dee2011-03-11 19:24:49 +00009285 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9286 E->getKind(),
9287 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009288 }
Mike Stump11289f42009-09-09 15:08:12 +00009289
Eli Friedmane4f22df2012-02-29 04:03:55 +00009290 // C++0x [expr.sizeof]p1:
9291 // The operand is either an expression, which is an unevaluated operand
9292 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009293 EnterExpressionEvaluationContext Unevaluated(
9294 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9295 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009296
Reid Kleckner32506ed2014-06-12 23:03:48 +00009297 // Try to recover if we have something like sizeof(T::X) where X is a type.
9298 // Notably, there must be *exactly* one set of parens if X is a type.
9299 TypeSourceInfo *RecoveryTSI = nullptr;
9300 ExprResult SubExpr;
9301 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9302 if (auto *DRE =
9303 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9304 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9305 PE, DRE, false, &RecoveryTSI);
9306 else
9307 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9308
9309 if (RecoveryTSI) {
9310 return getDerived().RebuildUnaryExprOrTypeTrait(
9311 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9312 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009313 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009314
Eli Friedmane4f22df2012-02-29 04:03:55 +00009315 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009316 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009317
Peter Collingbournee190dee2011-03-11 19:24:49 +00009318 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9319 E->getOperatorLoc(),
9320 E->getKind(),
9321 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009322}
Mike Stump11289f42009-09-09 15:08:12 +00009323
Douglas Gregora16548e2009-08-11 05:31:07 +00009324template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009325ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009326TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009327 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009328 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009329 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009330
John McCalldadc5752010-08-24 06:29:42 +00009331 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009332 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009334
9335
Douglas Gregora16548e2009-08-11 05:31:07 +00009336 if (!getDerived().AlwaysRebuild() &&
9337 LHS.get() == E->getLHS() &&
9338 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009339 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009340
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009341 return getDerived().RebuildArraySubscriptExpr(
9342 LHS.get(),
9343 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009344}
Mike Stump11289f42009-09-09 15:08:12 +00009345
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009346template <typename Derived>
9347ExprResult
9348TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9349 ExprResult Base = getDerived().TransformExpr(E->getBase());
9350 if (Base.isInvalid())
9351 return ExprError();
9352
9353 ExprResult LowerBound;
9354 if (E->getLowerBound()) {
9355 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9356 if (LowerBound.isInvalid())
9357 return ExprError();
9358 }
9359
9360 ExprResult Length;
9361 if (E->getLength()) {
9362 Length = getDerived().TransformExpr(E->getLength());
9363 if (Length.isInvalid())
9364 return ExprError();
9365 }
9366
9367 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9368 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9369 return E;
9370
9371 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009372 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009373 Length.get(), E->getRBracketLoc());
9374}
9375
Mike Stump11289f42009-09-09 15:08:12 +00009376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009378TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009379 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009380 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009381 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009382 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009383
9384 // Transform arguments.
9385 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009386 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009387 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009388 &ArgChanged))
9389 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009390
Douglas Gregora16548e2009-08-11 05:31:07 +00009391 if (!getDerived().AlwaysRebuild() &&
9392 Callee.get() == E->getCallee() &&
9393 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009394 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009395
Douglas Gregora16548e2009-08-11 05:31:07 +00009396 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009397 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009398 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009399 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009400 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009401 E->getRParenLoc());
9402}
Mike Stump11289f42009-09-09 15:08:12 +00009403
9404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009406TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009407 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009408 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009409 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009410
Douglas Gregorea972d32011-02-28 21:54:11 +00009411 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009412 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009413 QualifierLoc
9414 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009415
Douglas Gregorea972d32011-02-28 21:54:11 +00009416 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009417 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009418 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009419 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009420
Eli Friedman2cfcef62009-12-04 06:40:45 +00009421 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009422 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9423 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009424 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009426
John McCall16df1e52010-03-30 21:47:33 +00009427 NamedDecl *FoundDecl = E->getFoundDecl();
9428 if (FoundDecl == E->getMemberDecl()) {
9429 FoundDecl = Member;
9430 } else {
9431 FoundDecl = cast_or_null<NamedDecl>(
9432 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9433 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009434 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009435 }
9436
Douglas Gregora16548e2009-08-11 05:31:07 +00009437 if (!getDerived().AlwaysRebuild() &&
9438 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009439 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009440 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009441 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009442 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009443
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009444 // Mark it referenced in the new context regardless.
9445 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009446 SemaRef.MarkMemberReferenced(E);
9447
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009448 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009449 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009450
John McCall6b51f282009-11-23 01:53:49 +00009451 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009452 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009453 TransArgs.setLAngleLoc(E->getLAngleLoc());
9454 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009455 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9456 E->getNumTemplateArgs(),
9457 TransArgs))
9458 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009459 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009460
Douglas Gregora16548e2009-08-11 05:31:07 +00009461 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009462 SourceLocation FakeOperatorLoc =
9463 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009464
John McCall38836f02010-01-15 08:34:02 +00009465 // FIXME: to do this check properly, we will need to preserve the
9466 // first-qualifier-in-scope here, just in case we had a dependent
9467 // base (and therefore couldn't do the check) and a
9468 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009469 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009470 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9471 if (MemberNameInfo.getName()) {
9472 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9473 if (!MemberNameInfo.getName())
9474 return ExprError();
9475 }
John McCall38836f02010-01-15 08:34:02 +00009476
John McCallb268a282010-08-23 23:25:46 +00009477 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009478 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009479 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009480 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009481 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009482 Member,
John McCall16df1e52010-03-30 21:47:33 +00009483 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009484 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009485 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009486 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009487}
Mike Stump11289f42009-09-09 15:08:12 +00009488
Douglas Gregora16548e2009-08-11 05:31:07 +00009489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009491TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009492 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009493 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009494 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009495
John McCalldadc5752010-08-24 06:29:42 +00009496 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009497 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009498 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009499
Douglas Gregora16548e2009-08-11 05:31:07 +00009500 if (!getDerived().AlwaysRebuild() &&
9501 LHS.get() == E->getLHS() &&
9502 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009503 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009504
Lang Hames5de91cc2012-10-02 04:45:10 +00009505 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009506 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009507
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009509 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009510}
9511
Mike Stump11289f42009-09-09 15:08:12 +00009512template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009513ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009514TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009515 CompoundAssignOperator *E) {
9516 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009517}
Mike Stump11289f42009-09-09 15:08:12 +00009518
Douglas Gregora16548e2009-08-11 05:31:07 +00009519template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009520ExprResult TreeTransform<Derived>::
9521TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9522 // Just rebuild the common and RHS expressions and see whether we
9523 // get any changes.
9524
9525 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9526 if (commonExpr.isInvalid())
9527 return ExprError();
9528
9529 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9530 if (rhs.isInvalid())
9531 return ExprError();
9532
9533 if (!getDerived().AlwaysRebuild() &&
9534 commonExpr.get() == e->getCommon() &&
9535 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009536 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009537
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009538 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009539 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009540 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009541 e->getColonLoc(),
9542 rhs.get());
9543}
9544
9545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009546ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009547TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009548 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009549 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009551
John McCalldadc5752010-08-24 06:29:42 +00009552 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009553 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009555
John McCalldadc5752010-08-24 06:29:42 +00009556 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009557 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009559
Douglas Gregora16548e2009-08-11 05:31:07 +00009560 if (!getDerived().AlwaysRebuild() &&
9561 Cond.get() == E->getCond() &&
9562 LHS.get() == E->getLHS() &&
9563 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009564 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009565
John McCallb268a282010-08-23 23:25:46 +00009566 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009567 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009568 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009569 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009570 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009571}
Mike Stump11289f42009-09-09 15:08:12 +00009572
9573template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009574ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009575TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009576 // Implicit casts are eliminated during transformation, since they
9577 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009578 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009579}
Mike Stump11289f42009-09-09 15:08:12 +00009580
Douglas Gregora16548e2009-08-11 05:31:07 +00009581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009583TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009584 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9585 if (!Type)
9586 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009587
John McCalldadc5752010-08-24 06:29:42 +00009588 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009589 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009590 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009591 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009592
Douglas Gregora16548e2009-08-11 05:31:07 +00009593 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009594 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009595 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009596 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009597
John McCall97513962010-01-15 18:39:57 +00009598 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009599 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009600 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009601 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009602}
Mike Stump11289f42009-09-09 15:08:12 +00009603
Douglas Gregora16548e2009-08-11 05:31:07 +00009604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009605ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009606TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009607 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9608 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9609 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009610 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009611
John McCalldadc5752010-08-24 06:29:42 +00009612 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009613 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009614 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009615
Douglas Gregora16548e2009-08-11 05:31:07 +00009616 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009617 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009618 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009619 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009620
John McCall5d7aa7f2010-01-19 22:33:45 +00009621 // Note: the expression type doesn't necessarily match the
9622 // type-as-written, but that's okay, because it should always be
9623 // derivable from the initializer.
9624
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009625 return getDerived().RebuildCompoundLiteralExpr(
9626 E->getLParenLoc(), NewT,
9627 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009628}
Mike Stump11289f42009-09-09 15:08:12 +00009629
Douglas Gregora16548e2009-08-11 05:31:07 +00009630template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009631ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009632TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009633 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009634 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009635 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009636
Douglas Gregora16548e2009-08-11 05:31:07 +00009637 if (!getDerived().AlwaysRebuild() &&
9638 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009639 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009640
Douglas Gregora16548e2009-08-11 05:31:07 +00009641 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009642 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009643 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009644 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009645 E->getAccessorLoc(),
9646 E->getAccessor());
9647}
Mike Stump11289f42009-09-09 15:08:12 +00009648
Douglas Gregora16548e2009-08-11 05:31:07 +00009649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009651TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009652 if (InitListExpr *Syntactic = E->getSyntacticForm())
9653 E = Syntactic;
9654
Douglas Gregora16548e2009-08-11 05:31:07 +00009655 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009656
Richard Smith12938cf2018-09-26 04:36:55 +00009657 EnterExpressionEvaluationContext Context(
9658 getSema(), EnterExpressionEvaluationContext::InitList);
9659
Benjamin Kramerf0623432012-08-23 22:51:59 +00009660 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009661 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009662 Inits, &InitChanged))
9663 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009664
Richard Smith520449d2015-02-05 06:15:50 +00009665 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9666 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9667 // in some cases. We can't reuse it in general, because the syntactic and
9668 // semantic forms are linked, and we can't know that semantic form will
9669 // match even if the syntactic form does.
9670 }
Mike Stump11289f42009-09-09 15:08:12 +00009671
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009672 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009673 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009674}
Mike Stump11289f42009-09-09 15:08:12 +00009675
Douglas Gregora16548e2009-08-11 05:31:07 +00009676template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009677ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009678TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009679 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009680
Douglas Gregorebe10102009-08-20 07:17:43 +00009681 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009682 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009684 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009685
Douglas Gregorebe10102009-08-20 07:17:43 +00009686 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009687 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009688 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009689 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9690 if (D.isFieldDesignator()) {
9691 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9692 D.getDotLoc(),
9693 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009694 if (D.getField()) {
9695 FieldDecl *Field = cast_or_null<FieldDecl>(
9696 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9697 if (Field != D.getField())
9698 // Rebuild the expression when the transformed FieldDecl is
9699 // different to the already assigned FieldDecl.
9700 ExprChanged = true;
9701 } else {
9702 // Ensure that the designator expression is rebuilt when there isn't
9703 // a resolved FieldDecl in the designator as we don't want to assign
9704 // a FieldDecl to a pattern designator that will be instantiated again.
9705 ExprChanged = true;
9706 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009707 continue;
9708 }
Mike Stump11289f42009-09-09 15:08:12 +00009709
David Majnemerf7e36092016-06-23 00:15:04 +00009710 if (D.isArrayDesignator()) {
9711 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009713 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009714
David Majnemerf7e36092016-06-23 00:15:04 +00009715 Desig.AddDesignator(
9716 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009717
David Majnemerf7e36092016-06-23 00:15:04 +00009718 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009719 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009720 continue;
9721 }
Mike Stump11289f42009-09-09 15:08:12 +00009722
David Majnemerf7e36092016-06-23 00:15:04 +00009723 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009724 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009725 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009726 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009727 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009728
David Majnemerf7e36092016-06-23 00:15:04 +00009729 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009730 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009731 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009732
9733 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009734 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009735 D.getLBracketLoc(),
9736 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009737
David Majnemerf7e36092016-06-23 00:15:04 +00009738 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9739 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009740
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009741 ArrayExprs.push_back(Start.get());
9742 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009743 }
Mike Stump11289f42009-09-09 15:08:12 +00009744
Douglas Gregora16548e2009-08-11 05:31:07 +00009745 if (!getDerived().AlwaysRebuild() &&
9746 Init.get() == E->getInit() &&
9747 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009748 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009749
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009750 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009751 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009752 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009753}
Mike Stump11289f42009-09-09 15:08:12 +00009754
Yunzhong Gaocb779302015-06-10 00:27:52 +00009755// Seems that if TransformInitListExpr() only works on the syntactic form of an
9756// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9757template<typename Derived>
9758ExprResult
9759TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9760 DesignatedInitUpdateExpr *E) {
9761 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9762 "initializer");
9763 return ExprError();
9764}
9765
9766template<typename Derived>
9767ExprResult
9768TreeTransform<Derived>::TransformNoInitExpr(
9769 NoInitExpr *E) {
9770 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9771 return ExprError();
9772}
9773
Douglas Gregora16548e2009-08-11 05:31:07 +00009774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009775ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009776TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9777 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9778 return ExprError();
9779}
9780
9781template<typename Derived>
9782ExprResult
9783TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9784 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9785 return ExprError();
9786}
9787
9788template<typename Derived>
9789ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009790TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009791 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009792 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009793
Douglas Gregor3da3c062009-10-28 00:29:27 +00009794 // FIXME: Will we ever have proper type location here? Will we actually
9795 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009796 QualType T = getDerived().TransformType(E->getType());
9797 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009798 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009799
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 if (!getDerived().AlwaysRebuild() &&
9801 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009802 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009803
Douglas Gregora16548e2009-08-11 05:31:07 +00009804 return getDerived().RebuildImplicitValueInitExpr(T);
9805}
Mike Stump11289f42009-09-09 15:08:12 +00009806
Douglas Gregora16548e2009-08-11 05:31:07 +00009807template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009808ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009809TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009810 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9811 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009812 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009813
John McCalldadc5752010-08-24 06:29:42 +00009814 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009815 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009817
Douglas Gregora16548e2009-08-11 05:31:07 +00009818 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009819 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009820 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009822
John McCallb268a282010-08-23 23:25:46 +00009823 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009824 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009825}
9826
9827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009828ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009829TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009831 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009832 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9833 &ArgumentChanged))
9834 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009835
Douglas Gregora16548e2009-08-11 05:31:07 +00009836 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009837 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009838 E->getRParenLoc());
9839}
Mike Stump11289f42009-09-09 15:08:12 +00009840
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009841/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00009842///
9843/// By default, the transformation of an address-of-label expression always
9844/// rebuilds the expression, so that the label identifier can be resolved to
9845/// the corresponding label statement by semantic analysis.
9846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009847ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009848TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009849 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9850 E->getLabel());
9851 if (!LD)
9852 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009853
Douglas Gregora16548e2009-08-11 05:31:07 +00009854 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009855 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009856}
Mike Stump11289f42009-09-09 15:08:12 +00009857
9858template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009860TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009861 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009862 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009863 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009864 if (SubStmt.isInvalid()) {
9865 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009866 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009867 }
Mike Stump11289f42009-09-09 15:08:12 +00009868
Douglas Gregora16548e2009-08-11 05:31:07 +00009869 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009870 SubStmt.get() == E->getSubStmt()) {
9871 // Calling this an 'error' is unintuitive, but it does the right thing.
9872 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009873 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009874 }
Mike Stump11289f42009-09-09 15:08:12 +00009875
9876 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009877 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 E->getRParenLoc());
9879}
Mike Stump11289f42009-09-09 15:08:12 +00009880
Douglas Gregora16548e2009-08-11 05:31:07 +00009881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009883TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009884 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009885 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009886 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009887
John McCalldadc5752010-08-24 06:29:42 +00009888 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009889 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009890 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009891
John McCalldadc5752010-08-24 06:29:42 +00009892 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009893 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009895
Douglas Gregora16548e2009-08-11 05:31:07 +00009896 if (!getDerived().AlwaysRebuild() &&
9897 Cond.get() == E->getCond() &&
9898 LHS.get() == E->getLHS() &&
9899 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009900 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009901
Douglas Gregora16548e2009-08-11 05:31:07 +00009902 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009903 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009904 E->getRParenLoc());
9905}
Mike Stump11289f42009-09-09 15:08:12 +00009906
Douglas Gregora16548e2009-08-11 05:31:07 +00009907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009908ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009909TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009910 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009911}
9912
9913template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009914ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009915TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009916 switch (E->getOperator()) {
9917 case OO_New:
9918 case OO_Delete:
9919 case OO_Array_New:
9920 case OO_Array_Delete:
9921 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009922
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009923 case OO_Call: {
9924 // This is a call to an object's operator().
9925 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9926
9927 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009928 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009929 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009930 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009931
9932 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009933 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009934 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009935
9936 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009937 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009938 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009939 Args))
9940 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009941
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009942 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
9943 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009944 }
9945
9946#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9947 case OO_##Name:
9948#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9949#include "clang/Basic/OperatorKinds.def"
9950 case OO_Subscript:
9951 // Handled below.
9952 break;
9953
9954 case OO_Conditional:
9955 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009956
9957 case OO_None:
9958 case NUM_OVERLOADED_OPERATORS:
9959 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009960 }
9961
John McCalldadc5752010-08-24 06:29:42 +00009962 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009963 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009965
Richard Smithdb2630f2012-10-21 03:28:35 +00009966 ExprResult First;
9967 if (E->getOperator() == OO_Amp)
9968 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9969 else
9970 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009971 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009972 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009973
John McCalldadc5752010-08-24 06:29:42 +00009974 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009975 if (E->getNumArgs() == 2) {
9976 Second = getDerived().TransformExpr(E->getArg(1));
9977 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009978 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009979 }
Mike Stump11289f42009-09-09 15:08:12 +00009980
Douglas Gregora16548e2009-08-11 05:31:07 +00009981 if (!getDerived().AlwaysRebuild() &&
9982 Callee.get() == E->getCallee() &&
9983 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009984 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009985 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009986
Lang Hames5de91cc2012-10-02 04:45:10 +00009987 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009988 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009989
Douglas Gregora16548e2009-08-11 05:31:07 +00009990 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9991 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009992 Callee.get(),
9993 First.get(),
9994 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009995}
Mike Stump11289f42009-09-09 15:08:12 +00009996
Douglas Gregora16548e2009-08-11 05:31:07 +00009997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009999TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
10000 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010001}
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
Peter Collingbourne41f85462011-02-09 21:07:24 +000010005TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
10006 // Transform the callee.
10007 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
10008 if (Callee.isInvalid())
10009 return ExprError();
10010
10011 // Transform exec config.
10012 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
10013 if (EC.isInvalid())
10014 return ExprError();
10015
10016 // Transform arguments.
10017 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010018 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010019 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010020 &ArgChanged))
10021 return ExprError();
10022
10023 if (!getDerived().AlwaysRebuild() &&
10024 Callee.get() == E->getCallee() &&
10025 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010026 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010027
10028 // FIXME: Wrong source location information for the '('.
10029 SourceLocation FakeLParenLoc
10030 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10031 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010032 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010033 E->getRParenLoc(), EC.get());
10034}
10035
10036template<typename Derived>
10037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010038TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010039 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10040 if (!Type)
10041 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010042
John McCalldadc5752010-08-24 06:29:42 +000010043 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010044 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010045 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010046 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010047
Douglas Gregora16548e2009-08-11 05:31:07 +000010048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010049 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010050 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010051 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010052 return getDerived().RebuildCXXNamedCastExpr(
10053 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10054 Type, E->getAngleBrackets().getEnd(),
10055 // FIXME. this should be '(' location
10056 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010057}
Mike Stump11289f42009-09-09 15:08:12 +000010058
Douglas Gregora16548e2009-08-11 05:31:07 +000010059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010061TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10062 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010063}
Mike Stump11289f42009-09-09 15:08:12 +000010064
10065template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010066ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010067TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10068 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010069}
10070
Douglas Gregora16548e2009-08-11 05:31:07 +000010071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010072ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010073TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010074 CXXReinterpretCastExpr *E) {
10075 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010076}
Mike Stump11289f42009-09-09 15:08:12 +000010077
Douglas Gregora16548e2009-08-11 05:31:07 +000010078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010079ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010080TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10081 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010082}
Mike Stump11289f42009-09-09 15:08:12 +000010083
Douglas Gregora16548e2009-08-11 05:31:07 +000010084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010085ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010086TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010087 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010088 TypeSourceInfo *Type =
10089 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010090 if (!Type)
10091 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010092
John McCalldadc5752010-08-24 06:29:42 +000010093 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010094 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010095 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010096 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010097
Douglas Gregora16548e2009-08-11 05:31:07 +000010098 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010099 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010100 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010101 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010102
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010103 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010104 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010105 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010106 E->getRParenLoc(),
10107 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010108}
Mike Stump11289f42009-09-09 15:08:12 +000010109
Douglas Gregora16548e2009-08-11 05:31:07 +000010110template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010111ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010112TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010113 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010114 TypeSourceInfo *TInfo
10115 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10116 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010117 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010118
Douglas Gregora16548e2009-08-11 05:31:07 +000010119 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010120 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010121 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010122
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010123 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010124 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010125 }
Mike Stump11289f42009-09-09 15:08:12 +000010126
Eli Friedman456f0182012-01-20 01:26:23 +000010127 // We don't know whether the subexpression is potentially evaluated until
10128 // after we perform semantic analysis. We speculatively assume it is
10129 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010130 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010131 EnterExpressionEvaluationContext Unevaluated(
10132 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10133 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010134
John McCalldadc5752010-08-24 06:29:42 +000010135 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010136 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010138
Douglas Gregora16548e2009-08-11 05:31:07 +000010139 if (!getDerived().AlwaysRebuild() &&
10140 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010141 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010142
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010143 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010144 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010145}
10146
10147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010148ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010149TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10150 if (E->isTypeOperand()) {
10151 TypeSourceInfo *TInfo
10152 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10153 if (!TInfo)
10154 return ExprError();
10155
10156 if (!getDerived().AlwaysRebuild() &&
10157 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010158 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010159
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010160 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010161 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010162 }
10163
Faisal Valid143a0c2017-04-01 21:30:49 +000010164 EnterExpressionEvaluationContext Unevaluated(
10165 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010166
10167 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10168 if (SubExpr.isInvalid())
10169 return ExprError();
10170
10171 if (!getDerived().AlwaysRebuild() &&
10172 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010173 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010174
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010175 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010176 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010177}
10178
10179template<typename Derived>
10180ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010181TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010182 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010183}
Mike Stump11289f42009-09-09 15:08:12 +000010184
Douglas Gregora16548e2009-08-11 05:31:07 +000010185template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010186ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010187TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010188 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010189 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010190}
Mike Stump11289f42009-09-09 15:08:12 +000010191
Douglas Gregora16548e2009-08-11 05:31:07 +000010192template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010193ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010194TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010195 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010196
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010197 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10198 // Make sure that we capture 'this'.
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010199 getSema().CheckCXXThisCapture(E->getBeginLoc());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010200 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010201 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010202
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010203 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010204}
Mike Stump11289f42009-09-09 15:08:12 +000010205
Douglas Gregora16548e2009-08-11 05:31:07 +000010206template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010207ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010208TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010209 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010210 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010211 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010212
Douglas Gregora16548e2009-08-11 05:31:07 +000010213 if (!getDerived().AlwaysRebuild() &&
10214 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010215 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010216
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010217 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10218 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010219}
Mike Stump11289f42009-09-09 15:08:12 +000010220
Douglas Gregora16548e2009-08-11 05:31:07 +000010221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010223TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010224 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10225 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010226 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010228
Chandler Carruth794da4c2010-02-08 06:42:49 +000010229 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010230 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010231 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010232
Douglas Gregor033f6752009-12-23 23:03:06 +000010233 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010234}
Mike Stump11289f42009-09-09 15:08:12 +000010235
Douglas Gregora16548e2009-08-11 05:31:07 +000010236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010237ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010238TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010239 FieldDecl *Field = cast_or_null<FieldDecl>(
10240 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010241 if (!Field)
10242 return ExprError();
10243
10244 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010245 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010246
10247 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10248}
10249
10250template<typename Derived>
10251ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010252TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10253 CXXScalarValueInitExpr *E) {
10254 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10255 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010256 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010257
Douglas Gregora16548e2009-08-11 05:31:07 +000010258 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010259 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010260 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010261
Chad Rosier1dcde962012-08-08 18:46:20 +000010262 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010263 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010264 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010265}
Mike Stump11289f42009-09-09 15:08:12 +000010266
Douglas Gregora16548e2009-08-11 05:31:07 +000010267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010268ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010269TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010270 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010271 TypeSourceInfo *AllocTypeInfo =
10272 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010273 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010275
Douglas Gregora16548e2009-08-11 05:31:07 +000010276 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010277 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010278 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010280
Douglas Gregora16548e2009-08-11 05:31:07 +000010281 // Transform the placement arguments (if any).
10282 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010283 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010284 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010285 E->getNumPlacementArgs(), true,
10286 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010288
Sebastian Redl6047f072012-02-16 12:22:20 +000010289 // Transform the initializer (if any).
10290 Expr *OldInit = E->getInitializer();
10291 ExprResult NewInit;
10292 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010293 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010294 if (NewInit.isInvalid())
10295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010296
Sebastian Redl6047f072012-02-16 12:22:20 +000010297 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010298 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010299 if (E->getOperatorNew()) {
10300 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010301 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010302 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010303 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010304 }
10305
Craig Topperc3ec1492014-05-26 06:22:03 +000010306 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010307 if (E->getOperatorDelete()) {
10308 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010309 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010310 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010311 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010312 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010313
Douglas Gregora16548e2009-08-11 05:31:07 +000010314 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010315 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010316 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010317 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010318 OperatorNew == E->getOperatorNew() &&
10319 OperatorDelete == E->getOperatorDelete() &&
10320 !ArgumentChanged) {
10321 // Mark any declarations we need as referenced.
10322 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010323 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010324 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010325 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010326 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010327
Sebastian Redl6047f072012-02-16 12:22:20 +000010328 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010329 QualType ElementType
10330 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10331 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10332 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10333 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010334 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010335 }
10336 }
10337 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010338
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010339 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010340 }
Mike Stump11289f42009-09-09 15:08:12 +000010341
Douglas Gregor0744ef62010-09-07 21:49:58 +000010342 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010343 if (!ArraySize.get()) {
10344 // If no array size was specified, but the new expression was
10345 // instantiated with an array type (e.g., "new T" where T is
10346 // instantiated with "int[4]"), extract the outer bound from the
10347 // array type as our array size. We do this with constant and
10348 // dependently-sized array types.
10349 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10350 if (!ArrayT) {
10351 // Do nothing
10352 } else if (const ConstantArrayType *ConsArrayT
10353 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010354 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10355 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010356 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010357 AllocType = ConsArrayT->getElementType();
10358 } else if (const DependentSizedArrayType *DepArrayT
10359 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10360 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010361 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010362 AllocType = DepArrayT->getElementType();
10363 }
10364 }
10365 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010366
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010367 return getDerived().RebuildCXXNewExpr(
10368 E->getBeginLoc(), E->isGlobalNew(),
10369 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10370 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
10371 AllocTypeInfo, ArraySize.get(), E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010372}
Mike Stump11289f42009-09-09 15:08:12 +000010373
Douglas Gregora16548e2009-08-11 05:31:07 +000010374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010376TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010377 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010378 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010380
Douglas Gregord2d9da02010-02-26 00:38:10 +000010381 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010382 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010383 if (E->getOperatorDelete()) {
10384 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010385 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010386 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010387 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010388 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010389
Douglas Gregora16548e2009-08-11 05:31:07 +000010390 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010391 Operand.get() == E->getArgument() &&
10392 OperatorDelete == E->getOperatorDelete()) {
10393 // Mark any declarations we need as referenced.
10394 // FIXME: instantiation-specific.
10395 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010396 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010397
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010398 if (!E->getArgument()->isTypeDependent()) {
10399 QualType Destroyed = SemaRef.Context.getBaseElementType(
10400 E->getDestroyedType());
10401 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10402 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010403 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010404 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010405 }
10406 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010407
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010408 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010409 }
Mike Stump11289f42009-09-09 15:08:12 +000010410
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010411 return getDerived().RebuildCXXDeleteExpr(
10412 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010413}
Mike Stump11289f42009-09-09 15:08:12 +000010414
Douglas Gregora16548e2009-08-11 05:31:07 +000010415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010416ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010417TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010418 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010419 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010420 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010421 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010422
John McCallba7bf592010-08-24 05:47:05 +000010423 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010424 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010425 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010426 E->getOperatorLoc(),
10427 E->isArrow()? tok::arrow : tok::period,
10428 ObjectTypePtr,
10429 MayBePseudoDestructor);
10430 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010431 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010432
John McCallba7bf592010-08-24 05:47:05 +000010433 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010434 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10435 if (QualifierLoc) {
10436 QualifierLoc
10437 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10438 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010439 return ExprError();
10440 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010441 CXXScopeSpec SS;
10442 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010443
Douglas Gregor678f90d2010-02-25 01:56:36 +000010444 PseudoDestructorTypeStorage Destroyed;
10445 if (E->getDestroyedTypeInfo()) {
10446 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010447 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010448 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010449 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010450 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010451 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010452 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010453 // We aren't likely to be able to resolve the identifier down to a type
10454 // now anyway, so just retain the identifier.
10455 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10456 E->getDestroyedTypeLoc());
10457 } else {
10458 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010459 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010460 *E->getDestroyedTypeIdentifier(),
10461 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010462 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010463 SS, ObjectTypePtr,
10464 false);
10465 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010466 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010467
Douglas Gregor678f90d2010-02-25 01:56:36 +000010468 Destroyed
10469 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10470 E->getDestroyedTypeLoc());
10471 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010472
Craig Topperc3ec1492014-05-26 06:22:03 +000010473 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010474 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010475 CXXScopeSpec EmptySS;
10476 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010477 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010478 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010479 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010480 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010481
John McCallb268a282010-08-23 23:25:46 +000010482 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010483 E->getOperatorLoc(),
10484 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010485 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010486 ScopeTypeInfo,
10487 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010488 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010489 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010490}
Mike Stump11289f42009-09-09 15:08:12 +000010491
Richard Smith151c4562016-12-20 21:35:28 +000010492template <typename Derived>
10493bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10494 bool RequiresADL,
10495 LookupResult &R) {
10496 // Transform all the decls.
10497 bool AllEmptyPacks = true;
10498 for (auto *OldD : Old->decls()) {
10499 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10500 if (!InstD) {
10501 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10502 // This can happen because of dependent hiding.
10503 if (isa<UsingShadowDecl>(OldD))
10504 continue;
10505 else {
10506 R.clear();
10507 return true;
10508 }
10509 }
10510
10511 // Expand using pack declarations.
10512 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10513 ArrayRef<NamedDecl*> Decls = SingleDecl;
10514 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10515 Decls = UPD->expansions();
10516
10517 // Expand using declarations.
10518 for (auto *D : Decls) {
10519 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10520 for (auto *SD : UD->shadows())
10521 R.addDecl(SD);
10522 } else {
10523 R.addDecl(D);
10524 }
10525 }
10526
10527 AllEmptyPacks &= Decls.empty();
10528 };
10529
10530 // C++ [temp.res]/8.4.2:
10531 // The program is ill-formed, no diagnostic required, if [...] lookup for
10532 // a name in the template definition found a using-declaration, but the
10533 // lookup in the corresponding scope in the instantiation odoes not find
10534 // any declarations because the using-declaration was a pack expansion and
10535 // the corresponding pack is empty
10536 if (AllEmptyPacks && !RequiresADL) {
10537 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010538 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010539 return true;
10540 }
10541
10542 // Resolve a kind, but don't do any further analysis. If it's
10543 // ambiguous, the callee needs to deal with it.
10544 R.resolveKind();
10545 return false;
10546}
10547
Douglas Gregorad8a3362009-09-04 17:36:40 +000010548template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010549ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010550TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010551 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010552 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10553 Sema::LookupOrdinaryName);
10554
Richard Smith151c4562016-12-20 21:35:28 +000010555 // Transform the declaration set.
10556 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10557 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010558
10559 // Rebuild the nested-name qualifier, if present.
10560 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010561 if (Old->getQualifierLoc()) {
10562 NestedNameSpecifierLoc QualifierLoc
10563 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10564 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010565 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010566
Douglas Gregor0da1d432011-02-28 20:01:57 +000010567 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010568 }
10569
Douglas Gregor9262f472010-04-27 18:19:34 +000010570 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010571 CXXRecordDecl *NamingClass
10572 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10573 Old->getNameLoc(),
10574 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010575 if (!NamingClass) {
10576 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010577 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010578 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010579
Douglas Gregorda7be082010-04-27 16:10:10 +000010580 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010581 }
10582
Abramo Bagnara7945c982012-01-27 09:46:47 +000010583 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10584
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010585 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010586 // it's a normal declaration name or member reference.
10587 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10588 NamedDecl *D = R.getAsSingle<NamedDecl>();
10589 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10590 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10591 // give a good diagnostic.
10592 if (D && D->isCXXInstanceMember()) {
10593 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10594 /*TemplateArgs=*/nullptr,
10595 /*Scope=*/nullptr);
10596 }
10597
John McCalle66edc12009-11-24 19:00:30 +000010598 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010599 }
John McCalle66edc12009-11-24 19:00:30 +000010600
10601 // If we have template arguments, rebuild them, then rebuild the
10602 // templateid expression.
10603 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010604 if (Old->hasExplicitTemplateArgs() &&
10605 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010606 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010607 TransArgs)) {
10608 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010609 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010610 }
John McCalle66edc12009-11-24 19:00:30 +000010611
Abramo Bagnara7945c982012-01-27 09:46:47 +000010612 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010613 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010614}
Mike Stump11289f42009-09-09 15:08:12 +000010615
Douglas Gregora16548e2009-08-11 05:31:07 +000010616template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010617ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010618TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10619 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010620 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010621 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10622 TypeSourceInfo *From = E->getArg(I);
10623 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010624 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010625 TypeLocBuilder TLB;
10626 TLB.reserve(FromTL.getFullDataSize());
10627 QualType To = getDerived().TransformType(TLB, FromTL);
10628 if (To.isNull())
10629 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010630
Douglas Gregor29c42f22012-02-24 07:38:34 +000010631 if (To == From->getType())
10632 Args.push_back(From);
10633 else {
10634 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10635 ArgChanged = true;
10636 }
10637 continue;
10638 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010639
Douglas Gregor29c42f22012-02-24 07:38:34 +000010640 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010641
Douglas Gregor29c42f22012-02-24 07:38:34 +000010642 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010643 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010644 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10645 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10646 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010647
Douglas Gregor29c42f22012-02-24 07:38:34 +000010648 // Determine whether the set of unexpanded parameter packs can and should
10649 // be expanded.
10650 bool Expand = true;
10651 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010652 Optional<unsigned> OrigNumExpansions =
10653 ExpansionTL.getTypePtr()->getNumExpansions();
10654 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010655 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10656 PatternTL.getSourceRange(),
10657 Unexpanded,
10658 Expand, RetainExpansion,
10659 NumExpansions))
10660 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010661
Douglas Gregor29c42f22012-02-24 07:38:34 +000010662 if (!Expand) {
10663 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010664 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010665 // expansion.
10666 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010667
Douglas Gregor29c42f22012-02-24 07:38:34 +000010668 TypeLocBuilder TLB;
10669 TLB.reserve(From->getTypeLoc().getFullDataSize());
10670
10671 QualType To = getDerived().TransformType(TLB, PatternTL);
10672 if (To.isNull())
10673 return ExprError();
10674
Chad Rosier1dcde962012-08-08 18:46:20 +000010675 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010676 PatternTL.getSourceRange(),
10677 ExpansionTL.getEllipsisLoc(),
10678 NumExpansions);
10679 if (To.isNull())
10680 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010681
Douglas Gregor29c42f22012-02-24 07:38:34 +000010682 PackExpansionTypeLoc ToExpansionTL
10683 = TLB.push<PackExpansionTypeLoc>(To);
10684 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10685 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10686 continue;
10687 }
10688
10689 // Expand the pack expansion by substituting for each argument in the
10690 // pack(s).
10691 for (unsigned I = 0; I != *NumExpansions; ++I) {
10692 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10693 TypeLocBuilder TLB;
10694 TLB.reserve(PatternTL.getFullDataSize());
10695 QualType To = getDerived().TransformType(TLB, PatternTL);
10696 if (To.isNull())
10697 return ExprError();
10698
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010699 if (To->containsUnexpandedParameterPack()) {
10700 To = getDerived().RebuildPackExpansionType(To,
10701 PatternTL.getSourceRange(),
10702 ExpansionTL.getEllipsisLoc(),
10703 NumExpansions);
10704 if (To.isNull())
10705 return ExprError();
10706
10707 PackExpansionTypeLoc ToExpansionTL
10708 = TLB.push<PackExpansionTypeLoc>(To);
10709 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10710 }
10711
Douglas Gregor29c42f22012-02-24 07:38:34 +000010712 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10713 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010714
Douglas Gregor29c42f22012-02-24 07:38:34 +000010715 if (!RetainExpansion)
10716 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010717
Douglas Gregor29c42f22012-02-24 07:38:34 +000010718 // If we're supposed to retain a pack expansion, do so by temporarily
10719 // forgetting the partially-substituted parameter pack.
10720 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10721
10722 TypeLocBuilder TLB;
10723 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010724
Douglas Gregor29c42f22012-02-24 07:38:34 +000010725 QualType To = getDerived().TransformType(TLB, PatternTL);
10726 if (To.isNull())
10727 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010728
10729 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010730 PatternTL.getSourceRange(),
10731 ExpansionTL.getEllipsisLoc(),
10732 NumExpansions);
10733 if (To.isNull())
10734 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010735
Douglas Gregor29c42f22012-02-24 07:38:34 +000010736 PackExpansionTypeLoc ToExpansionTL
10737 = TLB.push<PackExpansionTypeLoc>(To);
10738 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10739 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10740 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010741
Douglas Gregor29c42f22012-02-24 07:38:34 +000010742 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010743 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010744
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010745 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010746 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010747}
10748
10749template<typename Derived>
10750ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010751TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10752 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10753 if (!T)
10754 return ExprError();
10755
10756 if (!getDerived().AlwaysRebuild() &&
10757 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010758 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010759
10760 ExprResult SubExpr;
10761 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010762 EnterExpressionEvaluationContext Unevaluated(
10763 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010764 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10765 if (SubExpr.isInvalid())
10766 return ExprError();
10767
10768 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010769 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010770 }
10771
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010772 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010773 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010774}
10775
10776template<typename Derived>
10777ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010778TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10779 ExprResult SubExpr;
10780 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010781 EnterExpressionEvaluationContext Unevaluated(
10782 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010783 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10784 if (SubExpr.isInvalid())
10785 return ExprError();
10786
10787 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010788 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010789 }
10790
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010791 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010792 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010793}
10794
Reid Kleckner32506ed2014-06-12 23:03:48 +000010795template <typename Derived>
10796ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10797 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10798 TypeSourceInfo **RecoveryTSI) {
10799 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10800 DRE, AddrTaken, RecoveryTSI);
10801
10802 // Propagate both errors and recovered types, which return ExprEmpty.
10803 if (!NewDRE.isUsable())
10804 return NewDRE;
10805
10806 // We got an expr, wrap it up in parens.
10807 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10808 return PE;
10809 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10810 PE->getRParen());
10811}
10812
10813template <typename Derived>
10814ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10815 DependentScopeDeclRefExpr *E) {
10816 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10817 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010818}
10819
10820template<typename Derived>
10821ExprResult
10822TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10823 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010824 bool IsAddressOfOperand,
10825 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010826 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010827 NestedNameSpecifierLoc QualifierLoc
10828 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10829 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010830 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010831 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010832
John McCall31f82722010-11-12 08:19:04 +000010833 // TODO: If this is a conversion-function-id, verify that the
10834 // destination type name (if present) resolves the same way after
10835 // instantiation as it did in the local scope.
10836
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010837 DeclarationNameInfo NameInfo
10838 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10839 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010841
John McCalle66edc12009-11-24 19:00:30 +000010842 if (!E->hasExplicitTemplateArgs()) {
10843 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010844 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010845 // Note: it is sufficient to compare the Name component of NameInfo:
10846 // if name has not changed, DNLoc has not changed either.
10847 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010848 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010849
Reid Kleckner32506ed2014-06-12 23:03:48 +000010850 return getDerived().RebuildDependentScopeDeclRefExpr(
10851 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10852 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010853 }
John McCall6b51f282009-11-23 01:53:49 +000010854
10855 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010856 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10857 E->getNumTemplateArgs(),
10858 TransArgs))
10859 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010860
Reid Kleckner32506ed2014-06-12 23:03:48 +000010861 return getDerived().RebuildDependentScopeDeclRefExpr(
10862 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10863 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010864}
10865
10866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010868TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010869 // CXXConstructExprs other than for list-initialization and
10870 // CXXTemporaryObjectExpr are always implicit, so when we have
10871 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010872 if ((E->getNumArgs() == 1 ||
10873 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010874 (!getDerived().DropCallArgument(E->getArg(0))) &&
10875 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010876 return getDerived().TransformExpr(E->getArg(0));
10877
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010878 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000010879
10880 QualType T = getDerived().TransformType(E->getType());
10881 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010882 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010883
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010884 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10885 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010886 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010887 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010888
Douglas Gregora16548e2009-08-11 05:31:07 +000010889 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010890 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000010891 {
10892 EnterExpressionEvaluationContext Context(
10893 getSema(), EnterExpressionEvaluationContext::InitList,
10894 E->isListInitialization());
10895 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10896 &ArgumentChanged))
10897 return ExprError();
10898 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010899
Douglas Gregora16548e2009-08-11 05:31:07 +000010900 if (!getDerived().AlwaysRebuild() &&
10901 T == E->getType() &&
10902 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010903 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010904 // Mark the constructor as referenced.
10905 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010906 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010907 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010908 }
Mike Stump11289f42009-09-09 15:08:12 +000010909
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010910 return getDerived().RebuildCXXConstructExpr(
10911 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
10912 E->hadMultipleCandidates(), E->isListInitialization(),
10913 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
10914 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010915}
Mike Stump11289f42009-09-09 15:08:12 +000010916
Richard Smith5179eb72016-06-28 19:03:57 +000010917template<typename Derived>
10918ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10919 CXXInheritedCtorInitExpr *E) {
10920 QualType T = getDerived().TransformType(E->getType());
10921 if (T.isNull())
10922 return ExprError();
10923
10924 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010925 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000010926 if (!Constructor)
10927 return ExprError();
10928
10929 if (!getDerived().AlwaysRebuild() &&
10930 T == E->getType() &&
10931 Constructor == E->getConstructor()) {
10932 // Mark the constructor as referenced.
10933 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010934 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000010935 return E;
10936 }
10937
10938 return getDerived().RebuildCXXInheritedCtorInitExpr(
10939 T, E->getLocation(), Constructor,
10940 E->constructsVBase(), E->inheritedFromVBase());
10941}
10942
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010943/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010944///
Douglas Gregor363b1512009-12-24 18:51:59 +000010945/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10946/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010947template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010948ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010949TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010950 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010951}
Mike Stump11289f42009-09-09 15:08:12 +000010952
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010953/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000010954/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010955///
John McCall5d413782010-12-06 08:20:24 +000010956/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010957/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010959ExprResult
John McCall5d413782010-12-06 08:20:24 +000010960TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010961 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010962}
Mike Stump11289f42009-09-09 15:08:12 +000010963
Douglas Gregora16548e2009-08-11 05:31:07 +000010964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010965ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010966TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010967 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010968 TypeSourceInfo *T =
10969 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010970 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010972
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010973 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10974 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010975 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010976 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010977
Douglas Gregora16548e2009-08-11 05:31:07 +000010978 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010979 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010980 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000010981 {
10982 EnterExpressionEvaluationContext Context(
10983 getSema(), EnterExpressionEvaluationContext::InitList,
10984 E->isListInitialization());
10985 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10986 &ArgumentChanged))
10987 return ExprError();
10988 }
Mike Stump11289f42009-09-09 15:08:12 +000010989
Douglas Gregora16548e2009-08-11 05:31:07 +000010990 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010991 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010992 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010993 !ArgumentChanged) {
10994 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010995 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010996 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010997 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010998
Vedant Kumara14a1f92018-01-17 18:53:51 +000010999 // FIXME: We should just pass E->isListInitialization(), but we're not
11000 // prepared to handle list-initialization without a child InitListExpr.
11001 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
11002 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011003 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000011004 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000011005}
Mike Stump11289f42009-09-09 15:08:12 +000011006
Douglas Gregora16548e2009-08-11 05:31:07 +000011007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011008ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000011009TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000011010 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011011 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000011012 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011013 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
11014 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000011015 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011016 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000011017 CEnd = E->capture_end();
11018 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000011019 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011020 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000011021 EnterExpressionEvaluationContext EEEC(
11022 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011023 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11024 C->getCapturedVar()->getInit(),
11025 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000011026
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011027 if (NewExprInitResult.isInvalid())
11028 return ExprError();
11029 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000011030
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011031 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000011032 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000011033 getSema().buildLambdaInitCaptureInitialization(
11034 C->getLocation(), OldVD->getType()->isReferenceType(),
11035 OldVD->getIdentifier(),
11036 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011037 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011038 InitCaptureExprsAndTypes[C - E->capture_begin()] =
11039 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011040 }
11041
Faisal Vali2cba1332013-10-23 06:44:28 +000011042 // Transform the template parameters, and add them to the current
11043 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011044 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011045 E->getTemplateParameterList());
11046
Richard Smith01014ce2014-11-20 23:53:14 +000011047 // Transform the type of the original lambda's call operator.
11048 // The transformation MUST be done in the CurrentInstantiationScope since
11049 // it introduces a mapping of the original to the newly created
11050 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011051 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011052 {
11053 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011054 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011055 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011056
11057 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011058 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011059 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011060 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011061 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011062 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11063 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11064 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011065 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011066 if (NewCallOpType.isNull())
11067 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011068 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11069 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011070 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011071
Richard Smithc38498f2015-04-27 21:27:54 +000011072 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11073 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11074 LSI->GLTemplateParameterList = TPL;
11075
Eli Friedmand564afb2012-09-19 01:18:11 +000011076 // Create the local class that will describe the lambda.
11077 CXXRecordDecl *Class
11078 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011079 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011080 /*KnownDependent=*/false,
11081 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000011082 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
11083
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011084 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011085 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11086 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011087 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011088 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
11089 E->getCallOperator()->isConstexpr());
11090
Faisal Vali2cba1332013-10-23 06:44:28 +000011091 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011092
Akira Hatanaka402818462016-12-16 21:16:57 +000011093 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11094 I != NumParams; ++I) {
11095 auto *P = NewCallOperator->getParamDecl(I);
11096 if (P->hasUninstantiatedDefaultArg()) {
11097 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011098 getSema(),
11099 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011100 ExprResult R = getDerived().TransformExpr(
11101 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11102 P->setDefaultArg(R.get());
11103 }
11104 }
11105
Faisal Vali2cba1332013-10-23 06:44:28 +000011106 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000011107 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000011108
Douglas Gregorb4328232012-02-14 00:00:48 +000011109 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011110 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011111 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011112
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011113 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011114 getSema().buildLambdaScope(LSI, NewCallOperator,
11115 E->getIntroducerRange(),
11116 E->getCaptureDefault(),
11117 E->getCaptureDefaultLoc(),
11118 E->hasExplicitParameters(),
11119 E->hasExplicitResultType(),
11120 E->isMutable());
11121
11122 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011123
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011124 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011125 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011126 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011127 CEnd = E->capture_end();
11128 C != CEnd; ++C) {
11129 // When we hit the first implicit capture, tell Sema that we've finished
11130 // the list of explicit captures.
11131 if (!FinishedExplicitCaptures && C->isImplicit()) {
11132 getSema().finishLambdaExplicitCaptures(LSI);
11133 FinishedExplicitCaptures = true;
11134 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011135
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011136 // Capturing 'this' is trivial.
11137 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011138 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11139 /*BuildAndDiagnose*/ true, nullptr,
11140 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011141 continue;
11142 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011143 // Captured expression will be recaptured during captured variables
11144 // rebuilding.
11145 if (C->capturesVLAType())
11146 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011147
Richard Smithba71c082013-05-16 06:20:58 +000011148 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011149 if (E->isInitCapture(C)) {
Fangrui Song6907ce22018-07-30 19:24:48 +000011150 InitCaptureInfoTy InitExprTypePair =
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011151 InitCaptureExprsAndTypes[C - E->capture_begin()];
11152 ExprResult Init = InitExprTypePair.first;
11153 QualType InitQualType = InitExprTypePair.second;
11154 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011155 Invalid = true;
11156 continue;
11157 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011158 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011159 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011160 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11161 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011162 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011163 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011164 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011165 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011166 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011167 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011168 continue;
11169 }
11170
11171 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11172
Douglas Gregor3e308b12012-02-14 19:27:52 +000011173 // Determine the capture kind for Sema.
11174 Sema::TryCaptureKind Kind
11175 = C->isImplicit()? Sema::TryCapture_Implicit
11176 : C->getCaptureKind() == LCK_ByCopy
11177 ? Sema::TryCapture_ExplicitByVal
11178 : Sema::TryCapture_ExplicitByRef;
11179 SourceLocation EllipsisLoc;
11180 if (C->isPackExpansion()) {
11181 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11182 bool ShouldExpand = false;
11183 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011184 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011185 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11186 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011187 Unexpanded,
11188 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011189 NumExpansions)) {
11190 Invalid = true;
11191 continue;
11192 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011193
Douglas Gregor3e308b12012-02-14 19:27:52 +000011194 if (ShouldExpand) {
11195 // The transform has determined that we should perform an expansion;
11196 // transform and capture each of the arguments.
11197 // expansion of the pattern. Do so.
11198 VarDecl *Pack = C->getCapturedVar();
11199 for (unsigned I = 0; I != *NumExpansions; ++I) {
11200 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11201 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011202 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011203 Pack));
11204 if (!CapturedVar) {
11205 Invalid = true;
11206 continue;
11207 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011208
Douglas Gregor3e308b12012-02-14 19:27:52 +000011209 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011210 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11211 }
Richard Smith9467be42014-06-06 17:33:35 +000011212
11213 // FIXME: Retain a pack expansion if RetainExpansion is true.
11214
Douglas Gregor3e308b12012-02-14 19:27:52 +000011215 continue;
11216 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011217
Douglas Gregor3e308b12012-02-14 19:27:52 +000011218 EllipsisLoc = C->getEllipsisLoc();
11219 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011220
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011221 // Transform the captured variable.
11222 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011223 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011224 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011225 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011226 Invalid = true;
11227 continue;
11228 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011229
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011230 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011231 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11232 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011233 }
11234 if (!FinishedExplicitCaptures)
11235 getSema().finishLambdaExplicitCaptures(LSI);
11236
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011237 // Enter a new evaluation context to insulate the lambda from any
11238 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011239 getSema().PushExpressionEvaluationContext(
11240 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011241
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011242 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011243 StmtResult Body =
11244 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11245
11246 // ActOnLambda* will pop the function scope for us.
11247 FuncScopeCleanup.disable();
11248
Douglas Gregorb4328232012-02-14 00:00:48 +000011249 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011250 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011251 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011252 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011253 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011254 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011255
Richard Smithc38498f2015-04-27 21:27:54 +000011256 // Copy the LSI before ActOnFinishFunctionBody removes it.
11257 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11258 // the call operator.
11259 auto LSICopy = *LSI;
11260 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11261 /*IsInstantiation*/ true);
11262 SavedContext.pop();
11263
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011264 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011265 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011266}
11267
11268template<typename Derived>
11269ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011270TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011271 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011272 TypeSourceInfo *T =
11273 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011274 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011275 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011276
Douglas Gregora16548e2009-08-11 05:31:07 +000011277 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011278 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011279 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011280 {
11281 EnterExpressionEvaluationContext Context(
11282 getSema(), EnterExpressionEvaluationContext::InitList,
11283 E->isListInitialization());
11284 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11285 &ArgumentChanged))
11286 return ExprError();
11287 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011288
Douglas Gregora16548e2009-08-11 05:31:07 +000011289 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011290 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011291 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011292 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011293
Douglas Gregora16548e2009-08-11 05:31:07 +000011294 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011295 return getDerived().RebuildCXXUnresolvedConstructExpr(
11296 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011297}
Mike Stump11289f42009-09-09 15:08:12 +000011298
Douglas Gregora16548e2009-08-11 05:31:07 +000011299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011300ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011301TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011302 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011303 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011304 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011305 Expr *OldBase;
11306 QualType BaseType;
11307 QualType ObjectType;
11308 if (!E->isImplicitAccess()) {
11309 OldBase = E->getBase();
11310 Base = getDerived().TransformExpr(OldBase);
11311 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011312 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011313
John McCall2d74de92009-12-01 22:10:20 +000011314 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011315 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011316 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011317 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011318 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011319 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011320 ObjectTy,
11321 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011322 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011323 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011324
John McCallba7bf592010-08-24 05:47:05 +000011325 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011326 BaseType = ((Expr*) Base.get())->getType();
11327 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011328 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011329 BaseType = getDerived().TransformType(E->getBaseType());
11330 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11331 }
Mike Stump11289f42009-09-09 15:08:12 +000011332
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011333 // Transform the first part of the nested-name-specifier that qualifies
11334 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011335 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011336 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011337 E->getFirstQualifierFoundInScope(),
11338 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011339
Douglas Gregore16af532011-02-28 18:50:33 +000011340 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011341 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011342 QualifierLoc
11343 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11344 ObjectType,
11345 FirstQualifierInScope);
11346 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011347 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011348 }
Mike Stump11289f42009-09-09 15:08:12 +000011349
Abramo Bagnara7945c982012-01-27 09:46:47 +000011350 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11351
John McCall31f82722010-11-12 08:19:04 +000011352 // TODO: If this is a conversion-function-id, verify that the
11353 // destination type name (if present) resolves the same way after
11354 // instantiation as it did in the local scope.
11355
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011356 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011357 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011358 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011359 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011360
John McCall2d74de92009-12-01 22:10:20 +000011361 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011362 // This is a reference to a member without an explicitly-specified
11363 // template argument list. Optimize for this common case.
11364 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011365 Base.get() == OldBase &&
11366 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011367 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011368 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011369 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011370 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011371
John McCallb268a282010-08-23 23:25:46 +000011372 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011373 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011374 E->isArrow(),
11375 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011376 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011377 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011378 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011379 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011380 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011381 }
11382
John McCall6b51f282009-11-23 01:53:49 +000011383 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011384 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11385 E->getNumTemplateArgs(),
11386 TransArgs))
11387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011388
John McCallb268a282010-08-23 23:25:46 +000011389 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011390 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011391 E->isArrow(),
11392 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011393 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011394 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011395 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011396 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011397 &TransArgs);
11398}
11399
11400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011402TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011403 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011404 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011405 QualType BaseType;
11406 if (!Old->isImplicitAccess()) {
11407 Base = getDerived().TransformExpr(Old->getBase());
11408 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011409 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011410 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011411 Old->isArrow());
11412 if (Base.isInvalid())
11413 return ExprError();
11414 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011415 } else {
11416 BaseType = getDerived().TransformType(Old->getBaseType());
11417 }
John McCall10eae182009-11-30 22:42:35 +000011418
Douglas Gregor0da1d432011-02-28 20:01:57 +000011419 NestedNameSpecifierLoc QualifierLoc;
11420 if (Old->getQualifierLoc()) {
11421 QualifierLoc
11422 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11423 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011424 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011425 }
11426
Abramo Bagnara7945c982012-01-27 09:46:47 +000011427 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11428
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011429 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011430 Sema::LookupOrdinaryName);
11431
Richard Smith151c4562016-12-20 21:35:28 +000011432 // Transform the declaration set.
11433 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11434 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011435
Douglas Gregor9262f472010-04-27 18:19:34 +000011436 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011437 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011438 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011439 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011440 Old->getMemberLoc(),
11441 Old->getNamingClass()));
11442 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011443 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011444
Douglas Gregorda7be082010-04-27 16:10:10 +000011445 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011446 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011447
John McCall10eae182009-11-30 22:42:35 +000011448 TemplateArgumentListInfo TransArgs;
11449 if (Old->hasExplicitTemplateArgs()) {
11450 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11451 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011452 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11453 Old->getNumTemplateArgs(),
11454 TransArgs))
11455 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011456 }
John McCall38836f02010-01-15 08:34:02 +000011457
11458 // FIXME: to do this check properly, we will need to preserve the
11459 // first-qualifier-in-scope here, just in case we had a dependent
11460 // base (and therefore couldn't do the check) and a
11461 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011462 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011463
John McCallb268a282010-08-23 23:25:46 +000011464 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011465 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011466 Old->getOperatorLoc(),
11467 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011468 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011469 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011470 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011471 R,
11472 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011473 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011474}
11475
11476template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011477ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011478TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011479 EnterExpressionEvaluationContext Unevaluated(
11480 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011481 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11482 if (SubExpr.isInvalid())
11483 return ExprError();
11484
11485 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011486 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011487
11488 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11489}
11490
11491template<typename Derived>
11492ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011493TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011494 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11495 if (Pattern.isInvalid())
11496 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011497
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011498 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011499 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011500
Douglas Gregorb8840002011-01-14 21:20:45 +000011501 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11502 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011503}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011504
11505template<typename Derived>
11506ExprResult
11507TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11508 // If E is not value-dependent, then nothing will change when we transform it.
11509 // Note: This is an instantiation-centric view.
11510 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011511 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011512
Faisal Valid143a0c2017-04-01 21:30:49 +000011513 EnterExpressionEvaluationContext Unevaluated(
11514 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011515
Richard Smithd784e682015-09-23 21:41:42 +000011516 ArrayRef<TemplateArgument> PackArgs;
11517 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011518
Richard Smithd784e682015-09-23 21:41:42 +000011519 // Find the argument list to transform.
11520 if (E->isPartiallySubstituted()) {
11521 PackArgs = E->getPartialArguments();
11522 } else if (E->isValueDependent()) {
11523 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11524 bool ShouldExpand = false;
11525 bool RetainExpansion = false;
11526 Optional<unsigned> NumExpansions;
11527 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11528 Unexpanded,
11529 ShouldExpand, RetainExpansion,
11530 NumExpansions))
11531 return ExprError();
11532
11533 // If we need to expand the pack, build a template argument from it and
11534 // expand that.
11535 if (ShouldExpand) {
11536 auto *Pack = E->getPack();
11537 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11538 ArgStorage = getSema().Context.getPackExpansionType(
11539 getSema().Context.getTypeDeclType(TTPD), None);
11540 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11541 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11542 } else {
11543 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011544 ExprResult DRE = getSema().BuildDeclRefExpr(
11545 VD, VD->getType().getNonLValueExprType(getSema().Context),
11546 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11547 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011548 if (DRE.isInvalid())
11549 return ExprError();
11550 ArgStorage = new (getSema().Context) PackExpansionExpr(
11551 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11552 }
11553 PackArgs = ArgStorage;
11554 }
11555 }
11556
11557 // If we're not expanding the pack, just transform the decl.
11558 if (!PackArgs.size()) {
11559 auto *Pack = cast_or_null<NamedDecl>(
11560 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011561 if (!Pack)
11562 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011563 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11564 E->getPackLoc(),
11565 E->getRParenLoc(), None, None);
11566 }
11567
Richard Smithc5452ed2016-10-19 22:18:42 +000011568 // Try to compute the result without performing a partial substitution.
11569 Optional<unsigned> Result = 0;
11570 for (const TemplateArgument &Arg : PackArgs) {
11571 if (!Arg.isPackExpansion()) {
11572 Result = *Result + 1;
11573 continue;
11574 }
11575
11576 TemplateArgumentLoc ArgLoc;
11577 InventTemplateArgumentLoc(Arg, ArgLoc);
11578
11579 // Find the pattern of the pack expansion.
11580 SourceLocation Ellipsis;
11581 Optional<unsigned> OrigNumExpansions;
11582 TemplateArgumentLoc Pattern =
11583 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11584 OrigNumExpansions);
11585
11586 // Substitute under the pack expansion. Do not expand the pack (yet).
11587 TemplateArgumentLoc OutPattern;
11588 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11589 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11590 /*Uneval*/ true))
11591 return true;
11592
11593 // See if we can determine the number of arguments from the result.
11594 Optional<unsigned> NumExpansions =
11595 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11596 if (!NumExpansions) {
11597 // No: we must be in an alias template expansion, and we're going to need
11598 // to actually expand the packs.
11599 Result = None;
11600 break;
11601 }
11602
11603 Result = *Result + *NumExpansions;
11604 }
11605
11606 // Common case: we could determine the number of expansions without
11607 // substituting.
11608 if (Result)
11609 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11610 E->getPackLoc(),
11611 E->getRParenLoc(), *Result, None);
11612
Richard Smithd784e682015-09-23 21:41:42 +000011613 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11614 E->getPackLoc());
11615 {
11616 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11617 typedef TemplateArgumentLocInventIterator<
11618 Derived, const TemplateArgument*> PackLocIterator;
11619 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11620 PackLocIterator(*this, PackArgs.end()),
11621 TransformedPackArgs, /*Uneval*/true))
11622 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011623 }
11624
Richard Smithc5452ed2016-10-19 22:18:42 +000011625 // Check whether we managed to fully-expand the pack.
11626 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011627 SmallVector<TemplateArgument, 8> Args;
11628 bool PartialSubstitution = false;
11629 for (auto &Loc : TransformedPackArgs.arguments()) {
11630 Args.push_back(Loc.getArgument());
11631 if (Loc.getArgument().isPackExpansion())
11632 PartialSubstitution = true;
11633 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011634
Richard Smithd784e682015-09-23 21:41:42 +000011635 if (PartialSubstitution)
11636 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11637 E->getPackLoc(),
11638 E->getRParenLoc(), None, Args);
11639
11640 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011641 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011642 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011643}
11644
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011645template<typename Derived>
11646ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011647TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11648 SubstNonTypeTemplateParmPackExpr *E) {
11649 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011650 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011651}
11652
11653template<typename Derived>
11654ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011655TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11656 SubstNonTypeTemplateParmExpr *E) {
11657 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011658 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011659}
11660
11661template<typename Derived>
11662ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011663TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11664 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011665 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011666}
11667
11668template<typename Derived>
11669ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011670TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11671 MaterializeTemporaryExpr *E) {
11672 return getDerived().TransformExpr(E->GetTemporaryExpr());
11673}
Chad Rosier1dcde962012-08-08 18:46:20 +000011674
Douglas Gregorfe314812011-06-21 17:03:29 +000011675template<typename Derived>
11676ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011677TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11678 Expr *Pattern = E->getPattern();
11679
11680 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11681 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11682 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11683
11684 // Determine whether the set of unexpanded parameter packs can and should
11685 // be expanded.
11686 bool Expand = true;
11687 bool RetainExpansion = false;
11688 Optional<unsigned> NumExpansions;
11689 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11690 Pattern->getSourceRange(),
11691 Unexpanded,
11692 Expand, RetainExpansion,
11693 NumExpansions))
11694 return true;
11695
11696 if (!Expand) {
11697 // Do not expand any packs here, just transform and rebuild a fold
11698 // expression.
11699 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11700
11701 ExprResult LHS =
11702 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11703 if (LHS.isInvalid())
11704 return true;
11705
11706 ExprResult RHS =
11707 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11708 if (RHS.isInvalid())
11709 return true;
11710
11711 if (!getDerived().AlwaysRebuild() &&
11712 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11713 return E;
11714
11715 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011716 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011717 RHS.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011718 }
11719
11720 // The transform has determined that we should perform an elementwise
11721 // expansion of the pattern. Do so.
11722 ExprResult Result = getDerived().TransformExpr(E->getInit());
11723 if (Result.isInvalid())
11724 return true;
11725 bool LeftFold = E->isLeftFold();
11726
11727 // If we're retaining an expansion for a right fold, it is the innermost
11728 // component and takes the init (if any).
11729 if (!LeftFold && RetainExpansion) {
11730 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11731
11732 ExprResult Out = getDerived().TransformExpr(Pattern);
11733 if (Out.isInvalid())
11734 return true;
11735
11736 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011737 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011738 Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011739 if (Result.isInvalid())
11740 return true;
11741 }
11742
11743 for (unsigned I = 0; I != *NumExpansions; ++I) {
11744 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11745 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11746 ExprResult Out = getDerived().TransformExpr(Pattern);
11747 if (Out.isInvalid())
11748 return true;
11749
11750 if (Out.get()->containsUnexpandedParameterPack()) {
11751 // We still have a pack; retain a pack expansion for this slice.
11752 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011753 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000011754 E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011755 LeftFold ? Out.get() : Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011756 } else if (Result.isUsable()) {
11757 // We've got down to a single element; build a binary operator.
11758 Result = getDerived().RebuildBinaryOperator(
11759 E->getEllipsisLoc(), E->getOperator(),
11760 LeftFold ? Result.get() : Out.get(),
11761 LeftFold ? Out.get() : Result.get());
11762 } else
11763 Result = Out;
11764
11765 if (Result.isInvalid())
11766 return true;
11767 }
11768
11769 // If we're retaining an expansion for a left fold, it is the outermost
11770 // component and takes the complete expansion so far as its init (if any).
11771 if (LeftFold && RetainExpansion) {
11772 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11773
11774 ExprResult Out = getDerived().TransformExpr(Pattern);
11775 if (Out.isInvalid())
11776 return true;
11777
11778 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011779 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011780 Out.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011781 if (Result.isInvalid())
11782 return true;
11783 }
11784
11785 // If we had no init and an empty pack, and we're not retaining an expansion,
11786 // then produce a fallback value or error.
11787 if (Result.isUnset())
11788 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11789 E->getOperator());
11790
11791 return Result;
11792}
11793
11794template<typename Derived>
11795ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011796TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11797 CXXStdInitializerListExpr *E) {
11798 return getDerived().TransformExpr(E->getSubExpr());
11799}
11800
11801template<typename Derived>
11802ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011803TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011804 return SemaRef.MaybeBindToTemporary(E);
11805}
11806
11807template<typename Derived>
11808ExprResult
11809TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011810 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011811}
11812
11813template<typename Derived>
11814ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011815TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11816 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11817 if (SubExpr.isInvalid())
11818 return ExprError();
11819
11820 if (!getDerived().AlwaysRebuild() &&
11821 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011822 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011823
11824 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011825}
11826
11827template<typename Derived>
11828ExprResult
11829TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11830 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011831 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011832 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011833 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011834 /*IsCall=*/false, Elements, &ArgChanged))
11835 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011836
Ted Kremeneke65b0862012-03-06 20:05:56 +000011837 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11838 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011839
Ted Kremeneke65b0862012-03-06 20:05:56 +000011840 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11841 Elements.data(),
11842 Elements.size());
11843}
11844
11845template<typename Derived>
11846ExprResult
11847TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011848 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011849 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011850 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011851 bool ArgChanged = false;
11852 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11853 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011854
Ted Kremeneke65b0862012-03-06 20:05:56 +000011855 if (OrigElement.isPackExpansion()) {
11856 // This key/value element is a pack expansion.
11857 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11858 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11859 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11860 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11861
11862 // Determine whether the set of unexpanded parameter packs can
11863 // and should be expanded.
11864 bool Expand = true;
11865 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011866 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11867 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011868 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011869 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011870 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11871 PatternRange, Unexpanded, Expand,
11872 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000011873 return ExprError();
11874
11875 if (!Expand) {
11876 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011877 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011878 // expansion.
11879 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11880 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11881 if (Key.isInvalid())
11882 return ExprError();
11883
11884 if (Key.get() != OrigElement.Key)
11885 ArgChanged = true;
11886
11887 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11888 if (Value.isInvalid())
11889 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011890
Ted Kremeneke65b0862012-03-06 20:05:56 +000011891 if (Value.get() != OrigElement.Value)
11892 ArgChanged = true;
11893
Chad Rosier1dcde962012-08-08 18:46:20 +000011894 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011895 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11896 };
11897 Elements.push_back(Expansion);
11898 continue;
11899 }
11900
11901 // Record right away that the argument was changed. This needs
11902 // to happen even if the array expands to nothing.
11903 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011904
Ted Kremeneke65b0862012-03-06 20:05:56 +000011905 // The transform has determined that we should perform an elementwise
11906 // expansion of the pattern. Do so.
11907 for (unsigned I = 0; I != *NumExpansions; ++I) {
11908 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11909 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11910 if (Key.isInvalid())
11911 return ExprError();
11912
11913 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11914 if (Value.isInvalid())
11915 return ExprError();
11916
Chad Rosier1dcde962012-08-08 18:46:20 +000011917 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011918 Key.get(), Value.get(), SourceLocation(), NumExpansions
11919 };
11920
11921 // If any unexpanded parameter packs remain, we still have a
11922 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011923 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011924 if (Key.get()->containsUnexpandedParameterPack() ||
11925 Value.get()->containsUnexpandedParameterPack())
11926 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011927
Ted Kremeneke65b0862012-03-06 20:05:56 +000011928 Elements.push_back(Element);
11929 }
11930
Richard Smith9467be42014-06-06 17:33:35 +000011931 // FIXME: Retain a pack expansion if RetainExpansion is true.
11932
Ted Kremeneke65b0862012-03-06 20:05:56 +000011933 // We've finished with this pack expansion.
11934 continue;
11935 }
11936
11937 // Transform and check key.
11938 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11939 if (Key.isInvalid())
11940 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011941
Ted Kremeneke65b0862012-03-06 20:05:56 +000011942 if (Key.get() != OrigElement.Key)
11943 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011944
Ted Kremeneke65b0862012-03-06 20:05:56 +000011945 // Transform and check value.
11946 ExprResult Value
11947 = getDerived().TransformExpr(OrigElement.Value);
11948 if (Value.isInvalid())
11949 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011950
Ted Kremeneke65b0862012-03-06 20:05:56 +000011951 if (Value.get() != OrigElement.Value)
11952 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011953
11954 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011955 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011956 };
11957 Elements.push_back(Element);
11958 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011959
Ted Kremeneke65b0862012-03-06 20:05:56 +000011960 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11961 return SemaRef.MaybeBindToTemporary(E);
11962
11963 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011964 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011965}
11966
Mike Stump11289f42009-09-09 15:08:12 +000011967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011968ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011969TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011970 TypeSourceInfo *EncodedTypeInfo
11971 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11972 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011973 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011974
Douglas Gregora16548e2009-08-11 05:31:07 +000011975 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011976 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011977 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011978
11979 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011980 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011981 E->getRParenLoc());
11982}
Mike Stump11289f42009-09-09 15:08:12 +000011983
Douglas Gregora16548e2009-08-11 05:31:07 +000011984template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011985ExprResult TreeTransform<Derived>::
11986TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011987 // This is a kind of implicit conversion, and it needs to get dropped
11988 // and recomputed for the same general reasons that ImplicitCastExprs
11989 // do, as well a more specific one: this expression is only valid when
11990 // it appears *immediately* as an argument expression.
11991 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011992}
11993
11994template<typename Derived>
11995ExprResult TreeTransform<Derived>::
11996TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011997 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011998 = getDerived().TransformType(E->getTypeInfoAsWritten());
11999 if (!TSInfo)
12000 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012001
John McCall31168b02011-06-15 23:02:42 +000012002 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000012003 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000012004 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012005
John McCall31168b02011-06-15 23:02:42 +000012006 if (!getDerived().AlwaysRebuild() &&
12007 TSInfo == E->getTypeInfoAsWritten() &&
12008 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012009 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012010
John McCall31168b02011-06-15 23:02:42 +000012011 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000012012 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000012013 Result.get());
12014}
12015
Erik Pilkington29099de2016-07-16 00:35:23 +000012016template <typename Derived>
12017ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
12018 ObjCAvailabilityCheckExpr *E) {
12019 return E;
12020}
12021
John McCall31168b02011-06-15 23:02:42 +000012022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012024TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012025 // Transform arguments.
12026 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012027 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012028 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012029 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012030 &ArgChanged))
12031 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012032
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012033 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12034 // Class message: transform the receiver type.
12035 TypeSourceInfo *ReceiverTypeInfo
12036 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12037 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012039
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012040 // If nothing changed, just retain the existing message send.
12041 if (!getDerived().AlwaysRebuild() &&
12042 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012043 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012044
12045 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012046 SmallVector<SourceLocation, 16> SelLocs;
12047 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012048 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12049 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012050 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012051 E->getMethodDecl(),
12052 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012053 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012054 E->getRightLoc());
12055 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012056 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12057 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012058 if (!E->getMethodDecl())
12059 return ExprError();
12060
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012061 // Build a new class message send to 'super'.
12062 SmallVector<SourceLocation, 16> SelLocs;
12063 E->getSelectorLocs(SelLocs);
12064 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12065 E->getSelector(),
12066 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012067 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012068 E->getMethodDecl(),
12069 E->getLeftLoc(),
12070 Args,
12071 E->getRightLoc());
12072 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012073
12074 // Instance message: transform the receiver
12075 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12076 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012077 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012078 = getDerived().TransformExpr(E->getInstanceReceiver());
12079 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012080 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012081
12082 // If nothing changed, just retain the existing message send.
12083 if (!getDerived().AlwaysRebuild() &&
12084 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012085 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012086
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012087 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012088 SmallVector<SourceLocation, 16> SelLocs;
12089 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012090 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012091 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012092 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012093 E->getMethodDecl(),
12094 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012095 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012096 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012097}
12098
Mike Stump11289f42009-09-09 15:08:12 +000012099template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012101TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012102 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012103}
12104
Mike Stump11289f42009-09-09 15:08:12 +000012105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012107TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012108 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012109}
12110
Mike Stump11289f42009-09-09 15:08:12 +000012111template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012112ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012113TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012114 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012115 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012116 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012117 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012118
12119 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012120
Douglas Gregord51d90d2010-04-26 20:11:03 +000012121 // If nothing changed, just retain the existing expression.
12122 if (!getDerived().AlwaysRebuild() &&
12123 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012124 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012125
John McCallb268a282010-08-23 23:25:46 +000012126 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012127 E->getLocation(),
12128 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012129}
12130
Mike Stump11289f42009-09-09 15:08:12 +000012131template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012132ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012133TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012134 // 'super' and types never change. Property never changes. Just
12135 // retain the existing expression.
12136 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012137 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012138
Douglas Gregor9faee212010-04-26 20:47:02 +000012139 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012140 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012141 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012142 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012143
Douglas Gregor9faee212010-04-26 20:47:02 +000012144 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012145
Douglas Gregor9faee212010-04-26 20:47:02 +000012146 // If nothing changed, just retain the existing expression.
12147 if (!getDerived().AlwaysRebuild() &&
12148 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012149 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012150
John McCallb7bd14f2010-12-02 01:19:52 +000012151 if (E->isExplicitProperty())
12152 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12153 E->getExplicitProperty(),
12154 E->getLocation());
12155
12156 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012157 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012158 E->getImplicitPropertyGetter(),
12159 E->getImplicitPropertySetter(),
12160 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012161}
12162
Mike Stump11289f42009-09-09 15:08:12 +000012163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012164ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012165TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12166 // Transform the base expression.
12167 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12168 if (Base.isInvalid())
12169 return ExprError();
12170
12171 // Transform the key expression.
12172 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12173 if (Key.isInvalid())
12174 return ExprError();
12175
12176 // If nothing changed, just retain the existing expression.
12177 if (!getDerived().AlwaysRebuild() &&
12178 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012179 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012180
Chad Rosier1dcde962012-08-08 18:46:20 +000012181 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012182 Base.get(), Key.get(),
12183 E->getAtIndexMethodDecl(),
12184 E->setAtIndexMethodDecl());
12185}
12186
12187template<typename Derived>
12188ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012189TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012190 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012191 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012192 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012194
Douglas Gregord51d90d2010-04-26 20:11:03 +000012195 // If nothing changed, just retain the existing expression.
12196 if (!getDerived().AlwaysRebuild() &&
12197 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012198 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012199
John McCallb268a282010-08-23 23:25:46 +000012200 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012201 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012202 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012203}
12204
Mike Stump11289f42009-09-09 15:08:12 +000012205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012206ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012207TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012208 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012209 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012210 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012211 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012212 SubExprs, &ArgumentChanged))
12213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012214
Douglas Gregora16548e2009-08-11 05:31:07 +000012215 if (!getDerived().AlwaysRebuild() &&
12216 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012217 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012218
Douglas Gregora16548e2009-08-11 05:31:07 +000012219 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012220 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012221 E->getRParenLoc());
12222}
12223
Mike Stump11289f42009-09-09 15:08:12 +000012224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012225ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012226TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12227 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12228 if (SrcExpr.isInvalid())
12229 return ExprError();
12230
12231 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12232 if (!Type)
12233 return ExprError();
12234
12235 if (!getDerived().AlwaysRebuild() &&
12236 Type == E->getTypeSourceInfo() &&
12237 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012238 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012239
12240 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12241 SrcExpr.get(), Type,
12242 E->getRParenLoc());
12243}
12244
12245template<typename Derived>
12246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012247TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012248 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012249
Craig Topperc3ec1492014-05-26 06:22:03 +000012250 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012251 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12252
12253 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012254 blockScope->TheDecl->setBlockMissingReturnType(
12255 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012256
Chris Lattner01cf8db2011-07-20 06:58:45 +000012257 SmallVector<ParmVarDecl*, 4> params;
12258 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012259
John McCallc8e321d2016-03-01 02:09:25 +000012260 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12261
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012262 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012263 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012264 if (getDerived().TransformFunctionTypeParams(
12265 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12266 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12267 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012268 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012269 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012270 }
John McCall490112f2011-02-04 18:33:18 +000012271
Eli Friedman34b49062012-01-26 03:00:14 +000012272 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012273 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012274
John McCallc8e321d2016-03-01 02:09:25 +000012275 auto epi = exprFunctionType->getExtProtoInfo();
12276 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12277
Jordan Rose5c382722013-03-08 21:51:21 +000012278 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012279 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012280 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012281
12282 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012283 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012284 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012285
12286 if (!oldBlock->blockMissingReturnType()) {
12287 blockScope->HasImplicitReturnType = false;
12288 blockScope->ReturnType = exprResultType;
12289 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012290
John McCall3882ace2011-01-05 12:14:39 +000012291 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012292 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012293 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012294 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012295 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012296 }
John McCall3882ace2011-01-05 12:14:39 +000012297
John McCall490112f2011-02-04 18:33:18 +000012298#ifndef NDEBUG
12299 // In builds with assertions, make sure that we captured everything we
12300 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012301 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012302 for (const auto &I : oldBlock->captures()) {
12303 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012304
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012305 // Ignore parameter packs.
12306 if (isa<ParmVarDecl>(oldCapture) &&
12307 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12308 continue;
John McCall490112f2011-02-04 18:33:18 +000012309
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012310 VarDecl *newCapture =
12311 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12312 oldCapture));
12313 assert(blockScope->CaptureMap.count(newCapture));
12314 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012315 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012316 }
12317#endif
12318
12319 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012320 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012321}
12322
Mike Stump11289f42009-09-09 15:08:12 +000012323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012324ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012325TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012326 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012327}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012328
12329template<typename Derived>
12330ExprResult
12331TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012332 QualType RetTy = getDerived().TransformType(E->getType());
12333 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012334 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012335 SubExprs.reserve(E->getNumSubExprs());
12336 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12337 SubExprs, &ArgumentChanged))
12338 return ExprError();
12339
12340 if (!getDerived().AlwaysRebuild() &&
12341 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012342 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012343
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012344 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012345 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012346}
Chad Rosier1dcde962012-08-08 18:46:20 +000012347
Douglas Gregora16548e2009-08-11 05:31:07 +000012348//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012349// Type reconstruction
12350//===----------------------------------------------------------------------===//
12351
Mike Stump11289f42009-09-09 15:08:12 +000012352template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012353QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12354 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012355 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012356 getDerived().getBaseEntity());
12357}
12358
Mike Stump11289f42009-09-09 15:08:12 +000012359template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012360QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12361 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012362 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012363 getDerived().getBaseEntity());
12364}
12365
Mike Stump11289f42009-09-09 15:08:12 +000012366template<typename Derived>
12367QualType
John McCall70dd5f62009-10-30 00:06:24 +000012368TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12369 bool WrittenAsLValue,
12370 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012371 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012372 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012373}
12374
12375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012376QualType
John McCall70dd5f62009-10-30 00:06:24 +000012377TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12378 QualType ClassType,
12379 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012380 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12381 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012382}
12383
12384template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012385QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12386 const ObjCTypeParamDecl *Decl,
12387 SourceLocation ProtocolLAngleLoc,
12388 ArrayRef<ObjCProtocolDecl *> Protocols,
12389 ArrayRef<SourceLocation> ProtocolLocs,
12390 SourceLocation ProtocolRAngleLoc) {
12391 return SemaRef.BuildObjCTypeParamType(Decl,
12392 ProtocolLAngleLoc, Protocols,
12393 ProtocolLocs, ProtocolRAngleLoc,
12394 /*FailOnError=*/true);
12395}
12396
12397template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012398QualType TreeTransform<Derived>::RebuildObjCObjectType(
12399 QualType BaseType,
12400 SourceLocation Loc,
12401 SourceLocation TypeArgsLAngleLoc,
12402 ArrayRef<TypeSourceInfo *> TypeArgs,
12403 SourceLocation TypeArgsRAngleLoc,
12404 SourceLocation ProtocolLAngleLoc,
12405 ArrayRef<ObjCProtocolDecl *> Protocols,
12406 ArrayRef<SourceLocation> ProtocolLocs,
12407 SourceLocation ProtocolRAngleLoc) {
12408 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12409 TypeArgs, TypeArgsRAngleLoc,
12410 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12411 ProtocolRAngleLoc,
12412 /*FailOnError=*/true);
12413}
12414
12415template<typename Derived>
12416QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12417 QualType PointeeType,
12418 SourceLocation Star) {
12419 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12420}
12421
12422template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012423QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012424TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12425 ArrayType::ArraySizeModifier SizeMod,
12426 const llvm::APInt *Size,
12427 Expr *SizeExpr,
12428 unsigned IndexTypeQuals,
12429 SourceRange BracketsRange) {
12430 if (SizeExpr || !Size)
12431 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12432 IndexTypeQuals, BracketsRange,
12433 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012434
12435 QualType Types[] = {
12436 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12437 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12438 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012439 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012440 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012441 QualType SizeType;
12442 for (unsigned I = 0; I != NumTypes; ++I)
12443 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12444 SizeType = Types[I];
12445 break;
12446 }
Mike Stump11289f42009-09-09 15:08:12 +000012447
Eli Friedman9562f392012-01-25 23:20:27 +000012448 // Note that we can return a VariableArrayType here in the case where
12449 // the element type was a dependent VariableArrayType.
12450 IntegerLiteral *ArraySize
12451 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12452 /*FIXME*/BracketsRange.getBegin());
12453 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012454 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012455 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012456}
Mike Stump11289f42009-09-09 15:08:12 +000012457
Douglas Gregord6ff3322009-08-04 16:50:30 +000012458template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012459QualType
12460TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012461 ArrayType::ArraySizeModifier SizeMod,
12462 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012463 unsigned IndexTypeQuals,
12464 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012465 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012466 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012467}
12468
12469template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012470QualType
Mike Stump11289f42009-09-09 15:08:12 +000012471TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012472 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012473 unsigned IndexTypeQuals,
12474 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012475 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012476 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012477}
Mike Stump11289f42009-09-09 15:08:12 +000012478
Douglas Gregord6ff3322009-08-04 16:50:30 +000012479template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012480QualType
12481TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012482 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012483 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012484 unsigned IndexTypeQuals,
12485 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012486 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012487 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012488 IndexTypeQuals, BracketsRange);
12489}
12490
12491template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012492QualType
12493TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012494 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012495 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012496 unsigned IndexTypeQuals,
12497 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012498 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012499 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012500 IndexTypeQuals, BracketsRange);
12501}
12502
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012503template <typename Derived>
12504QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12505 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12506 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12507 AttributeLoc);
12508}
12509
12510template <typename Derived>
12511QualType
12512TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12513 unsigned NumElements,
12514 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012515 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012516 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012517}
Mike Stump11289f42009-09-09 15:08:12 +000012518
Erich Keanef702b022018-07-13 19:46:04 +000012519template <typename Derived>
12520QualType TreeTransform<Derived>::RebuildDependentVectorType(
12521 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12522 VectorType::VectorKind VecKind) {
12523 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12524}
12525
Douglas Gregord6ff3322009-08-04 16:50:30 +000012526template<typename Derived>
12527QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12528 unsigned NumElements,
12529 SourceLocation AttributeLoc) {
12530 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12531 NumElements, true);
12532 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012533 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12534 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012535 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012536}
Mike Stump11289f42009-09-09 15:08:12 +000012537
Douglas Gregord6ff3322009-08-04 16:50:30 +000012538template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012539QualType
12540TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012541 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012542 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012543 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012544}
Mike Stump11289f42009-09-09 15:08:12 +000012545
Douglas Gregord6ff3322009-08-04 16:50:30 +000012546template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012547QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12548 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012549 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012550 const FunctionProtoType::ExtProtoInfo &EPI) {
12551 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012552 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012553 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012554 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012555}
Mike Stump11289f42009-09-09 15:08:12 +000012556
Douglas Gregord6ff3322009-08-04 16:50:30 +000012557template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012558QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12559 return SemaRef.Context.getFunctionNoProtoType(T);
12560}
12561
12562template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012563QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12564 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012565 assert(D && "no decl found");
12566 if (D->isInvalidDecl()) return QualType();
12567
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012568 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012569 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012570 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12571 // A valid resolved using typename pack expansion decl can have multiple
12572 // UsingDecls, but they must each have exactly one type, and it must be
12573 // the same type in every case. But we must have at least one expansion!
12574 if (UPD->expansions().empty()) {
12575 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12576 << UPD->isCXXClassMember() << UPD;
12577 return QualType();
12578 }
12579
12580 // We might still have some unresolved types. Try to pick a resolved type
12581 // if we can. The final instantiation will check that the remaining
12582 // unresolved types instantiate to the type we pick.
12583 QualType FallbackT;
12584 QualType T;
12585 for (auto *E : UPD->expansions()) {
12586 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12587 if (ThisT.isNull())
12588 continue;
12589 else if (ThisT->getAs<UnresolvedUsingType>())
12590 FallbackT = ThisT;
12591 else if (T.isNull())
12592 T = ThisT;
12593 else
12594 assert(getSema().Context.hasSameType(ThisT, T) &&
12595 "mismatched resolved types in using pack expansion");
12596 }
12597 return T.isNull() ? FallbackT : T;
12598 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012599 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012600 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12601
12602 // A valid resolved using typename decl points to exactly one type decl.
12603 assert(++Using->shadow_begin() == Using->shadow_end());
12604 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012605 } else {
12606 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12607 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12608 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12609 }
12610
12611 return SemaRef.Context.getTypeDeclType(Ty);
12612}
12613
12614template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012615QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12616 SourceLocation Loc) {
12617 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012618}
12619
12620template<typename Derived>
12621QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12622 return SemaRef.Context.getTypeOfType(Underlying);
12623}
12624
12625template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012626QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12627 SourceLocation Loc) {
12628 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012629}
12630
12631template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012632QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12633 UnaryTransformType::UTTKind UKind,
12634 SourceLocation Loc) {
12635 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12636}
12637
12638template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012639QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012640 TemplateName Template,
12641 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012642 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012643 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012644}
Mike Stump11289f42009-09-09 15:08:12 +000012645
Douglas Gregor1135c352009-08-06 05:28:30 +000012646template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012647QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12648 SourceLocation KWLoc) {
12649 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12650}
12651
12652template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012653QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012654 SourceLocation KWLoc,
12655 bool isReadPipe) {
12656 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12657 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012658}
12659
12660template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012661TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012662TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012663 bool TemplateKW,
12664 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012665 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012666 Template);
12667}
12668
12669template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012670TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012671TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012672 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012673 const IdentifierInfo &Name,
12674 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012675 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012676 NamedDecl *FirstQualifierInScope,
12677 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012678 UnqualifiedId TemplateName;
12679 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012680 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012681 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012682 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012683 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012684 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012685 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012686 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012687}
Mike Stump11289f42009-09-09 15:08:12 +000012688
Douglas Gregora16548e2009-08-11 05:31:07 +000012689template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012690TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012691TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012692 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012693 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012694 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012695 QualType ObjectType,
12696 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012697 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012698 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012699 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012700 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012701 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012702 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012703 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012704 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012705 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012706 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012707 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012708}
Chad Rosier1dcde962012-08-08 18:46:20 +000012709
Douglas Gregor71395fa2009-11-04 00:56:37 +000012710template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012711ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012712TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12713 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012714 Expr *OrigCallee,
12715 Expr *First,
12716 Expr *Second) {
12717 Expr *Callee = OrigCallee->IgnoreParenCasts();
12718 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012719
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012720 if (First->getObjectKind() == OK_ObjCProperty) {
12721 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12722 if (BinaryOperator::isAssignmentOp(Opc))
12723 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12724 First, Second);
12725 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12726 if (Result.isInvalid())
12727 return ExprError();
12728 First = Result.get();
12729 }
12730
12731 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12732 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12733 if (Result.isInvalid())
12734 return ExprError();
12735 Second = Result.get();
12736 }
12737
Douglas Gregora16548e2009-08-11 05:31:07 +000012738 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012739 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012740 if (!First->getType()->isOverloadableType() &&
12741 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012742 return getSema().CreateBuiltinArraySubscriptExpr(
12743 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012744 } else if (Op == OO_Arrow) {
12745 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012746 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12747 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000012748 if (!First->getType()->isOverloadableType() ||
12749 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
12750 // The argument is not of overloadable type, or this is an expression
12751 // of the form &Class::member, so try to create a built-in unary
12752 // operation.
John McCalle3027922010-08-25 11:45:40 +000012753 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012754 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012755
John McCallb268a282010-08-23 23:25:46 +000012756 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012757 }
12758 } else {
John McCallb268a282010-08-23 23:25:46 +000012759 if (!First->getType()->isOverloadableType() &&
12760 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012761 // Neither of the arguments is an overloadable type, so try to
12762 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012763 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012764 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012765 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012766 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012767 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012768
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012769 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012770 }
12771 }
Mike Stump11289f42009-09-09 15:08:12 +000012772
12773 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012774 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012775 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012776 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012777
John McCallb268a282010-08-23 23:25:46 +000012778 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012779 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012780 // If the overload could not be resolved in the template definition
12781 // (because we had a dependent argument), ADL is performed as part of
12782 // template instantiation.
12783 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012784 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012785 // If we've resolved this to a particular non-member function, just call
12786 // that function. If we resolved it to a member function,
12787 // CreateOverloaded* will find that function for us.
12788 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12789 if (!isa<CXXMethodDecl>(ND))
12790 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012791 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012792 }
Mike Stump11289f42009-09-09 15:08:12 +000012793
Douglas Gregora16548e2009-08-11 05:31:07 +000012794 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012795 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012796 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012797
Douglas Gregora16548e2009-08-11 05:31:07 +000012798 // Create the overloaded operator invocation for unary operators.
12799 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012800 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012801 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012802 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12803 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012804 }
Mike Stump11289f42009-09-09 15:08:12 +000012805
Douglas Gregore9d62932011-07-15 16:25:15 +000012806 if (Op == OO_Subscript) {
12807 SourceLocation LBrace;
12808 SourceLocation RBrace;
12809
12810 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012811 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012812 LBrace = SourceLocation::getFromRawEncoding(
12813 NameLoc.CXXOperatorName.BeginOpNameLoc);
12814 RBrace = SourceLocation::getFromRawEncoding(
12815 NameLoc.CXXOperatorName.EndOpNameLoc);
12816 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012817 LBrace = Callee->getBeginLoc();
12818 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000012819 }
12820
12821 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12822 First, Second);
12823 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012824
Douglas Gregora16548e2009-08-11 05:31:07 +000012825 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012826 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012827 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12828 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012829 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012831
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012832 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012833}
Mike Stump11289f42009-09-09 15:08:12 +000012834
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012835template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012836ExprResult
John McCallb268a282010-08-23 23:25:46 +000012837TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012838 SourceLocation OperatorLoc,
12839 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012840 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012841 TypeSourceInfo *ScopeType,
12842 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012843 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012844 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012845 QualType BaseType = Base->getType();
12846 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012847 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012848 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012849 !BaseType->getAs<PointerType>()->getPointeeType()
12850 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012851 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012852 return SemaRef.BuildPseudoDestructorExpr(
12853 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12854 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012855 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012856
Douglas Gregor678f90d2010-02-25 01:56:36 +000012857 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012858 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12859 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12860 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12861 NameInfo.setNamedTypeInfo(DestroyedType);
12862
Richard Smith8e4a3862012-05-15 06:15:11 +000012863 // The scope type is now known to be a valid nested name specifier
12864 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012865 if (ScopeType) {
12866 if (!ScopeType->getType()->getAs<TagType>()) {
12867 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12868 diag::err_expected_class_or_namespace)
12869 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12870 return ExprError();
12871 }
12872 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12873 CCLoc);
12874 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012875
Abramo Bagnara7945c982012-01-27 09:46:47 +000012876 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012877 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012878 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012879 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012880 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012881 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012882 /*TemplateArgs*/ nullptr,
12883 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012884}
12885
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012886template<typename Derived>
12887StmtResult
12888TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012889 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000012890 CapturedDecl *CD = S->getCapturedDecl();
12891 unsigned NumParams = CD->getNumParams();
12892 unsigned ContextParamPos = CD->getContextParamPosition();
12893 SmallVector<Sema::CapturedParamNameType, 4> Params;
12894 for (unsigned I = 0; I < NumParams; ++I) {
12895 if (I != ContextParamPos) {
12896 Params.push_back(
12897 std::make_pair(
12898 CD->getParam(I)->getName(),
12899 getDerived().TransformType(CD->getParam(I)->getType())));
12900 } else {
12901 Params.push_back(std::make_pair(StringRef(), QualType()));
12902 }
12903 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012904 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012905 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012906 StmtResult Body;
12907 {
12908 Sema::CompoundScopeRAII CompoundScope(getSema());
12909 Body = getDerived().TransformStmt(S->getCapturedStmt());
12910 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012911
12912 if (Body.isInvalid()) {
12913 getSema().ActOnCapturedRegionError();
12914 return StmtError();
12915 }
12916
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012917 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012918}
12919
Douglas Gregord6ff3322009-08-04 16:50:30 +000012920} // end namespace clang
12921
Hans Wennborg59dbe862015-09-29 20:56:43 +000012922#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H