blob: e411a2ad47c916d1c9d3800c2705c3a401ba762b [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
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000321 /// Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000322 ///
Mike Stump11289f42009-09-09 15:08:12 +0000323 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 /// appropriate TransformXXXStmt function to transform a specific kind of
325 /// statement or the TransformExpr() function to transform an expression.
326 /// Subclasses may override this function to transform statements using some
327 /// other mechanism.
328 ///
329 /// \returns the transformed statement.
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +0000330 StmtResult TransformStmt(Stmt *S, bool DiscardedValue = false);
Mike Stump11289f42009-09-09 15:08:12 +0000331
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000332 /// Transform the given statement.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000333 ///
334 /// By default, this routine transforms a statement by delegating to the
335 /// appropriate TransformOMPXXXClause function to transform a specific kind
336 /// of clause. Subclasses may override this function to transform statements
337 /// using some other mechanism.
338 ///
339 /// \returns the transformed OpenMP clause.
340 OMPClause *TransformOMPClause(OMPClause *S);
341
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000342 /// Transform the given attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000343 ///
344 /// By default, this routine transforms a statement by delegating to the
345 /// appropriate TransformXXXAttr function to transform a specific kind
346 /// of attribute. Subclasses may override this function to transform
347 /// attributed statements using some other mechanism.
348 ///
349 /// \returns the transformed attribute
350 const Attr *TransformAttr(const Attr *S);
351
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000352/// Transform the specified attribute.
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000353///
354/// Subclasses should override the transformation of attributes with a pragma
355/// spelling to transform expressions stored within the attribute.
356///
357/// \returns the transformed attribute.
358#define ATTR(X)
359#define PRAGMA_SPELLING_ATTR(X) \
360 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
361#include "clang/Basic/AttrList.inc"
362
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000363 /// Transform the given expression.
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000364 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000365 /// By default, this routine transforms an expression by delegating to the
366 /// appropriate TransformXXXExpr function to build a new expression.
367 /// Subclasses may override this function to transform expressions using some
368 /// other mechanism.
369 ///
370 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000371 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000373 /// Transform the given initializer.
Richard Smithd59b8322012-12-19 01:39:02 +0000374 ///
375 /// By default, this routine transforms an initializer by stripping off the
376 /// semantic nodes added by initialization, then passing the result to
377 /// TransformExpr or TransformExprs.
378 ///
379 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000380 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000381
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000382 /// Transform the given list of expressions.
Douglas Gregora3efea12011-01-03 19:04:46 +0000383 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// This routine transforms a list of expressions by invoking
385 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000386 /// support for variadic templates by expanding any pack expansions (if the
387 /// derived class permits such expansion) along the way. When pack expansions
388 /// are present, the number of outputs may not equal the number of inputs.
389 ///
390 /// \param Inputs The set of expressions to be transformed.
391 ///
392 /// \param NumInputs The number of expressions in \c Inputs.
393 ///
394 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000395 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000396 /// be.
397 ///
398 /// \param Outputs The transformed input expressions will be added to this
399 /// vector.
400 ///
401 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
402 /// due to transformation.
403 ///
404 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000405 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000406 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000407 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000408
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000409 /// Transform the given declaration, which is referenced from a type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// or expression.
411 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000412 /// By default, acts as the identity function on declarations, unless the
413 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000414 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000415 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000416 llvm::DenseMap<Decl *, Decl *>::iterator Known
417 = TransformedLocalDecls.find(D);
418 if (Known != TransformedLocalDecls.end())
419 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000420
421 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000422 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000423
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000424 /// Transform the specified condition.
Richard Smith03a4aa32016-06-23 19:02:52 +0000425 ///
426 /// By default, this transforms the variable and expression and rebuilds
427 /// the condition.
428 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
429 Expr *Expr,
430 Sema::ConditionKind Kind);
431
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000432 /// Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000433 /// place them on the new declaration.
434 ///
435 /// By default, this operation does nothing. Subclasses may override this
436 /// behavior to transform attributes.
437 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000438
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000439 /// Note that a local declaration has been transformed by this
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000440 /// transformer.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000443 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
444 /// the transformer itself has to transform the declarations. This routine
445 /// can be overridden by a subclass that keeps track of such mappings.
446 void transformedLocalDecl(Decl *Old, Decl *New) {
447 TransformedLocalDecls[Old] = New;
448 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000449
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000450 /// Transform the definition of the given declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000451 ///
Mike Stump11289f42009-09-09 15:08:12 +0000452 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000453 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000454 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
455 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000456 }
Mike Stump11289f42009-09-09 15:08:12 +0000457
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000458 /// Transform the given declaration, which was the first part of a
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000459 /// nested-name-specifier in a member access expression.
460 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000461 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000462 /// identifier in a nested-name-specifier of a member access expression, e.g.,
463 /// the \c T in \c x->T::member
464 ///
465 /// By default, invokes TransformDecl() to transform the declaration.
466 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000467 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
468 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000469 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000470
Richard Smith151c4562016-12-20 21:35:28 +0000471 /// Transform the set of declarations in an OverloadExpr.
472 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
473 LookupResult &R);
474
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000475 /// Transform the given nested-name-specifier with source-location
Douglas Gregor14454802011-02-25 02:25:35 +0000476 /// information.
477 ///
478 /// By default, transforms all of the types and declarations within the
479 /// nested-name-specifier. Subclasses may override this function to provide
480 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000481 NestedNameSpecifierLoc
482 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
483 QualType ObjectType = QualType(),
484 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000485
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000486 /// Transform the given declaration name.
Douglas Gregorf816bd72009-09-03 22:13:48 +0000487 ///
488 /// By default, transforms the types of conversion function, constructor,
489 /// and destructor names and then (if needed) rebuilds the declaration name.
490 /// Identifiers and selectors are returned unmodified. Sublcasses may
491 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000492 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000493 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000494
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000495 /// Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000496 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000497 /// \param SS The nested-name-specifier that qualifies the template
498 /// name. This nested-name-specifier must already have been transformed.
499 ///
500 /// \param Name The template name to transform.
501 ///
502 /// \param NameLoc The source location of the template name.
503 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000504 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000505 /// access expression, this is the type of the object whose member template
506 /// is being referenced.
507 ///
508 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
509 /// also refers to a name within the current (lexical) scope, this is the
510 /// declaration it refers to.
511 ///
512 /// By default, transforms the template name by transforming the declarations
513 /// and nested-name-specifiers that occur within the template name.
514 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000515 TemplateName
516 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
517 SourceLocation NameLoc,
518 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000519 NamedDecl *FirstQualifierInScope = nullptr,
520 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000521
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000522 /// Transform the given template argument.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 ///
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// By default, this operation transforms the type, expression, or
525 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000526 /// new template argument from the transformed result. Subclasses may
527 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000528 ///
529 /// Returns true if there was an error.
530 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000531 TemplateArgumentLoc &Output,
532 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000533
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000534 /// Transform the given set of template arguments.
Douglas Gregor62e06f22010-12-20 17:31:10 +0000535 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000536 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000537 /// in the input set using \c TransformTemplateArgument(), and appends
538 /// the transformed arguments to the output list.
539 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000540 /// Note that this overload of \c TransformTemplateArguments() is merely
541 /// a convenience function. Subclasses that wish to override this behavior
542 /// should override the iterator-based member template version.
543 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000544 /// \param Inputs The set of template arguments to be transformed.
545 ///
546 /// \param NumInputs The number of template arguments in \p Inputs.
547 ///
548 /// \param Outputs The set of transformed template arguments output by this
549 /// routine.
550 ///
551 /// Returns true if an error occurred.
552 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
553 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000554 TemplateArgumentListInfo &Outputs,
555 bool Uneval = false) {
556 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
557 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000558 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000559
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000560 /// Transform the given set of template arguments.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000561 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000562 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000563 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000564 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000565 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000566 /// \param First An iterator to the first template argument.
567 ///
568 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000569 ///
570 /// \param Outputs The set of transformed template arguments output by this
571 /// routine.
572 ///
573 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000574 template<typename InputIterator>
575 bool TransformTemplateArguments(InputIterator First,
576 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000577 TemplateArgumentListInfo &Outputs,
578 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000579
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000580 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
John McCall0ad16662009-10-29 08:12:44 +0000581 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
582 TemplateArgumentLoc &ArgLoc);
583
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000584 /// Fakes up a TypeSourceInfo for a type.
John McCallbcd03502009-12-07 02:54:59 +0000585 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
586 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000587 getDerived().getBaseLocation());
588 }
Mike Stump11289f42009-09-09 15:08:12 +0000589
John McCall550e0c22009-10-21 00:40:46 +0000590#define ABSTRACT_TYPELOC(CLASS, PARENT)
591#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000592 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000593#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594
Richard Smith2e321552014-11-12 02:00:47 +0000595 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000596 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
597 FunctionProtoTypeLoc TL,
598 CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +0000599 Qualifiers ThisTypeQuals,
Richard Smith2e321552014-11-12 02:00:47 +0000600 Fn TransformExceptionSpec);
601
602 bool TransformExceptionSpec(SourceLocation Loc,
603 FunctionProtoType::ExceptionSpecInfo &ESI,
604 SmallVectorImpl<QualType> &Exceptions,
605 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000606
David Majnemerfad8f482013-10-15 09:33:02 +0000607 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000608
Chad Rosier1dcde962012-08-08 18:46:20 +0000609 QualType
John McCall31f82722010-11-12 08:19:04 +0000610 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
611 TemplateSpecializationTypeLoc TL,
612 TemplateName Template);
613
Chad Rosier1dcde962012-08-08 18:46:20 +0000614 QualType
John McCall31f82722010-11-12 08:19:04 +0000615 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
616 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000617 TemplateName Template,
618 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000619
Nico Weberc153d242014-07-28 00:02:09 +0000620 QualType TransformDependentTemplateSpecializationType(
621 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
622 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000623
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000624 /// Transforms the parameters of a function type into the
John McCall58f10c32010-03-11 09:03:00 +0000625 /// given vectors.
626 ///
627 /// The result vectors should be kept in sync; null entries in the
628 /// variables vector are acceptable.
629 ///
630 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000631 bool TransformFunctionTypeParams(
632 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
633 const QualType *ParamTypes,
634 const FunctionProtoType::ExtParameterInfo *ParamInfos,
635 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
636 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000637
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000638 /// Transforms a single function-type parameter. Return null
John McCall58f10c32010-03-11 09:03:00 +0000639 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000640 ///
641 /// \param indexAdjustment - A number to add to the parameter's
642 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000643 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000644 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000645 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000646 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000647
John McCall31f82722010-11-12 08:19:04 +0000648 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000649
John McCalldadc5752010-08-24 06:29:42 +0000650 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
651 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000652
Faisal Vali2cba1332013-10-23 06:44:28 +0000653 TemplateParameterList *TransformTemplateParameterList(
654 TemplateParameterList *TPL) {
655 return TPL;
656 }
657
Richard Smithdb2630f2012-10-21 03:28:35 +0000658 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000659
Richard Smithdb2630f2012-10-21 03:28:35 +0000660 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000661 bool IsAddressOfOperand,
662 TypeSourceInfo **RecoveryTSI);
663
664 ExprResult TransformParenDependentScopeDeclRefExpr(
665 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
666 TypeSourceInfo **RecoveryTSI);
667
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000668 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000669
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000670// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
671// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000672#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000673 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000674 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000675#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000676 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000677 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000678#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000679#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000680
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000681#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000682 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000683 OMPClause *Transform ## Class(Class *S);
Roman Lebedev23019f92019-01-28 17:04:11 +0000684 OPENMP_CLAUSE(flush, OMPFlushClause)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000685#include "clang/Basic/OpenMPKinds.def"
686
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000687 /// Build a new qualified type given its unqualified type and type location.
Richard Smithee579842017-01-30 20:39:26 +0000688 ///
689 /// By default, this routine adds type qualifiers only to types that can
690 /// have qualifiers, and silently suppresses those qualifiers that are not
691 /// permitted. Subclasses may override this routine to provide different
692 /// behavior.
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +0000693 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
Richard Smithee579842017-01-30 20:39:26 +0000694
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000695 /// Build a new pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000696 ///
697 /// By default, performs semantic analysis when building the pointer type.
698 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000699 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000700
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000701 /// Build a new block pointer type given its pointee type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702 ///
Mike Stump11289f42009-09-09 15:08:12 +0000703 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000704 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000705 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000707 /// Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708 ///
John McCall70dd5f62009-10-30 00:06:24 +0000709 /// By default, performs semantic analysis when building the
710 /// reference type. Subclasses may override this routine to provide
711 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000712 ///
John McCall70dd5f62009-10-30 00:06:24 +0000713 /// \param LValue whether the type was written with an lvalue sigil
714 /// or an rvalue sigil.
715 QualType RebuildReferenceType(QualType ReferentType,
716 bool LValue,
717 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000718
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000719 /// Build a new member pointer type given the pointee type and the
Douglas Gregord6ff3322009-08-04 16:50:30 +0000720 /// class type it refers into.
721 ///
722 /// By default, performs semantic analysis when building the member pointer
723 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000724 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
725 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000726
Manman Rene6be26c2016-09-13 17:25:08 +0000727 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
728 SourceLocation ProtocolLAngleLoc,
729 ArrayRef<ObjCProtocolDecl *> Protocols,
730 ArrayRef<SourceLocation> ProtocolLocs,
731 SourceLocation ProtocolRAngleLoc);
732
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000733 /// Build an Objective-C object type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000734 ///
735 /// By default, performs semantic analysis when building the object type.
736 /// Subclasses may override this routine to provide different behavior.
737 QualType RebuildObjCObjectType(QualType BaseType,
738 SourceLocation Loc,
739 SourceLocation TypeArgsLAngleLoc,
740 ArrayRef<TypeSourceInfo *> TypeArgs,
741 SourceLocation TypeArgsRAngleLoc,
742 SourceLocation ProtocolLAngleLoc,
743 ArrayRef<ObjCProtocolDecl *> Protocols,
744 ArrayRef<SourceLocation> ProtocolLocs,
745 SourceLocation ProtocolRAngleLoc);
746
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000747 /// Build a new Objective-C object pointer type given the pointee type.
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000748 ///
749 /// By default, directly builds the pointer type, with no additional semantic
750 /// analysis.
751 QualType RebuildObjCObjectPointerType(QualType PointeeType,
752 SourceLocation Star);
753
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000754 /// Build a new array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 /// modifier, size of the array (if known), size expression, and index type
756 /// qualifiers.
757 ///
758 /// By default, performs semantic analysis when building the array type.
759 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 QualType RebuildArrayType(QualType ElementType,
762 ArrayType::ArraySizeModifier SizeMod,
763 const llvm::APInt *Size,
764 Expr *SizeExpr,
765 unsigned IndexTypeQuals,
766 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000767
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000768 /// Build a new constant array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000769 /// modifier, (known) size of the array, and index type qualifiers.
770 ///
771 /// By default, performs semantic analysis when building the array type.
772 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000773 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000774 ArrayType::ArraySizeModifier SizeMod,
775 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000776 unsigned IndexTypeQuals,
777 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000778
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000779 /// Build a new incomplete array type given the element type, size
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780 /// modifier, and index type qualifiers.
781 ///
782 /// By default, performs semantic analysis when building the array type.
783 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000784 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000785 ArrayType::ArraySizeModifier SizeMod,
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 variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 /// size modifier, size expression, 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 RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000795 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000796 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 unsigned IndexTypeQuals,
798 SourceRange BracketsRange);
799
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000800 /// Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000801 /// size modifier, size expression, and index type qualifiers.
802 ///
803 /// By default, performs semantic analysis when building the array type.
804 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000805 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000806 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000807 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 unsigned IndexTypeQuals,
809 SourceRange BracketsRange);
810
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000811 /// Build a new vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000812 /// number of elements.
813 ///
814 /// By default, performs semantic analysis when building the vector type.
815 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000816 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000817 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000818
Erich Keanef702b022018-07-13 19:46:04 +0000819 /// Build a new potentially dependently-sized extended vector type
820 /// given the element type and number of elements.
821 ///
822 /// By default, performs semantic analysis when building the vector type.
823 /// Subclasses may override this routine to provide different behavior.
824 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
825 SourceLocation AttributeLoc,
826 VectorType::VectorKind);
827
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000828 /// Build a new extended vector type given the element type and
Douglas Gregord6ff3322009-08-04 16:50:30 +0000829 /// number of elements.
830 ///
831 /// By default, performs semantic analysis when building the vector type.
832 /// Subclasses may override this routine to provide different behavior.
833 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
834 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000835
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000836 /// Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000837 /// given the element type and number of elements.
838 ///
839 /// By default, performs semantic analysis when building the vector type.
840 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000841 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000842 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000844
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000845 /// Build a new DependentAddressSpaceType or return the pointee
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000846 /// type variable with the correct address space (retrieved from
847 /// AddrSpaceExpr) applied to it. The former will be returned in cases
848 /// where the address space remains dependent.
849 ///
850 /// By default, performs semantic analysis when building the type with address
851 /// space applied. Subclasses may override this routine to provide different
852 /// behavior.
853 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
854 Expr *AddrSpaceExpr,
855 SourceLocation AttributeLoc);
856
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000857 /// Build a new function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000858 ///
859 /// By default, performs semantic analysis when building the function type.
860 /// Subclasses may override this routine to provide different behavior.
861 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000862 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000863 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000864
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000865 /// Build a new unprototyped function type.
John McCall550e0c22009-10-21 00:40:46 +0000866 QualType RebuildFunctionNoProtoType(QualType ResultType);
867
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000868 /// Rebuild an unresolved typename type, given the decl that
John McCallb96ec562009-12-04 22:46:56 +0000869 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000870 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000871
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000872 /// Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000873 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000874 return SemaRef.Context.getTypeDeclType(Typedef);
875 }
876
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000877 /// Build a new class/struct/union type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000878 QualType RebuildRecordType(RecordDecl *Record) {
879 return SemaRef.Context.getTypeDeclType(Record);
880 }
881
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000882 /// Build a new Enum type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000883 QualType RebuildEnumType(EnumDecl *Enum) {
884 return SemaRef.Context.getTypeDeclType(Enum);
885 }
John McCallfcc33b02009-09-05 00:15:47 +0000886
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000887 /// Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000888 ///
889 /// By default, performs semantic analysis when building the typeof type.
890 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000891 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000892
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000893 /// Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000894 ///
895 /// By default, builds a new TypeOfType with the given underlying type.
896 QualType RebuildTypeOfType(QualType Underlying);
897
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000898 /// Build a new unary transform type.
Alexis Hunte852b102011-05-24 22:41:36 +0000899 QualType RebuildUnaryTransformType(QualType BaseType,
900 UnaryTransformType::UTTKind UKind,
901 SourceLocation Loc);
902
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000903 /// Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000904 ///
905 /// By default, performs semantic analysis when building the decltype type.
906 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000907 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000908
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000909 /// Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000910 ///
911 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000912 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000913 // Note, IsDependent is always false here: we implicitly convert an 'auto'
914 // which has been deduced to a dependent type into an undeduced 'auto', so
915 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000916 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000917 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000918 }
919
Richard Smith600b5262017-01-26 20:40:47 +0000920 /// By default, builds a new DeducedTemplateSpecializationType with the given
921 /// deduced type.
922 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
923 QualType Deduced) {
924 return SemaRef.Context.getDeducedTemplateSpecializationType(
925 Template, Deduced, /*IsDependent*/ false);
926 }
927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000928 /// Build a new template specialization type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000929 ///
930 /// By default, performs semantic analysis when building the template
931 /// specialization type. Subclasses may override this routine to provide
932 /// different behavior.
933 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000934 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000935 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000936
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000937 /// Build a new parenthesized type.
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000938 ///
939 /// By default, builds a new ParenType type from the inner type.
940 /// Subclasses may override this routine to provide different behavior.
941 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000942 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000943 }
944
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000945 /// Build a new qualified name type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000946 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000947 /// By default, builds a new ElaboratedType type from the keyword,
948 /// the nested-name-specifier and the named type.
949 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000950 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
951 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000952 NestedNameSpecifierLoc QualifierLoc,
953 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000954 return SemaRef.Context.getElaboratedType(Keyword,
955 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000956 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000957 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000958
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000959 /// Build a new typename type that refers to a template-id.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000960 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000961 /// By default, builds a new DependentNameType type from the
962 /// nested-name-specifier and the given type. Subclasses may override
963 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000964 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000965 ElaboratedTypeKeyword Keyword,
966 NestedNameSpecifierLoc QualifierLoc,
Richard Smith79810042018-05-11 02:43:08 +0000967 SourceLocation TemplateKWLoc,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000968 const IdentifierInfo *Name,
969 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000970 TemplateArgumentListInfo &Args,
971 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000972 // Rebuild the template name.
973 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000974 CXXScopeSpec SS;
975 SS.Adopt(QualifierLoc);
Richard Smith79810042018-05-11 02:43:08 +0000976 TemplateName InstName = getDerived().RebuildTemplateName(
977 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
978 AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000979
Douglas Gregora7a795b2011-03-01 20:11:18 +0000980 if (InstName.isNull())
981 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000982
Douglas Gregora7a795b2011-03-01 20:11:18 +0000983 // If it's still dependent, make a dependent specialization.
984 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000985 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
986 QualifierLoc.getNestedNameSpecifier(),
987 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000988 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000989
Douglas Gregora7a795b2011-03-01 20:11:18 +0000990 // Otherwise, make an elaborated type wrapping a non-dependent
991 // specialization.
992 QualType T =
993 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
994 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000995
Craig Topperc3ec1492014-05-26 06:22:03 +0000996 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000997 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000998
999 return SemaRef.Context.getElaboratedType(Keyword,
1000 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00001001 T);
1002 }
1003
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001004 /// Build a new typename type that refers to an identifier.
Douglas Gregord6ff3322009-08-04 16:50:30 +00001005 ///
1006 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +00001007 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001008 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001009 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001010 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001011 NestedNameSpecifierLoc QualifierLoc,
1012 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001013 SourceLocation IdLoc,
1014 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001015 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001016 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001017
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001018 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001019 // If the name is still dependent, just build a new dependent name type.
1020 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001021 return SemaRef.Context.getDependentNameType(Keyword,
1022 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001023 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001024 }
1025
Richard Smithee579842017-01-30 20:39:26 +00001026 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1027 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1028 *Id, IdLoc);
1029 // If a dependent name resolves to a deduced template specialization type,
1030 // check that we're in one of the syntactic contexts permitting it.
1031 if (!DeducedTSTContext) {
1032 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1033 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1034 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1035 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1036 Deduced->getTemplateName())
1037 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1038 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1039 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1040 return QualType();
1041 }
1042 }
1043 return T;
1044 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001045
1046 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1047
Abramo Bagnarad7548482010-05-19 21:37:53 +00001048 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001049 // into a non-dependent elaborated-type-specifier. Find the tag we're
1050 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001051 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001052 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1053 if (!DC)
1054 return QualType();
1055
John McCallbf8c5192010-05-27 06:40:31 +00001056 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1057 return QualType();
1058
Craig Topperc3ec1492014-05-26 06:22:03 +00001059 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001060 SemaRef.LookupQualifiedName(Result, DC);
1061 switch (Result.getResultKind()) {
1062 case LookupResult::NotFound:
1063 case LookupResult::NotFoundInCurrentInstantiation:
1064 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001065
Douglas Gregore677daf2010-03-31 22:19:08 +00001066 case LookupResult::Found:
1067 Tag = Result.getAsSingle<TagDecl>();
1068 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001069
Douglas Gregore677daf2010-03-31 22:19:08 +00001070 case LookupResult::FoundOverloaded:
1071 case LookupResult::FoundUnresolvedValue:
1072 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001073
Douglas Gregore677daf2010-03-31 22:19:08 +00001074 case LookupResult::Ambiguous:
1075 // Let the LookupResult structure handle ambiguities.
1076 return QualType();
1077 }
1078
1079 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001080 // Check where the name exists but isn't a tag type and use that to emit
1081 // better diagnostics.
1082 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1083 SemaRef.LookupQualifiedName(Result, DC);
1084 switch (Result.getResultKind()) {
1085 case LookupResult::Found:
1086 case LookupResult::FoundOverloaded:
1087 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001088 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001089 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1090 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1091 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001092 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1093 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001094 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001095 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001096 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001097 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001098 break;
1099 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001100 return QualType();
1101 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001102
Richard Trieucaa33d32011-06-10 03:11:26 +00001103 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001104 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001105 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001106 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1107 return QualType();
1108 }
1109
1110 // Build the elaborated-type-specifier type.
1111 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001112 return SemaRef.Context.getElaboratedType(Keyword,
1113 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001114 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001117 /// Build a new pack expansion type.
Douglas Gregor822d0302011-01-12 17:07:58 +00001118 ///
1119 /// By default, builds a new PackExpansionType type from the given pattern.
1120 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001121 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001122 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001123 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001124 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001125 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1126 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001127 }
1128
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001129 /// Build a new atomic type given its value type.
Eli Friedman0dfb8892011-10-06 23:00:33 +00001130 ///
1131 /// By default, performs semantic analysis when building the atomic type.
1132 /// Subclasses may override this routine to provide different behavior.
1133 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1134
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001135 /// Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001136 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1137 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001138
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001139 /// Build a new template name given a nested name specifier, a flag
Douglas Gregor71dc5092009-08-06 06:41:21 +00001140 /// indicating whether the "template" keyword was provided, and the template
1141 /// that the template name refers to.
1142 ///
1143 /// By default, builds the new template name directly. Subclasses may override
1144 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001145 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001146 bool TemplateKW,
1147 TemplateDecl *Template);
1148
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001149 /// Build a new template name given a nested name specifier and the
Douglas Gregor71dc5092009-08-06 06:41:21 +00001150 /// name that is referred to as a template.
1151 ///
1152 /// By default, performs semantic analysis to determine whether the name can
1153 /// be resolved to a specific template, then builds the appropriate kind of
1154 /// template name. Subclasses may override this routine to provide different
1155 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001156 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001157 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00001158 const IdentifierInfo &Name,
Richard Smith79810042018-05-11 02:43:08 +00001159 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001160 NamedDecl *FirstQualifierInScope,
1161 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001162
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001163 /// Build a new template name given a nested name specifier and the
Douglas Gregor71395fa2009-11-04 00:56:37 +00001164 /// overloaded operator name that is referred to as a template.
1165 ///
1166 /// By default, performs semantic analysis to determine whether the name can
1167 /// be resolved to a specific template, then builds the appropriate kind of
1168 /// template name. Subclasses may override this routine to provide different
1169 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001170 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +00001171 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001172 OverloadedOperatorKind Operator,
Richard Smith79810042018-05-11 02:43:08 +00001173 SourceLocation NameLoc, QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001174 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001175
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001176 /// Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001177 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001178 ///
1179 /// By default, performs semantic analysis to determine whether the name can
1180 /// be resolved to a specific template, then builds the appropriate kind of
1181 /// template name. Subclasses may override this routine to provide different
1182 /// behavior.
1183 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1184 const TemplateArgument &ArgPack) {
1185 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1186 }
1187
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001188 /// Build a new compound statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 ///
1190 /// By default, performs semantic analysis to build the new statement.
1191 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001192 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 MultiStmtArg Statements,
1194 SourceLocation RBraceLoc,
1195 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001196 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001197 IsStmtExpr);
1198 }
1199
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001200 /// Build a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001201 ///
1202 /// By default, performs semantic analysis to build the new statement.
1203 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001204 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001205 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001206 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001207 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001208 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001209 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001210 ColonLoc);
1211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001213 /// Attach the body to a new case statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001217 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001218 getSema().ActOnCaseStmtBody(S, Body);
1219 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001222 /// Build a new default statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001226 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001227 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001228 Stmt *SubStmt) {
1229 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001230 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001233 /// Build a new label statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001234 ///
1235 /// By default, performs semantic analysis to build the new statement.
1236 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001237 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1238 SourceLocation ColonLoc, Stmt *SubStmt) {
1239 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001242 /// Build a new label statement.
Richard Smithc202b282012-04-14 00:33:13 +00001243 ///
1244 /// By default, performs semantic analysis to build the new statement.
1245 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001246 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1247 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001248 Stmt *SubStmt) {
1249 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1250 }
1251
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001252 /// Build a new "if" statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001256 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001257 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001258 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001259 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001260 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001261 }
Mike Stump11289f42009-09-09 15:08:12 +00001262
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001263 /// Start building a new switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001264 ///
1265 /// By default, performs semantic analysis to build the new statement.
1266 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001267 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001268 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001269 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001270 }
Mike Stump11289f42009-09-09 15:08:12 +00001271
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001272 /// Attach the body to the switch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 ///
1274 /// By default, performs semantic analysis to build the new statement.
1275 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001276 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001277 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001278 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
1280
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001281 /// Build a new while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001285 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1286 Sema::ConditionResult Cond, Stmt *Body) {
1287 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001288 }
Mike Stump11289f42009-09-09 15:08:12 +00001289
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001290 /// Build a new do-while statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001295 SourceLocation WhileLoc, SourceLocation LParenLoc,
1296 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001297 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1298 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001299 }
1300
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001301 /// Build a new for statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001302 ///
1303 /// By default, performs semantic analysis to build the new statement.
1304 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001305 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001306 Stmt *Init, Sema::ConditionResult Cond,
1307 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1308 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001309 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001310 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001311 }
Mike Stump11289f42009-09-09 15:08:12 +00001312
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001313 /// Build a new goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001314 ///
1315 /// By default, performs semantic analysis to build the new statement.
1316 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001317 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1318 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001319 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001320 }
1321
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001322 /// Build a new indirect goto statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001326 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001327 SourceLocation StarLoc,
1328 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001329 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001332 /// Build a new return 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.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001336 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001337 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001338 }
Mike Stump11289f42009-09-09 15:08:12 +00001339
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001340 /// Build a new declaration statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00001341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001344 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001345 SourceLocation StartLoc, SourceLocation EndLoc) {
1346 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001347 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
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 inline asm statement.
Anders Carlssonaaeef072010-01-24 05:50:09 +00001351 ///
1352 /// By default, performs semantic analysis to build the new statement.
1353 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001354 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1355 bool IsVolatile, unsigned NumOutputs,
1356 unsigned NumInputs, IdentifierInfo **Names,
1357 MultiExprArg Constraints, MultiExprArg Exprs,
1358 Expr *AsmString, MultiExprArg Clobbers,
1359 SourceLocation RParenLoc) {
1360 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1361 NumInputs, Names, Constraints, Exprs,
1362 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001363 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001364
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001365 /// Build a new MS style inline asm statement.
Chad Rosier32503022012-06-11 20:47:18 +00001366 ///
1367 /// By default, performs semantic analysis to build the new statement.
1368 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001369 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001370 ArrayRef<Token> AsmToks,
1371 StringRef AsmString,
1372 unsigned NumOutputs, unsigned NumInputs,
1373 ArrayRef<StringRef> Constraints,
1374 ArrayRef<StringRef> Clobbers,
1375 ArrayRef<Expr*> Exprs,
1376 SourceLocation EndLoc) {
1377 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1378 NumOutputs, NumInputs,
1379 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001380 }
1381
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001382 /// Build a new co_return statement.
Richard Smith9f690bd2015-10-27 06:02:45 +00001383 ///
1384 /// By default, performs semantic analysis to build the new statement.
1385 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001386 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1387 bool IsImplicit) {
1388 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001389 }
1390
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001391 /// Build a new co_await expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001395 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1396 bool IsImplicit) {
1397 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1398 }
1399
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001400 /// Build a new co_await expression.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001401 ///
1402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
1404 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1405 Expr *Result,
1406 UnresolvedLookupExpr *Lookup) {
1407 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001408 }
1409
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001410 /// Build a new co_yield expression.
Richard Smith9f690bd2015-10-27 06:02:45 +00001411 ///
1412 /// By default, performs semantic analysis to build the new expression.
1413 /// Subclasses may override this routine to provide different behavior.
1414 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1415 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1416 }
1417
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001418 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1419 return getSema().BuildCoroutineBodyStmt(Args);
1420 }
1421
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001422 /// Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001423 ///
1424 /// By default, performs semantic analysis to build the new statement.
1425 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001426 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001427 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001428 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001429 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001430 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001431 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001432 }
1433
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001434 /// Rebuild an Objective-C exception declaration.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001435 ///
1436 /// By default, performs semantic analysis to build the new declaration.
1437 /// Subclasses may override this routine to provide different behavior.
1438 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1439 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001440 return getSema().BuildObjCExceptionDecl(TInfo, T,
1441 ExceptionDecl->getInnerLocStart(),
1442 ExceptionDecl->getLocation(),
1443 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001444 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001445
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001446 /// Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001447 ///
1448 /// By default, performs semantic analysis to build the new statement.
1449 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001450 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001451 SourceLocation RParenLoc,
1452 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001453 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001454 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001457
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001458 /// Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001459 ///
1460 /// By default, performs semantic analysis to build the new statement.
1461 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001462 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001463 Stmt *Body) {
1464 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001466
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001467 /// Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001471 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001472 Expr *Operand) {
1473 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001474 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001475
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001476 /// Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001477 ///
1478 /// By default, performs semantic analysis to build the new statement.
1479 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001480 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001481 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001482 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001483 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001484 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001485 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001486 return getSema().ActOnOpenMPExecutableDirective(
1487 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001488 }
1489
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001490 /// Build a new OpenMP 'if' clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001493 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001494 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1495 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001496 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001497 SourceLocation NameModifierLoc,
1498 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001499 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001500 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1501 LParenLoc, NameModifierLoc, ColonLoc,
1502 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001503 }
1504
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001505 /// Build a new OpenMP 'final' clause.
Alexey Bataev3778b602014-07-17 07:32:53 +00001506 ///
1507 /// By default, performs semantic analysis to build the new OpenMP clause.
1508 /// Subclasses may override this routine to provide different behavior.
1509 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1510 SourceLocation LParenLoc,
1511 SourceLocation EndLoc) {
1512 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1513 EndLoc);
1514 }
1515
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001516 /// Build a new OpenMP 'num_threads' clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001517 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001518 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001519 /// Subclasses may override this routine to provide different behavior.
1520 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1521 SourceLocation StartLoc,
1522 SourceLocation LParenLoc,
1523 SourceLocation EndLoc) {
1524 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1525 LParenLoc, EndLoc);
1526 }
1527
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001528 /// Build a new OpenMP 'safelen' clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001529 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001530 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1533 SourceLocation LParenLoc,
1534 SourceLocation EndLoc) {
1535 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1536 }
1537
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001538 /// Build a new OpenMP 'simdlen' clause.
Alexey Bataev66b15b52015-08-21 11:14:16 +00001539 ///
1540 /// By default, performs semantic analysis to build the new OpenMP clause.
1541 /// Subclasses may override this routine to provide different behavior.
1542 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1543 SourceLocation LParenLoc,
1544 SourceLocation EndLoc) {
1545 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1546 }
1547
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001548 /// Build a new OpenMP 'collapse' clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001549 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001550 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001551 /// Subclasses may override this routine to provide different behavior.
1552 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1553 SourceLocation LParenLoc,
1554 SourceLocation EndLoc) {
1555 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1556 EndLoc);
1557 }
1558
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001559 /// Build a new OpenMP 'default' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001560 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001561 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001562 /// Subclasses may override this routine to provide different behavior.
1563 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1564 SourceLocation KindKwLoc,
1565 SourceLocation StartLoc,
1566 SourceLocation LParenLoc,
1567 SourceLocation EndLoc) {
1568 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1569 StartLoc, LParenLoc, EndLoc);
1570 }
1571
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001572 /// Build a new OpenMP 'proc_bind' clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001573 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001574 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001575 /// Subclasses may override this routine to provide different behavior.
1576 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1577 SourceLocation KindKwLoc,
1578 SourceLocation StartLoc,
1579 SourceLocation LParenLoc,
1580 SourceLocation EndLoc) {
1581 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1582 StartLoc, LParenLoc, EndLoc);
1583 }
1584
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001585 /// Build a new OpenMP 'schedule' clause.
Alexey Bataev56dafe82014-06-20 07:16:17 +00001586 ///
1587 /// By default, performs semantic analysis to build the new OpenMP clause.
1588 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001589 OMPClause *RebuildOMPScheduleClause(
1590 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1591 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1592 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1593 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001594 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001595 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1596 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001597 }
1598
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001599 /// Build a new OpenMP 'ordered' clause.
Alexey Bataev10e775f2015-07-30 11:36:16 +00001600 ///
1601 /// By default, performs semantic analysis to build the new OpenMP clause.
1602 /// Subclasses may override this routine to provide different behavior.
1603 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1604 SourceLocation EndLoc,
1605 SourceLocation LParenLoc, Expr *Num) {
1606 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1607 }
1608
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001609 /// Build a new OpenMP 'private' clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001610 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001611 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001612 /// Subclasses may override this routine to provide different behavior.
1613 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1614 SourceLocation StartLoc,
1615 SourceLocation LParenLoc,
1616 SourceLocation EndLoc) {
1617 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1618 EndLoc);
1619 }
1620
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001621 /// Build a new OpenMP 'firstprivate' clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001622 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001623 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001624 /// Subclasses may override this routine to provide different behavior.
1625 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1626 SourceLocation StartLoc,
1627 SourceLocation LParenLoc,
1628 SourceLocation EndLoc) {
1629 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1630 EndLoc);
1631 }
1632
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001633 /// Build a new OpenMP 'lastprivate' clause.
Alexander Musman1bb328c2014-06-04 13:06:39 +00001634 ///
1635 /// By default, performs semantic analysis to build the new OpenMP clause.
1636 /// Subclasses may override this routine to provide different behavior.
1637 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1638 SourceLocation StartLoc,
1639 SourceLocation LParenLoc,
1640 SourceLocation EndLoc) {
1641 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1642 EndLoc);
1643 }
1644
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001645 /// Build a new OpenMP 'shared' clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001646 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001647 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001648 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001649 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1650 SourceLocation StartLoc,
1651 SourceLocation LParenLoc,
1652 SourceLocation EndLoc) {
1653 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1654 EndLoc);
1655 }
1656
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001657 /// Build a new OpenMP 'reduction' clause.
Alexey Bataevc5e02582014-06-16 07:08:35 +00001658 ///
1659 /// By default, performs semantic analysis to build the new statement.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1662 SourceLocation StartLoc,
1663 SourceLocation LParenLoc,
1664 SourceLocation ColonLoc,
1665 SourceLocation EndLoc,
1666 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001667 const DeclarationNameInfo &ReductionId,
1668 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001669 return getSema().ActOnOpenMPReductionClause(
1670 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001671 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001672 }
1673
Alexey Bataev169d96a2017-07-18 20:17:46 +00001674 /// Build a new OpenMP 'task_reduction' clause.
1675 ///
1676 /// By default, performs semantic analysis to build the new statement.
1677 /// Subclasses may override this routine to provide different behavior.
1678 OMPClause *RebuildOMPTaskReductionClause(
1679 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1680 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1681 CXXScopeSpec &ReductionIdScopeSpec,
1682 const DeclarationNameInfo &ReductionId,
1683 ArrayRef<Expr *> UnresolvedReductions) {
1684 return getSema().ActOnOpenMPTaskReductionClause(
1685 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1686 ReductionId, UnresolvedReductions);
1687 }
1688
Alexey Bataevfa312f32017-07-21 18:48:21 +00001689 /// Build a new OpenMP 'in_reduction' clause.
1690 ///
1691 /// By default, performs semantic analysis to build the new statement.
1692 /// Subclasses may override this routine to provide different behavior.
1693 OMPClause *
1694 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1695 SourceLocation LParenLoc, SourceLocation ColonLoc,
1696 SourceLocation EndLoc,
1697 CXXScopeSpec &ReductionIdScopeSpec,
1698 const DeclarationNameInfo &ReductionId,
1699 ArrayRef<Expr *> UnresolvedReductions) {
1700 return getSema().ActOnOpenMPInReductionClause(
1701 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1702 ReductionId, UnresolvedReductions);
1703 }
1704
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001705 /// Build a new OpenMP 'linear' clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001706 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001707 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001708 /// Subclasses may override this routine to provide different behavior.
1709 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1710 SourceLocation StartLoc,
1711 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001712 OpenMPLinearClauseKind Modifier,
1713 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001714 SourceLocation ColonLoc,
1715 SourceLocation EndLoc) {
1716 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001717 Modifier, ModifierLoc, ColonLoc,
1718 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001719 }
1720
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001721 /// Build a new OpenMP 'aligned' clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001722 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001723 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001724 /// Subclasses may override this routine to provide different behavior.
1725 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1726 SourceLocation StartLoc,
1727 SourceLocation LParenLoc,
1728 SourceLocation ColonLoc,
1729 SourceLocation EndLoc) {
1730 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1731 LParenLoc, ColonLoc, EndLoc);
1732 }
1733
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001734 /// Build a new OpenMP 'copyin' clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001735 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001736 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001737 /// Subclasses may override this routine to provide different behavior.
1738 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1739 SourceLocation StartLoc,
1740 SourceLocation LParenLoc,
1741 SourceLocation EndLoc) {
1742 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1743 EndLoc);
1744 }
1745
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001746 /// Build a new OpenMP 'copyprivate' clause.
Alexey Bataevbae9a792014-06-27 10:37:06 +00001747 ///
1748 /// By default, performs semantic analysis to build the new OpenMP clause.
1749 /// Subclasses may override this routine to provide different behavior.
1750 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1751 SourceLocation StartLoc,
1752 SourceLocation LParenLoc,
1753 SourceLocation EndLoc) {
1754 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1755 EndLoc);
1756 }
1757
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001758 /// Build a new OpenMP 'flush' pseudo clause.
Alexey Bataev6125da92014-07-21 11:26:11 +00001759 ///
1760 /// By default, performs semantic analysis to build the new OpenMP clause.
1761 /// Subclasses may override this routine to provide different behavior.
1762 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1763 SourceLocation StartLoc,
1764 SourceLocation LParenLoc,
1765 SourceLocation EndLoc) {
1766 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1767 EndLoc);
1768 }
1769
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001770 /// Build a new OpenMP 'depend' pseudo clause.
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001771 ///
1772 /// By default, performs semantic analysis to build the new OpenMP clause.
1773 /// Subclasses may override this routine to provide different behavior.
1774 OMPClause *
1775 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1776 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1777 SourceLocation StartLoc, SourceLocation LParenLoc,
1778 SourceLocation EndLoc) {
1779 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1780 StartLoc, LParenLoc, EndLoc);
1781 }
1782
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001783 /// Build a new OpenMP 'device' clause.
Michael Wonge710d542015-08-07 16:16:36 +00001784 ///
1785 /// By default, performs semantic analysis to build the new statement.
1786 /// Subclasses may override this routine to provide different behavior.
1787 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1788 SourceLocation LParenLoc,
1789 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001790 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001791 EndLoc);
1792 }
1793
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001794 /// Build a new OpenMP 'map' clause.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001795 ///
1796 /// By default, performs semantic analysis to build the new OpenMP clause.
1797 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001798 OMPClause *
Kelvin Lief579432018-12-18 22:18:41 +00001799 RebuildOMPMapClause(ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
1800 ArrayRef<SourceLocation> MapTypeModifiersLoc,
Samuel Antao23abd722016-01-19 20:40:49 +00001801 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1802 SourceLocation MapLoc, SourceLocation ColonLoc,
1803 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1804 SourceLocation LParenLoc, SourceLocation EndLoc) {
Kelvin Lief579432018-12-18 22:18:41 +00001805 return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc,
1806 MapType, IsMapTypeImplicit, MapLoc,
1807 ColonLoc, VarList, StartLoc,
1808 LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001809 }
1810
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001811 /// Build a new OpenMP 'num_teams' clause.
Kelvin Li099bb8c2015-11-24 20:50:12 +00001812 ///
1813 /// By default, performs semantic analysis to build the new statement.
1814 /// Subclasses may override this routine to provide different behavior.
1815 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1816 SourceLocation LParenLoc,
1817 SourceLocation EndLoc) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001818 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
Kelvin Li099bb8c2015-11-24 20:50:12 +00001819 EndLoc);
1820 }
1821
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001822 /// Build a new OpenMP 'thread_limit' clause.
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001823 ///
1824 /// By default, performs semantic analysis to build the new statement.
1825 /// Subclasses may override this routine to provide different behavior.
1826 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1827 SourceLocation StartLoc,
1828 SourceLocation LParenLoc,
1829 SourceLocation EndLoc) {
1830 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1831 LParenLoc, EndLoc);
1832 }
1833
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001834 /// Build a new OpenMP 'priority' clause.
Alexey Bataeva0569352015-12-01 10:17:31 +00001835 ///
1836 /// By default, performs semantic analysis to build the new statement.
1837 /// Subclasses may override this routine to provide different behavior.
1838 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1839 SourceLocation LParenLoc,
1840 SourceLocation EndLoc) {
1841 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1842 EndLoc);
1843 }
1844
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001845 /// Build a new OpenMP 'grainsize' clause.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001846 ///
1847 /// By default, performs semantic analysis to build the new statement.
1848 /// Subclasses may override this routine to provide different behavior.
1849 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1850 SourceLocation LParenLoc,
1851 SourceLocation EndLoc) {
1852 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1853 EndLoc);
1854 }
1855
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001856 /// Build a new OpenMP 'num_tasks' clause.
Alexey Bataev382967a2015-12-08 12:06:20 +00001857 ///
1858 /// By default, performs semantic analysis to build the new statement.
1859 /// Subclasses may override this routine to provide different behavior.
1860 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1861 SourceLocation LParenLoc,
1862 SourceLocation EndLoc) {
1863 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1864 EndLoc);
1865 }
1866
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001867 /// Build a new OpenMP 'hint' clause.
Alexey Bataev28c75412015-12-15 08:19:24 +00001868 ///
1869 /// By default, performs semantic analysis to build the new statement.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1872 SourceLocation LParenLoc,
1873 SourceLocation EndLoc) {
1874 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1875 }
1876
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001877 /// Build a new OpenMP 'dist_schedule' clause.
Carlo Bertollib4adf552016-01-15 18:50:31 +00001878 ///
1879 /// By default, performs semantic analysis to build the new OpenMP clause.
1880 /// Subclasses may override this routine to provide different behavior.
1881 OMPClause *
1882 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1883 Expr *ChunkSize, SourceLocation StartLoc,
1884 SourceLocation LParenLoc, SourceLocation KindLoc,
1885 SourceLocation CommaLoc, SourceLocation EndLoc) {
1886 return getSema().ActOnOpenMPDistScheduleClause(
1887 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1888 }
1889
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001890 /// Build a new OpenMP 'to' clause.
Samuel Antao661c0902016-05-26 17:39:58 +00001891 ///
1892 /// By default, performs semantic analysis to build the new statement.
1893 /// Subclasses may override this routine to provide different behavior.
1894 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1895 SourceLocation StartLoc,
1896 SourceLocation LParenLoc,
1897 SourceLocation EndLoc) {
1898 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1899 }
1900
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001901 /// Build a new OpenMP 'from' clause.
Samuel Antaoec172c62016-05-26 17:49:04 +00001902 ///
1903 /// By default, performs semantic analysis to build the new statement.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1906 SourceLocation StartLoc,
1907 SourceLocation LParenLoc,
1908 SourceLocation EndLoc) {
1909 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1910 EndLoc);
1911 }
1912
Carlo Bertolli2404b172016-07-13 15:37:16 +00001913 /// Build a new OpenMP 'use_device_ptr' clause.
1914 ///
1915 /// By default, performs semantic analysis to build the new OpenMP clause.
1916 /// Subclasses may override this routine to provide different behavior.
1917 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1918 SourceLocation StartLoc,
1919 SourceLocation LParenLoc,
1920 SourceLocation EndLoc) {
1921 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1922 EndLoc);
1923 }
1924
Carlo Bertolli70594e92016-07-13 17:16:49 +00001925 /// Build a new OpenMP 'is_device_ptr' clause.
1926 ///
1927 /// By default, performs semantic analysis to build the new OpenMP clause.
1928 /// Subclasses may override this routine to provide different behavior.
1929 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1930 SourceLocation StartLoc,
1931 SourceLocation LParenLoc,
1932 SourceLocation EndLoc) {
1933 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1934 EndLoc);
1935 }
1936
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001937 /// Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001938 ///
1939 /// By default, performs semantic analysis to build the new statement.
1940 /// Subclasses may override this routine to provide different behavior.
1941 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1942 Expr *object) {
1943 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1944 }
1945
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001946 /// Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001947 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001948 /// By default, performs semantic analysis to build the new statement.
1949 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001950 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001951 Expr *Object, Stmt *Body) {
1952 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001953 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001955 /// Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001956 ///
1957 /// By default, performs semantic analysis to build the new statement.
1958 /// Subclasses may override this routine to provide different behavior.
1959 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1960 Stmt *Body) {
1961 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1962 }
John McCall53848232011-07-27 01:07:15 +00001963
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001964 /// Build a new Objective-C fast enumeration statement.
Douglas Gregorf68a5082010-04-22 23:10:45 +00001965 ///
1966 /// By default, performs semantic analysis to build the new statement.
1967 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001968 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001969 Stmt *Element,
1970 Expr *Collection,
1971 SourceLocation RParenLoc,
1972 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001973 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001974 Element,
John McCallb268a282010-08-23 23:25:46 +00001975 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001976 RParenLoc);
1977 if (ForEachStmt.isInvalid())
1978 return StmtError();
1979
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001980 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001981 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001982
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001983 /// Build a new C++ exception declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +00001984 ///
1985 /// By default, performs semantic analysis to build the new decaration.
1986 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001987 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001988 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001989 SourceLocation StartLoc,
1990 SourceLocation IdLoc,
1991 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001992 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001993 StartLoc, IdLoc, Id);
1994 if (Var)
1995 getSema().CurContext->addDecl(Var);
1996 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 }
1998
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001999 /// Build a new C++ catch statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 ///
2001 /// By default, performs semantic analysis to build the new statement.
2002 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002003 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002004 VarDecl *ExceptionDecl,
2005 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00002006 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2007 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002010 /// Build a new C++ try statement.
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 ///
2012 /// By default, performs semantic analysis to build the new statement.
2013 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002014 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2015 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002016 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002019 /// Build a new C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002020 ///
2021 /// By default, performs semantic analysis to build the new statement.
2022 /// Subclasses may override this routine to provide different behavior.
2023 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith8baa5002018-09-28 18:44:09 +00002024 SourceLocation CoawaitLoc, Stmt *Init,
2025 SourceLocation ColonLoc, Stmt *Range,
2026 Stmt *Begin, Stmt *End, Expr *Cond,
2027 Expr *Inc, Stmt *LoopVar,
Richard Smith02e85f32011-04-14 22:09:26 +00002028 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002029 // If we've just learned that the range is actually an Objective-C
2030 // collection, treat this as an Objective-C fast enumeration loop.
2031 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2032 if (RangeStmt->isSingleDecl()) {
2033 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002034 if (RangeVar->isInvalidDecl())
2035 return StmtError();
2036
Douglas Gregorf7106af2013-04-08 18:40:13 +00002037 Expr *RangeExpr = RangeVar->getInit();
2038 if (!RangeExpr->isTypeDependent() &&
Richard Smith8baa5002018-09-28 18:44:09 +00002039 RangeExpr->getType()->isObjCObjectPointerType()) {
2040 // FIXME: Support init-statements in Objective-C++20 ranged for
2041 // statement.
2042 if (Init) {
2043 return SemaRef.Diag(Init->getBeginLoc(),
2044 diag::err_objc_for_range_init_stmt)
2045 << Init->getSourceRange();
2046 }
2047 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2048 RangeExpr, RParenLoc);
2049 }
Douglas Gregorf7106af2013-04-08 18:40:13 +00002050 }
2051 }
2052 }
2053
Richard Smith8baa5002018-09-28 18:44:09 +00002054 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
2055 Range, Begin, End, Cond, Inc, LoopVar,
2056 RParenLoc, Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002057 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002058
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002059 /// Build a new C++0x range-based for statement.
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002060 ///
2061 /// By default, performs semantic analysis to build the new statement.
2062 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002063 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002064 bool IsIfExists,
2065 NestedNameSpecifierLoc QualifierLoc,
2066 DeclarationNameInfo NameInfo,
2067 Stmt *Nested) {
2068 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2069 QualifierLoc, NameInfo, Nested);
2070 }
2071
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002072 /// Attach body to a C++0x range-based for statement.
Richard Smith02e85f32011-04-14 22:09:26 +00002073 ///
2074 /// By default, performs semantic analysis to finish the new statement.
2075 /// Subclasses may override this routine to provide different behavior.
2076 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2077 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2078 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002079
David Majnemerfad8f482013-10-15 09:33:02 +00002080 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002081 Stmt *TryBlock, Stmt *Handler) {
2082 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002083 }
2084
David Majnemerfad8f482013-10-15 09:33:02 +00002085 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002086 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002087 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002088 }
2089
David Majnemerfad8f482013-10-15 09:33:02 +00002090 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002091 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002092 }
2093
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002094 /// Build a new predefined expression.
Alexey Bataevec474782014-10-09 08:45:04 +00002095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
2098 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
Bruno Ricci17ff0262018-10-27 19:21:19 +00002099 PredefinedExpr::IdentKind IK) {
2100 return getSema().BuildPredefinedExpr(Loc, IK);
Alexey Bataevec474782014-10-09 08:45:04 +00002101 }
2102
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002103 /// Build a new expression that references a declaration.
Douglas Gregora16548e2009-08-11 05:31:07 +00002104 ///
2105 /// By default, performs semantic analysis to build the new expression.
2106 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002107 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002108 LookupResult &R,
2109 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002110 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2111 }
2112
2113
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002114 /// Build a new expression that references a declaration.
John McCalle66edc12009-11-24 19:00:30 +00002115 ///
2116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002118 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002119 ValueDecl *VD,
2120 const DeclarationNameInfo &NameInfo,
2121 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002122 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002123 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002124
2125 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002126
2127 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 }
Mike Stump11289f42009-09-09 15:08:12 +00002129
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002130 /// Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002131 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002132 /// By default, performs semantic analysis to build the new expression.
2133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002134 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002136 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 }
2138
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002139 /// Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002140 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002141 /// By default, performs semantic analysis to build the new expression.
2142 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002143 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002144 SourceLocation OperatorLoc,
2145 bool isArrow,
2146 CXXScopeSpec &SS,
2147 TypeSourceInfo *ScopeType,
2148 SourceLocation CCLoc,
2149 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002150 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002151
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002152 /// Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002153 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002154 /// By default, performs semantic analysis to build the new expression.
2155 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002156 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002157 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002158 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002159 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002162 /// Build a new builtin offsetof expression.
Douglas Gregor882211c2010-04-28 22:16:22 +00002163 ///
2164 /// 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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002167 TypeSourceInfo *Type,
2168 ArrayRef<Sema::OffsetOfComponent> Components,
2169 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002170 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002171 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002173
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002174 /// Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002175 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002176 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 /// By default, performs semantic analysis to build the new expression.
2178 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002179 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2180 SourceLocation OpLoc,
2181 UnaryExprOrTypeTrait ExprKind,
2182 SourceRange R) {
2183 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
2185
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002186 /// Build a new sizeof, alignof or vec step expression with an
Peter Collingbournee190dee2011-03-11 19:24:49 +00002187 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002188 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 /// By default, performs semantic analysis to build the new expression.
2190 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002191 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2192 UnaryExprOrTypeTrait ExprKind,
2193 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002194 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002195 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002197 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002198
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002199 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 }
Mike Stump11289f42009-09-09 15:08:12 +00002201
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002202 /// Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002203 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002204 /// By default, performs semantic analysis to build the new expression.
2205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002206 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002208 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002210 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002211 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002212 RBracketLoc);
2213 }
2214
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002215 /// Build a new array section expression.
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002216 ///
2217 /// By default, performs semantic analysis to build the new expression.
2218 /// Subclasses may override this routine to provide different behavior.
2219 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2220 Expr *LowerBound,
2221 SourceLocation ColonLoc, Expr *Length,
2222 SourceLocation RBracketLoc) {
2223 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2224 ColonLoc, Length, RBracketLoc);
2225 }
2226
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002227 /// Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002228 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002233 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002234 Expr *ExecConfig = nullptr) {
2235 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002236 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002237 }
2238
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002239 /// Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002240 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 /// By default, performs semantic analysis to build the new expression.
2242 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002243 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002244 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002245 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002246 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002247 const DeclarationNameInfo &MemberNameInfo,
2248 ValueDecl *Member,
2249 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002250 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002251 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002252 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2253 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002254 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002255 // We have a reference to an unnamed field. This is always the
2256 // base of an anonymous struct/union member access, i.e. the
2257 // field is always of record type.
John McCall7decc9e2010-11-18 06:31:45 +00002258 assert(Member->getType()->isRecordType() &&
2259 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002260
Richard Smithcab9a7d2011-10-26 19:06:56 +00002261 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002262 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002263 QualifierLoc.getNestedNameSpecifier(),
2264 FoundDecl, Member);
2265 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002266 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002267 Base = BaseResult.get();
Eric Fiselier84393612018-04-08 05:11:59 +00002268
2269 CXXScopeSpec EmptySS;
2270 return getSema().BuildFieldReferenceExpr(
2271 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2272 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
Anders Carlsson5da84842009-09-01 04:26:58 +00002273 }
Mike Stump11289f42009-09-09 15:08:12 +00002274
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002275 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002276 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002277
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002278 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002279 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002280
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002281 if (isArrow && !BaseType->isPointerType())
2282 return ExprError();
2283
John McCall16df1e52010-03-30 21:47:33 +00002284 // FIXME: this involves duplicating earlier analysis in a lot of
2285 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002286 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002287 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002288 R.resolveKind();
2289
John McCallb268a282010-08-23 23:25:46 +00002290 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002291 SS, TemplateKWLoc,
2292 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002293 R, ExplicitTemplateArgs,
2294 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 }
Mike Stump11289f42009-09-09 15:08:12 +00002296
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002297 /// Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002298 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// By default, performs semantic analysis to build the new expression.
2300 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002301 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002302 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002303 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002304 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 }
2306
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002307 /// Build a new conditional 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 RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002312 SourceLocation QuestionLoc,
2313 Expr *LHS,
2314 SourceLocation ColonLoc,
2315 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002316 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2317 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002318 }
2319
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002320 /// Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002321 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002324 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002325 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002326 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002327 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002328 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002329 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002330 }
Mike Stump11289f42009-09-09 15:08:12 +00002331
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002332 /// Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002333 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 /// By default, performs semantic analysis to build the new expression.
2335 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002336 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002337 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002338 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002339 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002340 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002341 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002342 }
Mike Stump11289f42009-09-09 15:08:12 +00002343
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002344 /// Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002345 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 /// By default, performs semantic analysis to build the new expression.
2347 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002348 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 SourceLocation OpLoc,
2350 SourceLocation AccessorLoc,
2351 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002352
John McCall10eae182009-11-30 22:42:35 +00002353 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002354 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002355 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002356 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002357 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002358 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002359 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002360 /* TemplateArgs */ nullptr,
2361 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002362 }
Mike Stump11289f42009-09-09 15:08:12 +00002363
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002364 /// Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002365 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 /// By default, performs semantic analysis to build the new expression.
2367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002368 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002369 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002370 SourceLocation RBraceLoc) {
2371 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
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 designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 MultiExprArg ArrayExprs,
2380 SourceLocation EqualOrColonLoc,
2381 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002382 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002383 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002385 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002388
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002389 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002392 /// Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002393 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002394 /// By default, builds the implicit value initialization without performing
2395 /// any semantic analysis. Subclasses may override this routine to provide
2396 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002397 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002398 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 }
Mike Stump11289f42009-09-09 15:08:12 +00002400
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002401 /// Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002402 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002405 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002406 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002407 SourceLocation RParenLoc) {
2408 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002409 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002410 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 }
2412
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002413 /// Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002414 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002415 /// By default, performs semantic analysis to build the new expression.
2416 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002417 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002418 MultiExprArg SubExprs,
2419 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002420 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002421 }
Mike Stump11289f42009-09-09 15:08:12 +00002422
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002423 /// Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002424 ///
2425 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 /// rather than attempting to map the label statement itself.
2427 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002428 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002429 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002430 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
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 GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002434 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 /// By default, performs semantic analysis to build the new expression.
2436 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002437 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002438 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002440 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
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 __builtin_choose_expr expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002444 ///
2445 /// 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 RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002448 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002449 SourceLocation RParenLoc) {
2450 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002451 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002452 RParenLoc);
2453 }
Mike Stump11289f42009-09-09 15:08:12 +00002454
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002455 /// Build a new generic selection expression.
Peter Collingbourne91147592011-04-15 00:35:48 +00002456 ///
2457 /// By default, performs semantic analysis to build the new expression.
2458 /// Subclasses may override this routine to provide different behavior.
2459 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2460 SourceLocation DefaultLoc,
2461 SourceLocation RParenLoc,
2462 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002463 ArrayRef<TypeSourceInfo *> Types,
2464 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002465 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002466 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002467 }
2468
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002469 /// Build a new overloaded operator call expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 ///
2471 /// By default, performs semantic analysis to build the new expression.
2472 /// The semantic analysis provides the behavior of template instantiation,
2473 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002474 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 /// argument-dependent lookup, etc. Subclasses may override this routine to
2476 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002479 Expr *Callee,
2480 Expr *First,
2481 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002482
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002483 /// Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002484 /// reinterpret_cast.
2485 ///
2486 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002487 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002489 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002490 Stmt::StmtClass Class,
2491 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002492 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002493 SourceLocation RAngleLoc,
2494 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002495 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 SourceLocation RParenLoc) {
2497 switch (Class) {
2498 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002499 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002500 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002501 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002502
2503 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002504 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002505 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002506 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002507
Douglas Gregora16548e2009-08-11 05:31:07 +00002508 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002509 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002510 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002511 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002513
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002515 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002516 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002517 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002518
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002520 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002521 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
Mike Stump11289f42009-09-09 15:08:12 +00002523
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002524 /// Build a new C++ static_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002525 ///
2526 /// By default, performs semantic analysis to build the new expression.
2527 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002528 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002529 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002530 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 SourceLocation RAngleLoc,
2532 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002533 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002534 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002535 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002536 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002537 SourceRange(LAngleLoc, RAngleLoc),
2538 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 }
2540
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002541 /// Build a new C++ dynamic_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002545 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002546 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002547 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 SourceLocation RAngleLoc,
2549 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002550 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002552 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002553 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002554 SourceRange(LAngleLoc, RAngleLoc),
2555 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002556 }
2557
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002558 /// Build a new C++ reinterpret_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002562 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002564 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 SourceLocation RAngleLoc,
2566 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002567 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002568 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002569 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002570 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002571 SourceRange(LAngleLoc, RAngleLoc),
2572 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002573 }
2574
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002575 /// Build a new C++ const_cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002576 ///
2577 /// By default, performs semantic analysis to build the new expression.
2578 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002579 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002581 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 SourceLocation RAngleLoc,
2583 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002584 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002586 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002587 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002588 SourceRange(LAngleLoc, RAngleLoc),
2589 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002590 }
Mike Stump11289f42009-09-09 15:08:12 +00002591
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002592 /// Build a new C++ functional-style cast expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002593 ///
2594 /// By default, performs semantic analysis to build the new expression.
2595 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002596 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2597 SourceLocation LParenLoc,
2598 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002599 SourceLocation RParenLoc,
2600 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002601 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002602 MultiExprArg(&Sub, 1), RParenLoc,
2603 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 }
Mike Stump11289f42009-09-09 15:08:12 +00002605
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002606 /// Build a new C++ typeid(type) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 ///
2608 /// By default, performs semantic analysis to build the new expression.
2609 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002610 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002611 SourceLocation TypeidLoc,
2612 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002614 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002615 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002616 }
Mike Stump11289f42009-09-09 15:08:12 +00002617
Francois Pichet9f4f2072010-09-08 12:20:18 +00002618
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002619 /// Build a new C++ typeid(expr) expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002620 ///
2621 /// By default, performs semantic analysis to build the new expression.
2622 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002623 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002624 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002625 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002626 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002627 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002628 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002629 }
2630
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002631 /// Build a new C++ __uuidof(type) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002632 ///
2633 /// By default, performs semantic analysis to build the new expression.
2634 /// Subclasses may override this routine to provide different behavior.
2635 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2636 SourceLocation TypeidLoc,
2637 TypeSourceInfo *Operand,
2638 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002639 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002640 RParenLoc);
2641 }
2642
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002643 /// Build a new C++ __uuidof(expr) expression.
Francois Pichet9f4f2072010-09-08 12:20:18 +00002644 ///
2645 /// By default, performs semantic analysis to build the new expression.
2646 /// Subclasses may override this routine to provide different behavior.
2647 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2648 SourceLocation TypeidLoc,
2649 Expr *Operand,
2650 SourceLocation RParenLoc) {
2651 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2652 RParenLoc);
2653 }
2654
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002655 /// Build a new C++ "this" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002656 ///
2657 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002658 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002660 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002661 QualType ThisType,
2662 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002663 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002664 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002665 }
2666
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002667 /// Build a new C++ throw expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 ///
2669 /// By default, performs semantic analysis to build the new expression.
2670 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002671 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2672 bool IsThrownVariableInScope) {
2673 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002674 }
2675
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002676 /// Build a new C++ default-argument expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002677 ///
2678 /// By default, builds a new default-argument expression, which does not
2679 /// require any semantic analysis. Subclasses may override this routine to
2680 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002681 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002682 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002683 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002684 }
2685
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002686 /// Build a new C++11 default-initialization expression.
Richard Smith852c9db2013-04-20 22:23:05 +00002687 ///
2688 /// By default, builds a new default field initialization expression, which
2689 /// does not require any semantic analysis. Subclasses may override this
2690 /// routine to provide different behavior.
2691 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2692 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002693 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002694 }
2695
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002696 /// Build a new C++ zero-initialization expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002697 ///
2698 /// By default, performs semantic analysis to build the new expression.
2699 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002700 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2701 SourceLocation LParenLoc,
2702 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002703 return getSema().BuildCXXTypeConstructExpr(
2704 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 }
Mike Stump11289f42009-09-09 15:08:12 +00002706
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002707 /// Build a new C++ "new" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002708 ///
2709 /// By default, performs semantic analysis to build the new expression.
2710 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002711 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002712 bool UseGlobal,
2713 SourceLocation PlacementLParen,
2714 MultiExprArg PlacementArgs,
2715 SourceLocation PlacementRParen,
2716 SourceRange TypeIdParens,
2717 QualType AllocatedType,
2718 TypeSourceInfo *AllocatedTypeInfo,
2719 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002720 SourceRange DirectInitRange,
2721 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002722 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002723 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002724 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002725 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002726 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002727 AllocatedType,
2728 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002729 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002730 DirectInitRange,
2731 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002732 }
Mike Stump11289f42009-09-09 15:08:12 +00002733
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002734 /// Build a new C++ "delete" expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002735 ///
2736 /// By default, performs semantic analysis to build the new expression.
2737 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002738 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002739 bool IsGlobalDelete,
2740 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002741 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002742 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002743 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002744 }
Mike Stump11289f42009-09-09 15:08:12 +00002745
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002746 /// Build a new type trait expression.
Douglas Gregor29c42f22012-02-24 07:38:34 +00002747 ///
2748 /// By default, performs semantic analysis to build the new expression.
2749 /// Subclasses may override this routine to provide different behavior.
2750 ExprResult RebuildTypeTrait(TypeTrait Trait,
2751 SourceLocation StartLoc,
2752 ArrayRef<TypeSourceInfo *> Args,
2753 SourceLocation RParenLoc) {
2754 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002756
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002757 /// Build a new array type trait expression.
John Wiegley6242b6a2011-04-28 00:16:57 +00002758 ///
2759 /// By default, performs semantic analysis to build the new expression.
2760 /// Subclasses may override this routine to provide different behavior.
2761 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2762 SourceLocation StartLoc,
2763 TypeSourceInfo *TSInfo,
2764 Expr *DimExpr,
2765 SourceLocation RParenLoc) {
2766 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2767 }
2768
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002769 /// Build a new expression trait expression.
John Wiegleyf9f65842011-04-25 06:54:41 +00002770 ///
2771 /// By default, performs semantic analysis to build the new expression.
2772 /// Subclasses may override this routine to provide different behavior.
2773 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2774 SourceLocation StartLoc,
2775 Expr *Queried,
2776 SourceLocation RParenLoc) {
2777 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2778 }
2779
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002780 /// Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002781 /// expression.
2782 ///
2783 /// By default, performs semantic analysis to build the new expression.
2784 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002785 ExprResult RebuildDependentScopeDeclRefExpr(
2786 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002787 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002788 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002789 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002790 bool IsAddressOfOperand,
2791 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002792 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002793 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002794
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002795 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002796 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2797 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002798
Reid Kleckner32506ed2014-06-12 23:03:48 +00002799 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002800 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002801 }
2802
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002803 /// Build a new template-id expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002804 ///
2805 /// By default, performs semantic analysis to build the new expression.
2806 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002807 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002808 SourceLocation TemplateKWLoc,
2809 LookupResult &R,
2810 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002811 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002812 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2813 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002814 }
2815
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002816 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002820 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002821 SourceLocation Loc,
2822 CXXConstructorDecl *Constructor,
2823 bool IsElidable,
2824 MultiExprArg Args,
2825 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002826 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002827 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002828 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002829 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002830 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002831 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002832 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002833 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002834 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002835
Richard Smithc83bf822016-06-10 00:58:19 +00002836 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002837 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002838 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002839 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002840 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002841 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002842 RequiresZeroInit, ConstructKind,
2843 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002844 }
2845
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002846 /// Build a new implicit construction via inherited constructor
Richard Smith5179eb72016-06-28 19:03:57 +00002847 /// expression.
2848 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2849 CXXConstructorDecl *Constructor,
2850 bool ConstructsVBase,
2851 bool InheritedFromVBase) {
2852 return new (getSema().Context) CXXInheritedCtorInitExpr(
2853 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2854 }
2855
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002856 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002857 ///
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002860 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002861 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002862 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002863 SourceLocation RParenOrBraceLoc,
2864 bool ListInitialization) {
2865 return getSema().BuildCXXTypeConstructExpr(
2866 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002867 }
2868
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002869 /// Build a new object-construction expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002870 ///
2871 /// By default, performs semantic analysis to build the new expression.
2872 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002873 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2874 SourceLocation LParenLoc,
2875 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002876 SourceLocation RParenLoc,
2877 bool ListInitialization) {
2878 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2879 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002880 }
Mike Stump11289f42009-09-09 15:08:12 +00002881
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002882 /// Build a new member reference expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002883 ///
2884 /// By default, performs semantic analysis to build the new expression.
2885 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002886 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002887 QualType BaseType,
2888 bool IsArrow,
2889 SourceLocation OperatorLoc,
2890 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002891 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002892 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002893 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002894 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002895 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002896 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002897
John McCallb268a282010-08-23 23:25:46 +00002898 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002899 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002900 SS, TemplateKWLoc,
2901 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002902 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002903 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002904 }
2905
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002906 /// Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002907 ///
2908 /// By default, performs semantic analysis to build the new expression.
2909 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002910 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2911 SourceLocation OperatorLoc,
2912 bool IsArrow,
2913 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002914 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002915 NamedDecl *FirstQualifierInScope,
2916 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002917 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002918 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002919 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002920
John McCallb268a282010-08-23 23:25:46 +00002921 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002922 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002923 SS, TemplateKWLoc,
2924 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002925 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002926 }
Mike Stump11289f42009-09-09 15:08:12 +00002927
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002928 /// Build a new noexcept expression.
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002929 ///
2930 /// By default, performs semantic analysis to build the new expression.
2931 /// Subclasses may override this routine to provide different behavior.
2932 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2933 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2934 }
2935
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002936 /// Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002937 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2938 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002939 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002940 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002941 Optional<unsigned> Length,
2942 ArrayRef<TemplateArgument> PartialArgs) {
2943 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2944 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002945 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002946
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002947 /// Build a new Objective-C boxed expression.
Patrick Beard0caa3942012-04-19 00:25:12 +00002948 ///
2949 /// By default, performs semantic analysis to build the new expression.
2950 /// Subclasses may override this routine to provide different behavior.
2951 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2952 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2953 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002954
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002955 /// Build a new Objective-C array literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002956 ///
2957 /// By default, performs semantic analysis to build the new expression.
2958 /// Subclasses may override this routine to provide different behavior.
2959 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2960 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002961 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002962 MultiExprArg(Elements, NumElements));
2963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002964
2965 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002966 Expr *Base, Expr *Key,
2967 ObjCMethodDecl *getterMethod,
2968 ObjCMethodDecl *setterMethod) {
2969 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2970 getterMethod, setterMethod);
2971 }
2972
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002973 /// Build a new Objective-C dictionary literal.
Ted Kremeneke65b0862012-03-06 20:05:56 +00002974 ///
2975 /// By default, performs semantic analysis to build the new expression.
2976 /// Subclasses may override this routine to provide different behavior.
2977 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002978 MutableArrayRef<ObjCDictionaryElement> Elements) {
2979 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002980 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002981
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002982 /// Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002983 ///
2984 /// By default, performs semantic analysis to build the new expression.
2985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002986 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002987 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002988 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002989 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002990 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002991
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002992 /// Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002993 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002995 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002996 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002997 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002998 MultiExprArg Args,
2999 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003000 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3001 ReceiverTypeInfo->getType(),
3002 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003003 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003004 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003005 }
3006
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003007 /// Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00003008 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003009 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003010 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003011 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00003012 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003013 MultiExprArg Args,
3014 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003015 return SemaRef.BuildInstanceMessage(Receiver,
3016 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003017 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003018 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003019 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003020 }
3021
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003022 /// Build a new Objective-C instance/class message to 'super'.
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003023 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3024 Selector Sel,
3025 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003026 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003027 ObjCMethodDecl *Method,
3028 SourceLocation LBracLoc,
3029 MultiExprArg Args,
3030 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003031 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003032 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003033 SuperLoc,
3034 Sel, Method, LBracLoc, SelectorLocs,
3035 RBracLoc, Args)
3036 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003037 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003038 SuperLoc,
3039 Sel, Method, LBracLoc, SelectorLocs,
3040 RBracLoc, Args);
3041
Fangrui Song6907ce22018-07-30 19:24:48 +00003042
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003043 }
3044
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003045 /// Build a new Objective-C ivar reference expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003046 ///
3047 /// By default, performs semantic analysis to build the new expression.
3048 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003049 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003050 SourceLocation IvarLoc,
3051 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003052 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003053 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003054 ExprResult Result = getSema().BuildMemberReferenceExpr(
3055 BaseArg, BaseArg->getType(),
3056 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3057 /*FirstQualifierInScope=*/nullptr, NameInfo,
3058 /*TemplateArgs=*/nullptr,
3059 /*S=*/nullptr);
3060 if (IsFreeIvar && Result.isUsable())
3061 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3062 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003063 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003064
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003065 /// Build a new Objective-C property reference expression.
Douglas Gregor9faee212010-04-26 20:47:02 +00003066 ///
3067 /// By default, performs semantic analysis to build the new expression.
3068 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003069 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003070 ObjCPropertyDecl *Property,
3071 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003072 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003073 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3074 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3075 /*FIXME:*/PropertyLoc,
3076 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003077 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003078 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003079 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003080 /*TemplateArgs=*/nullptr,
3081 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003082 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003083
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003084 /// Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003085 ///
3086 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003087 /// Subclasses may override this routine to provide different behavior.
3088 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3089 ObjCMethodDecl *Getter,
3090 ObjCMethodDecl *Setter,
3091 SourceLocation PropertyLoc) {
3092 // Since these expressions can only be value-dependent, we do not
3093 // need to perform semantic analysis again.
3094 return Owned(
3095 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3096 VK_LValue, OK_ObjCProperty,
3097 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003098 }
3099
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003100 /// Build a new Objective-C "isa" expression.
Douglas Gregord51d90d2010-04-26 20:11:03 +00003101 ///
3102 /// By default, performs semantic analysis to build the new expression.
3103 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003104 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003105 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003106 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003107 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3108 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003109 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003110 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003111 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003112 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003113 /*TemplateArgs=*/nullptr,
3114 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003115 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003116
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003117 /// Build a new shuffle vector expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00003118 ///
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003121 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003122 MultiExprArg SubExprs,
3123 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003124 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003125 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003126 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3127 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3128 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003129 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003130
Douglas Gregora16548e2009-08-11 05:31:07 +00003131 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003132 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Bruno Ricci5fc4db72018-12-21 14:10:18 +00003133 Expr *Callee = new (SemaRef.Context)
3134 DeclRefExpr(SemaRef.Context, Builtin, false,
3135 SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc);
Eli Friedman34866c72012-08-31 00:14:07 +00003136 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3137 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003138 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003139
3140 // Build the CallExpr
Bruno Riccic5885cf2018-12-21 15:20:32 +00003141 ExprResult TheCall = CallExpr::Create(
Alp Toker314cc812014-01-25 16:55:45 +00003142 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003143 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003144
Douglas Gregora16548e2009-08-11 05:31:07 +00003145 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003146 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003147 }
John McCall31f82722010-11-12 08:19:04 +00003148
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003149 /// Build a new convert vector expression.
Hal Finkelc4d7c822013-09-18 03:29:45 +00003150 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3151 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3152 SourceLocation RParenLoc) {
3153 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3154 BuiltinLoc, RParenLoc);
3155 }
3156
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003157 /// Build a new template argument pack expansion.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003158 ///
3159 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003160 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003161 /// different behavior.
3162 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003163 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003164 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003165 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003166 case TemplateArgument::Expression: {
3167 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003168 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3169 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003170 if (Result.isInvalid())
3171 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor98318c22011-01-03 21:37:45 +00003173 return TemplateArgumentLoc(Result.get(), Result.get());
3174 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003175
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003176 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003177 return TemplateArgumentLoc(TemplateArgument(
3178 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003179 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003180 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003181 Pattern.getTemplateNameLoc(),
3182 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003183
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003184 case TemplateArgument::Null:
3185 case TemplateArgument::Integral:
3186 case TemplateArgument::Declaration:
3187 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003188 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003189 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003190 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003191
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003192 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003193 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003194 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003195 EllipsisLoc,
3196 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003197 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3198 Expansion);
3199 break;
3200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003201
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003202 return TemplateArgumentLoc();
3203 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003204
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003205 /// Build a new expression pack expansion.
Douglas Gregor968f23a2011-01-03 19:31:53 +00003206 ///
3207 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003208 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003209 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003210 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003211 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003212 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003213 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003214
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003215 /// Build a new C++1z fold-expression.
Richard Smith0f0af192014-11-08 05:07:16 +00003216 ///
3217 /// By default, performs semantic analysis in order to build a new fold
3218 /// expression.
3219 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3220 BinaryOperatorKind Operator,
3221 SourceLocation EllipsisLoc, Expr *RHS,
3222 SourceLocation RParenLoc) {
3223 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3224 RHS, RParenLoc);
3225 }
3226
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003227 /// Build an empty C++1z fold-expression with the given operator.
Richard Smith0f0af192014-11-08 05:07:16 +00003228 ///
3229 /// By default, produces the fallback value for the fold-expression, or
3230 /// produce an error if there is no fallback value.
3231 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3232 BinaryOperatorKind Operator) {
3233 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3234 }
3235
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003236 /// Build a new atomic operation expression.
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003237 ///
3238 /// By default, performs semantic analysis to build the new expression.
3239 /// Subclasses may override this routine to provide different behavior.
3240 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3241 MultiExprArg SubExprs,
3242 QualType RetTy,
3243 AtomicExpr::AtomicOp Op,
3244 SourceLocation RParenLoc) {
3245 // Just create the expression; there is not any interesting semantic
3246 // analysis here because we can't actually build an AtomicExpr until
3247 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003248 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003249 RParenLoc);
3250 }
3251
John McCall31f82722010-11-12 08:19:04 +00003252private:
Douglas Gregor14454802011-02-25 02:25:35 +00003253 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3254 QualType ObjectType,
3255 NamedDecl *FirstQualifierInScope,
3256 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003257
3258 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3259 QualType ObjectType,
3260 NamedDecl *FirstQualifierInScope,
3261 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003262
3263 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3264 NamedDecl *FirstQualifierInScope,
3265 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003266
3267 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3268 DependentNameTypeLoc TL,
3269 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003270};
Douglas Gregora16548e2009-08-11 05:31:07 +00003271
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003272template <typename Derived>
3273StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, bool DiscardedValue) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003274 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003275 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003276
Douglas Gregorebe10102009-08-20 07:17:43 +00003277 switch (S->getStmtClass()) {
3278 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 // Transform individual statement nodes
3281#define STMT(Node, Parent) \
3282 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003283#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003284#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003285#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 // Transform expressions by calling TransformExpr.
3288#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003289#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003290#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003291#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 {
John McCalldadc5752010-08-24 06:29:42 +00003293 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003294 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003295 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003296
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00003297 return getSema().ActOnExprStmt(E, DiscardedValue);
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 }
Mike Stump11289f42009-09-09 15:08:12 +00003299 }
3300
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003301 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003302}
Mike Stump11289f42009-09-09 15:08:12 +00003303
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003304template<typename Derived>
3305OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3306 if (!S)
3307 return S;
3308
3309 switch (S->getClauseKind()) {
3310 default: break;
3311 // Transform individual clause nodes
3312#define OPENMP_CLAUSE(Name, Class) \
3313 case OMPC_ ## Name : \
3314 return getDerived().Transform ## Class(cast<Class>(S));
Roman Lebedev23019f92019-01-28 17:04:11 +00003315 OPENMP_CLAUSE(flush, OMPFlushClause)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003316#include "clang/Basic/OpenMPKinds.def"
3317 }
3318
3319 return S;
3320}
3321
Mike Stump11289f42009-09-09 15:08:12 +00003322
Douglas Gregore922c772009-08-04 22:27:00 +00003323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003324ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003325 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003326 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003327
3328 switch (E->getStmtClass()) {
3329 case Stmt::NoStmtClass: break;
3330#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003331#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003332#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003333 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003334#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003335 }
3336
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003337 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003338}
3339
3340template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003341ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003342 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003343 // Initializers are instantiated like expressions, except that various outer
3344 // layers are stripped.
3345 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003346 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003347
Bill Wendling7c44da22018-10-31 03:48:47 +00003348 if (auto *FE = dyn_cast<FullExpr>(Init))
3349 Init = FE->getSubExpr();
Richard Smithd59b8322012-12-19 01:39:02 +00003350
Richard Smith410306b2016-12-12 02:53:20 +00003351 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3352 Init = AIL->getCommonExpr();
3353
Richard Smithe6ca4752013-05-30 22:40:16 +00003354 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3355 Init = MTE->GetTemporaryExpr();
3356
Richard Smithd59b8322012-12-19 01:39:02 +00003357 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3358 Init = Binder->getSubExpr();
3359
3360 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3361 Init = ICE->getSubExprAsWritten();
3362
Richard Smithcc1b96d2013-06-12 22:31:48 +00003363 if (CXXStdInitializerListExpr *ILE =
3364 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003365 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003366
Richard Smithc6abd962014-07-25 01:12:44 +00003367 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003368 // InitListExprs. Other forms of copy-initialization will be a no-op if
3369 // the initializer is already the right type.
3370 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003371 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003372 return getDerived().TransformExpr(Init);
3373
3374 // Revert value-initialization back to empty parens.
3375 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3376 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003377 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003378 Parens.getEnd());
3379 }
3380
3381 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3382 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003383 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003384 SourceLocation());
3385
3386 // Revert initialization by constructor back to a parenthesized or braced list
3387 // of expressions. Any other form of initializer can just be reused directly.
3388 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003389 return getDerived().TransformExpr(Init);
3390
Richard Smithf8adcdc2014-07-17 05:12:35 +00003391 // If the initialization implicitly converted an initializer list to a
3392 // std::initializer_list object, unwrap the std::initializer_list too.
3393 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003394 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003395
Richard Smith12938cf2018-09-26 04:36:55 +00003396 // Enter a list-init context if this was list initialization.
3397 EnterExpressionEvaluationContext Context(
3398 getSema(), EnterExpressionEvaluationContext::InitList,
3399 Construct->isListInitialization());
3400
Richard Smithd59b8322012-12-19 01:39:02 +00003401 SmallVector<Expr*, 8> NewArgs;
3402 bool ArgChanged = false;
3403 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003404 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003405 return ExprError();
3406
Richard Smithd1036122018-01-12 22:21:33 +00003407 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003408 if (Construct->isListInitialization())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00003409 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00003410 Construct->getEndLoc());
Richard Smithd59b8322012-12-19 01:39:02 +00003411
Richard Smithd59b8322012-12-19 01:39:02 +00003412 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003413 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003414 if (Parens.isInvalid()) {
3415 // This was a variable declaration's initialization for which no initializer
3416 // was specified.
3417 assert(NewArgs.empty() &&
3418 "no parens or braces but have direct init with arguments?");
3419 return ExprEmpty();
3420 }
Richard Smithd59b8322012-12-19 01:39:02 +00003421 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3422 Parens.getEnd());
3423}
3424
3425template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003426bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003427 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003428 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003429 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003430 bool *ArgChanged) {
3431 for (unsigned I = 0; I != NumInputs; ++I) {
3432 // If requested, drop call arguments that need to be dropped.
3433 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3434 if (ArgChanged)
3435 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003436
Douglas Gregora3efea12011-01-03 19:04:46 +00003437 break;
3438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor968f23a2011-01-03 19:31:53 +00003440 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3441 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003442
Chris Lattner01cf8db2011-07-20 06:58:45 +00003443 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003444 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3445 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003446
Douglas Gregor968f23a2011-01-03 19:31:53 +00003447 // Determine whether the set of unexpanded parameter packs can and should
3448 // be expanded.
3449 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003450 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003451 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3452 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003453 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3454 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003455 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003456 Expand, RetainExpansion,
3457 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003458 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003459
Douglas Gregor968f23a2011-01-03 19:31:53 +00003460 if (!Expand) {
3461 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003462 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003463 // expansion.
3464 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3465 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3466 if (OutPattern.isInvalid())
3467 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003468
3469 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003470 Expansion->getEllipsisLoc(),
3471 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003472 if (Out.isInvalid())
3473 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
Douglas Gregor968f23a2011-01-03 19:31:53 +00003475 if (ArgChanged)
3476 *ArgChanged = true;
3477 Outputs.push_back(Out.get());
3478 continue;
3479 }
John McCall542e7c62011-07-06 07:30:07 +00003480
3481 // Record right away that the argument was changed. This needs
3482 // to happen even if the array expands to nothing.
3483 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003484
Douglas Gregor968f23a2011-01-03 19:31:53 +00003485 // The transform has determined that we should perform an elementwise
3486 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003487 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003488 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3489 ExprResult Out = getDerived().TransformExpr(Pattern);
3490 if (Out.isInvalid())
3491 return true;
3492
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003493 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003494 Out = getDerived().RebuildPackExpansion(
3495 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003496 if (Out.isInvalid())
3497 return true;
3498 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003499
Douglas Gregor968f23a2011-01-03 19:31:53 +00003500 Outputs.push_back(Out.get());
3501 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003502
Richard Smith9467be42014-06-06 17:33:35 +00003503 // If we're supposed to retain a pack expansion, do so by temporarily
3504 // forgetting the partially-substituted parameter pack.
3505 if (RetainExpansion) {
3506 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3507
3508 ExprResult Out = getDerived().TransformExpr(Pattern);
3509 if (Out.isInvalid())
3510 return true;
3511
3512 Out = getDerived().RebuildPackExpansion(
3513 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3514 if (Out.isInvalid())
3515 return true;
3516
3517 Outputs.push_back(Out.get());
3518 }
3519
Douglas Gregor968f23a2011-01-03 19:31:53 +00003520 continue;
3521 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003522
Richard Smithd59b8322012-12-19 01:39:02 +00003523 ExprResult Result =
3524 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3525 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003526 if (Result.isInvalid())
3527 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003528
Douglas Gregora3efea12011-01-03 19:04:46 +00003529 if (Result.get() != Inputs[I] && ArgChanged)
3530 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003531
3532 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003533 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003534
Douglas Gregora3efea12011-01-03 19:04:46 +00003535 return false;
3536}
3537
Richard Smith03a4aa32016-06-23 19:02:52 +00003538template <typename Derived>
3539Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3540 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3541 if (Var) {
3542 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3543 getDerived().TransformDefinition(Var->getLocation(), Var));
3544
3545 if (!ConditionVar)
3546 return Sema::ConditionError();
3547
3548 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3549 }
3550
3551 if (Expr) {
3552 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3553
3554 if (CondExpr.isInvalid())
3555 return Sema::ConditionError();
3556
3557 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3558 }
3559
3560 return Sema::ConditionResult();
3561}
3562
Douglas Gregora3efea12011-01-03 19:04:46 +00003563template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003564NestedNameSpecifierLoc
3565TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3566 NestedNameSpecifierLoc NNS,
3567 QualType ObjectType,
3568 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003569 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003570 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003571 Qualifier = Qualifier.getPrefix())
3572 Qualifiers.push_back(Qualifier);
3573
3574 CXXScopeSpec SS;
3575 while (!Qualifiers.empty()) {
3576 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3577 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Douglas Gregor14454802011-02-25 02:25:35 +00003579 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003580 case NestedNameSpecifier::Identifier: {
3581 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3582 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3583 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3584 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003585 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003586 }
Douglas Gregor14454802011-02-25 02:25:35 +00003587 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregor14454802011-02-25 02:25:35 +00003589 case NestedNameSpecifier::Namespace: {
3590 NamespaceDecl *NS
3591 = cast_or_null<NamespaceDecl>(
3592 getDerived().TransformDecl(
3593 Q.getLocalBeginLoc(),
3594 QNNS->getAsNamespace()));
3595 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3596 break;
3597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003598
Douglas Gregor14454802011-02-25 02:25:35 +00003599 case NestedNameSpecifier::NamespaceAlias: {
3600 NamespaceAliasDecl *Alias
3601 = cast_or_null<NamespaceAliasDecl>(
3602 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3603 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003604 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003605 Q.getLocalEndLoc());
3606 break;
3607 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregor14454802011-02-25 02:25:35 +00003609 case NestedNameSpecifier::Global:
3610 // There is no meaningful transformation that one could perform on the
3611 // global scope.
3612 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3613 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003614
Nikola Smiljanic67860242014-09-26 00:28:20 +00003615 case NestedNameSpecifier::Super: {
3616 CXXRecordDecl *RD =
3617 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3618 SourceLocation(), QNNS->getAsRecordDecl()));
3619 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3620 break;
3621 }
3622
Douglas Gregor14454802011-02-25 02:25:35 +00003623 case NestedNameSpecifier::TypeSpecWithTemplate:
3624 case NestedNameSpecifier::TypeSpec: {
3625 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3626 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregor14454802011-02-25 02:25:35 +00003628 if (!TL)
3629 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor14454802011-02-25 02:25:35 +00003631 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003632 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003633 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003634 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003635 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003636 if (TL.getType()->isEnumeralType())
3637 SemaRef.Diag(TL.getBeginLoc(),
3638 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003639 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3640 Q.getLocalEndLoc());
3641 break;
3642 }
Richard Trieude756fb2011-05-07 01:36:37 +00003643 // If the nested-name-specifier is an invalid type def, don't emit an
3644 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003645 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3646 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003647 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003648 << TL.getType() << SS.getRange();
3649 }
Douglas Gregor14454802011-02-25 02:25:35 +00003650 return NestedNameSpecifierLoc();
3651 }
Douglas Gregore16af532011-02-28 18:50:33 +00003652 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003653
Douglas Gregore16af532011-02-28 18:50:33 +00003654 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003655 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003656 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor14454802011-02-25 02:25:35 +00003659 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003660 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003661 !getDerived().AlwaysRebuild())
3662 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
3664 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003665 // nested-name-specifier, do so.
3666 if (SS.location_size() == NNS.getDataLength() &&
3667 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3668 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3669
3670 // Allocate new nested-name-specifier location information.
3671 return SS.getWithLocInContext(SemaRef.Context);
3672}
3673
3674template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003675DeclarationNameInfo
3676TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003677::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003678 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003679 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003680 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003681
3682 switch (Name.getNameKind()) {
3683 case DeclarationName::Identifier:
3684 case DeclarationName::ObjCZeroArgSelector:
3685 case DeclarationName::ObjCOneArgSelector:
3686 case DeclarationName::ObjCMultiArgSelector:
3687 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003688 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003689 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003690 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003691
Richard Smith35845152017-02-07 01:37:30 +00003692 case DeclarationName::CXXDeductionGuideName: {
3693 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3694 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3695 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3696 if (!NewTemplate)
3697 return DeclarationNameInfo();
3698
3699 DeclarationNameInfo NewNameInfo(NameInfo);
3700 NewNameInfo.setName(
3701 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3702 return NewNameInfo;
3703 }
3704
Douglas Gregorf816bd72009-09-03 22:13:48 +00003705 case DeclarationName::CXXConstructorName:
3706 case DeclarationName::CXXDestructorName:
3707 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003708 TypeSourceInfo *NewTInfo;
3709 CanQualType NewCanTy;
3710 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003711 NewTInfo = getDerived().TransformType(OldTInfo);
3712 if (!NewTInfo)
3713 return DeclarationNameInfo();
3714 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003715 }
3716 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003717 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003718 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003719 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003720 if (NewT.isNull())
3721 return DeclarationNameInfo();
3722 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3723 }
Mike Stump11289f42009-09-09 15:08:12 +00003724
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003725 DeclarationName NewName
3726 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3727 NewCanTy);
3728 DeclarationNameInfo NewNameInfo(NameInfo);
3729 NewNameInfo.setName(NewName);
3730 NewNameInfo.setNamedTypeInfo(NewTInfo);
3731 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003732 }
Mike Stump11289f42009-09-09 15:08:12 +00003733 }
3734
David Blaikie83d382b2011-09-23 05:06:16 +00003735 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003736}
3737
3738template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003739TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003740TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3741 TemplateName Name,
3742 SourceLocation NameLoc,
3743 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003744 NamedDecl *FirstQualifierInScope,
3745 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003746 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3747 TemplateDecl *Template = QTN->getTemplateDecl();
3748 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003749
Douglas Gregor9db53502011-03-02 18:07:45 +00003750 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003751 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003752 Template));
3753 if (!TransTemplate)
3754 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregor9db53502011-03-02 18:07:45 +00003756 if (!getDerived().AlwaysRebuild() &&
3757 SS.getScopeRep() == QTN->getQualifier() &&
3758 TransTemplate == Template)
3759 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
Douglas Gregor9db53502011-03-02 18:07:45 +00003761 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3762 TransTemplate);
3763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor9db53502011-03-02 18:07:45 +00003765 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3766 if (SS.getScopeRep()) {
3767 // These apply to the scope specifier, not the template.
3768 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003769 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003770 }
3771
Douglas Gregor9db53502011-03-02 18:07:45 +00003772 if (!getDerived().AlwaysRebuild() &&
3773 SS.getScopeRep() == DTN->getQualifier() &&
3774 ObjectType.isNull())
3775 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003776
Richard Smith79810042018-05-11 02:43:08 +00003777 // FIXME: Preserve the location of the "template" keyword.
3778 SourceLocation TemplateKWLoc = NameLoc;
3779
Douglas Gregor9db53502011-03-02 18:07:45 +00003780 if (DTN->isIdentifier()) {
3781 return getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00003782 TemplateKWLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00003783 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003784 NameLoc,
3785 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003786 FirstQualifierInScope,
3787 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003788 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003789
Richard Smith79810042018-05-11 02:43:08 +00003790 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
3791 DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003792 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
Douglas Gregor9db53502011-03-02 18:07:45 +00003795 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3796 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003797 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003798 Template));
3799 if (!TransTemplate)
3800 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003801
Douglas Gregor9db53502011-03-02 18:07:45 +00003802 if (!getDerived().AlwaysRebuild() &&
3803 TransTemplate == Template)
3804 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003805
Douglas Gregor9db53502011-03-02 18:07:45 +00003806 return TemplateName(TransTemplate);
3807 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003808
Douglas Gregor9db53502011-03-02 18:07:45 +00003809 if (SubstTemplateTemplateParmPackStorage *SubstPack
3810 = Name.getAsSubstTemplateTemplateParmPack()) {
3811 TemplateTemplateParmDecl *TransParam
3812 = cast_or_null<TemplateTemplateParmDecl>(
3813 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3814 if (!TransParam)
3815 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
Douglas Gregor9db53502011-03-02 18:07:45 +00003817 if (!getDerived().AlwaysRebuild() &&
3818 TransParam == SubstPack->getParameterPack())
3819 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
3821 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003822 SubstPack->getArgumentPack());
3823 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003824
Douglas Gregor9db53502011-03-02 18:07:45 +00003825 // These should be getting filtered out before they reach the AST.
3826 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003827}
3828
3829template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003830void TreeTransform<Derived>::InventTemplateArgumentLoc(
3831 const TemplateArgument &Arg,
3832 TemplateArgumentLoc &Output) {
3833 SourceLocation Loc = getDerived().getBaseLocation();
3834 switch (Arg.getKind()) {
3835 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003836 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003837 break;
3838
3839 case TemplateArgument::Type:
3840 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003841 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003842
John McCall0ad16662009-10-29 08:12:44 +00003843 break;
3844
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003845 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003846 case TemplateArgument::TemplateExpansion: {
3847 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003848 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003849 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3850 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3851 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3852 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003853
Douglas Gregor9d802122011-03-02 17:09:35 +00003854 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003855 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003856 Builder.getWithLocInContext(SemaRef.Context),
3857 Loc);
3858 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003859 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003860 Builder.getWithLocInContext(SemaRef.Context),
3861 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003862
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003863 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003864 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003865
John McCall0ad16662009-10-29 08:12:44 +00003866 case TemplateArgument::Expression:
3867 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3868 break;
3869
3870 case TemplateArgument::Declaration:
3871 case TemplateArgument::Integral:
3872 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003873 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003874 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003875 break;
3876 }
3877}
3878
3879template<typename Derived>
3880bool TreeTransform<Derived>::TransformTemplateArgument(
3881 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003882 TemplateArgumentLoc &Output, bool Uneval) {
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00003883 EnterExpressionEvaluationContext EEEC(
3884 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated,
3885 /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
3886 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
John McCall0ad16662009-10-29 08:12:44 +00003887 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003888 switch (Arg.getKind()) {
3889 case TemplateArgument::Null:
3890 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003891 case TemplateArgument::Pack:
3892 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003893 case TemplateArgument::NullPtr:
3894 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregore922c772009-08-04 22:27:00 +00003896 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003897 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003898 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003899 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003900
3901 DI = getDerived().TransformType(DI);
3902 if (!DI) return true;
3903
3904 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3905 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003906 }
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003908 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003909 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3910 if (QualifierLoc) {
3911 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3912 if (!QualifierLoc)
3913 return true;
3914 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003915
Douglas Gregordf846d12011-03-02 18:46:51 +00003916 CXXScopeSpec SS;
3917 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003918 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003919 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3920 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003921 if (Template.isNull())
3922 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregor9d802122011-03-02 17:09:35 +00003924 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003925 Input.getTemplateNameLoc());
3926 return false;
3927 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003928
3929 case TemplateArgument::TemplateExpansion:
3930 llvm_unreachable("Caller should expand pack expansions");
3931
Douglas Gregore922c772009-08-04 22:27:00 +00003932 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003933 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003934 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003935 getSema(), Uneval
3936 ? Sema::ExpressionEvaluationContext::Unevaluated
3937 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003938
John McCall0ad16662009-10-29 08:12:44 +00003939 Expr *InputExpr = Input.getSourceExpression();
3940 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3941
Chris Lattnercdb591a2011-04-25 20:37:58 +00003942 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003943 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003944 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003945 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003946 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003947 }
Douglas Gregore922c772009-08-04 22:27:00 +00003948 }
Mike Stump11289f42009-09-09 15:08:12 +00003949
Douglas Gregore922c772009-08-04 22:27:00 +00003950 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003951 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003952}
3953
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003954/// Iterator adaptor that invents template argument location information
Douglas Gregorfe921a72010-12-20 23:36:19 +00003955/// for each of the template arguments in its underlying iterator.
3956template<typename Derived, typename InputIterator>
3957class TemplateArgumentLocInventIterator {
3958 TreeTransform<Derived> &Self;
3959 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003960
Douglas Gregorfe921a72010-12-20 23:36:19 +00003961public:
3962 typedef TemplateArgumentLoc value_type;
3963 typedef TemplateArgumentLoc reference;
3964 typedef typename std::iterator_traits<InputIterator>::difference_type
3965 difference_type;
3966 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003967
Douglas Gregorfe921a72010-12-20 23:36:19 +00003968 class pointer {
3969 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003970
Douglas Gregorfe921a72010-12-20 23:36:19 +00003971 public:
3972 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003973
Douglas Gregorfe921a72010-12-20 23:36:19 +00003974 const TemplateArgumentLoc *operator->() const { return &Arg; }
3975 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003976
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003977 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003978
Douglas Gregorfe921a72010-12-20 23:36:19 +00003979 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3980 InputIterator Iter)
3981 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003982
Douglas Gregorfe921a72010-12-20 23:36:19 +00003983 TemplateArgumentLocInventIterator &operator++() {
3984 ++Iter;
3985 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003986 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003987
Douglas Gregorfe921a72010-12-20 23:36:19 +00003988 TemplateArgumentLocInventIterator operator++(int) {
3989 TemplateArgumentLocInventIterator Old(*this);
3990 ++(*this);
3991 return Old;
3992 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003993
Douglas Gregorfe921a72010-12-20 23:36:19 +00003994 reference operator*() const {
3995 TemplateArgumentLoc Result;
3996 Self.InventTemplateArgumentLoc(*Iter, Result);
3997 return Result;
3998 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003999
Douglas Gregorfe921a72010-12-20 23:36:19 +00004000 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00004001
Douglas Gregorfe921a72010-12-20 23:36:19 +00004002 friend bool operator==(const TemplateArgumentLocInventIterator &X,
4003 const TemplateArgumentLocInventIterator &Y) {
4004 return X.Iter == Y.Iter;
4005 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00004006
Douglas Gregorfe921a72010-12-20 23:36:19 +00004007 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
4008 const TemplateArgumentLocInventIterator &Y) {
4009 return X.Iter != Y.Iter;
4010 }
4011};
Chad Rosier1dcde962012-08-08 18:46:20 +00004012
Douglas Gregor42cafa82010-12-20 17:42:22 +00004013template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00004014template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00004015bool TreeTransform<Derived>::TransformTemplateArguments(
4016 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4017 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004018 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00004019 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00004020 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00004021
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004022 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4023 // Unpack argument packs, which we translate them into separate
4024 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00004025 // FIXME: We could do much better if we could guarantee that the
4026 // TemplateArgumentLocInfo for the pack expansion would be usable for
4027 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00004028 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004029 TemplateArgument::pack_iterator>
4030 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004031 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004032 In.getArgument().pack_begin()),
4033 PackLocIterator(*this,
4034 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004035 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004036 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004037
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004038 continue;
4039 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004040
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004041 if (In.getArgument().isPackExpansion()) {
4042 // We have a pack expansion, for which we will be substituting into
4043 // the pattern.
4044 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004045 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004046 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004047 = getSema().getTemplateArgumentPackExpansionPattern(
4048 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004049
Chris Lattner01cf8db2011-07-20 06:58:45 +00004050 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004051 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4052 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004053
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004054 // Determine whether the set of unexpanded parameter packs can and should
4055 // be expanded.
4056 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004057 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004058 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004059 if (getDerived().TryExpandParameterPacks(Ellipsis,
4060 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004061 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004062 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004063 RetainExpansion,
4064 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004065 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004066
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004067 if (!Expand) {
4068 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004069 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004070 // expansion.
4071 TemplateArgumentLoc OutPattern;
4072 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004073 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004074 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004075
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004076 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4077 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004078 if (Out.getArgument().isNull())
4079 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004081 Outputs.addArgument(Out);
4082 continue;
4083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004084
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004085 // The transform has determined that we should perform an elementwise
4086 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004087 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4089
Richard Smithd784e682015-09-23 21:41:42 +00004090 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004091 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004092
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004093 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004094 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4095 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004096 if (Out.getArgument().isNull())
4097 return true;
4098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004099
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004100 Outputs.addArgument(Out);
4101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004102
Douglas Gregor48d24112011-01-10 20:53:55 +00004103 // If we're supposed to retain a pack expansion, do so by temporarily
4104 // forgetting the partially-substituted parameter pack.
4105 if (RetainExpansion) {
4106 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004107
Richard Smithd784e682015-09-23 21:41:42 +00004108 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004109 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004110
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004111 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4112 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004113 if (Out.getArgument().isNull())
4114 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004115
Douglas Gregor48d24112011-01-10 20:53:55 +00004116 Outputs.addArgument(Out);
4117 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004118
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004119 continue;
4120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004121
4122 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004123 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004124 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004125
Douglas Gregor42cafa82010-12-20 17:42:22 +00004126 Outputs.addArgument(Out);
4127 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004128
Douglas Gregor42cafa82010-12-20 17:42:22 +00004129 return false;
4130
4131}
4132
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133//===----------------------------------------------------------------------===//
4134// Type transformation
4135//===----------------------------------------------------------------------===//
4136
4137template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004138QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139 if (getDerived().AlreadyTransformed(T))
4140 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004141
John McCall550e0c22009-10-21 00:40:46 +00004142 // Temporary workaround. All of these transformations should
4143 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004144 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4145 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004146
John McCall31f82722010-11-12 08:19:04 +00004147 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004148
John McCall550e0c22009-10-21 00:40:46 +00004149 if (!NewDI)
4150 return QualType();
4151
4152 return NewDI->getType();
4153}
4154
4155template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004156TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004157 // Refine the base location to the type's location.
4158 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4159 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004160 if (getDerived().AlreadyTransformed(DI->getType()))
4161 return DI;
4162
4163 TypeLocBuilder TLB;
4164
4165 TypeLoc TL = DI->getTypeLoc();
4166 TLB.reserve(TL.getFullDataSize());
4167
John McCall31f82722010-11-12 08:19:04 +00004168 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004169 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004170 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004171
John McCallbcd03502009-12-07 02:54:59 +00004172 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004173}
4174
4175template<typename Derived>
4176QualType
John McCall31f82722010-11-12 08:19:04 +00004177TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004178 switch (T.getTypeLocClass()) {
4179#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004180#define TYPELOC(CLASS, PARENT) \
4181 case TypeLoc::CLASS: \
4182 return getDerived().Transform##CLASS##Type(TLB, \
4183 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004184#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004185 }
Mike Stump11289f42009-09-09 15:08:12 +00004186
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004187 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004188}
4189
Richard Smithee579842017-01-30 20:39:26 +00004190template<typename Derived>
4191QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4192 if (!isa<DependentNameType>(T))
4193 return TransformType(T);
4194
4195 if (getDerived().AlreadyTransformed(T))
4196 return T;
4197 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4198 getDerived().getBaseLocation());
4199 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4200 return NewDI ? NewDI->getType() : QualType();
4201}
4202
4203template<typename Derived>
4204TypeSourceInfo *
4205TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4206 if (!isa<DependentNameType>(DI->getType()))
4207 return TransformType(DI);
4208
4209 // Refine the base location to the type's location.
4210 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4211 getDerived().getBaseEntity());
4212 if (getDerived().AlreadyTransformed(DI->getType()))
4213 return DI;
4214
4215 TypeLocBuilder TLB;
4216
4217 TypeLoc TL = DI->getTypeLoc();
4218 TLB.reserve(TL.getFullDataSize());
4219
Richard Smithee579842017-01-30 20:39:26 +00004220 auto QTL = TL.getAs<QualifiedTypeLoc>();
4221 if (QTL)
4222 TL = QTL.getUnqualifiedLoc();
4223
4224 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4225
4226 QualType Result = getDerived().TransformDependentNameType(
4227 TLB, DNTL, /*DeducedTSTContext*/true);
4228 if (Result.isNull())
4229 return nullptr;
4230
4231 if (QTL) {
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004232 Result = getDerived().RebuildQualifiedType(Result, QTL);
4233 if (Result.isNull())
4234 return nullptr;
Richard Smithee579842017-01-30 20:39:26 +00004235 TLB.TypeWasModifiedSafely(Result);
4236 }
4237
4238 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4239}
4240
John McCall550e0c22009-10-21 00:40:46 +00004241template<typename Derived>
4242QualType
4243TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004244 QualifiedTypeLoc T) {
John McCall31f82722010-11-12 08:19:04 +00004245 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004246 if (Result.isNull())
4247 return QualType();
4248
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004249 Result = getDerived().RebuildQualifiedType(Result, T);
4250
4251 if (Result.isNull())
4252 return QualType();
Richard Smithee579842017-01-30 20:39:26 +00004253
4254 // RebuildQualifiedType might have updated the type, but not in a way
4255 // that invalidates the TypeLoc. (There's no location information for
4256 // qualifiers.)
4257 TLB.TypeWasModifiedSafely(Result);
4258
4259 return Result;
4260}
4261
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004262template <typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00004263QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
Anastasia Stulova12e3a8a2018-12-05 17:02:22 +00004264 QualifiedTypeLoc TL) {
4265
4266 SourceLocation Loc = TL.getBeginLoc();
4267 Qualifiers Quals = TL.getType().getLocalQualifiers();
4268
4269 if (((T.getAddressSpace() != LangAS::Default &&
4270 Quals.getAddressSpace() != LangAS::Default)) &&
4271 T.getAddressSpace() != Quals.getAddressSpace()) {
4272 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
4273 << TL.getType() << T;
4274 return QualType();
4275 }
4276
Richard Smithee579842017-01-30 20:39:26 +00004277 // C++ [dcl.fct]p7:
4278 // [When] adding cv-qualifications on top of the function type [...] the
4279 // cv-qualifiers are ignored.
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004280 if (T->isFunctionType()) {
4281 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
4282 Quals.getAddressSpace());
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004283 return T;
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00004284 }
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004285
Richard Smithee579842017-01-30 20:39:26 +00004286 // C++ [dcl.ref]p1:
4287 // when the cv-qualifiers are introduced through the use of a typedef-name
4288 // or decltype-specifier [...] the cv-qualifiers are ignored.
4289 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4290 // applied to a reference type.
Erik Pilkingtonf4523372018-09-20 18:12:24 +00004291 if (T->isReferenceType()) {
4292 // The only qualifier that applies to a reference type is restrict.
4293 if (!Quals.hasRestrict())
4294 return T;
4295 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
4296 }
Mike Stump11289f42009-09-09 15:08:12 +00004297
John McCall31168b02011-06-15 23:02:42 +00004298 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004299 // resulting type.
4300 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004301 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004302 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004303 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004304 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004305 // A lifetime qualifier applied to a substituted template parameter
4306 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004307 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004308 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004309 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004310 QualType Replacement = SubstTypeParam->getReplacementType();
4311 Qualifiers Qs = Replacement.getQualifiers();
4312 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004313 Replacement = SemaRef.Context.getQualifiedType(
4314 Replacement.getUnqualifiedType(), Qs);
4315 T = SemaRef.Context.getSubstTemplateTypeParmType(
4316 SubstTypeParam->getReplacedParameter(), Replacement);
4317 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004318 // 'auto' types behave the same way as template parameters.
4319 QualType Deduced = AutoTy->getDeducedType();
4320 Qualifiers Qs = Deduced.getQualifiers();
4321 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004322 Deduced =
4323 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4324 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4325 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004326 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004327 // Otherwise, complain about the addition of a qualifier to an
4328 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004329 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4330 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004331 Quals.removeObjCLifetime();
4332 }
4333 }
4334 }
John McCall550e0c22009-10-21 00:40:46 +00004335
Richard Smithee579842017-01-30 20:39:26 +00004336 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004337}
4338
Douglas Gregor14454802011-02-25 02:25:35 +00004339template<typename Derived>
4340TypeLoc
4341TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4342 QualType ObjectType,
4343 NamedDecl *UnqualLookup,
4344 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004345 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004346 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004348 TypeSourceInfo *TSI =
4349 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4350 if (TSI)
4351 return TSI->getTypeLoc();
4352 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004353}
4354
Douglas Gregor579c15f2011-03-02 18:32:08 +00004355template<typename Derived>
4356TypeSourceInfo *
4357TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4358 QualType ObjectType,
4359 NamedDecl *UnqualLookup,
4360 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004361 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004362 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004363
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004364 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4365 UnqualLookup, SS);
4366}
4367
4368template <typename Derived>
4369TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4370 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4371 CXXScopeSpec &SS) {
4372 QualType T = TL.getType();
4373 assert(!getDerived().AlreadyTransformed(T));
4374
Douglas Gregor579c15f2011-03-02 18:32:08 +00004375 TypeLocBuilder TLB;
4376 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004377
Douglas Gregor579c15f2011-03-02 18:32:08 +00004378 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004379 TemplateSpecializationTypeLoc SpecTL =
4380 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004381
Richard Smithfd3dae02017-01-20 00:20:39 +00004382 TemplateName Template = getDerived().TransformTemplateName(
4383 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4384 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004385 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004386 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004387
4388 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004389 Template);
4390 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004391 DependentTemplateSpecializationTypeLoc SpecTL =
4392 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004393
Douglas Gregor579c15f2011-03-02 18:32:08 +00004394 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004395 = getDerived().RebuildTemplateName(SS,
Richard Smith79810042018-05-11 02:43:08 +00004396 SpecTL.getTemplateKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004397 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004398 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004399 ObjectType, UnqualLookup,
4400 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004401 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004402 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004403
4404 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004405 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004406 Template,
4407 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004408 } else {
4409 // Nothing special needs to be done for these.
4410 Result = getDerived().TransformType(TLB, TL);
4411 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004412
4413 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004414 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004415
Douglas Gregor579c15f2011-03-02 18:32:08 +00004416 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4417}
4418
John McCall550e0c22009-10-21 00:40:46 +00004419template <class TyLoc> static inline
4420QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4421 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4422 NewT.setNameLoc(T.getNameLoc());
4423 return T.getType();
4424}
4425
John McCall550e0c22009-10-21 00:40:46 +00004426template<typename Derived>
4427QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004428 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004429 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4430 NewT.setBuiltinLoc(T.getBuiltinLoc());
4431 if (T.needsExtraLocalData())
4432 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4433 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregord6ff3322009-08-04 16:50:30 +00004436template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004437QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004438 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004439 // FIXME: recurse?
4440 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004441}
Mike Stump11289f42009-09-09 15:08:12 +00004442
Reid Kleckner0503a872013-12-05 01:23:43 +00004443template <typename Derived>
4444QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4445 AdjustedTypeLoc TL) {
4446 // Adjustments applied during transformation are handled elsewhere.
4447 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4448}
4449
Douglas Gregord6ff3322009-08-04 16:50:30 +00004450template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004451QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4452 DecayedTypeLoc TL) {
4453 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4454 if (OriginalType.isNull())
4455 return QualType();
4456
4457 QualType Result = TL.getType();
4458 if (getDerived().AlwaysRebuild() ||
4459 OriginalType != TL.getOriginalLoc().getType())
4460 Result = SemaRef.Context.getDecayedType(OriginalType);
4461 TLB.push<DecayedTypeLoc>(Result);
4462 // Nothing to set for DecayedTypeLoc.
4463 return Result;
4464}
4465
4466template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004467QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004468 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004469 QualType PointeeType
4470 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004471 if (PointeeType.isNull())
4472 return QualType();
4473
4474 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004475 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004476 // A dependent pointer type 'T *' has is being transformed such
4477 // that an Objective-C class type is being replaced for 'T'. The
4478 // resulting pointer type is an ObjCObjectPointerType, not a
4479 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004480 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004481
John McCall8b07ec22010-05-15 11:32:37 +00004482 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4483 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004484 return Result;
4485 }
John McCall31f82722010-11-12 08:19:04 +00004486
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004487 if (getDerived().AlwaysRebuild() ||
4488 PointeeType != TL.getPointeeLoc().getType()) {
4489 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4490 if (Result.isNull())
4491 return QualType();
4492 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004493
John McCall31168b02011-06-15 23:02:42 +00004494 // Objective-C ARC can add lifetime qualifiers to the type that we're
4495 // pointing to.
4496 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004497
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004498 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4499 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004500 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004501}
Mike Stump11289f42009-09-09 15:08:12 +00004502
4503template<typename Derived>
4504QualType
John McCall550e0c22009-10-21 00:40:46 +00004505TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004506 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004507 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004508 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4509 if (PointeeType.isNull())
4510 return QualType();
4511
4512 QualType Result = TL.getType();
4513 if (getDerived().AlwaysRebuild() ||
4514 PointeeType != TL.getPointeeLoc().getType()) {
4515 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004516 TL.getSigilLoc());
4517 if (Result.isNull())
4518 return QualType();
4519 }
4520
Douglas Gregor049211a2010-04-22 16:50:51 +00004521 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004522 NewT.setSigilLoc(TL.getSigilLoc());
4523 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004524}
4525
John McCall70dd5f62009-10-30 00:06:24 +00004526/// Transforms a reference type. Note that somewhat paradoxically we
4527/// don't care whether the type itself is an l-value type or an r-value
4528/// type; we only care if the type was *written* as an l-value type
4529/// or an r-value type.
4530template<typename Derived>
4531QualType
4532TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004533 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004534 const ReferenceType *T = TL.getTypePtr();
4535
4536 // Note that this works with the pointee-as-written.
4537 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4538 if (PointeeType.isNull())
4539 return QualType();
4540
4541 QualType Result = TL.getType();
4542 if (getDerived().AlwaysRebuild() ||
4543 PointeeType != T->getPointeeTypeAsWritten()) {
4544 Result = getDerived().RebuildReferenceType(PointeeType,
4545 T->isSpelledAsLValue(),
4546 TL.getSigilLoc());
4547 if (Result.isNull())
4548 return QualType();
4549 }
4550
John McCall31168b02011-06-15 23:02:42 +00004551 // Objective-C ARC can add lifetime qualifiers to the type that we're
4552 // referring to.
4553 TLB.TypeWasModifiedSafely(
4554 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4555
John McCall70dd5f62009-10-30 00:06:24 +00004556 // r-value references can be rebuilt as l-value references.
4557 ReferenceTypeLoc NewTL;
4558 if (isa<LValueReferenceType>(Result))
4559 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4560 else
4561 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4562 NewTL.setSigilLoc(TL.getSigilLoc());
4563
4564 return Result;
4565}
4566
Mike Stump11289f42009-09-09 15:08:12 +00004567template<typename Derived>
4568QualType
John McCall550e0c22009-10-21 00:40:46 +00004569TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004570 LValueReferenceTypeLoc TL) {
4571 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004572}
4573
Mike Stump11289f42009-09-09 15:08:12 +00004574template<typename Derived>
4575QualType
John McCall550e0c22009-10-21 00:40:46 +00004576TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004577 RValueReferenceTypeLoc TL) {
4578 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004579}
Mike Stump11289f42009-09-09 15:08:12 +00004580
Douglas Gregord6ff3322009-08-04 16:50:30 +00004581template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004582QualType
John McCall550e0c22009-10-21 00:40:46 +00004583TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004584 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004585 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586 if (PointeeType.isNull())
4587 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004588
Abramo Bagnara509357842011-03-05 14:42:21 +00004589 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004590 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004591 if (OldClsTInfo) {
4592 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4593 if (!NewClsTInfo)
4594 return QualType();
4595 }
4596
4597 const MemberPointerType *T = TL.getTypePtr();
4598 QualType OldClsType = QualType(T->getClass(), 0);
4599 QualType NewClsType;
4600 if (NewClsTInfo)
4601 NewClsType = NewClsTInfo->getType();
4602 else {
4603 NewClsType = getDerived().TransformType(OldClsType);
4604 if (NewClsType.isNull())
4605 return QualType();
4606 }
Mike Stump11289f42009-09-09 15:08:12 +00004607
John McCall550e0c22009-10-21 00:40:46 +00004608 QualType Result = TL.getType();
4609 if (getDerived().AlwaysRebuild() ||
4610 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004611 NewClsType != OldClsType) {
4612 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004613 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004614 if (Result.isNull())
4615 return QualType();
4616 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004617
Reid Kleckner0503a872013-12-05 01:23:43 +00004618 // If we had to adjust the pointee type when building a member pointer, make
4619 // sure to push TypeLoc info for it.
4620 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4621 if (MPT && PointeeType != MPT->getPointeeType()) {
4622 assert(isa<AdjustedType>(MPT->getPointeeType()));
4623 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4624 }
4625
John McCall550e0c22009-10-21 00:40:46 +00004626 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4627 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004628 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004629
4630 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004631}
4632
Mike Stump11289f42009-09-09 15:08:12 +00004633template<typename Derived>
4634QualType
John McCall550e0c22009-10-21 00:40:46 +00004635TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004636 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004637 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004638 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004639 if (ElementType.isNull())
4640 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004641
John McCall550e0c22009-10-21 00:40:46 +00004642 QualType Result = TL.getType();
4643 if (getDerived().AlwaysRebuild() ||
4644 ElementType != T->getElementType()) {
4645 Result = getDerived().RebuildConstantArrayType(ElementType,
4646 T->getSizeModifier(),
4647 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004648 T->getIndexTypeCVRQualifiers(),
4649 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004650 if (Result.isNull())
4651 return QualType();
4652 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004653
4654 // We might have either a ConstantArrayType or a VariableArrayType now:
4655 // a ConstantArrayType is allowed to have an element type which is a
4656 // VariableArrayType if the type is dependent. Fortunately, all array
4657 // types have the same location layout.
4658 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004659 NewTL.setLBracketLoc(TL.getLBracketLoc());
4660 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004661
John McCall550e0c22009-10-21 00:40:46 +00004662 Expr *Size = TL.getSizeExpr();
4663 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004664 EnterExpressionEvaluationContext Unevaluated(
4665 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004666 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4667 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004668 }
4669 NewTL.setSizeExpr(Size);
4670
4671 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004672}
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregord6ff3322009-08-04 16:50:30 +00004674template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004675QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004676 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004677 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004678 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004679 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004680 if (ElementType.isNull())
4681 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004682
John McCall550e0c22009-10-21 00:40:46 +00004683 QualType Result = TL.getType();
4684 if (getDerived().AlwaysRebuild() ||
4685 ElementType != T->getElementType()) {
4686 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004687 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004688 T->getIndexTypeCVRQualifiers(),
4689 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004690 if (Result.isNull())
4691 return QualType();
4692 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004693
John McCall550e0c22009-10-21 00:40:46 +00004694 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4695 NewTL.setLBracketLoc(TL.getLBracketLoc());
4696 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004697 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004698
4699 return Result;
4700}
4701
4702template<typename Derived>
4703QualType
4704TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004705 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004706 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004707 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4708 if (ElementType.isNull())
4709 return QualType();
4710
Tim Shenb34d0ef2017-02-14 23:46:37 +00004711 ExprResult SizeResult;
4712 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004713 EnterExpressionEvaluationContext Context(
4714 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004715 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4716 }
4717 if (SizeResult.isInvalid())
4718 return QualType();
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00004719 SizeResult =
4720 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
John McCall550e0c22009-10-21 00:40:46 +00004721 if (SizeResult.isInvalid())
4722 return QualType();
4723
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004724 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004725
4726 QualType Result = TL.getType();
4727 if (getDerived().AlwaysRebuild() ||
4728 ElementType != T->getElementType() ||
4729 Size != T->getSizeExpr()) {
4730 Result = getDerived().RebuildVariableArrayType(ElementType,
4731 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004732 Size,
John McCall550e0c22009-10-21 00:40:46 +00004733 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004734 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004735 if (Result.isNull())
4736 return QualType();
4737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004738
Serge Pavlov774c6d02014-02-06 03:49:11 +00004739 // We might have constant size array now, but fortunately it has the same
4740 // location layout.
4741 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004742 NewTL.setLBracketLoc(TL.getLBracketLoc());
4743 NewTL.setRBracketLoc(TL.getRBracketLoc());
4744 NewTL.setSizeExpr(Size);
4745
4746 return Result;
4747}
4748
4749template<typename Derived>
4750QualType
4751TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004752 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004753 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004754 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4755 if (ElementType.isNull())
4756 return QualType();
4757
Richard Smith764d2fe2011-12-20 02:08:33 +00004758 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004759 EnterExpressionEvaluationContext Unevaluated(
4760 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004761
John McCall33ddac02011-01-19 10:06:00 +00004762 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4763 Expr *origSize = TL.getSizeExpr();
4764 if (!origSize) origSize = T->getSizeExpr();
4765
4766 ExprResult sizeResult
4767 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004768 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004769 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004770 return QualType();
4771
John McCall33ddac02011-01-19 10:06:00 +00004772 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004773
4774 QualType Result = TL.getType();
4775 if (getDerived().AlwaysRebuild() ||
4776 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004777 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004778 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4779 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004780 size,
John McCall550e0c22009-10-21 00:40:46 +00004781 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004782 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004783 if (Result.isNull())
4784 return QualType();
4785 }
John McCall550e0c22009-10-21 00:40:46 +00004786
4787 // We might have any sort of array type now, but fortunately they
4788 // all have the same location layout.
4789 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4790 NewTL.setLBracketLoc(TL.getLBracketLoc());
4791 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004792 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004793
4794 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004795}
Mike Stump11289f42009-09-09 15:08:12 +00004796
Erich Keanef702b022018-07-13 19:46:04 +00004797template <typename Derived>
4798QualType TreeTransform<Derived>::TransformDependentVectorType(
4799 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
4800 const DependentVectorType *T = TL.getTypePtr();
4801 QualType ElementType = getDerived().TransformType(T->getElementType());
4802 if (ElementType.isNull())
4803 return QualType();
4804
4805 EnterExpressionEvaluationContext Unevaluated(
4806 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4807
4808 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
4809 Size = SemaRef.ActOnConstantExpression(Size);
4810 if (Size.isInvalid())
4811 return QualType();
4812
4813 QualType Result = TL.getType();
4814 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
4815 Size.get() != T->getSizeExpr()) {
4816 Result = getDerived().RebuildDependentVectorType(
4817 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
4818 if (Result.isNull())
4819 return QualType();
4820 }
4821
4822 // Result might be dependent or not.
4823 if (isa<DependentVectorType>(Result)) {
4824 DependentVectorTypeLoc NewTL =
4825 TLB.push<DependentVectorTypeLoc>(Result);
4826 NewTL.setNameLoc(TL.getNameLoc());
4827 } else {
4828 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4829 NewTL.setNameLoc(TL.getNameLoc());
4830 }
4831
4832 return Result;
4833}
4834
Mike Stump11289f42009-09-09 15:08:12 +00004835template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004836QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004837 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004838 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004839 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004840
4841 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004842 QualType ElementType = getDerived().TransformType(T->getElementType());
4843 if (ElementType.isNull())
4844 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004845
Richard Smith764d2fe2011-12-20 02:08:33 +00004846 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004847 EnterExpressionEvaluationContext Unevaluated(
4848 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004849
John McCalldadc5752010-08-24 06:29:42 +00004850 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004851 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004852 if (Size.isInvalid())
4853 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004854
John McCall550e0c22009-10-21 00:40:46 +00004855 QualType Result = TL.getType();
4856 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004857 ElementType != T->getElementType() ||
4858 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004859 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004860 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004861 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004862 if (Result.isNull())
4863 return QualType();
4864 }
John McCall550e0c22009-10-21 00:40:46 +00004865
4866 // Result might be dependent or not.
4867 if (isa<DependentSizedExtVectorType>(Result)) {
4868 DependentSizedExtVectorTypeLoc NewTL
4869 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4870 NewTL.setNameLoc(TL.getNameLoc());
4871 } else {
4872 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4873 NewTL.setNameLoc(TL.getNameLoc());
4874 }
4875
4876 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004877}
Mike Stump11289f42009-09-09 15:08:12 +00004878
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004879template <typename Derived>
4880QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4881 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4882 const DependentAddressSpaceType *T = TL.getTypePtr();
4883
4884 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4885
4886 if (pointeeType.isNull())
4887 return QualType();
4888
4889 // Address spaces are constant expressions.
4890 EnterExpressionEvaluationContext Unevaluated(
4891 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4892
4893 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4894 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4895 if (AddrSpace.isInvalid())
4896 return QualType();
4897
4898 QualType Result = TL.getType();
4899 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4900 AddrSpace.get() != T->getAddrSpaceExpr()) {
4901 Result = getDerived().RebuildDependentAddressSpaceType(
4902 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4903 if (Result.isNull())
4904 return QualType();
4905 }
4906
4907 // Result might be dependent or not.
4908 if (isa<DependentAddressSpaceType>(Result)) {
4909 DependentAddressSpaceTypeLoc NewTL =
4910 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4911
4912 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4913 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4914 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4915
4916 } else {
4917 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4918 Result, getDerived().getBaseLocation());
4919 TransformType(TLB, DI->getTypeLoc());
4920 }
4921
4922 return Result;
4923}
4924
4925template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004926QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004927 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004928 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004929 QualType ElementType = getDerived().TransformType(T->getElementType());
4930 if (ElementType.isNull())
4931 return QualType();
4932
John McCall550e0c22009-10-21 00:40:46 +00004933 QualType Result = TL.getType();
4934 if (getDerived().AlwaysRebuild() ||
4935 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004936 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004937 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004938 if (Result.isNull())
4939 return QualType();
4940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004941
John McCall550e0c22009-10-21 00:40:46 +00004942 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4943 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004944
John McCall550e0c22009-10-21 00:40:46 +00004945 return Result;
4946}
4947
4948template<typename Derived>
4949QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004950 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004951 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004952 QualType ElementType = getDerived().TransformType(T->getElementType());
4953 if (ElementType.isNull())
4954 return QualType();
4955
4956 QualType Result = TL.getType();
4957 if (getDerived().AlwaysRebuild() ||
4958 ElementType != T->getElementType()) {
4959 Result = getDerived().RebuildExtVectorType(ElementType,
4960 T->getNumElements(),
4961 /*FIXME*/ SourceLocation());
4962 if (Result.isNull())
4963 return QualType();
4964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004965
John McCall550e0c22009-10-21 00:40:46 +00004966 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4967 NewTL.setNameLoc(TL.getNameLoc());
4968
4969 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004970}
Mike Stump11289f42009-09-09 15:08:12 +00004971
David Blaikie05785d12013-02-20 22:23:23 +00004972template <typename Derived>
4973ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4974 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4975 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004976 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004977 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004978
Douglas Gregor715e4612011-01-14 22:40:04 +00004979 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004980 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004981 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004982 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004983 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004984
Douglas Gregor715e4612011-01-14 22:40:04 +00004985 TypeLocBuilder TLB;
4986 TypeLoc NewTL = OldDI->getTypeLoc();
4987 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004988
4989 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004990 OldExpansionTL.getPatternLoc());
4991 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004992 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004993
4994 Result = RebuildPackExpansionType(Result,
4995 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004996 OldExpansionTL.getEllipsisLoc(),
4997 NumExpansions);
4998 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004999 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00005000
Douglas Gregor715e4612011-01-14 22:40:04 +00005001 PackExpansionTypeLoc NewExpansionTL
5002 = TLB.push<PackExpansionTypeLoc>(Result);
5003 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5004 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5005 } else
5006 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00005007 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00005008 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00005009
John McCall8fb0d9d2011-05-01 22:35:37 +00005010 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00005011 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00005012
5013 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5014 OldParm->getDeclContext(),
5015 OldParm->getInnerLocStart(),
5016 OldParm->getLocation(),
5017 OldParm->getIdentifier(),
5018 NewDI->getType(),
5019 NewDI,
5020 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00005021 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00005022 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5023 OldParm->getFunctionScopeIndex() + indexAdjustment);
5024 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00005025}
5026
David Majnemer59f77922016-06-24 04:05:48 +00005027template <typename Derived>
5028bool TreeTransform<Derived>::TransformFunctionTypeParams(
5029 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
5030 const QualType *ParamTypes,
5031 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5032 SmallVectorImpl<QualType> &OutParamTypes,
5033 SmallVectorImpl<ParmVarDecl *> *PVars,
5034 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005035 int indexAdjustment = 0;
5036
David Majnemer59f77922016-06-24 04:05:48 +00005037 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00005038 for (unsigned i = 0; i != NumParams; ++i) {
5039 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00005040 assert(OldParm->getFunctionScopeIndex() == i);
5041
David Blaikie05785d12013-02-20 22:23:23 +00005042 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00005043 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00005044 if (OldParm->isParameterPack()) {
5045 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00005046 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00005047
Douglas Gregor5499af42011-01-05 23:12:31 +00005048 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005049 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00005050 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005051 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5052 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005053 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
5054
Douglas Gregor5499af42011-01-05 23:12:31 +00005055 // Determine whether we should expand the parameter packs.
5056 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005057 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005058 Optional<unsigned> OrigNumExpansions =
5059 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00005060 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00005061 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5062 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005063 Unexpanded,
5064 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005065 RetainExpansion,
5066 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005067 return true;
5068 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005069
Douglas Gregor5499af42011-01-05 23:12:31 +00005070 if (ShouldExpand) {
5071 // Expand the function parameter pack into multiple, separate
5072 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00005073 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005074 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005075 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00005076 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005077 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005078 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005079 OrigNumExpansions,
5080 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005081 if (!NewParm)
5082 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005083
John McCallc8e321d2016-03-01 02:09:25 +00005084 if (ParamInfos)
5085 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005086 OutParamTypes.push_back(NewParm->getType());
5087 if (PVars)
5088 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005089 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005090
5091 // If we're supposed to retain a pack expansion, do so by temporarily
5092 // forgetting the partially-substituted parameter pack.
5093 if (RetainExpansion) {
5094 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005095 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005096 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005097 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005098 OrigNumExpansions,
5099 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005100 if (!NewParm)
5101 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005102
John McCallc8e321d2016-03-01 02:09:25 +00005103 if (ParamInfos)
5104 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005105 OutParamTypes.push_back(NewParm->getType());
5106 if (PVars)
5107 PVars->push_back(NewParm);
5108 }
5109
John McCall8fb0d9d2011-05-01 22:35:37 +00005110 // The next parameter should have the same adjustment as the
5111 // last thing we pushed, but we post-incremented indexAdjustment
5112 // on every push. Also, if we push nothing, the adjustment should
5113 // go down by one.
5114 indexAdjustment--;
5115
Douglas Gregor5499af42011-01-05 23:12:31 +00005116 // We're done with the pack expansion.
5117 continue;
5118 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005119
5120 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005121 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005122 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5123 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005124 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005125 NumExpansions,
5126 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005127 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005128 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005129 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005130 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005131
John McCall58f10c32010-03-11 09:03:00 +00005132 if (!NewParm)
5133 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005134
John McCallc8e321d2016-03-01 02:09:25 +00005135 if (ParamInfos)
5136 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005137 OutParamTypes.push_back(NewParm->getType());
5138 if (PVars)
5139 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005140 continue;
5141 }
John McCall58f10c32010-03-11 09:03:00 +00005142
5143 // Deal with the possibility that we don't have a parameter
5144 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005145 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005146 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005147 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005148 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005149 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005150 = dyn_cast<PackExpansionType>(OldType)) {
5151 // We have a function parameter pack that may need to be expanded.
5152 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005153 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005154 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005155
Douglas Gregor5499af42011-01-05 23:12:31 +00005156 // Determine whether we should expand the parameter packs.
5157 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005158 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005159 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005160 Unexpanded,
5161 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005162 RetainExpansion,
5163 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005164 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005166
Douglas Gregor5499af42011-01-05 23:12:31 +00005167 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005168 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005169 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005170 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005171 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5172 QualType NewType = getDerived().TransformType(Pattern);
5173 if (NewType.isNull())
5174 return true;
John McCall58f10c32010-03-11 09:03:00 +00005175
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005176 if (NewType->containsUnexpandedParameterPack()) {
5177 NewType =
5178 getSema().getASTContext().getPackExpansionType(NewType, None);
5179
5180 if (NewType.isNull())
5181 return true;
5182 }
5183
John McCallc8e321d2016-03-01 02:09:25 +00005184 if (ParamInfos)
5185 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005186 OutParamTypes.push_back(NewType);
5187 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005188 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005189 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005190
Douglas Gregor5499af42011-01-05 23:12:31 +00005191 // We're done with the pack expansion.
5192 continue;
5193 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005194
Douglas Gregor48d24112011-01-10 20:53:55 +00005195 // If we're supposed to retain a pack expansion, do so by temporarily
5196 // forgetting the partially-substituted parameter pack.
5197 if (RetainExpansion) {
5198 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5199 QualType NewType = getDerived().TransformType(Pattern);
5200 if (NewType.isNull())
5201 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
John McCallc8e321d2016-03-01 02:09:25 +00005203 if (ParamInfos)
5204 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005205 OutParamTypes.push_back(NewType);
5206 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005207 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005208 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005209
Chad Rosier1dcde962012-08-08 18:46:20 +00005210 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005211 // expansion.
5212 OldType = Expansion->getPattern();
5213 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005214 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5215 NewType = getDerived().TransformType(OldType);
5216 } else {
5217 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005218 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005219
Douglas Gregor5499af42011-01-05 23:12:31 +00005220 if (NewType.isNull())
5221 return true;
5222
5223 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005224 NewType = getSema().Context.getPackExpansionType(NewType,
5225 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005226
John McCallc8e321d2016-03-01 02:09:25 +00005227 if (ParamInfos)
5228 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005229 OutParamTypes.push_back(NewType);
5230 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005231 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005232 }
5233
John McCall8fb0d9d2011-05-01 22:35:37 +00005234#ifndef NDEBUG
5235 if (PVars) {
5236 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5237 if (ParmVarDecl *parm = (*PVars)[i])
5238 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005239 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005240#endif
5241
5242 return false;
5243}
John McCall58f10c32010-03-11 09:03:00 +00005244
5245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005246QualType
John McCall550e0c22009-10-21 00:40:46 +00005247TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005248 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005249 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005250 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005251 return getDerived().TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005252 TLB, TL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +00005253 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5254 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5255 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005256 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005257}
5258
Richard Smith2e321552014-11-12 02:00:47 +00005259template<typename Derived> template<typename Fn>
5260QualType TreeTransform<Derived>::TransformFunctionProtoType(
5261 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
Mikael Nilsson9d2872d2018-12-13 10:15:27 +00005262 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005263
Douglas Gregor4afc2362010-08-31 00:26:14 +00005264 // Transform the parameters and return type.
5265 //
Richard Smithf623c962012-04-17 00:58:00 +00005266 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005267 // When the function has a trailing return type, we instantiate the
5268 // parameters before the return type, since the return type can then refer
5269 // to the parameters themselves (via decltype, sizeof, etc.).
5270 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005271 SmallVector<QualType, 4> ParamTypes;
5272 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005273 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005274 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005275
Douglas Gregor7fb25412010-10-01 18:44:50 +00005276 QualType ResultType;
5277
Richard Smith1226c602012-08-14 22:51:13 +00005278 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005279 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005280 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005281 TL.getTypePtr()->param_type_begin(),
5282 T->getExtParameterInfosOrNull(),
5283 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005284 return QualType();
5285
Douglas Gregor3024f072012-04-16 07:05:22 +00005286 {
5287 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005288 // If a declaration declares a member function or member function
5289 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005290 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005291 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005292 // declarator.
5293 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005294
Alp Toker42a16a62014-01-25 23:51:36 +00005295 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005296 if (ResultType.isNull())
5297 return QualType();
5298 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005299 }
5300 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005301 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005302 if (ResultType.isNull())
5303 return QualType();
5304
Anastasia Stulova6a4c3462018-11-29 14:11:15 +00005305 // Return type can not be qualified with an address space.
5306 if (ResultType.getAddressSpace() != LangAS::Default) {
5307 SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),
5308 diag::err_attribute_address_function_type);
5309 return QualType();
5310 }
5311
Alp Toker9cacbab2014-01-20 20:26:09 +00005312 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005313 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005314 TL.getTypePtr()->param_type_begin(),
5315 T->getExtParameterInfosOrNull(),
5316 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005317 return QualType();
5318 }
5319
Richard Smith2e321552014-11-12 02:00:47 +00005320 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5321
5322 bool EPIChanged = false;
5323 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5324 return QualType();
5325
John McCallc8e321d2016-03-01 02:09:25 +00005326 // Handle extended parameter information.
5327 if (auto NewExtParamInfos =
5328 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5329 if (!EPI.ExtParameterInfos ||
5330 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5331 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5332 EPIChanged = true;
5333 }
5334 EPI.ExtParameterInfos = NewExtParamInfos;
5335 } else if (EPI.ExtParameterInfos) {
5336 EPIChanged = true;
5337 EPI.ExtParameterInfos = nullptr;
5338 }
Richard Smithf623c962012-04-17 00:58:00 +00005339
John McCall550e0c22009-10-21 00:40:46 +00005340 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005341 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005342 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005343 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005344 if (Result.isNull())
5345 return QualType();
5346 }
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall550e0c22009-10-21 00:40:46 +00005348 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005349 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005350 NewTL.setLParenLoc(TL.getLParenLoc());
5351 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005352 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005353 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005354 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5355 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005356
5357 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005358}
Mike Stump11289f42009-09-09 15:08:12 +00005359
Douglas Gregord6ff3322009-08-04 16:50:30 +00005360template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005361bool TreeTransform<Derived>::TransformExceptionSpec(
5362 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5363 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5364 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5365
5366 // Instantiate a dynamic noexcept expression, if any.
Richard Smitheaf11ad2018-05-03 03:58:32 +00005367 if (isComputedNoexcept(ESI.Type)) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005368 EnterExpressionEvaluationContext Unevaluated(
5369 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005370 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5371 if (NoexceptExpr.isInvalid())
5372 return true;
5373
Richard Smitheaf11ad2018-05-03 03:58:32 +00005374 ExceptionSpecificationType EST = ESI.Type;
5375 NoexceptExpr =
5376 getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST);
Richard Smith2e321552014-11-12 02:00:47 +00005377 if (NoexceptExpr.isInvalid())
5378 return true;
5379
Richard Smitheaf11ad2018-05-03 03:58:32 +00005380 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
Richard Smith2e321552014-11-12 02:00:47 +00005381 Changed = true;
5382 ESI.NoexceptExpr = NoexceptExpr.get();
Richard Smitheaf11ad2018-05-03 03:58:32 +00005383 ESI.Type = EST;
Richard Smith2e321552014-11-12 02:00:47 +00005384 }
5385
5386 if (ESI.Type != EST_Dynamic)
5387 return false;
5388
5389 // Instantiate a dynamic exception specification's type.
5390 for (QualType T : ESI.Exceptions) {
5391 if (const PackExpansionType *PackExpansion =
5392 T->getAs<PackExpansionType>()) {
5393 Changed = true;
5394
5395 // We have a pack expansion. Instantiate it.
5396 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5397 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5398 Unexpanded);
5399 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5400
5401 // Determine whether the set of unexpanded parameter packs can and
5402 // should
5403 // be expanded.
5404 bool Expand = false;
5405 bool RetainExpansion = false;
5406 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5407 // FIXME: Track the location of the ellipsis (and track source location
5408 // information for the types in the exception specification in general).
5409 if (getDerived().TryExpandParameterPacks(
5410 Loc, SourceRange(), Unexpanded, Expand,
5411 RetainExpansion, NumExpansions))
5412 return true;
5413
5414 if (!Expand) {
5415 // We can't expand this pack expansion into separate arguments yet;
5416 // just substitute into the pattern and create a new pack expansion
5417 // type.
5418 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5419 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5420 if (U.isNull())
5421 return true;
5422
5423 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5424 Exceptions.push_back(U);
5425 continue;
5426 }
5427
5428 // Substitute into the pack expansion pattern for each slice of the
5429 // pack.
5430 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5431 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5432
5433 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5434 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5435 return true;
5436
5437 Exceptions.push_back(U);
5438 }
5439 } else {
5440 QualType U = getDerived().TransformType(T);
5441 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5442 return true;
5443 if (T != U)
5444 Changed = true;
5445
5446 Exceptions.push_back(U);
5447 }
5448 }
5449
5450 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005451 if (ESI.Exceptions.empty())
5452 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005453 return false;
5454}
5455
5456template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005457QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005458 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005459 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005460 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005461 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005462 if (ResultType.isNull())
5463 return QualType();
5464
5465 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005466 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005467 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5468
5469 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005470 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005471 NewTL.setLParenLoc(TL.getLParenLoc());
5472 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005473 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005474
5475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005476}
Mike Stump11289f42009-09-09 15:08:12 +00005477
John McCallb96ec562009-12-04 22:46:56 +00005478template<typename Derived> QualType
5479TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005480 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005481 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005482 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005483 if (!D)
5484 return QualType();
5485
5486 QualType Result = TL.getType();
5487 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005488 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005489 if (Result.isNull())
5490 return QualType();
5491 }
5492
5493 // We might get an arbitrary type spec type back. We should at
5494 // least always get a type spec type, though.
5495 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5496 NewTL.setNameLoc(TL.getNameLoc());
5497
5498 return Result;
5499}
5500
Douglas Gregord6ff3322009-08-04 16:50:30 +00005501template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005502QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005503 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005504 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005505 TypedefNameDecl *Typedef
5506 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5507 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005508 if (!Typedef)
5509 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005510
John McCall550e0c22009-10-21 00:40:46 +00005511 QualType Result = TL.getType();
5512 if (getDerived().AlwaysRebuild() ||
5513 Typedef != T->getDecl()) {
5514 Result = getDerived().RebuildTypedefType(Typedef);
5515 if (Result.isNull())
5516 return QualType();
5517 }
Mike Stump11289f42009-09-09 15:08:12 +00005518
John McCall550e0c22009-10-21 00:40:46 +00005519 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5520 NewTL.setNameLoc(TL.getNameLoc());
5521
5522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005523}
Mike Stump11289f42009-09-09 15:08:12 +00005524
Douglas Gregord6ff3322009-08-04 16:50:30 +00005525template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005526QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005527 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005528 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005529 EnterExpressionEvaluationContext Unevaluated(
5530 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5531 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005532
John McCalldadc5752010-08-24 06:29:42 +00005533 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005534 if (E.isInvalid())
5535 return QualType();
5536
Eli Friedmane4f22df2012-02-29 04:03:55 +00005537 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5538 if (E.isInvalid())
5539 return QualType();
5540
John McCall550e0c22009-10-21 00:40:46 +00005541 QualType Result = TL.getType();
5542 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005543 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005544 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005545 if (Result.isNull())
5546 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005547 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005548 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005549
John McCall550e0c22009-10-21 00:40:46 +00005550 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005551 NewTL.setTypeofLoc(TL.getTypeofLoc());
5552 NewTL.setLParenLoc(TL.getLParenLoc());
5553 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005554
5555 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005556}
Mike Stump11289f42009-09-09 15:08:12 +00005557
5558template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005559QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005560 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005561 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5562 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5563 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005564 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005565
John McCall550e0c22009-10-21 00:40:46 +00005566 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005567 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5568 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005569 if (Result.isNull())
5570 return QualType();
5571 }
Mike Stump11289f42009-09-09 15:08:12 +00005572
John McCall550e0c22009-10-21 00:40:46 +00005573 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005574 NewTL.setTypeofLoc(TL.getTypeofLoc());
5575 NewTL.setLParenLoc(TL.getLParenLoc());
5576 NewTL.setRParenLoc(TL.getRParenLoc());
5577 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005578
5579 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005580}
Mike Stump11289f42009-09-09 15:08:12 +00005581
5582template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005583QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005584 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005585 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005586
Douglas Gregore922c772009-08-04 22:27:00 +00005587 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005588 EnterExpressionEvaluationContext Unevaluated(
5589 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
Nicolas Lesserb6d5c582018-07-12 18:45:41 +00005590 Sema::ExpressionEvaluationContextRecord::EK_Decltype);
Mike Stump11289f42009-09-09 15:08:12 +00005591
John McCalldadc5752010-08-24 06:29:42 +00005592 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005593 if (E.isInvalid())
5594 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005595
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005596 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005597 if (E.isInvalid())
5598 return QualType();
5599
John McCall550e0c22009-10-21 00:40:46 +00005600 QualType Result = TL.getType();
5601 if (getDerived().AlwaysRebuild() ||
5602 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005603 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005604 if (Result.isNull())
5605 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005606 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005607 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005608
John McCall550e0c22009-10-21 00:40:46 +00005609 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5610 NewTL.setNameLoc(TL.getNameLoc());
5611
5612 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005613}
5614
5615template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005616QualType TreeTransform<Derived>::TransformUnaryTransformType(
5617 TypeLocBuilder &TLB,
5618 UnaryTransformTypeLoc TL) {
5619 QualType Result = TL.getType();
5620 if (Result->isDependentType()) {
5621 const UnaryTransformType *T = TL.getTypePtr();
5622 QualType NewBase =
5623 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5624 Result = getDerived().RebuildUnaryTransformType(NewBase,
5625 T->getUTTKind(),
5626 TL.getKWLoc());
5627 if (Result.isNull())
5628 return QualType();
5629 }
5630
5631 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5632 NewTL.setKWLoc(TL.getKWLoc());
5633 NewTL.setParensRange(TL.getParensRange());
5634 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5635 return Result;
5636}
5637
5638template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005639QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5640 AutoTypeLoc TL) {
5641 const AutoType *T = TL.getTypePtr();
5642 QualType OldDeduced = T->getDeducedType();
5643 QualType NewDeduced;
5644 if (!OldDeduced.isNull()) {
5645 NewDeduced = getDerived().TransformType(OldDeduced);
5646 if (NewDeduced.isNull())
5647 return QualType();
5648 }
5649
5650 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005651 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5652 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005653 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005654 if (Result.isNull())
5655 return QualType();
5656 }
5657
5658 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5659 NewTL.setNameLoc(TL.getNameLoc());
5660
5661 return Result;
5662}
5663
5664template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005665QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5666 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5667 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5668
5669 CXXScopeSpec SS;
5670 TemplateName TemplateName = getDerived().TransformTemplateName(
5671 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5672 if (TemplateName.isNull())
5673 return QualType();
5674
5675 QualType OldDeduced = T->getDeducedType();
5676 QualType NewDeduced;
5677 if (!OldDeduced.isNull()) {
5678 NewDeduced = getDerived().TransformType(OldDeduced);
5679 if (NewDeduced.isNull())
5680 return QualType();
5681 }
5682
5683 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5684 TemplateName, NewDeduced);
5685 if (Result.isNull())
5686 return QualType();
5687
5688 DeducedTemplateSpecializationTypeLoc NewTL =
5689 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5690 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5691
5692 return Result;
5693}
5694
5695template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005696QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005697 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005698 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005699 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005700 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5701 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005702 if (!Record)
5703 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005704
John McCall550e0c22009-10-21 00:40:46 +00005705 QualType Result = TL.getType();
5706 if (getDerived().AlwaysRebuild() ||
5707 Record != T->getDecl()) {
5708 Result = getDerived().RebuildRecordType(Record);
5709 if (Result.isNull())
5710 return QualType();
5711 }
Mike Stump11289f42009-09-09 15:08:12 +00005712
John McCall550e0c22009-10-21 00:40:46 +00005713 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5714 NewTL.setNameLoc(TL.getNameLoc());
5715
5716 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005717}
Mike Stump11289f42009-09-09 15:08:12 +00005718
5719template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005720QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005721 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005722 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005723 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005724 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5725 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005726 if (!Enum)
5727 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005728
John McCall550e0c22009-10-21 00:40:46 +00005729 QualType Result = TL.getType();
5730 if (getDerived().AlwaysRebuild() ||
5731 Enum != T->getDecl()) {
5732 Result = getDerived().RebuildEnumType(Enum);
5733 if (Result.isNull())
5734 return QualType();
5735 }
Mike Stump11289f42009-09-09 15:08:12 +00005736
John McCall550e0c22009-10-21 00:40:46 +00005737 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5738 NewTL.setNameLoc(TL.getNameLoc());
5739
5740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005741}
John McCallfcc33b02009-09-05 00:15:47 +00005742
John McCalle78aac42010-03-10 03:28:59 +00005743template<typename Derived>
5744QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5745 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005746 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005747 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5748 TL.getTypePtr()->getDecl());
5749 if (!D) return QualType();
5750
5751 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5752 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5753 return T;
5754}
5755
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756template<typename Derived>
5757QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005758 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005759 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005760 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005761}
5762
Mike Stump11289f42009-09-09 15:08:12 +00005763template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005764QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005765 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005766 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005767 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005768
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005769 // Substitute into the replacement type, which itself might involve something
5770 // that needs to be transformed. This only tends to occur with default
5771 // template arguments of template template parameters.
5772 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5773 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5774 if (Replacement.isNull())
5775 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005776
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005777 // Always canonicalize the replacement type.
5778 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5779 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005780 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005781 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005782
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005783 // Propagate type-source information.
5784 SubstTemplateTypeParmTypeLoc NewTL
5785 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5786 NewTL.setNameLoc(TL.getNameLoc());
5787 return Result;
5788
John McCallcebee162009-10-18 09:09:24 +00005789}
5790
5791template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005792QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5793 TypeLocBuilder &TLB,
5794 SubstTemplateTypeParmPackTypeLoc TL) {
5795 return TransformTypeSpecType(TLB, TL);
5796}
5797
5798template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005799QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005800 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005801 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005802 const TemplateSpecializationType *T = TL.getTypePtr();
5803
Douglas Gregordf846d12011-03-02 18:46:51 +00005804 // The nested-name-specifier never matters in a TemplateSpecializationType,
5805 // because we can't have a dependent nested-name-specifier anyway.
5806 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005807 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005808 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5809 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005810 if (Template.isNull())
5811 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005812
John McCall31f82722010-11-12 08:19:04 +00005813 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5814}
5815
Eli Friedman0dfb8892011-10-06 23:00:33 +00005816template<typename Derived>
5817QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5818 AtomicTypeLoc TL) {
5819 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5820 if (ValueType.isNull())
5821 return QualType();
5822
5823 QualType Result = TL.getType();
5824 if (getDerived().AlwaysRebuild() ||
5825 ValueType != TL.getValueLoc().getType()) {
5826 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5827 if (Result.isNull())
5828 return QualType();
5829 }
5830
5831 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5832 NewTL.setKWLoc(TL.getKWLoc());
5833 NewTL.setLParenLoc(TL.getLParenLoc());
5834 NewTL.setRParenLoc(TL.getRParenLoc());
5835
5836 return Result;
5837}
5838
Xiuli Pan9c14e282016-01-09 12:53:17 +00005839template <typename Derived>
5840QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5841 PipeTypeLoc TL) {
5842 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5843 if (ValueType.isNull())
5844 return QualType();
5845
5846 QualType Result = TL.getType();
5847 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005848 const PipeType *PT = Result->getAs<PipeType>();
5849 bool isReadPipe = PT->isReadOnly();
5850 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005851 if (Result.isNull())
5852 return QualType();
5853 }
5854
5855 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5856 NewTL.setKWLoc(TL.getKWLoc());
5857
5858 return Result;
5859}
5860
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00005861 /// Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005862 /// container that provides a \c getArgLoc() member function.
5863 ///
5864 /// This iterator is intended to be used with the iterator form of
5865 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5866 template<typename ArgLocContainer>
5867 class TemplateArgumentLocContainerIterator {
5868 ArgLocContainer *Container;
5869 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Douglas Gregorfe921a72010-12-20 23:36:19 +00005871 public:
5872 typedef TemplateArgumentLoc value_type;
5873 typedef TemplateArgumentLoc reference;
5874 typedef int difference_type;
5875 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005876
Douglas Gregorfe921a72010-12-20 23:36:19 +00005877 class pointer {
5878 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005879
Douglas Gregorfe921a72010-12-20 23:36:19 +00005880 public:
5881 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
Douglas Gregorfe921a72010-12-20 23:36:19 +00005883 const TemplateArgumentLoc *operator->() const {
5884 return &Arg;
5885 }
5886 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005887
5888
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005889 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005890
Douglas Gregorfe921a72010-12-20 23:36:19 +00005891 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5892 unsigned Index)
5893 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005894
Douglas Gregorfe921a72010-12-20 23:36:19 +00005895 TemplateArgumentLocContainerIterator &operator++() {
5896 ++Index;
5897 return *this;
5898 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005899
Douglas Gregorfe921a72010-12-20 23:36:19 +00005900 TemplateArgumentLocContainerIterator operator++(int) {
5901 TemplateArgumentLocContainerIterator Old(*this);
5902 ++(*this);
5903 return Old;
5904 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005905
Douglas Gregorfe921a72010-12-20 23:36:19 +00005906 TemplateArgumentLoc operator*() const {
5907 return Container->getArgLoc(Index);
5908 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005909
Douglas Gregorfe921a72010-12-20 23:36:19 +00005910 pointer operator->() const {
5911 return pointer(Container->getArgLoc(Index));
5912 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005913
Douglas Gregorfe921a72010-12-20 23:36:19 +00005914 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005915 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005916 return X.Container == Y.Container && X.Index == Y.Index;
5917 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005918
Douglas Gregorfe921a72010-12-20 23:36:19 +00005919 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005920 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005921 return !(X == Y);
5922 }
5923 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005924
5925
John McCall31f82722010-11-12 08:19:04 +00005926template <typename Derived>
5927QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5928 TypeLocBuilder &TLB,
5929 TemplateSpecializationTypeLoc TL,
5930 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005931 TemplateArgumentListInfo NewTemplateArgs;
5932 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5933 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005934 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5935 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005936 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005937 ArgIterator(TL, TL.getNumArgs()),
5938 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005939 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005940
John McCall0ad16662009-10-29 08:12:44 +00005941 // FIXME: maybe don't rebuild if all the template arguments are the same.
5942
5943 QualType Result =
5944 getDerived().RebuildTemplateSpecializationType(Template,
5945 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005946 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005947
5948 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005949 // Specializations of template template parameters are represented as
5950 // TemplateSpecializationTypes, and substitution of type alias templates
5951 // within a dependent context can transform them into
5952 // DependentTemplateSpecializationTypes.
5953 if (isa<DependentTemplateSpecializationType>(Result)) {
5954 DependentTemplateSpecializationTypeLoc NewTL
5955 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005956 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005957 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005958 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005959 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005960 NewTL.setLAngleLoc(TL.getLAngleLoc());
5961 NewTL.setRAngleLoc(TL.getRAngleLoc());
5962 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5963 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5964 return Result;
5965 }
5966
John McCall0ad16662009-10-29 08:12:44 +00005967 TemplateSpecializationTypeLoc NewTL
5968 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005969 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005970 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5971 NewTL.setLAngleLoc(TL.getLAngleLoc());
5972 NewTL.setRAngleLoc(TL.getRAngleLoc());
5973 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5974 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005975 }
Mike Stump11289f42009-09-09 15:08:12 +00005976
John McCall0ad16662009-10-29 08:12:44 +00005977 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005978}
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregor5a064722011-02-28 17:23:35 +00005980template <typename Derived>
5981QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5982 TypeLocBuilder &TLB,
5983 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005984 TemplateName Template,
5985 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005986 TemplateArgumentListInfo NewTemplateArgs;
5987 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5988 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5989 typedef TemplateArgumentLocContainerIterator<
5990 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005991 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005992 ArgIterator(TL, TL.getNumArgs()),
5993 NewTemplateArgs))
5994 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005995
Douglas Gregor5a064722011-02-28 17:23:35 +00005996 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005997
Douglas Gregor5a064722011-02-28 17:23:35 +00005998 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5999 QualType Result
6000 = getSema().Context.getDependentTemplateSpecializationType(
6001 TL.getTypePtr()->getKeyword(),
6002 DTN->getQualifier(),
6003 DTN->getIdentifier(),
6004 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006005
Douglas Gregor5a064722011-02-28 17:23:35 +00006006 DependentTemplateSpecializationTypeLoc NewTL
6007 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006008 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006009 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006010 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006011 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006012 NewTL.setLAngleLoc(TL.getLAngleLoc());
6013 NewTL.setRAngleLoc(TL.getRAngleLoc());
6014 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6015 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6016 return Result;
6017 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006018
6019 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00006020 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006021 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00006022 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
Douglas Gregor5a064722011-02-28 17:23:35 +00006024 if (!Result.isNull()) {
6025 /// FIXME: Wrap this in an elaborated-type-specifier?
6026 TemplateSpecializationTypeLoc NewTL
6027 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006028 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006029 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00006030 NewTL.setLAngleLoc(TL.getLAngleLoc());
6031 NewTL.setRAngleLoc(TL.getRAngleLoc());
6032 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
6033 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
6034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006035
Douglas Gregor5a064722011-02-28 17:23:35 +00006036 return Result;
6037}
6038
Mike Stump11289f42009-09-09 15:08:12 +00006039template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006040QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00006041TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006042 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00006043 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00006044
Douglas Gregor844cb502011-03-01 18:12:44 +00006045 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00006046 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00006047 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006048 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00006049 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6050 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00006051 return QualType();
6052 }
Mike Stump11289f42009-09-09 15:08:12 +00006053
John McCall31f82722010-11-12 08:19:04 +00006054 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
6055 if (NamedT.isNull())
6056 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00006057
Richard Smith3f1b5d02011-05-05 21:57:07 +00006058 // C++0x [dcl.type.elab]p2:
6059 // If the identifier resolves to a typedef-name or the simple-template-id
6060 // resolves to an alias template specialization, the
6061 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00006062 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
6063 if (const TemplateSpecializationType *TST =
6064 NamedT->getAs<TemplateSpecializationType>()) {
6065 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00006066 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
6067 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00006068 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00006069 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00006070 << TAT << Sema::NTK_TypeAliasTemplate
6071 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00006072 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
6073 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00006074 }
6075 }
6076
John McCall550e0c22009-10-21 00:40:46 +00006077 QualType Result = TL.getType();
6078 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00006079 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00006080 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006081 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00006082 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00006083 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00006084 if (Result.isNull())
6085 return QualType();
6086 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00006087
Abramo Bagnara6150c882010-05-11 21:36:43 +00006088 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006089 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006090 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00006091 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006092}
Mike Stump11289f42009-09-09 15:08:12 +00006093
6094template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006095QualType TreeTransform<Derived>::TransformAttributedType(
6096 TypeLocBuilder &TLB,
6097 AttributedTypeLoc TL) {
6098 const AttributedType *oldType = TL.getTypePtr();
6099 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6100 if (modifiedType.isNull())
6101 return QualType();
6102
Richard Smithe43e2b32018-08-20 21:47:29 +00006103 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
6104 const Attr *oldAttr = TL.getAttr();
6105 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
6106 if (oldAttr && !newAttr)
6107 return QualType();
6108
John McCall81904512011-01-06 01:58:22 +00006109 QualType result = TL.getType();
6110
6111 // FIXME: dependent operand expressions?
6112 if (getDerived().AlwaysRebuild() ||
6113 modifiedType != oldType->getModifiedType()) {
6114 // TODO: this is really lame; we should really be rebuilding the
6115 // equivalent type from first principles.
6116 QualType equivalentType
6117 = getDerived().TransformType(oldType->getEquivalentType());
6118 if (equivalentType.isNull())
6119 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006120
6121 // Check whether we can add nullability; it is only represented as
6122 // type sugar, and therefore cannot be diagnosed in any other way.
6123 if (auto nullability = oldType->getImmediateNullability()) {
6124 if (!modifiedType->canHaveNullability()) {
Richard Smithe43e2b32018-08-20 21:47:29 +00006125 SemaRef.Diag(TL.getAttr()->getLocation(),
6126 diag::err_nullability_nonpointer)
6127 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006128 return QualType();
6129 }
6130 }
6131
Richard Smithe43e2b32018-08-20 21:47:29 +00006132 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
John McCall81904512011-01-06 01:58:22 +00006133 modifiedType,
6134 equivalentType);
6135 }
6136
6137 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
Richard Smithe43e2b32018-08-20 21:47:29 +00006138 newTL.setAttr(newAttr);
John McCall81904512011-01-06 01:58:22 +00006139 return result;
6140}
6141
6142template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006143QualType
6144TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6145 ParenTypeLoc TL) {
6146 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6147 if (Inner.isNull())
6148 return QualType();
6149
6150 QualType Result = TL.getType();
6151 if (getDerived().AlwaysRebuild() ||
6152 Inner != TL.getInnerLoc().getType()) {
6153 Result = getDerived().RebuildParenType(Inner);
6154 if (Result.isNull())
6155 return QualType();
6156 }
6157
6158 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6159 NewTL.setLParenLoc(TL.getLParenLoc());
6160 NewTL.setRParenLoc(TL.getRParenLoc());
6161 return Result;
6162}
6163
6164template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006165QualType TreeTransform<Derived>::TransformDependentNameType(
6166 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6167 return TransformDependentNameType(TLB, TL, false);
6168}
6169
6170template<typename Derived>
6171QualType TreeTransform<Derived>::TransformDependentNameType(
6172 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006173 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006174
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006175 NestedNameSpecifierLoc QualifierLoc
6176 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6177 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006178 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006179
John McCallc392f372010-06-11 00:33:02 +00006180 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006181 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006182 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006183 QualifierLoc,
6184 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006185 TL.getNameLoc(),
6186 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006187 if (Result.isNull())
6188 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006189
Abramo Bagnarad7548482010-05-19 21:37:53 +00006190 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6191 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006192 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6193
Abramo Bagnarad7548482010-05-19 21:37:53 +00006194 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006195 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006196 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006197 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006198 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006199 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006200 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006201 NewTL.setNameLoc(TL.getNameLoc());
6202 }
John McCall550e0c22009-10-21 00:40:46 +00006203 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006204}
Mike Stump11289f42009-09-09 15:08:12 +00006205
Douglas Gregord6ff3322009-08-04 16:50:30 +00006206template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006207QualType TreeTransform<Derived>::
6208 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006209 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006210 NestedNameSpecifierLoc QualifierLoc;
6211 if (TL.getQualifierLoc()) {
6212 QualifierLoc
6213 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6214 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006215 return QualType();
6216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006217
John McCall31f82722010-11-12 08:19:04 +00006218 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006219 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006220}
6221
6222template<typename Derived>
6223QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006224TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6225 DependentTemplateSpecializationTypeLoc TL,
6226 NestedNameSpecifierLoc QualifierLoc) {
6227 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006228
Douglas Gregora7a795b2011-03-01 20:11:18 +00006229 TemplateArgumentListInfo NewTemplateArgs;
6230 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6231 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006232
Douglas Gregora7a795b2011-03-01 20:11:18 +00006233 typedef TemplateArgumentLocContainerIterator<
6234 DependentTemplateSpecializationTypeLoc> ArgIterator;
6235 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6236 ArgIterator(TL, TL.getNumArgs()),
6237 NewTemplateArgs))
6238 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
Richard Smithfd3dae02017-01-20 00:20:39 +00006240 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
Richard Smith79810042018-05-11 02:43:08 +00006241 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
6242 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
Richard Smithfd3dae02017-01-20 00:20:39 +00006243 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006244 if (Result.isNull())
6245 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006246
Douglas Gregora7a795b2011-03-01 20:11:18 +00006247 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6248 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006249
Douglas Gregora7a795b2011-03-01 20:11:18 +00006250 // Copy information relevant to the template specialization.
6251 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006252 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006253 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006254 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006255 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6256 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006257 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006258 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006259
Douglas Gregora7a795b2011-03-01 20:11:18 +00006260 // Copy information relevant to the elaborated type.
6261 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006262 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006263 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006264 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6265 DependentTemplateSpecializationTypeLoc SpecTL
6266 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006267 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006268 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006269 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006270 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006271 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6272 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006273 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006274 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006275 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006276 TemplateSpecializationTypeLoc SpecTL
6277 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006278 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006279 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006280 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6281 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006282 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006283 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006284 }
6285 return Result;
6286}
6287
6288template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006289QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6290 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006291 QualType Pattern
6292 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006293 if (Pattern.isNull())
6294 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006295
6296 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006297 if (getDerived().AlwaysRebuild() ||
6298 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006299 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006300 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006301 TL.getEllipsisLoc(),
6302 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006303 if (Result.isNull())
6304 return QualType();
6305 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006306
Douglas Gregor822d0302011-01-12 17:07:58 +00006307 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6308 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6309 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006310}
6311
6312template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006313QualType
6314TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006315 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006316 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006317 TLB.pushFullCopy(TL);
6318 return TL.getType();
6319}
6320
6321template<typename Derived>
6322QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006323TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6324 ObjCTypeParamTypeLoc TL) {
6325 const ObjCTypeParamType *T = TL.getTypePtr();
6326 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6327 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6328 if (!OTP)
6329 return QualType();
6330
6331 QualType Result = TL.getType();
6332 if (getDerived().AlwaysRebuild() ||
6333 OTP != T->getDecl()) {
6334 Result = getDerived().RebuildObjCTypeParamType(OTP,
6335 TL.getProtocolLAngleLoc(),
6336 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6337 TL.getNumProtocols()),
6338 TL.getProtocolLocs(),
6339 TL.getProtocolRAngleLoc());
6340 if (Result.isNull())
6341 return QualType();
6342 }
6343
6344 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6345 if (TL.getNumProtocols()) {
6346 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6347 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6348 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6349 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6350 }
6351 return Result;
6352}
6353
6354template<typename Derived>
6355QualType
John McCall8b07ec22010-05-15 11:32:37 +00006356TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006357 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006358 // Transform base type.
6359 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6360 if (BaseType.isNull())
6361 return QualType();
6362
6363 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6364
6365 // Transform type arguments.
6366 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6367 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6368 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6369 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6370 QualType TypeArg = TypeArgInfo->getType();
6371 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6372 AnyChanged = true;
6373
6374 // We have a pack expansion. Instantiate it.
6375 const auto *PackExpansion = PackExpansionLoc.getType()
6376 ->castAs<PackExpansionType>();
6377 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6378 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6379 Unexpanded);
6380 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6381
6382 // Determine whether the set of unexpanded parameter packs can
6383 // and should be expanded.
6384 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6385 bool Expand = false;
6386 bool RetainExpansion = false;
6387 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6388 if (getDerived().TryExpandParameterPacks(
6389 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6390 Unexpanded, Expand, RetainExpansion, NumExpansions))
6391 return QualType();
6392
6393 if (!Expand) {
6394 // We can't expand this pack expansion into separate arguments yet;
6395 // just substitute into the pattern and create a new pack expansion
6396 // type.
6397 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6398
6399 TypeLocBuilder TypeArgBuilder;
6400 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
Fangrui Song6907ce22018-07-30 19:24:48 +00006401 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006402 PatternLoc);
6403 if (NewPatternType.isNull())
6404 return QualType();
6405
6406 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6407 NewPatternType, NumExpansions);
6408 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6409 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6410 NewTypeArgInfos.push_back(
6411 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6412 continue;
6413 }
6414
6415 // Substitute into the pack expansion pattern for each slice of the
6416 // pack.
6417 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6418 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6419
6420 TypeLocBuilder TypeArgBuilder;
6421 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6422
6423 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6424 PatternLoc);
6425 if (NewTypeArg.isNull())
6426 return QualType();
6427
6428 NewTypeArgInfos.push_back(
6429 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6430 }
6431
6432 continue;
6433 }
6434
6435 TypeLocBuilder TypeArgBuilder;
6436 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6437 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6438 if (NewTypeArg.isNull())
6439 return QualType();
6440
6441 // If nothing changed, just keep the old TypeSourceInfo.
6442 if (NewTypeArg == TypeArg) {
6443 NewTypeArgInfos.push_back(TypeArgInfo);
6444 continue;
6445 }
6446
6447 NewTypeArgInfos.push_back(
6448 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6449 AnyChanged = true;
6450 }
6451
6452 QualType Result = TL.getType();
6453 if (getDerived().AlwaysRebuild() || AnyChanged) {
6454 // Rebuild the type.
6455 Result = getDerived().RebuildObjCObjectType(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006456 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
6457 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
6458 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
6459 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006460
6461 if (Result.isNull())
6462 return QualType();
6463 }
6464
6465 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006466 NewT.setHasBaseTypeAsWritten(true);
6467 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6468 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6469 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6470 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6471 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6472 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6473 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6474 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6475 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006476}
Mike Stump11289f42009-09-09 15:08:12 +00006477
6478template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006479QualType
6480TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006481 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006482 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6483 if (PointeeType.isNull())
6484 return QualType();
6485
6486 QualType Result = TL.getType();
6487 if (getDerived().AlwaysRebuild() ||
6488 PointeeType != TL.getPointeeLoc().getType()) {
6489 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6490 TL.getStarLoc());
6491 if (Result.isNull())
6492 return QualType();
6493 }
6494
6495 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6496 NewT.setStarLoc(TL.getStarLoc());
6497 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006498}
6499
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006501// Statement transformation
6502//===----------------------------------------------------------------------===//
6503template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006504StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006505TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006506 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006507}
6508
6509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006510StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006511TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6512 return getDerived().TransformCompoundStmt(S, false);
6513}
6514
6515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006517TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006518 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006519 Sema::CompoundScopeRAII CompoundScope(getSema());
6520
John McCall1ababa62010-08-27 19:56:05 +00006521 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006522 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006523 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006524 for (auto *B : S->body()) {
Aaron Ballmanfb6deeb2019-01-04 16:58:14 +00006525 StmtResult Result =
6526 getDerived().TransformStmt(B, !IsStmtExpr || B != S->body_back());
6527
John McCall1ababa62010-08-27 19:56:05 +00006528 if (Result.isInvalid()) {
6529 // Immediately fail if this was a DeclStmt, since it's very
6530 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006531 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006532 return StmtError();
6533
6534 // Otherwise, just keep processing substatements and fail later.
6535 SubStmtInvalid = true;
6536 continue;
6537 }
Mike Stump11289f42009-09-09 15:08:12 +00006538
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006539 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006540 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006541 }
Mike Stump11289f42009-09-09 15:08:12 +00006542
John McCall1ababa62010-08-27 19:56:05 +00006543 if (SubStmtInvalid)
6544 return StmtError();
6545
Douglas Gregorebe10102009-08-20 07:17:43 +00006546 if (!getDerived().AlwaysRebuild() &&
6547 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006548 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006549
6550 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006551 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006552 S->getRBracLoc(),
6553 IsStmtExpr);
6554}
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregorebe10102009-08-20 07:17:43 +00006556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006557StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006558TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006559 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006560 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006561 EnterExpressionEvaluationContext Unevaluated(
6562 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006563
Eli Friedman06577382009-11-19 03:14:00 +00006564 // Transform the left-hand case value.
6565 LHS = getDerived().TransformExpr(S->getLHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006566 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006567 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006568 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006569
Eli Friedman06577382009-11-19 03:14:00 +00006570 // Transform the right-hand case value (for the GNU case-range extension).
6571 RHS = getDerived().TransformExpr(S->getRHS());
Richard Smithef6c43d2018-07-26 18:41:30 +00006572 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006573 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006575 }
Mike Stump11289f42009-09-09 15:08:12 +00006576
Douglas Gregorebe10102009-08-20 07:17:43 +00006577 // Build the case statement.
6578 // Case statements are always rebuilt so that they will attached to their
6579 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006580 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006581 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006582 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006583 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006584 S->getColonLoc());
6585 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006586 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006587
Douglas Gregorebe10102009-08-20 07:17:43 +00006588 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006589 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006590 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregorebe10102009-08-20 07:17:43 +00006593 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006594 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006595}
6596
6597template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006598StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006599TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006601 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006602 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006603 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006604
Douglas Gregorebe10102009-08-20 07:17:43 +00006605 // Default statements are always rebuilt
6606 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006607 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006608}
Mike Stump11289f42009-09-09 15:08:12 +00006609
Douglas Gregorebe10102009-08-20 07:17:43 +00006610template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006611StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006612TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006613 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006616
Chris Lattnercab02a62011-02-17 20:34:02 +00006617 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6618 S->getDecl());
6619 if (!LD)
6620 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006621
6622
Douglas Gregorebe10102009-08-20 07:17:43 +00006623 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006624 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006625 cast<LabelDecl>(LD), SourceLocation(),
6626 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006627}
Mike Stump11289f42009-09-09 15:08:12 +00006628
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006629template <typename Derived>
6630const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6631 if (!R)
6632 return R;
6633
6634 switch (R->getKind()) {
6635// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6636#define ATTR(X)
6637#define PRAGMA_SPELLING_ATTR(X) \
6638 case attr::X: \
6639 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6640#include "clang/Basic/AttrList.inc"
6641 default:
6642 return R;
6643 }
6644}
6645
6646template <typename Derived>
6647StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6648 bool AttrsChanged = false;
6649 SmallVector<const Attr *, 1> Attrs;
6650
6651 // Visit attributes and keep track if any are transformed.
6652 for (const auto *I : S->getAttrs()) {
6653 const Attr *R = getDerived().TransformAttr(I);
6654 AttrsChanged |= (I != R);
6655 Attrs.push_back(R);
6656 }
6657
Richard Smithc202b282012-04-14 00:33:13 +00006658 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6659 if (SubStmt.isInvalid())
6660 return StmtError();
6661
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006662 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006663 return S;
6664
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006665 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006666 SubStmt.get());
6667}
6668
6669template<typename Derived>
6670StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006671TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006672 // Transform the initialization statement
6673 StmtResult Init = getDerived().TransformStmt(S->getInit());
6674 if (Init.isInvalid())
6675 return StmtError();
6676
Douglas Gregorebe10102009-08-20 07:17:43 +00006677 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006678 Sema::ConditionResult Cond = getDerived().TransformCondition(
6679 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006680 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6681 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006682 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006683 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006684
Richard Smithb130fe72016-06-23 19:16:49 +00006685 // If this is a constexpr if, determine which arm we should instantiate.
6686 llvm::Optional<bool> ConstexprConditionValue;
6687 if (S->isConstexpr())
6688 ConstexprConditionValue = Cond.getKnownValue();
6689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006691 StmtResult Then;
6692 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6693 Then = getDerived().TransformStmt(S->getThen());
6694 if (Then.isInvalid())
6695 return StmtError();
6696 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00006697 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
Richard Smithb130fe72016-06-23 19:16:49 +00006698 }
Mike Stump11289f42009-09-09 15:08:12 +00006699
Douglas Gregorebe10102009-08-20 07:17:43 +00006700 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006701 StmtResult Else;
6702 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6703 Else = getDerived().TransformStmt(S->getElse());
6704 if (Else.isInvalid())
6705 return StmtError();
6706 }
Mike Stump11289f42009-09-09 15:08:12 +00006707
Douglas Gregorebe10102009-08-20 07:17:43 +00006708 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006709 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006710 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006711 Then.get() == S->getThen() &&
6712 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006713 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006714
Richard Smithb130fe72016-06-23 19:16:49 +00006715 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006716 Init.get(), Then.get(), S->getElseLoc(),
6717 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006718}
6719
6720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006721StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006722TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006723 // Transform the initialization statement
6724 StmtResult Init = getDerived().TransformStmt(S->getInit());
6725 if (Init.isInvalid())
6726 return StmtError();
6727
Douglas Gregorebe10102009-08-20 07:17:43 +00006728 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006729 Sema::ConditionResult Cond = getDerived().TransformCondition(
6730 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6731 Sema::ConditionKind::Switch);
6732 if (Cond.isInvalid())
6733 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006734
Douglas Gregorebe10102009-08-20 07:17:43 +00006735 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006736 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006737 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006738 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006740
Douglas Gregorebe10102009-08-20 07:17:43 +00006741 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006742 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006743 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006744 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006745
Douglas Gregorebe10102009-08-20 07:17:43 +00006746 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006747 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6748 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006749}
Mike Stump11289f42009-09-09 15:08:12 +00006750
Douglas Gregorebe10102009-08-20 07:17:43 +00006751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006752StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006753TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006754 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006755 Sema::ConditionResult Cond = getDerived().TransformCondition(
6756 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6757 Sema::ConditionKind::Boolean);
6758 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006759 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006760
Douglas Gregorebe10102009-08-20 07:17:43 +00006761 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006762 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006763 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006764 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006765
Douglas Gregorebe10102009-08-20 07:17:43 +00006766 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006767 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006768 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006769 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006770
Richard Smith03a4aa32016-06-23 19:02:52 +00006771 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, 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
Douglas Gregorebe10102009-08-20 07:17:43 +00006776TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006777 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006778 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006779 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006780 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006781
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006782 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006783 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006784 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006785 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006786
Douglas Gregorebe10102009-08-20 07:17:43 +00006787 if (!getDerived().AlwaysRebuild() &&
6788 Cond.get() == S->getCond() &&
6789 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006790 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006791
John McCallb268a282010-08-23 23:25:46 +00006792 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6793 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006794 S->getRParenLoc());
6795}
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
Mike Stump11289f42009-09-09 15:08:12 +00006799TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Alexey Bataev92b33652018-11-21 19:41:10 +00006800 if (getSema().getLangOpts().OpenMP)
6801 getSema().startOpenMPLoop();
6802
Douglas Gregorebe10102009-08-20 07:17:43 +00006803 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006804 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006805 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006806 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006807
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006808 // In OpenMP loop region loop control variable must be captured and be
6809 // private. Perform analysis of first part (if any).
6810 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6811 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6812
Douglas Gregorebe10102009-08-20 07:17:43 +00006813 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006814 Sema::ConditionResult Cond = getDerived().TransformCondition(
6815 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6816 Sema::ConditionKind::Boolean);
6817 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006818 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006819
Douglas Gregorebe10102009-08-20 07:17:43 +00006820 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006821 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006822 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006823 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006824
Richard Smith945f8d32013-01-14 22:39:08 +00006825 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006826 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006827 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006828
Douglas Gregorebe10102009-08-20 07:17:43 +00006829 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006830 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006831 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006832 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006833
Douglas Gregorebe10102009-08-20 07:17:43 +00006834 if (!getDerived().AlwaysRebuild() &&
6835 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006836 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006837 Inc.get() == S->getInc() &&
6838 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006839 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006840
Douglas Gregorebe10102009-08-20 07:17:43 +00006841 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006842 Init.get(), Cond, FullInc,
6843 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006844}
6845
6846template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006847StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006848TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006849 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6850 S->getLabel());
6851 if (!LD)
6852 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006853
Douglas Gregorebe10102009-08-20 07:17:43 +00006854 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006855 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006856 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006857}
6858
6859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006860StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006861TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006862 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006863 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006864 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006865 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregorebe10102009-08-20 07:17:43 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006869 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006870
6871 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006872 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006873}
6874
6875template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006876StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006877TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006878 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006879}
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregorebe10102009-08-20 07:17:43 +00006881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006882StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006883TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006884 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006885}
Mike Stump11289f42009-09-09 15:08:12 +00006886
Douglas Gregorebe10102009-08-20 07:17:43 +00006887template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006888StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006889TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006890 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6891 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006892 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006893 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006894
Mike Stump11289f42009-09-09 15:08:12 +00006895 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006896 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006897 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006898}
Mike Stump11289f42009-09-09 15:08:12 +00006899
Douglas Gregorebe10102009-08-20 07:17:43 +00006900template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006901StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006902TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006903 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006904 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006905 for (auto *D : S->decls()) {
6906 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006907 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006908 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006909
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006910 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006911 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006912
Douglas Gregorebe10102009-08-20 07:17:43 +00006913 Decls.push_back(Transformed);
6914 }
Mike Stump11289f42009-09-09 15:08:12 +00006915
Douglas Gregorebe10102009-08-20 07:17:43 +00006916 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006917 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006918
Stephen Kellya6e43582018-08-09 21:05:56 +00006919 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006920}
Mike Stump11289f42009-09-09 15:08:12 +00006921
Douglas Gregorebe10102009-08-20 07:17:43 +00006922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006923StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006924TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006925
Benjamin Kramerf0623432012-08-23 22:51:59 +00006926 SmallVector<Expr*, 8> Constraints;
6927 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006928 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006929
John McCalldadc5752010-08-24 06:29:42 +00006930 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006931 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006932
6933 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006934
Anders Carlssonaaeef072010-01-24 05:50:09 +00006935 // Go through the outputs.
6936 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006937 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006938
Anders Carlssonaaeef072010-01-24 05:50:09 +00006939 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006940 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006941
Anders Carlssonaaeef072010-01-24 05:50:09 +00006942 // Transform the output expr.
6943 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006944 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006945 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006946 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006947
Anders Carlssonaaeef072010-01-24 05:50:09 +00006948 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006949
John McCallb268a282010-08-23 23:25:46 +00006950 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006951 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006952
Anders Carlssonaaeef072010-01-24 05:50:09 +00006953 // Go through the inputs.
6954 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006955 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006956
Anders Carlssonaaeef072010-01-24 05:50:09 +00006957 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006958 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006959
Anders Carlssonaaeef072010-01-24 05:50:09 +00006960 // Transform the input expr.
6961 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006962 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006963 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006964 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006965
Anders Carlssonaaeef072010-01-24 05:50:09 +00006966 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006967
John McCallb268a282010-08-23 23:25:46 +00006968 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006969 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006970
Anders Carlssonaaeef072010-01-24 05:50:09 +00006971 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006972 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006973
6974 // Go through the clobbers.
6975 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006976 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006977
6978 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006979 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006980 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6981 S->isVolatile(), S->getNumOutputs(),
6982 S->getNumInputs(), Names.data(),
6983 Constraints, Exprs, AsmString.get(),
6984 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006985}
6986
Chad Rosier32503022012-06-11 20:47:18 +00006987template<typename Derived>
6988StmtResult
6989TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006990 ArrayRef<Token> AsmToks =
6991 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006992
John McCallf413f5e2013-05-03 00:10:13 +00006993 bool HadError = false, HadChange = false;
6994
6995 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6996 SmallVector<Expr*, 8> TransformedExprs;
6997 TransformedExprs.reserve(SrcExprs.size());
6998 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6999 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
7000 if (!Result.isUsable()) {
7001 HadError = true;
7002 } else {
7003 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007004 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00007005 }
7006 }
7007
7008 if (HadError) return StmtError();
7009 if (!HadChange && !getDerived().AlwaysRebuild())
7010 return Owned(S);
7011
Chad Rosierb6f46c12012-08-15 16:53:30 +00007012 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00007013 AsmToks, S->getAsmString(),
7014 S->getNumOutputs(), S->getNumInputs(),
7015 S->getAllConstraints(), S->getClobbers(),
7016 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00007017}
Douglas Gregorebe10102009-08-20 07:17:43 +00007018
Richard Smith9f690bd2015-10-27 06:02:45 +00007019// C++ Coroutines TS
7020
7021template<typename Derived>
7022StmtResult
7023TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007024 auto *ScopeInfo = SemaRef.getCurFunction();
7025 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00007026 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007027 ScopeInfo->NeedsCoroutineSuspends &&
7028 ScopeInfo->CoroutineSuspends.first == nullptr &&
7029 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00007030 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007031
7032 // Set that we have (possibly-invalid) suspend points before we do anything
7033 // that may fail.
7034 ScopeInfo->setNeedsCoroutineSuspends(false);
7035
7036 // The new CoroutinePromise object needs to be built and put into the current
7037 // FunctionScopeInfo before any transformations or rebuilding occurs.
Brian Gesiak61f4ac92018-01-24 22:15:42 +00007038 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
7039 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007040 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
7041 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007042 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007043 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
7044 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007045
7046 // Transform the implicit coroutine statements we built during the initial
7047 // parse.
7048 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
7049 if (InitSuspend.isInvalid())
7050 return StmtError();
7051 StmtResult FinalSuspend =
7052 getDerived().TransformStmt(S->getFinalSuspendStmt());
7053 if (FinalSuspend.isInvalid())
7054 return StmtError();
7055 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
7056 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007057
7058 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
7059 if (BodyRes.isInvalid())
7060 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007061
Eric Fiselierbee782b2017-04-03 19:21:00 +00007062 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
7063 if (Builder.isInvalid())
7064 return StmtError();
7065
7066 Expr *ReturnObject = S->getReturnValueInit();
7067 assert(ReturnObject && "the return object is expected to be valid");
7068 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
7069 /*NoCopyInit*/ false);
7070 if (Res.isInvalid())
7071 return StmtError();
7072 Builder.ReturnValue = Res.get();
7073
7074 if (S->hasDependentPromiseType()) {
7075 assert(!Promise->getType()->isDependentType() &&
7076 "the promise type must no longer be dependent");
7077 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
7078 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
7079 "these nodes should not have been built yet");
7080 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007081 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007082 } else {
7083 if (auto *OnFallthrough = S->getFallthroughHandler()) {
7084 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
7085 if (Res.isInvalid())
7086 return StmtError();
7087 Builder.OnFallthrough = Res.get();
7088 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007089
Eric Fiselierbee782b2017-04-03 19:21:00 +00007090 if (auto *OnException = S->getExceptionHandler()) {
7091 StmtResult Res = getDerived().TransformStmt(OnException);
7092 if (Res.isInvalid())
7093 return StmtError();
7094 Builder.OnException = Res.get();
7095 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007096
Eric Fiselierbee782b2017-04-03 19:21:00 +00007097 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7098 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7099 if (Res.isInvalid())
7100 return StmtError();
7101 Builder.ReturnStmtOnAllocFailure = Res.get();
7102 }
7103
7104 // Transform any additional statements we may have already built
7105 assert(S->getAllocate() && S->getDeallocate() &&
7106 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007107 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7108 if (AllocRes.isInvalid())
7109 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007110 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007111
7112 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7113 if (DeallocRes.isInvalid())
7114 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007115 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007116
7117 assert(S->getResultDecl() && "ResultDecl must already be built");
7118 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7119 if (ResultDecl.isInvalid())
7120 return StmtError();
7121 Builder.ResultDecl = ResultDecl.get();
7122
7123 if (auto *ReturnStmt = S->getReturnStmt()) {
7124 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7125 if (Res.isInvalid())
7126 return StmtError();
7127 Builder.ReturnStmt = Res.get();
7128 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007129 }
7130
Eric Fiselierbee782b2017-04-03 19:21:00 +00007131 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007132}
7133
7134template<typename Derived>
7135StmtResult
7136TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7137 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7138 /*NotCopyInit*/false);
7139 if (Result.isInvalid())
7140 return StmtError();
7141
7142 // Always rebuild; we don't know if this needs to be injected into a new
7143 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007144 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7145 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007146}
7147
7148template<typename Derived>
7149ExprResult
7150TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7151 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7152 /*NotCopyInit*/false);
7153 if (Result.isInvalid())
7154 return ExprError();
7155
7156 // Always rebuild; we don't know if this needs to be injected into a new
7157 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007158 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7159 E->isImplicit());
7160}
7161
7162template <typename Derived>
7163ExprResult
7164TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7165 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7166 /*NotCopyInit*/ false);
7167 if (OperandResult.isInvalid())
7168 return ExprError();
7169
7170 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7171 E->getOperatorCoawaitLookup());
7172
7173 if (LookupResult.isInvalid())
7174 return ExprError();
7175
7176 // Always rebuild; we don't know if this needs to be injected into a new
7177 // context or if the promise type has changed.
7178 return getDerived().RebuildDependentCoawaitExpr(
7179 E->getKeywordLoc(), OperandResult.get(),
7180 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007181}
7182
7183template<typename Derived>
7184ExprResult
7185TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7186 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7187 /*NotCopyInit*/false);
7188 if (Result.isInvalid())
7189 return ExprError();
7190
7191 // Always rebuild; we don't know if this needs to be injected into a new
7192 // context or if the promise type has changed.
7193 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7194}
7195
7196// Objective-C Statements.
7197
Douglas Gregorebe10102009-08-20 07:17:43 +00007198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007200TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007201 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007202 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007203 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007204 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007205
Douglas Gregor96c79492010-04-23 22:50:49 +00007206 // Transform the @catch statements (if present).
7207 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007208 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007209 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007210 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007211 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007212 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007213 if (Catch.get() != S->getCatchStmt(I))
7214 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007215 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007216 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007217
Douglas Gregor306de2f2010-04-22 23:59:56 +00007218 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007219 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007220 if (S->getFinallyStmt()) {
7221 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7222 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007223 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007224 }
7225
7226 // If nothing changed, just retain this statement.
7227 if (!getDerived().AlwaysRebuild() &&
7228 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007229 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007230 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007231 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007232
Douglas Gregor306de2f2010-04-22 23:59:56 +00007233 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007234 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007235 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007236}
Mike Stump11289f42009-09-09 15:08:12 +00007237
Douglas Gregorebe10102009-08-20 07:17:43 +00007238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007239StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007240TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007241 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007242 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007243 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007244 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007245 if (FromVar->getTypeSourceInfo()) {
7246 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7247 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007248 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007250
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007251 QualType T;
7252 if (TSInfo)
7253 T = TSInfo->getType();
7254 else {
7255 T = getDerived().TransformType(FromVar->getType());
7256 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007257 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007259
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007260 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7261 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007262 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007264
John McCalldadc5752010-08-24 06:29:42 +00007265 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007266 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007267 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007268
7269 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007270 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007271 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007272}
Mike Stump11289f42009-09-09 15:08:12 +00007273
Douglas Gregorebe10102009-08-20 07:17:43 +00007274template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007275StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007276TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007277 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007278 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007279 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007280 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007281
Douglas Gregor306de2f2010-04-22 23:59:56 +00007282 // If nothing changed, just retain this statement.
7283 if (!getDerived().AlwaysRebuild() &&
7284 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007285 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007286
7287 // Build a new statement.
7288 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007289 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007290}
Mike Stump11289f42009-09-09 15:08:12 +00007291
Douglas Gregorebe10102009-08-20 07:17:43 +00007292template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007293StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007294TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007295 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007296 if (S->getThrowExpr()) {
7297 Operand = getDerived().TransformExpr(S->getThrowExpr());
7298 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007299 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007300 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007301
Douglas Gregor2900c162010-04-22 21:44:01 +00007302 if (!getDerived().AlwaysRebuild() &&
7303 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007304 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007305
John McCallb268a282010-08-23 23:25:46 +00007306 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007307}
Mike Stump11289f42009-09-09 15:08:12 +00007308
Douglas Gregorebe10102009-08-20 07:17:43 +00007309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007310StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007311TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007312 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007313 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007314 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007315 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007316 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007317 Object =
7318 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7319 Object.get());
7320 if (Object.isInvalid())
7321 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007322
Douglas Gregor6148de72010-04-22 22:01:21 +00007323 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007324 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007325 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007326 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007327
Douglas Gregor6148de72010-04-22 22:01:21 +00007328 // If nothing change, just retain the current statement.
7329 if (!getDerived().AlwaysRebuild() &&
7330 Object.get() == S->getSynchExpr() &&
7331 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007332 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007333
7334 // Build a new statement.
7335 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007336 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007337}
7338
7339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007340StmtResult
John McCall31168b02011-06-15 23:02:42 +00007341TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7342 ObjCAutoreleasePoolStmt *S) {
7343 // Transform the body.
7344 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7345 if (Body.isInvalid())
7346 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007347
John McCall31168b02011-06-15 23:02:42 +00007348 // If nothing changed, just retain this statement.
7349 if (!getDerived().AlwaysRebuild() &&
7350 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007351 return S;
John McCall31168b02011-06-15 23:02:42 +00007352
7353 // Build a new statement.
7354 return getDerived().RebuildObjCAutoreleasePoolStmt(
7355 S->getAtLoc(), Body.get());
7356}
7357
7358template<typename Derived>
7359StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007360TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007361 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007362 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007363 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007364 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007365 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007366
Douglas Gregorf68a5082010-04-22 23:10:45 +00007367 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007368 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007369 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007370 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007371
Douglas Gregorf68a5082010-04-22 23:10:45 +00007372 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007373 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007374 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007375 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007376
Douglas Gregorf68a5082010-04-22 23:10:45 +00007377 // If nothing changed, just retain this statement.
7378 if (!getDerived().AlwaysRebuild() &&
7379 Element.get() == S->getElement() &&
7380 Collection.get() == S->getCollection() &&
7381 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007382 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007383
Douglas Gregorf68a5082010-04-22 23:10:45 +00007384 // Build a new statement.
7385 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007386 Element.get(),
7387 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007388 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007389 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007390}
7391
David Majnemer5f7efef2013-10-15 09:50:08 +00007392template <typename Derived>
7393StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007394 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007395 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007396 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7397 TypeSourceInfo *T =
7398 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007399 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007400 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007401
David Majnemer5f7efef2013-10-15 09:50:08 +00007402 Var = getDerived().RebuildExceptionDecl(
7403 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7404 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007405 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007406 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007407 }
Mike Stump11289f42009-09-09 15:08:12 +00007408
Douglas Gregorebe10102009-08-20 07:17:43 +00007409 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007410 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007411 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007412 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007413
David Majnemer5f7efef2013-10-15 09:50:08 +00007414 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007415 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007416 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007417
David Majnemer5f7efef2013-10-15 09:50:08 +00007418 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007419}
Mike Stump11289f42009-09-09 15:08:12 +00007420
David Majnemer5f7efef2013-10-15 09:50:08 +00007421template <typename Derived>
7422StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007423 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007424 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007425 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007426 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007427
Douglas Gregorebe10102009-08-20 07:17:43 +00007428 // Transform the handlers.
7429 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007430 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007431 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007432 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007433 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007434 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007435
Douglas Gregorebe10102009-08-20 07:17:43 +00007436 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007437 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007438 }
Mike Stump11289f42009-09-09 15:08:12 +00007439
David Majnemer5f7efef2013-10-15 09:50:08 +00007440 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007441 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007442 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007443
John McCallb268a282010-08-23 23:25:46 +00007444 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007445 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007446}
Mike Stump11289f42009-09-09 15:08:12 +00007447
Richard Smith02e85f32011-04-14 22:09:26 +00007448template<typename Derived>
7449StmtResult
7450TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
Richard Smith8baa5002018-09-28 18:44:09 +00007451 StmtResult Init =
7452 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
7453 if (Init.isInvalid())
7454 return StmtError();
7455
Richard Smith02e85f32011-04-14 22:09:26 +00007456 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7457 if (Range.isInvalid())
7458 return StmtError();
7459
Richard Smith01694c32016-03-20 10:33:40 +00007460 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7461 if (Begin.isInvalid())
7462 return StmtError();
7463 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7464 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007465 return StmtError();
7466
7467 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7468 if (Cond.isInvalid())
7469 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007470 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007471 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007472 if (Cond.isInvalid())
7473 return StmtError();
7474 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007475 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007476
7477 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7478 if (Inc.isInvalid())
7479 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007480 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007481 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007482
7483 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7484 if (LoopVar.isInvalid())
7485 return StmtError();
7486
7487 StmtResult NewStmt = S;
7488 if (getDerived().AlwaysRebuild() ||
Richard Smith8baa5002018-09-28 18:44:09 +00007489 Init.get() != S->getInit() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007490 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007491 Begin.get() != S->getBeginStmt() ||
7492 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007493 Cond.get() != S->getCond() ||
7494 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007495 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007496 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007497 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007498 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007499 Begin.get(), End.get(),
7500 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007501 Inc.get(), LoopVar.get(),
7502 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007503 if (NewStmt.isInvalid())
7504 return StmtError();
7505 }
Richard Smith02e85f32011-04-14 22:09:26 +00007506
7507 StmtResult Body = getDerived().TransformStmt(S->getBody());
7508 if (Body.isInvalid())
7509 return StmtError();
7510
7511 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7512 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007513 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007514 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith8baa5002018-09-28 18:44:09 +00007515 S->getCoawaitLoc(), Init.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007516 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007517 Begin.get(), End.get(),
7518 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007519 Inc.get(), LoopVar.get(),
7520 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007521 if (NewStmt.isInvalid())
7522 return StmtError();
7523 }
Richard Smith02e85f32011-04-14 22:09:26 +00007524
7525 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007526 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007527
7528 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7529}
7530
John Wiegley1c0675e2011-04-28 01:08:34 +00007531template<typename Derived>
7532StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007533TreeTransform<Derived>::TransformMSDependentExistsStmt(
7534 MSDependentExistsStmt *S) {
7535 // Transform the nested-name-specifier, if any.
7536 NestedNameSpecifierLoc QualifierLoc;
7537 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007538 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007539 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7540 if (!QualifierLoc)
7541 return StmtError();
7542 }
7543
7544 // Transform the declaration name.
7545 DeclarationNameInfo NameInfo = S->getNameInfo();
7546 if (NameInfo.getName()) {
7547 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7548 if (!NameInfo.getName())
7549 return StmtError();
7550 }
7551
7552 // Check whether anything changed.
7553 if (!getDerived().AlwaysRebuild() &&
7554 QualifierLoc == S->getQualifierLoc() &&
7555 NameInfo.getName() == S->getNameInfo().getName())
7556 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007557
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007558 // Determine whether this name exists, if we can.
7559 CXXScopeSpec SS;
7560 SS.Adopt(QualifierLoc);
7561 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007562 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007563 case Sema::IER_Exists:
7564 if (S->isIfExists())
7565 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007566
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007567 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7568
7569 case Sema::IER_DoesNotExist:
7570 if (S->isIfNotExists())
7571 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007572
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007573 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007574
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007575 case Sema::IER_Dependent:
7576 Dependent = true;
7577 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007578
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007579 case Sema::IER_Error:
7580 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007581 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007582
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007583 // We need to continue with the instantiation, so do so now.
7584 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7585 if (SubStmt.isInvalid())
7586 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007587
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007588 // If we have resolved the name, just transform to the substatement.
7589 if (!Dependent)
7590 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007591
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007592 // The name is still dependent, so build a dependent expression again.
7593 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7594 S->isIfExists(),
7595 QualifierLoc,
7596 NameInfo,
7597 SubStmt.get());
7598}
7599
7600template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007601ExprResult
7602TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7603 NestedNameSpecifierLoc QualifierLoc;
7604 if (E->getQualifierLoc()) {
7605 QualifierLoc
7606 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7607 if (!QualifierLoc)
7608 return ExprError();
7609 }
7610
7611 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7612 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7613 if (!PD)
7614 return ExprError();
7615
7616 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7617 if (Base.isInvalid())
7618 return ExprError();
7619
7620 return new (SemaRef.getASTContext())
7621 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7622 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7623 QualifierLoc, E->getMemberLoc());
7624}
7625
David Majnemerfad8f482013-10-15 09:33:02 +00007626template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007627ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7628 MSPropertySubscriptExpr *E) {
7629 auto BaseRes = getDerived().TransformExpr(E->getBase());
7630 if (BaseRes.isInvalid())
7631 return ExprError();
7632 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7633 if (IdxRes.isInvalid())
7634 return ExprError();
7635
7636 if (!getDerived().AlwaysRebuild() &&
7637 BaseRes.get() == E->getBase() &&
7638 IdxRes.get() == E->getIdx())
7639 return E;
7640
7641 return getDerived().RebuildArraySubscriptExpr(
7642 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7643}
7644
7645template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007646StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007647 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007648 if (TryBlock.isInvalid())
7649 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007650
7651 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007652 if (Handler.isInvalid())
7653 return StmtError();
7654
David Majnemerfad8f482013-10-15 09:33:02 +00007655 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7656 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007657 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007658
Warren Huntf6be4cb2014-07-25 20:52:51 +00007659 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7660 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007661}
7662
David Majnemerfad8f482013-10-15 09:33:02 +00007663template <typename Derived>
7664StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007665 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007666 if (Block.isInvalid())
7667 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007668
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007669 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007670}
7671
David Majnemerfad8f482013-10-15 09:33:02 +00007672template <typename Derived>
7673StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007674 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007675 if (FilterExpr.isInvalid())
7676 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007677
David Majnemer7e755502013-10-15 09:30:14 +00007678 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007679 if (Block.isInvalid())
7680 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007681
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007682 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7683 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007684}
7685
David Majnemerfad8f482013-10-15 09:33:02 +00007686template <typename Derived>
7687StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7688 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007689 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7690 else
7691 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7692}
7693
Nico Weber9b982072014-07-07 00:12:30 +00007694template<typename Derived>
7695StmtResult
7696TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7697 return S;
7698}
7699
Alexander Musman64d33f12014-06-04 07:53:32 +00007700//===----------------------------------------------------------------------===//
7701// OpenMP directive transformation
7702//===----------------------------------------------------------------------===//
7703template <typename Derived>
7704StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7705 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007706
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007707 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007708 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007709 ArrayRef<OMPClause *> Clauses = D->clauses();
7710 TClauses.reserve(Clauses.size());
7711 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7712 I != E; ++I) {
7713 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007714 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007715 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007716 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007717 if (Clause)
7718 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007719 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007720 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007721 }
7722 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007723 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007724 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007725 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7726 /*CurScope=*/nullptr);
7727 StmtResult Body;
7728 {
7729 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007730 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007731 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007732 }
7733 AssociatedStmt =
7734 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007735 if (AssociatedStmt.isInvalid()) {
7736 return StmtError();
7737 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007738 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007739 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007740 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007741 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007742
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007743 // Transform directive name for 'omp critical' directive.
7744 DeclarationNameInfo DirName;
7745 if (D->getDirectiveKind() == OMPD_critical) {
7746 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7747 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7748 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007749 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7750 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7751 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007752 } else if (D->getDirectiveKind() == OMPD_cancel) {
7753 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007754 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007755
Alexander Musman64d33f12014-06-04 07:53:32 +00007756 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007757 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00007758 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007759}
7760
Alexander Musman64d33f12014-06-04 07:53:32 +00007761template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007762StmtResult
7763TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7764 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007765 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007766 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007767 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7768 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769 return Res;
7770}
7771
Alexander Musman64d33f12014-06-04 07:53:32 +00007772template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007773StmtResult
7774TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7775 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007776 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007777 D->getBeginLoc());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007778 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007780 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007781}
7782
Alexey Bataevf29276e2014-06-18 04:14:57 +00007783template <typename Derived>
7784StmtResult
7785TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7786 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007787 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007788 D->getBeginLoc());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007789 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7790 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7791 return Res;
7792}
7793
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007794template <typename Derived>
7795StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007796TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7797 DeclarationNameInfo DirName;
7798 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007799 D->getBeginLoc());
Alexander Musmanf82886e2014-09-18 05:12:34 +00007800 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7801 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7802 return Res;
7803}
7804
7805template <typename Derived>
7806StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007807TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7808 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007809 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007810 D->getBeginLoc());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007811 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7812 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7813 return Res;
7814}
7815
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007816template <typename Derived>
7817StmtResult
7818TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7819 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007820 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007821 D->getBeginLoc());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7824 return Res;
7825}
7826
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007827template <typename Derived>
7828StmtResult
7829TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7830 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007831 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007832 D->getBeginLoc());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007833 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7834 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7835 return Res;
7836}
7837
Alexey Bataev4acb8592014-07-07 13:01:15 +00007838template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007839StmtResult
7840TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7841 DeclarationNameInfo DirName;
7842 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007843 D->getBeginLoc());
Alexander Musman80c22892014-07-17 08:54:58 +00007844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7846 return Res;
7847}
7848
7849template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007850StmtResult
7851TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7852 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007853 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007854 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7855 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7856 return Res;
7857}
7858
7859template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007860StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7861 OMPParallelForDirective *D) {
7862 DeclarationNameInfo DirName;
7863 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007864 nullptr, D->getBeginLoc());
Alexey Bataev4acb8592014-07-07 13:01:15 +00007865 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7866 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7867 return Res;
7868}
7869
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007870template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007871StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7872 OMPParallelForSimdDirective *D) {
7873 DeclarationNameInfo DirName;
7874 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007875 nullptr, D->getBeginLoc());
Alexander Musmane4e893b2014-09-23 09:33:00 +00007876 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7877 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7878 return Res;
7879}
7880
7881template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007882StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7883 OMPParallelSectionsDirective *D) {
7884 DeclarationNameInfo DirName;
7885 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007886 nullptr, D->getBeginLoc());
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007887 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7888 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7889 return Res;
7890}
7891
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007892template <typename Derived>
7893StmtResult
7894TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7895 DeclarationNameInfo DirName;
7896 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007897 D->getBeginLoc());
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007898 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7899 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7900 return Res;
7901}
7902
Alexey Bataev68446b72014-07-18 07:47:19 +00007903template <typename Derived>
7904StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7905 OMPTaskyieldDirective *D) {
7906 DeclarationNameInfo DirName;
7907 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007908 D->getBeginLoc());
Alexey Bataev68446b72014-07-18 07:47:19 +00007909 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7910 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7911 return Res;
7912}
7913
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007914template <typename Derived>
7915StmtResult
7916TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7917 DeclarationNameInfo DirName;
7918 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007919 D->getBeginLoc());
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007920 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7921 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7922 return Res;
7923}
7924
Alexey Bataev2df347a2014-07-18 10:17:07 +00007925template <typename Derived>
7926StmtResult
7927TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7928 DeclarationNameInfo DirName;
7929 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007930 D->getBeginLoc());
Alexey Bataev2df347a2014-07-18 10:17:07 +00007931 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7932 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7933 return Res;
7934}
7935
Alexey Bataev6125da92014-07-21 11:26:11 +00007936template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007937StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7938 OMPTaskgroupDirective *D) {
7939 DeclarationNameInfo DirName;
7940 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007941 D->getBeginLoc());
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007942 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7943 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7944 return Res;
7945}
7946
7947template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007948StmtResult
7949TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7950 DeclarationNameInfo DirName;
7951 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007952 D->getBeginLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00007953 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7954 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7955 return Res;
7956}
7957
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007958template <typename Derived>
7959StmtResult
7960TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7961 DeclarationNameInfo DirName;
7962 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007963 D->getBeginLoc());
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007964 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7965 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7966 return Res;
7967}
7968
Alexey Bataev0162e452014-07-22 10:10:35 +00007969template <typename Derived>
7970StmtResult
7971TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7972 DeclarationNameInfo DirName;
7973 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007974 D->getBeginLoc());
Alexey Bataev0162e452014-07-22 10:10:35 +00007975 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7976 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7977 return Res;
7978}
7979
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007980template <typename Derived>
7981StmtResult
7982TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7983 DeclarationNameInfo DirName;
7984 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007985 D->getBeginLoc());
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007986 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7987 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7988 return Res;
7989}
7990
Alexey Bataev13314bf2014-10-09 04:18:56 +00007991template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007992StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7993 OMPTargetDataDirective *D) {
7994 DeclarationNameInfo DirName;
7995 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00007996 D->getBeginLoc());
Michael Wong65f367f2015-07-21 13:44:28 +00007997 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7998 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7999 return Res;
8000}
8001
8002template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00008003StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
8004 OMPTargetEnterDataDirective *D) {
8005 DeclarationNameInfo DirName;
8006 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008007 nullptr, D->getBeginLoc());
Samuel Antaodf67fc42016-01-19 19:15:56 +00008008 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8009 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8010 return Res;
8011}
8012
8013template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00008014StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
8015 OMPTargetExitDataDirective *D) {
8016 DeclarationNameInfo DirName;
8017 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008018 nullptr, D->getBeginLoc());
Samuel Antao72590762016-01-19 20:04:50 +00008019 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8020 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8021 return Res;
8022}
8023
8024template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008025StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
8026 OMPTargetParallelDirective *D) {
8027 DeclarationNameInfo DirName;
8028 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008029 nullptr, D->getBeginLoc());
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00008030 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8031 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8032 return Res;
8033}
8034
8035template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008036StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
8037 OMPTargetParallelForDirective *D) {
8038 DeclarationNameInfo DirName;
8039 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008040 nullptr, D->getBeginLoc());
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00008041 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8042 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8043 return Res;
8044}
8045
8046template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00008047StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
8048 OMPTargetUpdateDirective *D) {
8049 DeclarationNameInfo DirName;
8050 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008051 nullptr, D->getBeginLoc());
Samuel Antao686c70c2016-05-26 17:30:50 +00008052 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8053 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8054 return Res;
8055}
8056
8057template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00008058StmtResult
8059TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
8060 DeclarationNameInfo DirName;
8061 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008062 D->getBeginLoc());
Alexey Bataev13314bf2014-10-09 04:18:56 +00008063 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8064 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8065 return Res;
8066}
8067
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008068template <typename Derived>
8069StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
8070 OMPCancellationPointDirective *D) {
8071 DeclarationNameInfo DirName;
8072 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008073 nullptr, D->getBeginLoc());
Alexey Bataev6d4ed052015-07-01 06:57:41 +00008074 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8075 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8076 return Res;
8077}
8078
Alexey Bataev80909872015-07-02 11:25:17 +00008079template <typename Derived>
8080StmtResult
8081TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
8082 DeclarationNameInfo DirName;
8083 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008084 D->getBeginLoc());
Alexey Bataev80909872015-07-02 11:25:17 +00008085 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8086 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8087 return Res;
8088}
8089
Alexey Bataev49f6e782015-12-01 04:18:41 +00008090template <typename Derived>
8091StmtResult
8092TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
8093 DeclarationNameInfo DirName;
8094 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008095 D->getBeginLoc());
Alexey Bataev49f6e782015-12-01 04:18:41 +00008096 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8097 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8098 return Res;
8099}
8100
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008101template <typename Derived>
8102StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8103 OMPTaskLoopSimdDirective *D) {
8104 DeclarationNameInfo DirName;
8105 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008106 nullptr, D->getBeginLoc());
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008107 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8108 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8109 return Res;
8110}
8111
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008112template <typename Derived>
8113StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8114 OMPDistributeDirective *D) {
8115 DeclarationNameInfo DirName;
8116 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008117 D->getBeginLoc());
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008118 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8119 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8120 return Res;
8121}
8122
Carlo Bertolli9925f152016-06-27 14:55:37 +00008123template <typename Derived>
8124StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8125 OMPDistributeParallelForDirective *D) {
8126 DeclarationNameInfo DirName;
8127 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008128 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Carlo Bertolli9925f152016-06-27 14:55:37 +00008129 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8130 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8131 return Res;
8132}
8133
Kelvin Li4a39add2016-07-05 05:00:15 +00008134template <typename Derived>
8135StmtResult
8136TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8137 OMPDistributeParallelForSimdDirective *D) {
8138 DeclarationNameInfo DirName;
8139 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008140 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4a39add2016-07-05 05:00:15 +00008141 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8142 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8143 return Res;
8144}
8145
Kelvin Li787f3fc2016-07-06 04:45:38 +00008146template <typename Derived>
8147StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8148 OMPDistributeSimdDirective *D) {
8149 DeclarationNameInfo DirName;
8150 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008151 nullptr, D->getBeginLoc());
Kelvin Li787f3fc2016-07-06 04:45:38 +00008152 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8153 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8154 return Res;
8155}
8156
Kelvin Lia579b912016-07-14 02:54:56 +00008157template <typename Derived>
8158StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8159 OMPTargetParallelForSimdDirective *D) {
8160 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008161 getDerived().getSema().StartOpenMPDSABlock(
8162 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lia579b912016-07-14 02:54:56 +00008163 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8164 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8165 return Res;
8166}
8167
Kelvin Li986330c2016-07-20 22:57:10 +00008168template <typename Derived>
8169StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8170 OMPTargetSimdDirective *D) {
8171 DeclarationNameInfo DirName;
8172 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008173 D->getBeginLoc());
Kelvin Li986330c2016-07-20 22:57:10 +00008174 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8175 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8176 return Res;
8177}
8178
Kelvin Li02532872016-08-05 14:37:37 +00008179template <typename Derived>
8180StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8181 OMPTeamsDistributeDirective *D) {
8182 DeclarationNameInfo DirName;
8183 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008184 nullptr, D->getBeginLoc());
Kelvin Li02532872016-08-05 14:37:37 +00008185 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8186 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8187 return Res;
8188}
8189
Kelvin Li4e325f72016-10-25 12:50:55 +00008190template <typename Derived>
8191StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8192 OMPTeamsDistributeSimdDirective *D) {
8193 DeclarationNameInfo DirName;
8194 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008195 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Li4e325f72016-10-25 12:50:55 +00008196 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8197 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8198 return Res;
8199}
8200
Kelvin Li579e41c2016-11-30 23:51:03 +00008201template <typename Derived>
8202StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8203 OMPTeamsDistributeParallelForSimdDirective *D) {
8204 DeclarationNameInfo DirName;
8205 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008206 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
8207 D->getBeginLoc());
Kelvin Li579e41c2016-11-30 23:51:03 +00008208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8210 return Res;
8211}
8212
Kelvin Li7ade93f2016-12-09 03:24:30 +00008213template <typename Derived>
8214StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8215 OMPTeamsDistributeParallelForDirective *D) {
8216 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008217 getDerived().getSema().StartOpenMPDSABlock(
8218 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
Kelvin Li7ade93f2016-12-09 03:24:30 +00008219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8221 return Res;
8222}
8223
Kelvin Libf594a52016-12-17 05:48:59 +00008224template <typename Derived>
8225StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8226 OMPTargetTeamsDirective *D) {
8227 DeclarationNameInfo DirName;
8228 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008229 nullptr, D->getBeginLoc());
Kelvin Libf594a52016-12-17 05:48:59 +00008230 auto Res = getDerived().TransformOMPExecutableDirective(D);
8231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8232 return Res;
8233}
Kelvin Li579e41c2016-11-30 23:51:03 +00008234
Kelvin Li83c451e2016-12-25 04:52:54 +00008235template <typename Derived>
8236StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8237 OMPTargetTeamsDistributeDirective *D) {
8238 DeclarationNameInfo DirName;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008239 getDerived().getSema().StartOpenMPDSABlock(
8240 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
Kelvin Li83c451e2016-12-25 04:52:54 +00008241 auto Res = getDerived().TransformOMPExecutableDirective(D);
8242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8243 return Res;
8244}
8245
Kelvin Li80e8f562016-12-29 22:16:30 +00008246template <typename Derived>
8247StmtResult
8248TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8249 OMPTargetTeamsDistributeParallelForDirective *D) {
8250 DeclarationNameInfo DirName;
8251 getDerived().getSema().StartOpenMPDSABlock(
8252 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008253 D->getBeginLoc());
Kelvin Li80e8f562016-12-29 22:16:30 +00008254 auto Res = getDerived().TransformOMPExecutableDirective(D);
8255 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8256 return Res;
8257}
8258
Kelvin Li1851df52017-01-03 05:23:48 +00008259template <typename Derived>
8260StmtResult TreeTransform<Derived>::
8261 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8262 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8263 DeclarationNameInfo DirName;
8264 getDerived().getSema().StartOpenMPDSABlock(
8265 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008266 D->getBeginLoc());
Kelvin Li1851df52017-01-03 05:23:48 +00008267 auto Res = getDerived().TransformOMPExecutableDirective(D);
8268 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8269 return Res;
8270}
8271
Kelvin Lida681182017-01-10 18:08:18 +00008272template <typename Derived>
8273StmtResult
8274TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8275 OMPTargetTeamsDistributeSimdDirective *D) {
8276 DeclarationNameInfo DirName;
8277 getDerived().getSema().StartOpenMPDSABlock(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008278 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
Kelvin Lida681182017-01-10 18:08:18 +00008279 auto Res = getDerived().TransformOMPExecutableDirective(D);
8280 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8281 return Res;
8282}
8283
Kelvin Li1851df52017-01-03 05:23:48 +00008284
Alexander Musman64d33f12014-06-04 07:53:32 +00008285//===----------------------------------------------------------------------===//
8286// OpenMP clause transformation
8287//===----------------------------------------------------------------------===//
8288template <typename Derived>
8289OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008290 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8291 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008292 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008293 return getDerived().RebuildOMPIfClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008294 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008295 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008296}
8297
Alexander Musman64d33f12014-06-04 07:53:32 +00008298template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008299OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8300 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8301 if (Cond.isInvalid())
8302 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008303 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008304 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev3778b602014-07-17 07:32:53 +00008305}
8306
8307template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008308OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008309TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8310 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8311 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008312 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008313 return getDerived().RebuildOMPNumThreadsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008314 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev568a8332014-03-06 06:15:19 +00008315}
8316
Alexey Bataev62c87d22014-03-21 04:51:18 +00008317template <typename Derived>
8318OMPClause *
8319TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8320 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8321 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008322 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008323 return getDerived().RebuildOMPSafelenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008324 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008325}
8326
Alexander Musman8bd31e62014-05-27 15:12:19 +00008327template <typename Derived>
8328OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008329TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8330 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8331 if (E.isInvalid())
8332 return nullptr;
8333 return getDerived().RebuildOMPSimdlenClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008334 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev66b15b52015-08-21 11:14:16 +00008335}
8336
8337template <typename Derived>
8338OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008339TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8340 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8341 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008342 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008343 return getDerived().RebuildOMPCollapseClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008344 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008345}
8346
Alexander Musman64d33f12014-06-04 07:53:32 +00008347template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008348OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008349TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008350 return getDerived().RebuildOMPDefaultClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008351 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008352 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008353}
8354
Alexander Musman64d33f12014-06-04 07:53:32 +00008355template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008356OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008357TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008358 return getDerived().RebuildOMPProcBindClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008359 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008360 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008361}
8362
Alexander Musman64d33f12014-06-04 07:53:32 +00008363template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008364OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008365TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8366 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8367 if (E.isInvalid())
8368 return nullptr;
8369 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008370 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008371 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008372 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008373 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Alexey Bataev56dafe82014-06-20 07:16:17 +00008374}
8375
8376template <typename Derived>
8377OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008378TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008379 ExprResult E;
8380 if (auto *Num = C->getNumForLoops()) {
8381 E = getDerived().TransformExpr(Num);
8382 if (E.isInvalid())
8383 return nullptr;
8384 }
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008385 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
Alexey Bataev10e775f2015-07-30 11:36:16 +00008386 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008387}
8388
8389template <typename Derived>
8390OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008391TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8392 // No need to rebuild this clause, no template-dependent parameters.
8393 return C;
8394}
8395
8396template <typename Derived>
8397OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008398TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8399 // No need to rebuild this clause, no template-dependent parameters.
8400 return C;
8401}
8402
8403template <typename Derived>
8404OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008405TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8406 // No need to rebuild this clause, no template-dependent parameters.
8407 return C;
8408}
8409
8410template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008411OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8412 // No need to rebuild this clause, no template-dependent parameters.
8413 return C;
8414}
8415
8416template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008417OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8418 // No need to rebuild this clause, no template-dependent parameters.
8419 return C;
8420}
8421
8422template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008423OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008424TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8425 // No need to rebuild this clause, no template-dependent parameters.
8426 return C;
8427}
8428
8429template <typename Derived>
8430OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008431TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8432 // No need to rebuild this clause, no template-dependent parameters.
8433 return C;
8434}
8435
8436template <typename Derived>
8437OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008438TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8439 // No need to rebuild this clause, no template-dependent parameters.
8440 return C;
8441}
8442
8443template <typename Derived>
8444OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008445TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8446 // No need to rebuild this clause, no template-dependent parameters.
8447 return C;
8448}
8449
8450template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008451OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8452 // No need to rebuild this clause, no template-dependent parameters.
8453 return C;
8454}
8455
8456template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008457OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008458TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8459 // No need to rebuild this clause, no template-dependent parameters.
8460 return C;
8461}
8462
8463template <typename Derived>
Kelvin Li1408f912018-09-26 04:28:39 +00008464OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
8465 OMPUnifiedAddressClause *C) {
Patrick Lystere653b632018-09-27 19:30:32 +00008466 llvm_unreachable("unified_address clause cannot appear in dependent context");
Kelvin Li1408f912018-09-26 04:28:39 +00008467}
8468
8469template <typename Derived>
Patrick Lyster4a370b92018-10-01 13:47:43 +00008470OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
8471 OMPUnifiedSharedMemoryClause *C) {
8472 llvm_unreachable(
8473 "unified_shared_memory clause cannot appear in dependent context");
8474}
8475
8476template <typename Derived>
Patrick Lyster6bdf63b2018-10-03 20:07:58 +00008477OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
8478 OMPReverseOffloadClause *C) {
8479 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
8480}
8481
8482template <typename Derived>
Patrick Lyster3fe9e392018-10-11 14:41:10 +00008483OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
8484 OMPDynamicAllocatorsClause *C) {
8485 llvm_unreachable(
8486 "dynamic_allocators clause cannot appear in dependent context");
8487}
8488
8489template <typename Derived>
Patrick Lyster7a2a27c2018-11-02 12:18:11 +00008490OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
8491 OMPAtomicDefaultMemOrderClause *C) {
8492 llvm_unreachable(
8493 "atomic_default_mem_order clause cannot appear in dependent context");
8494}
8495
8496template <typename Derived>
Alexey Bataevb825de12015-12-07 10:51:44 +00008497OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008498TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008499 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008500 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008501 for (auto *VE : C->varlists()) {
8502 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008503 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008504 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008505 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008506 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008507 return getDerived().RebuildOMPPrivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008508 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008509}
8510
Alexander Musman64d33f12014-06-04 07:53:32 +00008511template <typename Derived>
8512OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8513 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008514 llvm::SmallVector<Expr *, 16> Vars;
8515 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008516 for (auto *VE : C->varlists()) {
8517 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008518 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008519 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008520 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008521 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008522 return getDerived().RebuildOMPFirstprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008523 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008524}
8525
Alexander Musman64d33f12014-06-04 07:53:32 +00008526template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008527OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008528TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8529 llvm::SmallVector<Expr *, 16> Vars;
8530 Vars.reserve(C->varlist_size());
8531 for (auto *VE : C->varlists()) {
8532 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8533 if (EVar.isInvalid())
8534 return nullptr;
8535 Vars.push_back(EVar.get());
8536 }
8537 return getDerived().RebuildOMPLastprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008538 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexander Musman1bb328c2014-06-04 13:06:39 +00008539}
8540
8541template <typename Derived>
8542OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008543TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8544 llvm::SmallVector<Expr *, 16> Vars;
8545 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008546 for (auto *VE : C->varlists()) {
8547 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008548 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008549 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008550 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008551 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008552 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008553 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008554}
8555
Alexander Musman64d33f12014-06-04 07:53:32 +00008556template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008557OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008558TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8559 llvm::SmallVector<Expr *, 16> Vars;
8560 Vars.reserve(C->varlist_size());
8561 for (auto *VE : C->varlists()) {
8562 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8563 if (EVar.isInvalid())
8564 return nullptr;
8565 Vars.push_back(EVar.get());
8566 }
8567 CXXScopeSpec ReductionIdScopeSpec;
8568 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8569
8570 DeclarationNameInfo NameInfo = C->getNameInfo();
8571 if (NameInfo.getName()) {
8572 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8573 if (!NameInfo.getName())
8574 return nullptr;
8575 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008576 // Build a list of all UDR decls with the same names ranged by the Scopes.
8577 // The Scope boundary is a duplication of the previous decl.
8578 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8579 for (auto *E : C->reduction_ops()) {
8580 // Transform all the decls.
8581 if (E) {
8582 auto *ULE = cast<UnresolvedLookupExpr>(E);
8583 UnresolvedSet<8> Decls;
8584 for (auto *D : ULE->decls()) {
8585 NamedDecl *InstD =
8586 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8587 Decls.addDecl(InstD, InstD->getAccess());
8588 }
8589 UnresolvedReductions.push_back(
8590 UnresolvedLookupExpr::Create(
8591 SemaRef.Context, /*NamingClass=*/nullptr,
8592 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8593 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8594 Decls.begin(), Decls.end()));
8595 } else
8596 UnresolvedReductions.push_back(nullptr);
8597 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008598 return getDerived().RebuildOMPReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008599 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008600 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008601}
8602
8603template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008604OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8605 OMPTaskReductionClause *C) {
8606 llvm::SmallVector<Expr *, 16> Vars;
8607 Vars.reserve(C->varlist_size());
8608 for (auto *VE : C->varlists()) {
8609 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8610 if (EVar.isInvalid())
8611 return nullptr;
8612 Vars.push_back(EVar.get());
8613 }
8614 CXXScopeSpec ReductionIdScopeSpec;
8615 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8616
8617 DeclarationNameInfo NameInfo = C->getNameInfo();
8618 if (NameInfo.getName()) {
8619 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8620 if (!NameInfo.getName())
8621 return nullptr;
8622 }
8623 // Build a list of all UDR decls with the same names ranged by the Scopes.
8624 // The Scope boundary is a duplication of the previous decl.
8625 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8626 for (auto *E : C->reduction_ops()) {
8627 // Transform all the decls.
8628 if (E) {
8629 auto *ULE = cast<UnresolvedLookupExpr>(E);
8630 UnresolvedSet<8> Decls;
8631 for (auto *D : ULE->decls()) {
8632 NamedDecl *InstD =
8633 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8634 Decls.addDecl(InstD, InstD->getAccess());
8635 }
8636 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8637 SemaRef.Context, /*NamingClass=*/nullptr,
8638 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8639 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8640 } else
8641 UnresolvedReductions.push_back(nullptr);
8642 }
8643 return getDerived().RebuildOMPTaskReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008644 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008645 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataev169d96a2017-07-18 20:17:46 +00008646}
8647
8648template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008649OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008650TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8651 llvm::SmallVector<Expr *, 16> Vars;
8652 Vars.reserve(C->varlist_size());
8653 for (auto *VE : C->varlists()) {
8654 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8655 if (EVar.isInvalid())
8656 return nullptr;
8657 Vars.push_back(EVar.get());
8658 }
8659 CXXScopeSpec ReductionIdScopeSpec;
8660 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8661
8662 DeclarationNameInfo NameInfo = C->getNameInfo();
8663 if (NameInfo.getName()) {
8664 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8665 if (!NameInfo.getName())
8666 return nullptr;
8667 }
8668 // Build a list of all UDR decls with the same names ranged by the Scopes.
8669 // The Scope boundary is a duplication of the previous decl.
8670 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8671 for (auto *E : C->reduction_ops()) {
8672 // Transform all the decls.
8673 if (E) {
8674 auto *ULE = cast<UnresolvedLookupExpr>(E);
8675 UnresolvedSet<8> Decls;
8676 for (auto *D : ULE->decls()) {
8677 NamedDecl *InstD =
8678 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8679 Decls.addDecl(InstD, InstD->getAccess());
8680 }
8681 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8682 SemaRef.Context, /*NamingClass=*/nullptr,
8683 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8684 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8685 } else
8686 UnresolvedReductions.push_back(nullptr);
8687 }
8688 return getDerived().RebuildOMPInReductionClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008689 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008690 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevfa312f32017-07-21 18:48:21 +00008691}
8692
8693template <typename Derived>
8694OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008695TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8696 llvm::SmallVector<Expr *, 16> Vars;
8697 Vars.reserve(C->varlist_size());
8698 for (auto *VE : C->varlists()) {
8699 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8700 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008701 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008702 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008703 }
8704 ExprResult Step = getDerived().TransformExpr(C->getStep());
8705 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008706 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008707 return getDerived().RebuildOMPLinearClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008708 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008709 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
Alexander Musman8dba6642014-04-22 13:09:42 +00008710}
8711
Alexander Musman64d33f12014-06-04 07:53:32 +00008712template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008713OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008714TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8715 llvm::SmallVector<Expr *, 16> Vars;
8716 Vars.reserve(C->varlist_size());
8717 for (auto *VE : C->varlists()) {
8718 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8719 if (EVar.isInvalid())
8720 return nullptr;
8721 Vars.push_back(EVar.get());
8722 }
8723 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8724 if (Alignment.isInvalid())
8725 return nullptr;
8726 return getDerived().RebuildOMPAlignedClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008727 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008728 C->getColonLoc(), C->getEndLoc());
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008729}
8730
Alexander Musman64d33f12014-06-04 07:53:32 +00008731template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008732OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008733TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8734 llvm::SmallVector<Expr *, 16> Vars;
8735 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008736 for (auto *VE : C->varlists()) {
8737 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008738 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008739 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008740 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008741 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008742 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008743 C->getLParenLoc(), C->getEndLoc());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008744}
8745
Alexey Bataevbae9a792014-06-27 10:37:06 +00008746template <typename Derived>
8747OMPClause *
8748TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8749 llvm::SmallVector<Expr *, 16> Vars;
8750 Vars.reserve(C->varlist_size());
8751 for (auto *VE : C->varlists()) {
8752 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8753 if (EVar.isInvalid())
8754 return nullptr;
8755 Vars.push_back(EVar.get());
8756 }
8757 return getDerived().RebuildOMPCopyprivateClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008758 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataevbae9a792014-06-27 10:37:06 +00008759}
8760
Alexey Bataev6125da92014-07-21 11:26:11 +00008761template <typename Derived>
8762OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8763 llvm::SmallVector<Expr *, 16> Vars;
8764 Vars.reserve(C->varlist_size());
8765 for (auto *VE : C->varlists()) {
8766 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8767 if (EVar.isInvalid())
8768 return nullptr;
8769 Vars.push_back(EVar.get());
8770 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008771 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008772 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev6125da92014-07-21 11:26:11 +00008773}
8774
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008775template <typename Derived>
8776OMPClause *
8777TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8778 llvm::SmallVector<Expr *, 16> Vars;
8779 Vars.reserve(C->varlist_size());
8780 for (auto *VE : C->varlists()) {
8781 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8782 if (EVar.isInvalid())
8783 return nullptr;
8784 Vars.push_back(EVar.get());
8785 }
8786 return getDerived().RebuildOMPDependClause(
8787 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008788 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008789}
8790
Michael Wonge710d542015-08-07 16:16:36 +00008791template <typename Derived>
8792OMPClause *
8793TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8794 ExprResult E = getDerived().TransformExpr(C->getDevice());
8795 if (E.isInvalid())
8796 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008797 return getDerived().RebuildOMPDeviceClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008798 C->getLParenLoc(), C->getEndLoc());
Michael Wonge710d542015-08-07 16:16:36 +00008799}
8800
Kelvin Li0bff7af2015-11-23 05:32:03 +00008801template <typename Derived>
8802OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8803 llvm::SmallVector<Expr *, 16> Vars;
8804 Vars.reserve(C->varlist_size());
8805 for (auto *VE : C->varlists()) {
8806 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8807 if (EVar.isInvalid())
8808 return nullptr;
8809 Vars.push_back(EVar.get());
8810 }
8811 return getDerived().RebuildOMPMapClause(
Kelvin Lief579432018-12-18 22:18:41 +00008812 C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), C->getMapType(),
8813 C->isImplicitMapType(), C->getMapLoc(), C->getColonLoc(), Vars,
8814 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008815}
8816
Kelvin Li099bb8c2015-11-24 20:50:12 +00008817template <typename Derived>
8818OMPClause *
8819TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8820 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8821 if (E.isInvalid())
8822 return nullptr;
8823 return getDerived().RebuildOMPNumTeamsClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008824 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Li099bb8c2015-11-24 20:50:12 +00008825}
8826
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008827template <typename Derived>
8828OMPClause *
8829TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8830 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8831 if (E.isInvalid())
8832 return nullptr;
8833 return getDerived().RebuildOMPThreadLimitClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008834 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008835}
8836
Alexey Bataeva0569352015-12-01 10:17:31 +00008837template <typename Derived>
8838OMPClause *
8839TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8840 ExprResult E = getDerived().TransformExpr(C->getPriority());
8841 if (E.isInvalid())
8842 return nullptr;
8843 return getDerived().RebuildOMPPriorityClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008844 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataeva0569352015-12-01 10:17:31 +00008845}
8846
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008847template <typename Derived>
8848OMPClause *
8849TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8850 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8851 if (E.isInvalid())
8852 return nullptr;
8853 return getDerived().RebuildOMPGrainsizeClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008854 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008855}
8856
Alexey Bataev382967a2015-12-08 12:06:20 +00008857template <typename Derived>
8858OMPClause *
8859TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8860 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8861 if (E.isInvalid())
8862 return nullptr;
8863 return getDerived().RebuildOMPNumTasksClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008864 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Alexey Bataev382967a2015-12-08 12:06:20 +00008865}
8866
Alexey Bataev28c75412015-12-15 08:19:24 +00008867template <typename Derived>
8868OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8869 ExprResult E = getDerived().TransformExpr(C->getHint());
8870 if (E.isInvalid())
8871 return nullptr;
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008872 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008873 C->getLParenLoc(), C->getEndLoc());
Alexey Bataev28c75412015-12-15 08:19:24 +00008874}
8875
Carlo Bertollib4adf552016-01-15 18:50:31 +00008876template <typename Derived>
8877OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8878 OMPDistScheduleClause *C) {
8879 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8880 if (E.isInvalid())
8881 return nullptr;
8882 return getDerived().RebuildOMPDistScheduleClause(
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008883 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008884 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
Carlo Bertollib4adf552016-01-15 18:50:31 +00008885}
8886
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008887template <typename Derived>
8888OMPClause *
8889TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8890 return C;
8891}
8892
Samuel Antao661c0902016-05-26 17:39:58 +00008893template <typename Derived>
8894OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8895 llvm::SmallVector<Expr *, 16> Vars;
8896 Vars.reserve(C->varlist_size());
8897 for (auto *VE : C->varlists()) {
8898 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8899 if (EVar.isInvalid())
8900 return 0;
8901 Vars.push_back(EVar.get());
8902 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008903 return getDerived().RebuildOMPToClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008904 C->getLParenLoc(), C->getEndLoc());
Samuel Antao661c0902016-05-26 17:39:58 +00008905}
8906
Samuel Antaoec172c62016-05-26 17:49:04 +00008907template <typename Derived>
8908OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8909 llvm::SmallVector<Expr *, 16> Vars;
8910 Vars.reserve(C->varlist_size());
8911 for (auto *VE : C->varlists()) {
8912 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8913 if (EVar.isInvalid())
8914 return 0;
8915 Vars.push_back(EVar.get());
8916 }
Stephen Kellyf2ceec42018-08-09 21:08:08 +00008917 return getDerived().RebuildOMPFromClause(Vars, C->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008918 C->getLParenLoc(), C->getEndLoc());
Samuel Antaoec172c62016-05-26 17:49:04 +00008919}
8920
Carlo Bertolli2404b172016-07-13 15:37:16 +00008921template <typename Derived>
8922OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8923 OMPUseDevicePtrClause *C) {
8924 llvm::SmallVector<Expr *, 16> Vars;
8925 Vars.reserve(C->varlist_size());
8926 for (auto *VE : C->varlists()) {
8927 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8928 if (EVar.isInvalid())
8929 return nullptr;
8930 Vars.push_back(EVar.get());
8931 }
8932 return getDerived().RebuildOMPUseDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008933 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli2404b172016-07-13 15:37:16 +00008934}
8935
Carlo Bertolli70594e92016-07-13 17:16:49 +00008936template <typename Derived>
8937OMPClause *
8938TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8939 llvm::SmallVector<Expr *, 16> Vars;
8940 Vars.reserve(C->varlist_size());
8941 for (auto *VE : C->varlists()) {
8942 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8943 if (EVar.isInvalid())
8944 return nullptr;
8945 Vars.push_back(EVar.get());
8946 }
8947 return getDerived().RebuildOMPIsDevicePtrClause(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00008948 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
Carlo Bertolli70594e92016-07-13 17:16:49 +00008949}
8950
Douglas Gregorebe10102009-08-20 07:17:43 +00008951//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008952// Expression transformation
8953//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008954template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008955ExprResult
Bill Wendling7c44da22018-10-31 03:48:47 +00008956TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
8957 return TransformExpr(E->getSubExpr());
8958}
8959
8960template<typename Derived>
8961ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008962TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008963 if (!E->isTypeDependent())
8964 return E;
8965
8966 return getDerived().RebuildPredefinedExpr(E->getLocation(),
Bruno Ricci17ff0262018-10-27 19:21:19 +00008967 E->getIdentKind());
Douglas Gregora16548e2009-08-11 05:31:07 +00008968}
Mike Stump11289f42009-09-09 15:08:12 +00008969
8970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008972TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008973 NestedNameSpecifierLoc QualifierLoc;
8974 if (E->getQualifierLoc()) {
8975 QualifierLoc
8976 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8977 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008978 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008979 }
John McCallce546572009-12-08 09:08:17 +00008980
8981 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008982 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8983 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008984 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008986
John McCall815039a2010-08-17 21:27:17 +00008987 DeclarationNameInfo NameInfo = E->getNameInfo();
8988 if (NameInfo.getName()) {
8989 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8990 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008991 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008992 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008993
8994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008995 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008996 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008997 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008998 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008999
9000 // Mark it referenced in the new context regardless.
9001 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009002 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00009003
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009004 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00009005 }
John McCallce546572009-12-08 09:08:17 +00009006
Craig Topperc3ec1492014-05-26 06:22:03 +00009007 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00009008 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00009009 TemplateArgs = &TransArgs;
9010 TransArgs.setLAngleLoc(E->getLAngleLoc());
9011 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009012 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9013 E->getNumTemplateArgs(),
9014 TransArgs))
9015 return ExprError();
John McCallce546572009-12-08 09:08:17 +00009016 }
9017
Chad Rosier1dcde962012-08-08 18:46:20 +00009018 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00009019 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009020}
Mike Stump11289f42009-09-09 15:08:12 +00009021
Douglas Gregora16548e2009-08-11 05:31:07 +00009022template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009023ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009024TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009025 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009026}
Mike Stump11289f42009-09-09 15:08:12 +00009027
Leonard Chandb01c3a2018-06-20 17:19:40 +00009028template <typename Derived>
9029ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
9030 FixedPointLiteral *E) {
9031 return E;
9032}
9033
Douglas Gregora16548e2009-08-11 05:31:07 +00009034template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009035ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009036TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009037 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009038}
Mike Stump11289f42009-09-09 15:08:12 +00009039
Douglas Gregora16548e2009-08-11 05:31:07 +00009040template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009041ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009042TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009043 return E;
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>::TransformStringLiteral(StringLiteral *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
Douglas Gregora16548e2009-08-11 05:31:07 +00009052template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009053ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009054TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009055 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009056}
9057
9058template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009059ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00009060TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00009061 if (FunctionDecl *FD = E->getDirectCallee())
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009062 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00009063 return SemaRef.MaybeBindToTemporary(E);
9064}
9065
9066template<typename Derived>
9067ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00009068TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
9069 ExprResult ControllingExpr =
9070 getDerived().TransformExpr(E->getControllingExpr());
9071 if (ControllingExpr.isInvalid())
9072 return ExprError();
9073
Chris Lattner01cf8db2011-07-20 06:58:45 +00009074 SmallVector<Expr *, 4> AssocExprs;
9075 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009076 for (const GenericSelectionExpr::Association &Assoc : E->associations()) {
9077 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
9078 if (TSI) {
9079 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
Peter Collingbourne91147592011-04-15 00:35:48 +00009080 if (!AssocType)
9081 return ExprError();
9082 AssocTypes.push_back(AssocType);
9083 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009084 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00009085 }
9086
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00009087 ExprResult AssocExpr =
9088 getDerived().TransformExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00009089 if (AssocExpr.isInvalid())
9090 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009091 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00009092 }
9093
9094 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
9095 E->getDefaultLoc(),
9096 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009097 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00009098 AssocTypes,
9099 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00009100}
9101
9102template<typename Derived>
9103ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009104TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009105 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009106 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009107 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009108
Douglas Gregora16548e2009-08-11 05:31:07 +00009109 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009110 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009111
John McCallb268a282010-08-23 23:25:46 +00009112 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009113 E->getRParen());
9114}
9115
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009116/// The operand of a unary address-of operator has special rules: it's
Richard Smithdb2630f2012-10-21 03:28:35 +00009117/// allowed to refer to a non-static member of a class even if there's no 'this'
9118/// object available.
9119template<typename Derived>
9120ExprResult
9121TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
9122 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00009123 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009124 else
9125 return getDerived().TransformExpr(E);
9126}
9127
Mike Stump11289f42009-09-09 15:08:12 +00009128template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009129ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009130TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00009131 ExprResult SubExpr;
9132 if (E->getOpcode() == UO_AddrOf)
9133 SubExpr = TransformAddressOfOperand(E->getSubExpr());
9134 else
9135 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009136 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009138
Douglas Gregora16548e2009-08-11 05:31:07 +00009139 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009140 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009141
Douglas Gregora16548e2009-08-11 05:31:07 +00009142 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9143 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009144 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009145}
Mike Stump11289f42009-09-09 15:08:12 +00009146
Douglas Gregora16548e2009-08-11 05:31:07 +00009147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009148ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009149TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9150 // Transform the type.
9151 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9152 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009153 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009154
Douglas Gregor882211c2010-04-28 22:16:22 +00009155 // Transform all of the components into components similar to what the
9156 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009157 // FIXME: It would be slightly more efficient in the non-dependent case to
9158 // just map FieldDecls, rather than requiring the rebuilder to look for
9159 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009160 // template code that we don't care.
9161 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009162 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009163 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009164 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009165 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009166 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009167 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009168 Comp.LocStart = ON.getSourceRange().getBegin();
9169 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009170 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009171 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009172 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009173 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009174 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009175 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009176
Douglas Gregor882211c2010-04-28 22:16:22 +00009177 ExprChanged = ExprChanged || Index.get() != FromIndex;
9178 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009179 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009180 break;
9181 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009182
James Y Knight7281c352015-12-29 22:31:18 +00009183 case OffsetOfNode::Field:
9184 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009185 Comp.isBrackets = false;
9186 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009187 if (!Comp.U.IdentInfo)
9188 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009189
Douglas Gregor882211c2010-04-28 22:16:22 +00009190 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009191
James Y Knight7281c352015-12-29 22:31:18 +00009192 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009193 // Will be recomputed during the rebuild.
9194 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009196
Douglas Gregor882211c2010-04-28 22:16:22 +00009197 Components.push_back(Comp);
9198 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009199
Douglas Gregor882211c2010-04-28 22:16:22 +00009200 // If nothing changed, retain the existing expression.
9201 if (!getDerived().AlwaysRebuild() &&
9202 Type == E->getTypeSourceInfo() &&
9203 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009204 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009205
Douglas Gregor882211c2010-04-28 22:16:22 +00009206 // Build a new offsetof expression.
9207 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009208 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009209}
9210
9211template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009212ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009213TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009214 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009215 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009216 return E;
John McCall8d69a212010-11-15 23:31:06 +00009217}
9218
9219template<typename Derived>
9220ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009221TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9222 return E;
9223}
9224
9225template<typename Derived>
9226ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009227TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009228 // Rebuild the syntactic form. The original syntactic form has
9229 // opaque-value expressions in it, so strip those away and rebuild
9230 // the result. This is a really awful way of doing this, but the
9231 // better solution (rebuilding the semantic expressions and
9232 // rebinding OVEs as necessary) doesn't work; we'd need
9233 // TreeTransform to not strip away implicit conversions.
9234 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9235 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009236 if (result.isInvalid()) return ExprError();
9237
9238 // If that gives us a pseudo-object result back, the pseudo-object
9239 // expression must have been an lvalue-to-rvalue conversion which we
9240 // should reapply.
9241 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009242 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009243
9244 return result;
9245}
9246
9247template<typename Derived>
9248ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009249TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9250 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009251 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009252 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009253
John McCallbcd03502009-12-07 02:54:59 +00009254 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009255 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009256 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009257
John McCall4c98fd82009-11-04 07:28:41 +00009258 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009259 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009260
Peter Collingbournee190dee2011-03-11 19:24:49 +00009261 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9262 E->getKind(),
9263 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009264 }
Mike Stump11289f42009-09-09 15:08:12 +00009265
Eli Friedmane4f22df2012-02-29 04:03:55 +00009266 // C++0x [expr.sizeof]p1:
9267 // The operand is either an expression, which is an unevaluated operand
9268 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009269 EnterExpressionEvaluationContext Unevaluated(
9270 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9271 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009272
Reid Kleckner32506ed2014-06-12 23:03:48 +00009273 // Try to recover if we have something like sizeof(T::X) where X is a type.
9274 // Notably, there must be *exactly* one set of parens if X is a type.
9275 TypeSourceInfo *RecoveryTSI = nullptr;
9276 ExprResult SubExpr;
9277 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9278 if (auto *DRE =
9279 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9280 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9281 PE, DRE, false, &RecoveryTSI);
9282 else
9283 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9284
9285 if (RecoveryTSI) {
9286 return getDerived().RebuildUnaryExprOrTypeTrait(
9287 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9288 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009289 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009290
Eli Friedmane4f22df2012-02-29 04:03:55 +00009291 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009292 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009293
Peter Collingbournee190dee2011-03-11 19:24:49 +00009294 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9295 E->getOperatorLoc(),
9296 E->getKind(),
9297 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009298}
Mike Stump11289f42009-09-09 15:08:12 +00009299
Douglas Gregora16548e2009-08-11 05:31:07 +00009300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009301ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009302TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009303 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009304 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009305 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009306
John McCalldadc5752010-08-24 06:29:42 +00009307 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009308 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009309 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009310
9311
Douglas Gregora16548e2009-08-11 05:31:07 +00009312 if (!getDerived().AlwaysRebuild() &&
9313 LHS.get() == E->getLHS() &&
9314 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009315 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009316
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009317 return getDerived().RebuildArraySubscriptExpr(
9318 LHS.get(),
9319 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009320}
Mike Stump11289f42009-09-09 15:08:12 +00009321
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009322template <typename Derived>
9323ExprResult
9324TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9325 ExprResult Base = getDerived().TransformExpr(E->getBase());
9326 if (Base.isInvalid())
9327 return ExprError();
9328
9329 ExprResult LowerBound;
9330 if (E->getLowerBound()) {
9331 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9332 if (LowerBound.isInvalid())
9333 return ExprError();
9334 }
9335
9336 ExprResult Length;
9337 if (E->getLength()) {
9338 Length = getDerived().TransformExpr(E->getLength());
9339 if (Length.isInvalid())
9340 return ExprError();
9341 }
9342
9343 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9344 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9345 return E;
9346
9347 return getDerived().RebuildOMPArraySectionExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009348 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), E->getColonLoc(),
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009349 Length.get(), E->getRBracketLoc());
9350}
9351
Mike Stump11289f42009-09-09 15:08:12 +00009352template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009353ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009354TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009355 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009356 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009357 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009358 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009359
9360 // Transform arguments.
9361 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009362 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009363 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009364 &ArgChanged))
9365 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009366
Douglas Gregora16548e2009-08-11 05:31:07 +00009367 if (!getDerived().AlwaysRebuild() &&
9368 Callee.get() == E->getCallee() &&
9369 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009370 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009371
Douglas Gregora16548e2009-08-11 05:31:07 +00009372 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009373 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009374 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009375 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009376 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009377 E->getRParenLoc());
9378}
Mike Stump11289f42009-09-09 15:08:12 +00009379
9380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009382TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009383 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009384 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009386
Douglas Gregorea972d32011-02-28 21:54:11 +00009387 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009388 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009389 QualifierLoc
9390 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009391
Douglas Gregorea972d32011-02-28 21:54:11 +00009392 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009393 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009394 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009395 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009396
Eli Friedman2cfcef62009-12-04 06:40:45 +00009397 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009398 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9399 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009400 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009401 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009402
John McCall16df1e52010-03-30 21:47:33 +00009403 NamedDecl *FoundDecl = E->getFoundDecl();
9404 if (FoundDecl == E->getMemberDecl()) {
9405 FoundDecl = Member;
9406 } else {
9407 FoundDecl = cast_or_null<NamedDecl>(
9408 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9409 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009410 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009411 }
9412
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (!getDerived().AlwaysRebuild() &&
9414 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009415 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009416 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009417 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009418 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009419
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009420 // Mark it referenced in the new context regardless.
9421 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009422 SemaRef.MarkMemberReferenced(E);
9423
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009424 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009425 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009426
John McCall6b51f282009-11-23 01:53:49 +00009427 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009428 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009429 TransArgs.setLAngleLoc(E->getLAngleLoc());
9430 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009431 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9432 E->getNumTemplateArgs(),
9433 TransArgs))
9434 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009435 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009436
Douglas Gregora16548e2009-08-11 05:31:07 +00009437 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009438 SourceLocation FakeOperatorLoc =
9439 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009440
John McCall38836f02010-01-15 08:34:02 +00009441 // FIXME: to do this check properly, we will need to preserve the
9442 // first-qualifier-in-scope here, just in case we had a dependent
9443 // base (and therefore couldn't do the check) and a
9444 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009445 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009446 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9447 if (MemberNameInfo.getName()) {
9448 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9449 if (!MemberNameInfo.getName())
9450 return ExprError();
9451 }
John McCall38836f02010-01-15 08:34:02 +00009452
John McCallb268a282010-08-23 23:25:46 +00009453 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009454 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009455 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009456 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009457 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009458 Member,
John McCall16df1e52010-03-30 21:47:33 +00009459 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009460 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009461 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009462 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009463}
Mike Stump11289f42009-09-09 15:08:12 +00009464
Douglas Gregora16548e2009-08-11 05:31:07 +00009465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009466ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009467TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009468 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009469 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009470 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009471
John McCalldadc5752010-08-24 06:29:42 +00009472 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009473 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009474 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009475
Douglas Gregora16548e2009-08-11 05:31:07 +00009476 if (!getDerived().AlwaysRebuild() &&
9477 LHS.get() == E->getLHS() &&
9478 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009479 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009480
Lang Hames5de91cc2012-10-02 04:45:10 +00009481 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009482 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009483
Douglas Gregora16548e2009-08-11 05:31:07 +00009484 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009485 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009486}
9487
Mike Stump11289f42009-09-09 15:08:12 +00009488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009489ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009490TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009491 CompoundAssignOperator *E) {
9492 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009493}
Mike Stump11289f42009-09-09 15:08:12 +00009494
Douglas Gregora16548e2009-08-11 05:31:07 +00009495template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009496ExprResult TreeTransform<Derived>::
9497TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9498 // Just rebuild the common and RHS expressions and see whether we
9499 // get any changes.
9500
9501 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9502 if (commonExpr.isInvalid())
9503 return ExprError();
9504
9505 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9506 if (rhs.isInvalid())
9507 return ExprError();
9508
9509 if (!getDerived().AlwaysRebuild() &&
9510 commonExpr.get() == e->getCommon() &&
9511 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009512 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009513
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009514 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009515 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009516 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009517 e->getColonLoc(),
9518 rhs.get());
9519}
9520
9521template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009522ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009523TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009524 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009525 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009526 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009527
John McCalldadc5752010-08-24 06:29:42 +00009528 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009529 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009530 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009531
John McCalldadc5752010-08-24 06:29:42 +00009532 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009533 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009534 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009535
Douglas Gregora16548e2009-08-11 05:31:07 +00009536 if (!getDerived().AlwaysRebuild() &&
9537 Cond.get() == E->getCond() &&
9538 LHS.get() == E->getLHS() &&
9539 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009540 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009541
John McCallb268a282010-08-23 23:25:46 +00009542 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009543 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009544 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009545 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009546 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009547}
Mike Stump11289f42009-09-09 15:08:12 +00009548
9549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009550ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009551TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009552 // Implicit casts are eliminated during transformation, since they
9553 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009554 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009555}
Mike Stump11289f42009-09-09 15:08:12 +00009556
Douglas Gregora16548e2009-08-11 05:31:07 +00009557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009559TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009560 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9561 if (!Type)
9562 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009563
John McCalldadc5752010-08-24 06:29:42 +00009564 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009565 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009566 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009568
Douglas Gregora16548e2009-08-11 05:31:07 +00009569 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009570 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009571 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009572 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009573
John McCall97513962010-01-15 18:39:57 +00009574 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009575 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009576 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009577 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009578}
Mike Stump11289f42009-09-09 15:08:12 +00009579
Douglas Gregora16548e2009-08-11 05:31:07 +00009580template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009581ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009582TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009583 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9584 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9585 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009586 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009587
John McCalldadc5752010-08-24 06:29:42 +00009588 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009589 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009590 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009591
Douglas Gregora16548e2009-08-11 05:31:07 +00009592 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009593 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009594 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009595 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009596
John McCall5d7aa7f2010-01-19 22:33:45 +00009597 // Note: the expression type doesn't necessarily match the
9598 // type-as-written, but that's okay, because it should always be
9599 // derivable from the initializer.
9600
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009601 return getDerived().RebuildCompoundLiteralExpr(
9602 E->getLParenLoc(), NewT,
9603 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009604}
Mike Stump11289f42009-09-09 15:08:12 +00009605
Douglas Gregora16548e2009-08-11 05:31:07 +00009606template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009607ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009608TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009609 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009610 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009612
Douglas Gregora16548e2009-08-11 05:31:07 +00009613 if (!getDerived().AlwaysRebuild() &&
9614 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009615 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009616
Douglas Gregora16548e2009-08-11 05:31:07 +00009617 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009618 SourceLocation FakeOperatorLoc =
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009619 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
John McCallb268a282010-08-23 23:25:46 +00009620 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009621 E->getAccessorLoc(),
9622 E->getAccessor());
9623}
Mike Stump11289f42009-09-09 15:08:12 +00009624
Douglas Gregora16548e2009-08-11 05:31:07 +00009625template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009626ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009627TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009628 if (InitListExpr *Syntactic = E->getSyntacticForm())
9629 E = Syntactic;
9630
Douglas Gregora16548e2009-08-11 05:31:07 +00009631 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009632
Richard Smith12938cf2018-09-26 04:36:55 +00009633 EnterExpressionEvaluationContext Context(
9634 getSema(), EnterExpressionEvaluationContext::InitList);
9635
Benjamin Kramerf0623432012-08-23 22:51:59 +00009636 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009637 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009638 Inits, &InitChanged))
9639 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009640
Richard Smith520449d2015-02-05 06:15:50 +00009641 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9642 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9643 // in some cases. We can't reuse it in general, because the syntactic and
9644 // semantic forms are linked, and we can't know that semantic form will
9645 // match even if the syntactic form does.
9646 }
Mike Stump11289f42009-09-09 15:08:12 +00009647
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009648 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009649 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009650}
Mike Stump11289f42009-09-09 15:08:12 +00009651
Douglas Gregora16548e2009-08-11 05:31:07 +00009652template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009653ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009654TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009655 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009656
Douglas Gregorebe10102009-08-20 07:17:43 +00009657 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009658 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009659 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009660 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009661
Douglas Gregorebe10102009-08-20 07:17:43 +00009662 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009663 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009664 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009665 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9666 if (D.isFieldDesignator()) {
9667 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9668 D.getDotLoc(),
9669 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009670 if (D.getField()) {
9671 FieldDecl *Field = cast_or_null<FieldDecl>(
9672 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9673 if (Field != D.getField())
9674 // Rebuild the expression when the transformed FieldDecl is
9675 // different to the already assigned FieldDecl.
9676 ExprChanged = true;
9677 } else {
9678 // Ensure that the designator expression is rebuilt when there isn't
9679 // a resolved FieldDecl in the designator as we don't want to assign
9680 // a FieldDecl to a pattern designator that will be instantiated again.
9681 ExprChanged = true;
9682 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009683 continue;
9684 }
Mike Stump11289f42009-09-09 15:08:12 +00009685
David Majnemerf7e36092016-06-23 00:15:04 +00009686 if (D.isArrayDesignator()) {
9687 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009688 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009690
David Majnemerf7e36092016-06-23 00:15:04 +00009691 Desig.AddDesignator(
9692 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009693
David Majnemerf7e36092016-06-23 00:15:04 +00009694 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009695 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009696 continue;
9697 }
Mike Stump11289f42009-09-09 15:08:12 +00009698
David Majnemerf7e36092016-06-23 00:15:04 +00009699 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009700 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009701 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009702 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009704
David Majnemerf7e36092016-06-23 00:15:04 +00009705 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009707 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009708
9709 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009711 D.getLBracketLoc(),
9712 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009713
David Majnemerf7e36092016-06-23 00:15:04 +00009714 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9715 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009716
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009717 ArrayExprs.push_back(Start.get());
9718 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009719 }
Mike Stump11289f42009-09-09 15:08:12 +00009720
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 if (!getDerived().AlwaysRebuild() &&
9722 Init.get() == E->getInit() &&
9723 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009724 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009725
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009726 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009727 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009728 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009729}
Mike Stump11289f42009-09-09 15:08:12 +00009730
Yunzhong Gaocb779302015-06-10 00:27:52 +00009731// Seems that if TransformInitListExpr() only works on the syntactic form of an
9732// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9733template<typename Derived>
9734ExprResult
9735TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9736 DesignatedInitUpdateExpr *E) {
9737 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9738 "initializer");
9739 return ExprError();
9740}
9741
9742template<typename Derived>
9743ExprResult
9744TreeTransform<Derived>::TransformNoInitExpr(
9745 NoInitExpr *E) {
9746 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9747 return ExprError();
9748}
9749
Douglas Gregora16548e2009-08-11 05:31:07 +00009750template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009751ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009752TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9753 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9754 return ExprError();
9755}
9756
9757template<typename Derived>
9758ExprResult
9759TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9760 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9761 return ExprError();
9762}
9763
9764template<typename Derived>
9765ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009766TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009767 ImplicitValueInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +00009768 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009769
Douglas Gregor3da3c062009-10-28 00:29:27 +00009770 // FIXME: Will we ever have proper type location here? Will we actually
9771 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 QualType T = getDerived().TransformType(E->getType());
9773 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009774 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009775
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 if (!getDerived().AlwaysRebuild() &&
9777 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009778 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009779
Douglas Gregora16548e2009-08-11 05:31:07 +00009780 return getDerived().RebuildImplicitValueInitExpr(T);
9781}
Mike Stump11289f42009-09-09 15:08:12 +00009782
Douglas Gregora16548e2009-08-11 05:31:07 +00009783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009784ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009785TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009786 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9787 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009788 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009789
John McCalldadc5752010-08-24 06:29:42 +00009790 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009791 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009792 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora16548e2009-08-11 05:31:07 +00009794 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009795 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009796 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009797 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009798
John McCallb268a282010-08-23 23:25:46 +00009799 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009800 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009801}
9802
9803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009805TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009806 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009807 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009808 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9809 &ArgumentChanged))
9810 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009811
Douglas Gregora16548e2009-08-11 05:31:07 +00009812 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009813 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009814 E->getRParenLoc());
9815}
Mike Stump11289f42009-09-09 15:08:12 +00009816
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00009817/// Transform an address-of-label expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00009818///
9819/// By default, the transformation of an address-of-label expression always
9820/// rebuilds the expression, so that the label identifier can be resolved to
9821/// the corresponding label statement by semantic analysis.
9822template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009823ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009824TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009825 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9826 E->getLabel());
9827 if (!LD)
9828 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009829
Douglas Gregora16548e2009-08-11 05:31:07 +00009830 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009831 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009832}
Mike Stump11289f42009-09-09 15:08:12 +00009833
9834template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009836TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009837 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009838 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009839 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009840 if (SubStmt.isInvalid()) {
9841 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009842 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009843 }
Mike Stump11289f42009-09-09 15:08:12 +00009844
Douglas Gregora16548e2009-08-11 05:31:07 +00009845 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009846 SubStmt.get() == E->getSubStmt()) {
9847 // Calling this an 'error' is unintuitive, but it does the right thing.
9848 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009849 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009850 }
Mike Stump11289f42009-09-09 15:08:12 +00009851
9852 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009853 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009854 E->getRParenLoc());
9855}
Mike Stump11289f42009-09-09 15:08:12 +00009856
Douglas Gregora16548e2009-08-11 05:31:07 +00009857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009859TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009860 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009861 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009863
John McCalldadc5752010-08-24 06:29:42 +00009864 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009865 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009867
John McCalldadc5752010-08-24 06:29:42 +00009868 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009869 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009871
Douglas Gregora16548e2009-08-11 05:31:07 +00009872 if (!getDerived().AlwaysRebuild() &&
9873 Cond.get() == E->getCond() &&
9874 LHS.get() == E->getLHS() &&
9875 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009876 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009877
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009879 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009880 E->getRParenLoc());
9881}
Mike Stump11289f42009-09-09 15:08:12 +00009882
Douglas Gregora16548e2009-08-11 05:31:07 +00009883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009885TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009886 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009887}
9888
9889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009891TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009892 switch (E->getOperator()) {
9893 case OO_New:
9894 case OO_Delete:
9895 case OO_Array_New:
9896 case OO_Array_Delete:
9897 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009898
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009899 case OO_Call: {
9900 // This is a call to an object's operator().
9901 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9902
9903 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009904 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009905 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009906 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009907
9908 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009909 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009910 static_cast<Expr *>(Object.get())->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009911
9912 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009913 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009914 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009915 Args))
9916 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009917
Stephen Kelly1c301dc2018-08-09 21:09:38 +00009918 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
9919 E->getEndLoc());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009920 }
9921
9922#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9923 case OO_##Name:
9924#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9925#include "clang/Basic/OperatorKinds.def"
9926 case OO_Subscript:
9927 // Handled below.
9928 break;
9929
9930 case OO_Conditional:
9931 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009932
9933 case OO_None:
9934 case NUM_OVERLOADED_OPERATORS:
9935 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009936 }
9937
John McCalldadc5752010-08-24 06:29:42 +00009938 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009939 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009940 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009941
Richard Smithdb2630f2012-10-21 03:28:35 +00009942 ExprResult First;
9943 if (E->getOperator() == OO_Amp)
9944 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9945 else
9946 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009947 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009948 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009949
John McCalldadc5752010-08-24 06:29:42 +00009950 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009951 if (E->getNumArgs() == 2) {
9952 Second = getDerived().TransformExpr(E->getArg(1));
9953 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009954 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009955 }
Mike Stump11289f42009-09-09 15:08:12 +00009956
Douglas Gregora16548e2009-08-11 05:31:07 +00009957 if (!getDerived().AlwaysRebuild() &&
9958 Callee.get() == E->getCallee() &&
9959 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009960 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009961 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009962
Lang Hames5de91cc2012-10-02 04:45:10 +00009963 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009964 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009965
Douglas Gregora16548e2009-08-11 05:31:07 +00009966 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9967 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009968 Callee.get(),
9969 First.get(),
9970 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009971}
Mike Stump11289f42009-09-09 15:08:12 +00009972
Douglas Gregora16548e2009-08-11 05:31:07 +00009973template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009974ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009975TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9976 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009977}
Mike Stump11289f42009-09-09 15:08:12 +00009978
Douglas Gregora16548e2009-08-11 05:31:07 +00009979template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009980ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009981TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9982 // Transform the callee.
9983 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9984 if (Callee.isInvalid())
9985 return ExprError();
9986
9987 // Transform exec config.
9988 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9989 if (EC.isInvalid())
9990 return ExprError();
9991
9992 // Transform arguments.
9993 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009994 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009995 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009996 &ArgChanged))
9997 return ExprError();
9998
9999 if (!getDerived().AlwaysRebuild() &&
10000 Callee.get() == E->getCallee() &&
10001 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010002 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +000010003
10004 // FIXME: Wrong source location information for the '('.
10005 SourceLocation FakeLParenLoc
10006 = ((Expr *)Callee.get())->getSourceRange().getBegin();
10007 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010008 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +000010009 E->getRParenLoc(), EC.get());
10010}
10011
10012template<typename Derived>
10013ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010014TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010015 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
10016 if (!Type)
10017 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010018
John McCalldadc5752010-08-24 06:29:42 +000010019 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010020 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010021 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010022 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010023
Douglas Gregora16548e2009-08-11 05:31:07 +000010024 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010025 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010026 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010027 return E;
Nico Weberc153d242014-07-28 00:02:09 +000010028 return getDerived().RebuildCXXNamedCastExpr(
10029 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
10030 Type, E->getAngleBrackets().getEnd(),
10031 // FIXME. this should be '(' location
10032 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010033}
Mike Stump11289f42009-09-09 15:08:12 +000010034
Douglas Gregora16548e2009-08-11 05:31:07 +000010035template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010036ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010037TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
10038 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010039}
Mike Stump11289f42009-09-09 15:08:12 +000010040
10041template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010043TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
10044 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +000010045}
10046
Douglas Gregora16548e2009-08-11 05:31:07 +000010047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010048ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010049TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010050 CXXReinterpretCastExpr *E) {
10051 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010052}
Mike Stump11289f42009-09-09 15:08:12 +000010053
Douglas Gregora16548e2009-08-11 05:31:07 +000010054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010055ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010056TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
10057 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +000010058}
Mike Stump11289f42009-09-09 15:08:12 +000010059
Douglas Gregora16548e2009-08-11 05:31:07 +000010060template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010061ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010062TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010063 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010064 TypeSourceInfo *Type =
10065 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010066 if (!Type)
10067 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010068
John McCalldadc5752010-08-24 06:29:42 +000010069 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +000010070 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +000010071 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010072 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010073
Douglas Gregora16548e2009-08-11 05:31:07 +000010074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010075 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010076 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010077 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010078
Douglas Gregor3b29b2c2010-09-09 16:55:46 +000010079 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +000010080 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +000010081 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010082 E->getRParenLoc(),
10083 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000010084}
Mike Stump11289f42009-09-09 15:08:12 +000010085
Douglas Gregora16548e2009-08-11 05:31:07 +000010086template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010087ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010088TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010089 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +000010090 TypeSourceInfo *TInfo
10091 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10092 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010093 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010094
Douglas Gregora16548e2009-08-11 05:31:07 +000010095 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +000010096 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010097 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010098
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010099 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010100 TInfo, E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010101 }
Mike Stump11289f42009-09-09 15:08:12 +000010102
Eli Friedman456f0182012-01-20 01:26:23 +000010103 // We don't know whether the subexpression is potentially evaluated until
10104 // after we perform semantic analysis. We speculatively assume it is
10105 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +000010106 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +000010107 EnterExpressionEvaluationContext Unevaluated(
10108 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
10109 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +000010110
John McCalldadc5752010-08-24 06:29:42 +000010111 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +000010112 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010114
Douglas Gregora16548e2009-08-11 05:31:07 +000010115 if (!getDerived().AlwaysRebuild() &&
10116 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010117 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010118
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010119 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010120 SubExpr.get(), E->getEndLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010121}
10122
10123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010124ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +000010125TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
10126 if (E->isTypeOperand()) {
10127 TypeSourceInfo *TInfo
10128 = getDerived().TransformType(E->getTypeOperandSourceInfo());
10129 if (!TInfo)
10130 return ExprError();
10131
10132 if (!getDerived().AlwaysRebuild() &&
10133 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010134 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010135
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010136 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010137 TInfo, E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010138 }
10139
Faisal Valid143a0c2017-04-01 21:30:49 +000010140 EnterExpressionEvaluationContext Unevaluated(
10141 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010142
10143 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10144 if (SubExpr.isInvalid())
10145 return ExprError();
10146
10147 if (!getDerived().AlwaysRebuild() &&
10148 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010149 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010150
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010151 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010152 SubExpr.get(), E->getEndLoc());
Francois Pichet9f4f2072010-09-08 12:20:18 +000010153}
10154
10155template<typename Derived>
10156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010157TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010158 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010159}
Mike Stump11289f42009-09-09 15:08:12 +000010160
Douglas Gregora16548e2009-08-11 05:31:07 +000010161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010162ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010163TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010164 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010165 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010166}
Mike Stump11289f42009-09-09 15:08:12 +000010167
Douglas Gregora16548e2009-08-11 05:31:07 +000010168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010169ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010170TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010171 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010172
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010173 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10174 // Make sure that we capture 'this'.
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010175 getSema().CheckCXXThisCapture(E->getBeginLoc());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010176 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010177 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010178
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010179 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010180}
Mike Stump11289f42009-09-09 15:08:12 +000010181
Douglas Gregora16548e2009-08-11 05:31:07 +000010182template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010183ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010184TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010185 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010186 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010187 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010188
Douglas Gregora16548e2009-08-11 05:31:07 +000010189 if (!getDerived().AlwaysRebuild() &&
10190 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010191 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010192
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010193 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10194 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010195}
Mike Stump11289f42009-09-09 15:08:12 +000010196
Douglas Gregora16548e2009-08-11 05:31:07 +000010197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010198ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010199TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010200 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
10201 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010202 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010203 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010204
Chandler Carruth794da4c2010-02-08 06:42:49 +000010205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010206 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010207 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010208
Douglas Gregor033f6752009-12-23 23:03:06 +000010209 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010210}
Mike Stump11289f42009-09-09 15:08:12 +000010211
Douglas Gregora16548e2009-08-11 05:31:07 +000010212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010213ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010214TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010215 FieldDecl *Field = cast_or_null<FieldDecl>(
10216 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
Richard Smith852c9db2013-04-20 22:23:05 +000010217 if (!Field)
10218 return ExprError();
10219
10220 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010221 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010222
10223 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10224}
10225
10226template<typename Derived>
10227ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010228TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10229 CXXScalarValueInitExpr *E) {
10230 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10231 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010232 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010233
Douglas Gregora16548e2009-08-11 05:31:07 +000010234 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010235 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010236 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010237
Chad Rosier1dcde962012-08-08 18:46:20 +000010238 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010239 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010240 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010241}
Mike Stump11289f42009-09-09 15:08:12 +000010242
Douglas Gregora16548e2009-08-11 05:31:07 +000010243template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010244ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010245TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010246 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010247 TypeSourceInfo *AllocTypeInfo =
10248 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010249 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010250 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010251
Douglas Gregora16548e2009-08-11 05:31:07 +000010252 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010253 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010254 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010256
Douglas Gregora16548e2009-08-11 05:31:07 +000010257 // Transform the placement arguments (if any).
10258 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010259 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010260 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010261 E->getNumPlacementArgs(), true,
10262 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010264
Sebastian Redl6047f072012-02-16 12:22:20 +000010265 // Transform the initializer (if any).
10266 Expr *OldInit = E->getInitializer();
10267 ExprResult NewInit;
10268 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010269 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010270 if (NewInit.isInvalid())
10271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010272
Sebastian Redl6047f072012-02-16 12:22:20 +000010273 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010274 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010275 if (E->getOperatorNew()) {
10276 OperatorNew = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010277 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010278 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010279 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010280 }
10281
Craig Topperc3ec1492014-05-26 06:22:03 +000010282 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010283 if (E->getOperatorDelete()) {
10284 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010285 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010286 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010287 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010288 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010289
Douglas Gregora16548e2009-08-11 05:31:07 +000010290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010291 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010292 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010293 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010294 OperatorNew == E->getOperatorNew() &&
10295 OperatorDelete == E->getOperatorDelete() &&
10296 !ArgumentChanged) {
10297 // Mark any declarations we need as referenced.
10298 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010299 if (OperatorNew)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010300 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010301 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010302 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010303
Sebastian Redl6047f072012-02-16 12:22:20 +000010304 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010305 QualType ElementType
10306 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10307 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10308 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10309 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010310 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010311 }
10312 }
10313 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010314
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010315 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010316 }
Mike Stump11289f42009-09-09 15:08:12 +000010317
Douglas Gregor0744ef62010-09-07 21:49:58 +000010318 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010319 if (!ArraySize.get()) {
10320 // If no array size was specified, but the new expression was
10321 // instantiated with an array type (e.g., "new T" where T is
10322 // instantiated with "int[4]"), extract the outer bound from the
10323 // array type as our array size. We do this with constant and
10324 // dependently-sized array types.
10325 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10326 if (!ArrayT) {
10327 // Do nothing
10328 } else if (const ConstantArrayType *ConsArrayT
10329 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010330 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10331 SemaRef.Context.getSizeType(),
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010332 /*FIXME:*/ E->getBeginLoc());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010333 AllocType = ConsArrayT->getElementType();
10334 } else if (const DependentSizedArrayType *DepArrayT
10335 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10336 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010337 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010338 AllocType = DepArrayT->getElementType();
10339 }
10340 }
10341 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010342
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010343 return getDerived().RebuildCXXNewExpr(
10344 E->getBeginLoc(), E->isGlobalNew(),
10345 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
10346 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
10347 AllocTypeInfo, ArraySize.get(), E->getDirectInitRange(), NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010348}
Mike Stump11289f42009-09-09 15:08:12 +000010349
Douglas Gregora16548e2009-08-11 05:31:07 +000010350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010351ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010352TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010353 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010354 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010355 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010356
Douglas Gregord2d9da02010-02-26 00:38:10 +000010357 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010358 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010359 if (E->getOperatorDelete()) {
10360 OperatorDelete = cast_or_null<FunctionDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010361 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010362 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010363 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010364 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010365
Douglas Gregora16548e2009-08-11 05:31:07 +000010366 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010367 Operand.get() == E->getArgument() &&
10368 OperatorDelete == E->getOperatorDelete()) {
10369 // Mark any declarations we need as referenced.
10370 // FIXME: instantiation-specific.
10371 if (OperatorDelete)
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010372 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010373
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010374 if (!E->getArgument()->isTypeDependent()) {
10375 QualType Destroyed = SemaRef.Context.getBaseElementType(
10376 E->getDestroyedType());
10377 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10378 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010379 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010380 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010381 }
10382 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010383
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010384 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010385 }
Mike Stump11289f42009-09-09 15:08:12 +000010386
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010387 return getDerived().RebuildCXXDeleteExpr(
10388 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010389}
Mike Stump11289f42009-09-09 15:08:12 +000010390
Douglas Gregora16548e2009-08-11 05:31:07 +000010391template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010392ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010393TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010394 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010395 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010396 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010397 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010398
John McCallba7bf592010-08-24 05:47:05 +000010399 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010400 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010401 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010402 E->getOperatorLoc(),
10403 E->isArrow()? tok::arrow : tok::period,
10404 ObjectTypePtr,
10405 MayBePseudoDestructor);
10406 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010408
John McCallba7bf592010-08-24 05:47:05 +000010409 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010410 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10411 if (QualifierLoc) {
10412 QualifierLoc
10413 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10414 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010415 return ExprError();
10416 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010417 CXXScopeSpec SS;
10418 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010419
Douglas Gregor678f90d2010-02-25 01:56:36 +000010420 PseudoDestructorTypeStorage Destroyed;
10421 if (E->getDestroyedTypeInfo()) {
10422 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010423 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010424 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010425 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010426 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010427 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010428 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010429 // We aren't likely to be able to resolve the identifier down to a type
10430 // now anyway, so just retain the identifier.
10431 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10432 E->getDestroyedTypeLoc());
10433 } else {
10434 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010435 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010436 *E->getDestroyedTypeIdentifier(),
10437 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010438 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010439 SS, ObjectTypePtr,
10440 false);
10441 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010442 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010443
Douglas Gregor678f90d2010-02-25 01:56:36 +000010444 Destroyed
10445 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10446 E->getDestroyedTypeLoc());
10447 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010448
Craig Topperc3ec1492014-05-26 06:22:03 +000010449 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010450 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010451 CXXScopeSpec EmptySS;
10452 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010453 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010454 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010455 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010456 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010457
John McCallb268a282010-08-23 23:25:46 +000010458 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010459 E->getOperatorLoc(),
10460 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010461 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010462 ScopeTypeInfo,
10463 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010464 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010465 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010466}
Mike Stump11289f42009-09-09 15:08:12 +000010467
Richard Smith151c4562016-12-20 21:35:28 +000010468template <typename Derived>
10469bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10470 bool RequiresADL,
10471 LookupResult &R) {
10472 // Transform all the decls.
10473 bool AllEmptyPacks = true;
10474 for (auto *OldD : Old->decls()) {
10475 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10476 if (!InstD) {
10477 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10478 // This can happen because of dependent hiding.
10479 if (isa<UsingShadowDecl>(OldD))
10480 continue;
10481 else {
10482 R.clear();
10483 return true;
10484 }
10485 }
10486
10487 // Expand using pack declarations.
10488 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10489 ArrayRef<NamedDecl*> Decls = SingleDecl;
10490 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10491 Decls = UPD->expansions();
10492
10493 // Expand using declarations.
10494 for (auto *D : Decls) {
10495 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10496 for (auto *SD : UD->shadows())
10497 R.addDecl(SD);
10498 } else {
10499 R.addDecl(D);
10500 }
10501 }
10502
10503 AllEmptyPacks &= Decls.empty();
10504 };
10505
10506 // C++ [temp.res]/8.4.2:
10507 // The program is ill-formed, no diagnostic required, if [...] lookup for
10508 // a name in the template definition found a using-declaration, but the
10509 // lookup in the corresponding scope in the instantiation odoes not find
10510 // any declarations because the using-declaration was a pack expansion and
10511 // the corresponding pack is empty
10512 if (AllEmptyPacks && !RequiresADL) {
10513 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
Richard Trieub4025802018-03-28 04:16:13 +000010514 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
Richard Smith151c4562016-12-20 21:35:28 +000010515 return true;
10516 }
10517
10518 // Resolve a kind, but don't do any further analysis. If it's
10519 // ambiguous, the callee needs to deal with it.
10520 R.resolveKind();
10521 return false;
10522}
10523
Douglas Gregorad8a3362009-09-04 17:36:40 +000010524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010525ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010526TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010527 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010528 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10529 Sema::LookupOrdinaryName);
10530
Richard Smith151c4562016-12-20 21:35:28 +000010531 // Transform the declaration set.
10532 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10533 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010534
10535 // Rebuild the nested-name qualifier, if present.
10536 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010537 if (Old->getQualifierLoc()) {
10538 NestedNameSpecifierLoc QualifierLoc
10539 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10540 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010541 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010542
Douglas Gregor0da1d432011-02-28 20:01:57 +000010543 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010544 }
10545
Douglas Gregor9262f472010-04-27 18:19:34 +000010546 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010547 CXXRecordDecl *NamingClass
10548 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10549 Old->getNameLoc(),
10550 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010551 if (!NamingClass) {
10552 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010553 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010554 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010555
Douglas Gregorda7be082010-04-27 16:10:10 +000010556 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010557 }
10558
Abramo Bagnara7945c982012-01-27 09:46:47 +000010559 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10560
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010561 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010562 // it's a normal declaration name or member reference.
10563 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10564 NamedDecl *D = R.getAsSingle<NamedDecl>();
10565 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10566 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10567 // give a good diagnostic.
10568 if (D && D->isCXXInstanceMember()) {
10569 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10570 /*TemplateArgs=*/nullptr,
10571 /*Scope=*/nullptr);
10572 }
10573
John McCalle66edc12009-11-24 19:00:30 +000010574 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010575 }
John McCalle66edc12009-11-24 19:00:30 +000010576
10577 // If we have template arguments, rebuild them, then rebuild the
10578 // templateid expression.
10579 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010580 if (Old->hasExplicitTemplateArgs() &&
10581 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010582 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010583 TransArgs)) {
10584 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010585 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010586 }
John McCalle66edc12009-11-24 19:00:30 +000010587
Abramo Bagnara7945c982012-01-27 09:46:47 +000010588 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010589 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010590}
Mike Stump11289f42009-09-09 15:08:12 +000010591
Douglas Gregora16548e2009-08-11 05:31:07 +000010592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010593ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010594TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10595 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010596 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010597 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10598 TypeSourceInfo *From = E->getArg(I);
10599 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010600 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010601 TypeLocBuilder TLB;
10602 TLB.reserve(FromTL.getFullDataSize());
10603 QualType To = getDerived().TransformType(TLB, FromTL);
10604 if (To.isNull())
10605 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010606
Douglas Gregor29c42f22012-02-24 07:38:34 +000010607 if (To == From->getType())
10608 Args.push_back(From);
10609 else {
10610 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10611 ArgChanged = true;
10612 }
10613 continue;
10614 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010615
Douglas Gregor29c42f22012-02-24 07:38:34 +000010616 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010617
Douglas Gregor29c42f22012-02-24 07:38:34 +000010618 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010619 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010620 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10621 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10622 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010623
Douglas Gregor29c42f22012-02-24 07:38:34 +000010624 // Determine whether the set of unexpanded parameter packs can and should
10625 // be expanded.
10626 bool Expand = true;
10627 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010628 Optional<unsigned> OrigNumExpansions =
10629 ExpansionTL.getTypePtr()->getNumExpansions();
10630 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010631 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10632 PatternTL.getSourceRange(),
10633 Unexpanded,
10634 Expand, RetainExpansion,
10635 NumExpansions))
10636 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010637
Douglas Gregor29c42f22012-02-24 07:38:34 +000010638 if (!Expand) {
10639 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010640 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010641 // expansion.
10642 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010643
Douglas Gregor29c42f22012-02-24 07:38:34 +000010644 TypeLocBuilder TLB;
10645 TLB.reserve(From->getTypeLoc().getFullDataSize());
10646
10647 QualType To = getDerived().TransformType(TLB, PatternTL);
10648 if (To.isNull())
10649 return ExprError();
10650
Chad Rosier1dcde962012-08-08 18:46:20 +000010651 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010652 PatternTL.getSourceRange(),
10653 ExpansionTL.getEllipsisLoc(),
10654 NumExpansions);
10655 if (To.isNull())
10656 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010657
Douglas Gregor29c42f22012-02-24 07:38:34 +000010658 PackExpansionTypeLoc ToExpansionTL
10659 = TLB.push<PackExpansionTypeLoc>(To);
10660 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10661 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10662 continue;
10663 }
10664
10665 // Expand the pack expansion by substituting for each argument in the
10666 // pack(s).
10667 for (unsigned I = 0; I != *NumExpansions; ++I) {
10668 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10669 TypeLocBuilder TLB;
10670 TLB.reserve(PatternTL.getFullDataSize());
10671 QualType To = getDerived().TransformType(TLB, PatternTL);
10672 if (To.isNull())
10673 return ExprError();
10674
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010675 if (To->containsUnexpandedParameterPack()) {
10676 To = getDerived().RebuildPackExpansionType(To,
10677 PatternTL.getSourceRange(),
10678 ExpansionTL.getEllipsisLoc(),
10679 NumExpansions);
10680 if (To.isNull())
10681 return ExprError();
10682
10683 PackExpansionTypeLoc ToExpansionTL
10684 = TLB.push<PackExpansionTypeLoc>(To);
10685 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10686 }
10687
Douglas Gregor29c42f22012-02-24 07:38:34 +000010688 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10689 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010690
Douglas Gregor29c42f22012-02-24 07:38:34 +000010691 if (!RetainExpansion)
10692 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010693
Douglas Gregor29c42f22012-02-24 07:38:34 +000010694 // If we're supposed to retain a pack expansion, do so by temporarily
10695 // forgetting the partially-substituted parameter pack.
10696 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10697
10698 TypeLocBuilder TLB;
10699 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010700
Douglas Gregor29c42f22012-02-24 07:38:34 +000010701 QualType To = getDerived().TransformType(TLB, PatternTL);
10702 if (To.isNull())
10703 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010704
10705 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010706 PatternTL.getSourceRange(),
10707 ExpansionTL.getEllipsisLoc(),
10708 NumExpansions);
10709 if (To.isNull())
10710 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010711
Douglas Gregor29c42f22012-02-24 07:38:34 +000010712 PackExpansionTypeLoc ToExpansionTL
10713 = TLB.push<PackExpansionTypeLoc>(To);
10714 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10715 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10716 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010717
Douglas Gregor29c42f22012-02-24 07:38:34 +000010718 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010719 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010720
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010721 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010722 E->getEndLoc());
Douglas Gregor29c42f22012-02-24 07:38:34 +000010723}
10724
10725template<typename Derived>
10726ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010727TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10728 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10729 if (!T)
10730 return ExprError();
10731
10732 if (!getDerived().AlwaysRebuild() &&
10733 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010734 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010735
10736 ExprResult SubExpr;
10737 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010738 EnterExpressionEvaluationContext Unevaluated(
10739 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010740 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10741 if (SubExpr.isInvalid())
10742 return ExprError();
10743
10744 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010745 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010746 }
10747
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010748 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010749 SubExpr.get(), E->getEndLoc());
John Wiegley6242b6a2011-04-28 00:16:57 +000010750}
10751
10752template<typename Derived>
10753ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010754TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10755 ExprResult SubExpr;
10756 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010757 EnterExpressionEvaluationContext Unevaluated(
10758 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010759 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10760 if (SubExpr.isInvalid())
10761 return ExprError();
10762
10763 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010764 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010765 }
10766
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010767 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010768 SubExpr.get(), E->getEndLoc());
John Wiegleyf9f65842011-04-25 06:54:41 +000010769}
10770
Reid Kleckner32506ed2014-06-12 23:03:48 +000010771template <typename Derived>
10772ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10773 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10774 TypeSourceInfo **RecoveryTSI) {
10775 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10776 DRE, AddrTaken, RecoveryTSI);
10777
10778 // Propagate both errors and recovered types, which return ExprEmpty.
10779 if (!NewDRE.isUsable())
10780 return NewDRE;
10781
10782 // We got an expr, wrap it up in parens.
10783 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10784 return PE;
10785 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10786 PE->getRParen());
10787}
10788
10789template <typename Derived>
10790ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10791 DependentScopeDeclRefExpr *E) {
10792 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10793 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010794}
10795
10796template<typename Derived>
10797ExprResult
10798TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10799 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010800 bool IsAddressOfOperand,
10801 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010802 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010803 NestedNameSpecifierLoc QualifierLoc
10804 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10805 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010806 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010807 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010808
John McCall31f82722010-11-12 08:19:04 +000010809 // TODO: If this is a conversion-function-id, verify that the
10810 // destination type name (if present) resolves the same way after
10811 // instantiation as it did in the local scope.
10812
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010813 DeclarationNameInfo NameInfo
10814 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10815 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010816 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010817
John McCalle66edc12009-11-24 19:00:30 +000010818 if (!E->hasExplicitTemplateArgs()) {
10819 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010820 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010821 // Note: it is sufficient to compare the Name component of NameInfo:
10822 // if name has not changed, DNLoc has not changed either.
10823 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010824 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010825
Reid Kleckner32506ed2014-06-12 23:03:48 +000010826 return getDerived().RebuildDependentScopeDeclRefExpr(
10827 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10828 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010829 }
John McCall6b51f282009-11-23 01:53:49 +000010830
10831 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010832 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10833 E->getNumTemplateArgs(),
10834 TransArgs))
10835 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010836
Reid Kleckner32506ed2014-06-12 23:03:48 +000010837 return getDerived().RebuildDependentScopeDeclRefExpr(
10838 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10839 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010840}
10841
10842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010844TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010845 // CXXConstructExprs other than for list-initialization and
10846 // CXXTemporaryObjectExpr are always implicit, so when we have
10847 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010848 if ((E->getNumArgs() == 1 ||
10849 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010850 (!getDerived().DropCallArgument(E->getArg(0))) &&
10851 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010852 return getDerived().TransformExpr(E->getArg(0));
10853
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010854 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
Douglas Gregora16548e2009-08-11 05:31:07 +000010855
10856 QualType T = getDerived().TransformType(E->getType());
10857 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010858 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010859
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010860 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10861 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010862 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010864
Douglas Gregora16548e2009-08-11 05:31:07 +000010865 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010866 SmallVector<Expr*, 8> Args;
Richard Smith12938cf2018-09-26 04:36:55 +000010867 {
10868 EnterExpressionEvaluationContext Context(
10869 getSema(), EnterExpressionEvaluationContext::InitList,
10870 E->isListInitialization());
10871 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10872 &ArgumentChanged))
10873 return ExprError();
10874 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010875
Douglas Gregora16548e2009-08-11 05:31:07 +000010876 if (!getDerived().AlwaysRebuild() &&
10877 T == E->getType() &&
10878 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010879 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010880 // Mark the constructor as referenced.
10881 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010882 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010883 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010884 }
Mike Stump11289f42009-09-09 15:08:12 +000010885
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010886 return getDerived().RebuildCXXConstructExpr(
10887 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
10888 E->hadMultipleCandidates(), E->isListInitialization(),
10889 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
10890 E->getConstructionKind(), E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010891}
Mike Stump11289f42009-09-09 15:08:12 +000010892
Richard Smith5179eb72016-06-28 19:03:57 +000010893template<typename Derived>
10894ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10895 CXXInheritedCtorInitExpr *E) {
10896 QualType T = getDerived().TransformType(E->getType());
10897 if (T.isNull())
10898 return ExprError();
10899
10900 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010901 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Richard Smith5179eb72016-06-28 19:03:57 +000010902 if (!Constructor)
10903 return ExprError();
10904
10905 if (!getDerived().AlwaysRebuild() &&
10906 T == E->getType() &&
10907 Constructor == E->getConstructor()) {
10908 // Mark the constructor as referenced.
10909 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010910 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
Richard Smith5179eb72016-06-28 19:03:57 +000010911 return E;
10912 }
10913
10914 return getDerived().RebuildCXXInheritedCtorInitExpr(
10915 T, E->getLocation(), Constructor,
10916 E->constructsVBase(), E->inheritedFromVBase());
10917}
10918
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010919/// Transform a C++ temporary-binding expression.
Douglas Gregora16548e2009-08-11 05:31:07 +000010920///
Douglas Gregor363b1512009-12-24 18:51:59 +000010921/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10922/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010924ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010925TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010926 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010927}
Mike Stump11289f42009-09-09 15:08:12 +000010928
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000010929/// Transform a C++ expression that contains cleanups that should
John McCall5d413782010-12-06 08:20:24 +000010930/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010931///
John McCall5d413782010-12-06 08:20:24 +000010932/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010933/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010934template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010935ExprResult
John McCall5d413782010-12-06 08:20:24 +000010936TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010937 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010938}
Mike Stump11289f42009-09-09 15:08:12 +000010939
Douglas Gregora16548e2009-08-11 05:31:07 +000010940template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010941ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010942TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010943 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010944 TypeSourceInfo *T =
10945 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010946 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010947 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010948
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010949 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10950 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010951 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010952 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010953
Douglas Gregora16548e2009-08-11 05:31:07 +000010954 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010955 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010956 Args.reserve(E->getNumArgs());
Richard Smith12938cf2018-09-26 04:36:55 +000010957 {
10958 EnterExpressionEvaluationContext Context(
10959 getSema(), EnterExpressionEvaluationContext::InitList,
10960 E->isListInitialization());
10961 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
10962 &ArgumentChanged))
10963 return ExprError();
10964 }
Mike Stump11289f42009-09-09 15:08:12 +000010965
Douglas Gregora16548e2009-08-11 05:31:07 +000010966 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010967 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010968 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010969 !ArgumentChanged) {
10970 // FIXME: Instantiation-specific
Stephen Kellyf2ceec42018-08-09 21:08:08 +000010971 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010972 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010973 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010974
Vedant Kumara14a1f92018-01-17 18:53:51 +000010975 // FIXME: We should just pass E->isListInitialization(), but we're not
10976 // prepared to handle list-initialization without a child InitListExpr.
10977 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
10978 return getDerived().RebuildCXXTemporaryObjectExpr(
Stephen Kelly1c301dc2018-08-09 21:09:38 +000010979 T, LParenLoc, Args, E->getEndLoc(),
Vedant Kumara14a1f92018-01-17 18:53:51 +000010980 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000010981}
Mike Stump11289f42009-09-09 15:08:12 +000010982
Douglas Gregora16548e2009-08-11 05:31:07 +000010983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010984ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010985TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010986 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010987 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010988 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010989 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10990 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010991 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010992 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010993 CEnd = E->capture_end();
10994 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010995 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010996 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010997 EnterExpressionEvaluationContext EEEC(
10998 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010999 ExprResult NewExprInitResult = getDerived().TransformInitializer(
11000 C->getCapturedVar()->getInit(),
11001 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000011002
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011003 if (NewExprInitResult.isInvalid())
11004 return ExprError();
11005 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000011006
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011007 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000011008 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000011009 getSema().buildLambdaInitCaptureInitialization(
11010 C->getLocation(), OldVD->getType()->isReferenceType(),
11011 OldVD->getIdentifier(),
11012 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011013 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011014 InitCaptureExprsAndTypes[C - E->capture_begin()] =
11015 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011016 }
11017
Faisal Vali2cba1332013-10-23 06:44:28 +000011018 // Transform the template parameters, and add them to the current
11019 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000011020 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000011021 E->getTemplateParameterList());
11022
Richard Smith01014ce2014-11-20 23:53:14 +000011023 // Transform the type of the original lambda's call operator.
11024 // The transformation MUST be done in the CurrentInstantiationScope since
11025 // it introduces a mapping of the original to the newly created
11026 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000011027 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000011028 {
11029 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +000011030 FunctionProtoTypeLoc OldCallOpFPTL =
Richard Smith01014ce2014-11-20 23:53:14 +000011031 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000011032
11033 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000011034 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000011035 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000011036 QualType NewCallOpType = TransformFunctionProtoType(
Mikael Nilsson9d2872d2018-12-13 10:15:27 +000011037 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
Richard Smith775118a2014-11-12 02:09:03 +000011038 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
11039 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
11040 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000011041 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000011042 if (NewCallOpType.isNull())
11043 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000011044 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
11045 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000011046 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011047
Richard Smithc38498f2015-04-27 21:27:54 +000011048 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
11049 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
11050 LSI->GLTemplateParameterList = TPL;
11051
Eli Friedmand564afb2012-09-19 01:18:11 +000011052 // Create the local class that will describe the lambda.
11053 CXXRecordDecl *Class
11054 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000011055 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000011056 /*KnownDependent=*/false,
11057 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000011058 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
11059
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011060 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000011061 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
11062 Class, E->getIntroducerRange(), NewCallOpTSI,
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011063 E->getCallOperator()->getEndLoc(),
Faisal Valia734ab92016-03-26 16:11:37 +000011064 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
11065 E->getCallOperator()->isConstexpr());
11066
Faisal Vali2cba1332013-10-23 06:44:28 +000011067 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000011068
Akira Hatanaka402818462016-12-16 21:16:57 +000011069 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
11070 I != NumParams; ++I) {
11071 auto *P = NewCallOperator->getParamDecl(I);
11072 if (P->hasUninstantiatedDefaultArg()) {
11073 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000011074 getSema(),
11075 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000011076 ExprResult R = getDerived().TransformExpr(
11077 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
11078 P->setDefaultArg(R.get());
11079 }
11080 }
11081
Faisal Vali2cba1332013-10-23 06:44:28 +000011082 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000011083 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000011084
Douglas Gregorb4328232012-02-14 00:00:48 +000011085 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000011086 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000011087 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000011088
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011089 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000011090 getSema().buildLambdaScope(LSI, NewCallOperator,
11091 E->getIntroducerRange(),
11092 E->getCaptureDefault(),
11093 E->getCaptureDefaultLoc(),
11094 E->hasExplicitParameters(),
11095 E->hasExplicitResultType(),
11096 E->isMutable());
11097
11098 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011099
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011100 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011101 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011102 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011103 CEnd = E->capture_end();
11104 C != CEnd; ++C) {
11105 // When we hit the first implicit capture, tell Sema that we've finished
11106 // the list of explicit captures.
11107 if (!FinishedExplicitCaptures && C->isImplicit()) {
11108 getSema().finishLambdaExplicitCaptures(LSI);
11109 FinishedExplicitCaptures = true;
11110 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011111
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011112 // Capturing 'this' is trivial.
11113 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000011114 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
11115 /*BuildAndDiagnose*/ true, nullptr,
11116 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011117 continue;
11118 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000011119 // Captured expression will be recaptured during captured variables
11120 // rebuilding.
11121 if (C->capturesVLAType())
11122 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011123
Richard Smithba71c082013-05-16 06:20:58 +000011124 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011125 if (E->isInitCapture(C)) {
Fangrui Song6907ce22018-07-30 19:24:48 +000011126 InitCaptureInfoTy InitExprTypePair =
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011127 InitCaptureExprsAndTypes[C - E->capture_begin()];
11128 ExprResult Init = InitExprTypePair.first;
11129 QualType InitQualType = InitExprTypePair.second;
11130 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011131 Invalid = true;
11132 continue;
11133 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011134 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011135 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011136 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11137 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011138 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011139 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011140 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011141 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011142 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011143 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011144 continue;
11145 }
11146
11147 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11148
Douglas Gregor3e308b12012-02-14 19:27:52 +000011149 // Determine the capture kind for Sema.
11150 Sema::TryCaptureKind Kind
11151 = C->isImplicit()? Sema::TryCapture_Implicit
11152 : C->getCaptureKind() == LCK_ByCopy
11153 ? Sema::TryCapture_ExplicitByVal
11154 : Sema::TryCapture_ExplicitByRef;
11155 SourceLocation EllipsisLoc;
11156 if (C->isPackExpansion()) {
11157 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11158 bool ShouldExpand = false;
11159 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011160 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011161 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11162 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011163 Unexpanded,
11164 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011165 NumExpansions)) {
11166 Invalid = true;
11167 continue;
11168 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011169
Douglas Gregor3e308b12012-02-14 19:27:52 +000011170 if (ShouldExpand) {
11171 // The transform has determined that we should perform an expansion;
11172 // transform and capture each of the arguments.
11173 // expansion of the pattern. Do so.
11174 VarDecl *Pack = C->getCapturedVar();
11175 for (unsigned I = 0; I != *NumExpansions; ++I) {
11176 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11177 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011178 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011179 Pack));
11180 if (!CapturedVar) {
11181 Invalid = true;
11182 continue;
11183 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011184
Douglas Gregor3e308b12012-02-14 19:27:52 +000011185 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011186 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11187 }
Richard Smith9467be42014-06-06 17:33:35 +000011188
11189 // FIXME: Retain a pack expansion if RetainExpansion is true.
11190
Douglas Gregor3e308b12012-02-14 19:27:52 +000011191 continue;
11192 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011193
Douglas Gregor3e308b12012-02-14 19:27:52 +000011194 EllipsisLoc = C->getEllipsisLoc();
11195 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011196
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011197 // Transform the captured variable.
11198 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011199 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011200 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011201 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011202 Invalid = true;
11203 continue;
11204 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011205
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011206 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011207 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11208 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011209 }
11210 if (!FinishedExplicitCaptures)
11211 getSema().finishLambdaExplicitCaptures(LSI);
11212
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011213 // Enter a new evaluation context to insulate the lambda from any
11214 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011215 getSema().PushExpressionEvaluationContext(
11216 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011217
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011218 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011219 StmtResult Body =
11220 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11221
11222 // ActOnLambda* will pop the function scope for us.
11223 FuncScopeCleanup.disable();
11224
Douglas Gregorb4328232012-02-14 00:00:48 +000011225 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011226 SavedContext.pop();
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011227 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011228 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011229 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011230 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011231
Richard Smithc38498f2015-04-27 21:27:54 +000011232 // Copy the LSI before ActOnFinishFunctionBody removes it.
11233 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11234 // the call operator.
11235 auto LSICopy = *LSI;
11236 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11237 /*IsInstantiation*/ true);
11238 SavedContext.pop();
11239
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011240 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
Richard Smithc38498f2015-04-27 21:27:54 +000011241 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011242}
11243
11244template<typename Derived>
11245ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011246TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011247 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011248 TypeSourceInfo *T =
11249 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011250 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011252
Douglas Gregora16548e2009-08-11 05:31:07 +000011253 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011254 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011255 Args.reserve(E->arg_size());
Richard Smith12938cf2018-09-26 04:36:55 +000011256 {
11257 EnterExpressionEvaluationContext Context(
11258 getSema(), EnterExpressionEvaluationContext::InitList,
11259 E->isListInitialization());
11260 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
11261 &ArgumentChanged))
11262 return ExprError();
11263 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011264
Douglas Gregora16548e2009-08-11 05:31:07 +000011265 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011266 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011267 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011268 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011269
Douglas Gregora16548e2009-08-11 05:31:07 +000011270 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011271 return getDerived().RebuildCXXUnresolvedConstructExpr(
11272 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011273}
Mike Stump11289f42009-09-09 15:08:12 +000011274
Douglas Gregora16548e2009-08-11 05:31:07 +000011275template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011276ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011277TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011278 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011279 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011280 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011281 Expr *OldBase;
11282 QualType BaseType;
11283 QualType ObjectType;
11284 if (!E->isImplicitAccess()) {
11285 OldBase = E->getBase();
11286 Base = getDerived().TransformExpr(OldBase);
11287 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011289
John McCall2d74de92009-12-01 22:10:20 +000011290 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011291 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011292 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011293 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011294 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011295 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011296 ObjectTy,
11297 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011298 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011299 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011300
John McCallba7bf592010-08-24 05:47:05 +000011301 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011302 BaseType = ((Expr*) Base.get())->getType();
11303 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011304 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011305 BaseType = getDerived().TransformType(E->getBaseType());
11306 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11307 }
Mike Stump11289f42009-09-09 15:08:12 +000011308
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011309 // Transform the first part of the nested-name-specifier that qualifies
11310 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011311 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011312 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011313 E->getFirstQualifierFoundInScope(),
11314 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011315
Douglas Gregore16af532011-02-28 18:50:33 +000011316 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011317 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011318 QualifierLoc
11319 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11320 ObjectType,
11321 FirstQualifierInScope);
11322 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011323 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011324 }
Mike Stump11289f42009-09-09 15:08:12 +000011325
Abramo Bagnara7945c982012-01-27 09:46:47 +000011326 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11327
John McCall31f82722010-11-12 08:19:04 +000011328 // TODO: If this is a conversion-function-id, verify that the
11329 // destination type name (if present) resolves the same way after
11330 // instantiation as it did in the local scope.
11331
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011332 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011333 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011334 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011335 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011336
John McCall2d74de92009-12-01 22:10:20 +000011337 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011338 // This is a reference to a member without an explicitly-specified
11339 // template argument list. Optimize for this common case.
11340 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011341 Base.get() == OldBase &&
11342 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011343 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011344 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011345 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011346 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011347
John McCallb268a282010-08-23 23:25:46 +000011348 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011349 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011350 E->isArrow(),
11351 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011352 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011353 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011354 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011355 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011356 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011357 }
11358
John McCall6b51f282009-11-23 01:53:49 +000011359 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011360 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11361 E->getNumTemplateArgs(),
11362 TransArgs))
11363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011364
John McCallb268a282010-08-23 23:25:46 +000011365 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011366 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011367 E->isArrow(),
11368 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011369 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011370 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011371 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011372 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011373 &TransArgs);
11374}
11375
11376template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011377ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011378TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011379 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011380 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011381 QualType BaseType;
11382 if (!Old->isImplicitAccess()) {
11383 Base = getDerived().TransformExpr(Old->getBase());
11384 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011385 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011386 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011387 Old->isArrow());
11388 if (Base.isInvalid())
11389 return ExprError();
11390 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011391 } else {
11392 BaseType = getDerived().TransformType(Old->getBaseType());
11393 }
John McCall10eae182009-11-30 22:42:35 +000011394
Douglas Gregor0da1d432011-02-28 20:01:57 +000011395 NestedNameSpecifierLoc QualifierLoc;
11396 if (Old->getQualifierLoc()) {
11397 QualifierLoc
11398 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11399 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011400 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011401 }
11402
Abramo Bagnara7945c982012-01-27 09:46:47 +000011403 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11404
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011405 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011406 Sema::LookupOrdinaryName);
11407
Richard Smith151c4562016-12-20 21:35:28 +000011408 // Transform the declaration set.
11409 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11410 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011411
Douglas Gregor9262f472010-04-27 18:19:34 +000011412 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011413 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011414 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011415 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011416 Old->getMemberLoc(),
11417 Old->getNamingClass()));
11418 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011419 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011420
Douglas Gregorda7be082010-04-27 16:10:10 +000011421 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011422 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011423
John McCall10eae182009-11-30 22:42:35 +000011424 TemplateArgumentListInfo TransArgs;
11425 if (Old->hasExplicitTemplateArgs()) {
11426 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11427 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011428 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11429 Old->getNumTemplateArgs(),
11430 TransArgs))
11431 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011432 }
John McCall38836f02010-01-15 08:34:02 +000011433
11434 // FIXME: to do this check properly, we will need to preserve the
11435 // first-qualifier-in-scope here, just in case we had a dependent
11436 // base (and therefore couldn't do the check) and a
11437 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011438 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011439
John McCallb268a282010-08-23 23:25:46 +000011440 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011441 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011442 Old->getOperatorLoc(),
11443 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011444 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011445 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011446 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011447 R,
11448 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011449 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011450}
11451
11452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011453ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011454TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011455 EnterExpressionEvaluationContext Unevaluated(
11456 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011457 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11458 if (SubExpr.isInvalid())
11459 return ExprError();
11460
11461 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011462 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011463
11464 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11465}
11466
11467template<typename Derived>
11468ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011469TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011470 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11471 if (Pattern.isInvalid())
11472 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011473
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011474 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011475 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011476
Douglas Gregorb8840002011-01-14 21:20:45 +000011477 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11478 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011479}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011480
11481template<typename Derived>
11482ExprResult
11483TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11484 // If E is not value-dependent, then nothing will change when we transform it.
11485 // Note: This is an instantiation-centric view.
11486 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011487 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011488
Faisal Valid143a0c2017-04-01 21:30:49 +000011489 EnterExpressionEvaluationContext Unevaluated(
11490 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011491
Richard Smithd784e682015-09-23 21:41:42 +000011492 ArrayRef<TemplateArgument> PackArgs;
11493 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011494
Richard Smithd784e682015-09-23 21:41:42 +000011495 // Find the argument list to transform.
11496 if (E->isPartiallySubstituted()) {
11497 PackArgs = E->getPartialArguments();
11498 } else if (E->isValueDependent()) {
11499 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11500 bool ShouldExpand = false;
11501 bool RetainExpansion = false;
11502 Optional<unsigned> NumExpansions;
11503 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11504 Unexpanded,
11505 ShouldExpand, RetainExpansion,
11506 NumExpansions))
11507 return ExprError();
11508
11509 // If we need to expand the pack, build a template argument from it and
11510 // expand that.
11511 if (ShouldExpand) {
11512 auto *Pack = E->getPack();
11513 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11514 ArgStorage = getSema().Context.getPackExpansionType(
11515 getSema().Context.getTypeDeclType(TTPD), None);
11516 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11517 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11518 } else {
11519 auto *VD = cast<ValueDecl>(Pack);
Richard Smithf1f20e62018-02-14 02:07:53 +000011520 ExprResult DRE = getSema().BuildDeclRefExpr(
11521 VD, VD->getType().getNonLValueExprType(getSema().Context),
11522 VD->getType()->isReferenceType() ? VK_LValue : VK_RValue,
11523 E->getPackLoc());
Richard Smithd784e682015-09-23 21:41:42 +000011524 if (DRE.isInvalid())
11525 return ExprError();
11526 ArgStorage = new (getSema().Context) PackExpansionExpr(
11527 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11528 }
11529 PackArgs = ArgStorage;
11530 }
11531 }
11532
11533 // If we're not expanding the pack, just transform the decl.
11534 if (!PackArgs.size()) {
11535 auto *Pack = cast_or_null<NamedDecl>(
11536 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011537 if (!Pack)
11538 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011539 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11540 E->getPackLoc(),
11541 E->getRParenLoc(), None, None);
11542 }
11543
Richard Smithc5452ed2016-10-19 22:18:42 +000011544 // Try to compute the result without performing a partial substitution.
11545 Optional<unsigned> Result = 0;
11546 for (const TemplateArgument &Arg : PackArgs) {
11547 if (!Arg.isPackExpansion()) {
11548 Result = *Result + 1;
11549 continue;
11550 }
11551
11552 TemplateArgumentLoc ArgLoc;
11553 InventTemplateArgumentLoc(Arg, ArgLoc);
11554
11555 // Find the pattern of the pack expansion.
11556 SourceLocation Ellipsis;
11557 Optional<unsigned> OrigNumExpansions;
11558 TemplateArgumentLoc Pattern =
11559 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11560 OrigNumExpansions);
11561
11562 // Substitute under the pack expansion. Do not expand the pack (yet).
11563 TemplateArgumentLoc OutPattern;
11564 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11565 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11566 /*Uneval*/ true))
11567 return true;
11568
11569 // See if we can determine the number of arguments from the result.
11570 Optional<unsigned> NumExpansions =
11571 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11572 if (!NumExpansions) {
11573 // No: we must be in an alias template expansion, and we're going to need
11574 // to actually expand the packs.
11575 Result = None;
11576 break;
11577 }
11578
11579 Result = *Result + *NumExpansions;
11580 }
11581
11582 // Common case: we could determine the number of expansions without
11583 // substituting.
11584 if (Result)
11585 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11586 E->getPackLoc(),
11587 E->getRParenLoc(), *Result, None);
11588
Richard Smithd784e682015-09-23 21:41:42 +000011589 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11590 E->getPackLoc());
11591 {
11592 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11593 typedef TemplateArgumentLocInventIterator<
11594 Derived, const TemplateArgument*> PackLocIterator;
11595 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11596 PackLocIterator(*this, PackArgs.end()),
11597 TransformedPackArgs, /*Uneval*/true))
11598 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011599 }
11600
Richard Smithc5452ed2016-10-19 22:18:42 +000011601 // Check whether we managed to fully-expand the pack.
11602 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011603 SmallVector<TemplateArgument, 8> Args;
11604 bool PartialSubstitution = false;
11605 for (auto &Loc : TransformedPackArgs.arguments()) {
11606 Args.push_back(Loc.getArgument());
11607 if (Loc.getArgument().isPackExpansion())
11608 PartialSubstitution = true;
11609 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011610
Richard Smithd784e682015-09-23 21:41:42 +000011611 if (PartialSubstitution)
11612 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11613 E->getPackLoc(),
11614 E->getRParenLoc(), None, Args);
11615
11616 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011617 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011618 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011619}
11620
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011621template<typename Derived>
11622ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011623TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11624 SubstNonTypeTemplateParmPackExpr *E) {
11625 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011626 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011627}
11628
11629template<typename Derived>
11630ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011631TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11632 SubstNonTypeTemplateParmExpr *E) {
11633 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011634 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011635}
11636
11637template<typename Derived>
11638ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011639TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11640 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011641 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011642}
11643
11644template<typename Derived>
11645ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011646TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11647 MaterializeTemporaryExpr *E) {
11648 return getDerived().TransformExpr(E->GetTemporaryExpr());
11649}
Chad Rosier1dcde962012-08-08 18:46:20 +000011650
Douglas Gregorfe314812011-06-21 17:03:29 +000011651template<typename Derived>
11652ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011653TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11654 Expr *Pattern = E->getPattern();
11655
11656 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11657 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11658 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11659
11660 // Determine whether the set of unexpanded parameter packs can and should
11661 // be expanded.
11662 bool Expand = true;
11663 bool RetainExpansion = false;
11664 Optional<unsigned> NumExpansions;
11665 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11666 Pattern->getSourceRange(),
11667 Unexpanded,
11668 Expand, RetainExpansion,
11669 NumExpansions))
11670 return true;
11671
11672 if (!Expand) {
11673 // Do not expand any packs here, just transform and rebuild a fold
11674 // expression.
11675 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11676
11677 ExprResult LHS =
11678 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11679 if (LHS.isInvalid())
11680 return true;
11681
11682 ExprResult RHS =
11683 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11684 if (RHS.isInvalid())
11685 return true;
11686
11687 if (!getDerived().AlwaysRebuild() &&
11688 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11689 return E;
11690
11691 return getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011692 E->getBeginLoc(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011693 RHS.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011694 }
11695
11696 // The transform has determined that we should perform an elementwise
11697 // expansion of the pattern. Do so.
11698 ExprResult Result = getDerived().TransformExpr(E->getInit());
11699 if (Result.isInvalid())
11700 return true;
11701 bool LeftFold = E->isLeftFold();
11702
11703 // If we're retaining an expansion for a right fold, it is the innermost
11704 // component and takes the init (if any).
11705 if (!LeftFold && RetainExpansion) {
11706 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11707
11708 ExprResult Out = getDerived().TransformExpr(Pattern);
11709 if (Out.isInvalid())
11710 return true;
11711
11712 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011713 E->getBeginLoc(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011714 Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011715 if (Result.isInvalid())
11716 return true;
11717 }
11718
11719 for (unsigned I = 0; I != *NumExpansions; ++I) {
11720 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11721 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11722 ExprResult Out = getDerived().TransformExpr(Pattern);
11723 if (Out.isInvalid())
11724 return true;
11725
11726 if (Out.get()->containsUnexpandedParameterPack()) {
11727 // We still have a pack; retain a pack expansion for this slice.
11728 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011729 E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
Richard Smith0f0af192014-11-08 05:07:16 +000011730 E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011731 LeftFold ? Out.get() : Result.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011732 } else if (Result.isUsable()) {
11733 // We've got down to a single element; build a binary operator.
11734 Result = getDerived().RebuildBinaryOperator(
11735 E->getEllipsisLoc(), E->getOperator(),
11736 LeftFold ? Result.get() : Out.get(),
11737 LeftFold ? Out.get() : Result.get());
11738 } else
11739 Result = Out;
11740
11741 if (Result.isInvalid())
11742 return true;
11743 }
11744
11745 // If we're retaining an expansion for a left fold, it is the outermost
11746 // component and takes the complete expansion so far as its init (if any).
11747 if (LeftFold && RetainExpansion) {
11748 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11749
11750 ExprResult Out = getDerived().TransformExpr(Pattern);
11751 if (Out.isInvalid())
11752 return true;
11753
11754 Result = getDerived().RebuildCXXFoldExpr(
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011755 E->getBeginLoc(), Result.get(), E->getOperator(), E->getEllipsisLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011756 Out.get(), E->getEndLoc());
Richard Smith0f0af192014-11-08 05:07:16 +000011757 if (Result.isInvalid())
11758 return true;
11759 }
11760
11761 // If we had no init and an empty pack, and we're not retaining an expansion,
11762 // then produce a fallback value or error.
11763 if (Result.isUnset())
11764 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11765 E->getOperator());
11766
11767 return Result;
11768}
11769
11770template<typename Derived>
11771ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011772TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11773 CXXStdInitializerListExpr *E) {
11774 return getDerived().TransformExpr(E->getSubExpr());
11775}
11776
11777template<typename Derived>
11778ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011779TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011780 return SemaRef.MaybeBindToTemporary(E);
11781}
11782
11783template<typename Derived>
11784ExprResult
11785TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011786 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011787}
11788
11789template<typename Derived>
11790ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011791TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11792 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11793 if (SubExpr.isInvalid())
11794 return ExprError();
11795
11796 if (!getDerived().AlwaysRebuild() &&
11797 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011798 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011799
11800 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011801}
11802
11803template<typename Derived>
11804ExprResult
11805TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11806 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011807 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011808 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011809 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011810 /*IsCall=*/false, Elements, &ArgChanged))
11811 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011812
Ted Kremeneke65b0862012-03-06 20:05:56 +000011813 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11814 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011815
Ted Kremeneke65b0862012-03-06 20:05:56 +000011816 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11817 Elements.data(),
11818 Elements.size());
11819}
11820
11821template<typename Derived>
11822ExprResult
11823TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011824 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011825 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011826 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011827 bool ArgChanged = false;
11828 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11829 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011830
Ted Kremeneke65b0862012-03-06 20:05:56 +000011831 if (OrigElement.isPackExpansion()) {
11832 // This key/value element is a pack expansion.
11833 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11834 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11835 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11836 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11837
11838 // Determine whether the set of unexpanded parameter packs can
11839 // and should be expanded.
11840 bool Expand = true;
11841 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011842 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11843 Optional<unsigned> NumExpansions = OrigNumExpansions;
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011844 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
Stephen Kelly1c301dc2018-08-09 21:09:38 +000011845 OrigElement.Value->getEndLoc());
Stephen Kellyf2ceec42018-08-09 21:08:08 +000011846 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11847 PatternRange, Unexpanded, Expand,
11848 RetainExpansion, NumExpansions))
Ted Kremeneke65b0862012-03-06 20:05:56 +000011849 return ExprError();
11850
11851 if (!Expand) {
11852 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011853 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011854 // expansion.
11855 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11856 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11857 if (Key.isInvalid())
11858 return ExprError();
11859
11860 if (Key.get() != OrigElement.Key)
11861 ArgChanged = true;
11862
11863 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11864 if (Value.isInvalid())
11865 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011866
Ted Kremeneke65b0862012-03-06 20:05:56 +000011867 if (Value.get() != OrigElement.Value)
11868 ArgChanged = true;
11869
Chad Rosier1dcde962012-08-08 18:46:20 +000011870 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011871 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11872 };
11873 Elements.push_back(Expansion);
11874 continue;
11875 }
11876
11877 // Record right away that the argument was changed. This needs
11878 // to happen even if the array expands to nothing.
11879 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011880
Ted Kremeneke65b0862012-03-06 20:05:56 +000011881 // The transform has determined that we should perform an elementwise
11882 // expansion of the pattern. Do so.
11883 for (unsigned I = 0; I != *NumExpansions; ++I) {
11884 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11885 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11886 if (Key.isInvalid())
11887 return ExprError();
11888
11889 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11890 if (Value.isInvalid())
11891 return ExprError();
11892
Chad Rosier1dcde962012-08-08 18:46:20 +000011893 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011894 Key.get(), Value.get(), SourceLocation(), NumExpansions
11895 };
11896
11897 // If any unexpanded parameter packs remain, we still have a
11898 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011899 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011900 if (Key.get()->containsUnexpandedParameterPack() ||
11901 Value.get()->containsUnexpandedParameterPack())
11902 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011903
Ted Kremeneke65b0862012-03-06 20:05:56 +000011904 Elements.push_back(Element);
11905 }
11906
Richard Smith9467be42014-06-06 17:33:35 +000011907 // FIXME: Retain a pack expansion if RetainExpansion is true.
11908
Ted Kremeneke65b0862012-03-06 20:05:56 +000011909 // We've finished with this pack expansion.
11910 continue;
11911 }
11912
11913 // Transform and check key.
11914 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11915 if (Key.isInvalid())
11916 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011917
Ted Kremeneke65b0862012-03-06 20:05:56 +000011918 if (Key.get() != OrigElement.Key)
11919 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011920
Ted Kremeneke65b0862012-03-06 20:05:56 +000011921 // Transform and check value.
11922 ExprResult Value
11923 = getDerived().TransformExpr(OrigElement.Value);
11924 if (Value.isInvalid())
11925 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011926
Ted Kremeneke65b0862012-03-06 20:05:56 +000011927 if (Value.get() != OrigElement.Value)
11928 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011929
11930 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011931 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011932 };
11933 Elements.push_back(Element);
11934 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011935
Ted Kremeneke65b0862012-03-06 20:05:56 +000011936 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11937 return SemaRef.MaybeBindToTemporary(E);
11938
11939 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011940 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011941}
11942
Mike Stump11289f42009-09-09 15:08:12 +000011943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011945TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011946 TypeSourceInfo *EncodedTypeInfo
11947 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11948 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011950
Douglas Gregora16548e2009-08-11 05:31:07 +000011951 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011952 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011953 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011954
11955 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011956 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011957 E->getRParenLoc());
11958}
Mike Stump11289f42009-09-09 15:08:12 +000011959
Douglas Gregora16548e2009-08-11 05:31:07 +000011960template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011961ExprResult TreeTransform<Derived>::
11962TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011963 // This is a kind of implicit conversion, and it needs to get dropped
11964 // and recomputed for the same general reasons that ImplicitCastExprs
11965 // do, as well a more specific one: this expression is only valid when
11966 // it appears *immediately* as an argument expression.
11967 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011968}
11969
11970template<typename Derived>
11971ExprResult TreeTransform<Derived>::
11972TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011973 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011974 = getDerived().TransformType(E->getTypeInfoAsWritten());
11975 if (!TSInfo)
11976 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011977
John McCall31168b02011-06-15 23:02:42 +000011978 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011979 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011980 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011981
John McCall31168b02011-06-15 23:02:42 +000011982 if (!getDerived().AlwaysRebuild() &&
11983 TSInfo == E->getTypeInfoAsWritten() &&
11984 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011985 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011986
John McCall31168b02011-06-15 23:02:42 +000011987 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011988 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011989 Result.get());
11990}
11991
Erik Pilkington29099de2016-07-16 00:35:23 +000011992template <typename Derived>
11993ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11994 ObjCAvailabilityCheckExpr *E) {
11995 return E;
11996}
11997
John McCall31168b02011-06-15 23:02:42 +000011998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012000TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012001 // Transform arguments.
12002 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012003 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000012004 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012005 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000012006 &ArgChanged))
12007 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012008
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012009 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
12010 // Class message: transform the receiver type.
12011 TypeSourceInfo *ReceiverTypeInfo
12012 = getDerived().TransformType(E->getClassReceiverTypeInfo());
12013 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000012014 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012015
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012016 // If nothing changed, just retain the existing message send.
12017 if (!getDerived().AlwaysRebuild() &&
12018 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012019 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012020
12021 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012022 SmallVector<SourceLocation, 16> SelLocs;
12023 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012024 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
12025 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012026 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012027 E->getMethodDecl(),
12028 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012029 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012030 E->getRightLoc());
12031 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012032 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
12033 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000012034 if (!E->getMethodDecl())
12035 return ExprError();
12036
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012037 // Build a new class message send to 'super'.
12038 SmallVector<SourceLocation, 16> SelLocs;
12039 E->getSelectorLocs(SelLocs);
12040 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
12041 E->getSelector(),
12042 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000012043 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000012044 E->getMethodDecl(),
12045 E->getLeftLoc(),
12046 Args,
12047 E->getRightLoc());
12048 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012049
12050 // Instance message: transform the receiver
12051 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
12052 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000012053 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012054 = getDerived().TransformExpr(E->getInstanceReceiver());
12055 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012056 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012057
12058 // If nothing changed, just retain the existing message send.
12059 if (!getDerived().AlwaysRebuild() &&
12060 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012061 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000012062
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012063 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012064 SmallVector<SourceLocation, 16> SelLocs;
12065 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000012066 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012067 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000012068 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012069 E->getMethodDecl(),
12070 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012071 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012072 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000012073}
12074
Mike Stump11289f42009-09-09 15:08:12 +000012075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012076ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012077TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012078 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012079}
12080
Mike Stump11289f42009-09-09 15:08:12 +000012081template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012082ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012083TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012084 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012085}
12086
Mike Stump11289f42009-09-09 15:08:12 +000012087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012088ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012089TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012090 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012091 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012092 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012093 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000012094
12095 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012096
Douglas Gregord51d90d2010-04-26 20:11:03 +000012097 // If nothing changed, just retain the existing expression.
12098 if (!getDerived().AlwaysRebuild() &&
12099 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012100 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012101
John McCallb268a282010-08-23 23:25:46 +000012102 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012103 E->getLocation(),
12104 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000012105}
12106
Mike Stump11289f42009-09-09 15:08:12 +000012107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012108ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012109TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000012110 // 'super' and types never change. Property never changes. Just
12111 // retain the existing expression.
12112 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012113 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012114
Douglas Gregor9faee212010-04-26 20:47:02 +000012115 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012116 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000012117 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012118 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012119
Douglas Gregor9faee212010-04-26 20:47:02 +000012120 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000012121
Douglas Gregor9faee212010-04-26 20:47:02 +000012122 // If nothing changed, just retain the existing expression.
12123 if (!getDerived().AlwaysRebuild() &&
12124 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012125 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012126
John McCallb7bd14f2010-12-02 01:19:52 +000012127 if (E->isExplicitProperty())
12128 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12129 E->getExplicitProperty(),
12130 E->getLocation());
12131
12132 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012133 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012134 E->getImplicitPropertyGetter(),
12135 E->getImplicitPropertySetter(),
12136 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012137}
12138
Mike Stump11289f42009-09-09 15:08:12 +000012139template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012140ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012141TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12142 // Transform the base expression.
12143 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12144 if (Base.isInvalid())
12145 return ExprError();
12146
12147 // Transform the key expression.
12148 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12149 if (Key.isInvalid())
12150 return ExprError();
12151
12152 // If nothing changed, just retain the existing expression.
12153 if (!getDerived().AlwaysRebuild() &&
12154 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012155 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012156
Chad Rosier1dcde962012-08-08 18:46:20 +000012157 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012158 Base.get(), Key.get(),
12159 E->getAtIndexMethodDecl(),
12160 E->setAtIndexMethodDecl());
12161}
12162
12163template<typename Derived>
12164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012165TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012166 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012167 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012168 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012169 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012170
Douglas Gregord51d90d2010-04-26 20:11:03 +000012171 // If nothing changed, just retain the existing expression.
12172 if (!getDerived().AlwaysRebuild() &&
12173 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012174 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012175
John McCallb268a282010-08-23 23:25:46 +000012176 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012177 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012178 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012179}
12180
Mike Stump11289f42009-09-09 15:08:12 +000012181template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012182ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012183TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012184 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012185 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012186 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012187 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012188 SubExprs, &ArgumentChanged))
12189 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012190
Douglas Gregora16548e2009-08-11 05:31:07 +000012191 if (!getDerived().AlwaysRebuild() &&
12192 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012193 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012194
Douglas Gregora16548e2009-08-11 05:31:07 +000012195 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012196 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012197 E->getRParenLoc());
12198}
12199
Mike Stump11289f42009-09-09 15:08:12 +000012200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012201ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012202TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12203 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12204 if (SrcExpr.isInvalid())
12205 return ExprError();
12206
12207 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12208 if (!Type)
12209 return ExprError();
12210
12211 if (!getDerived().AlwaysRebuild() &&
12212 Type == E->getTypeSourceInfo() &&
12213 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012214 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012215
12216 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12217 SrcExpr.get(), Type,
12218 E->getRParenLoc());
12219}
12220
12221template<typename Derived>
12222ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012223TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012224 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012225
Craig Topperc3ec1492014-05-26 06:22:03 +000012226 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012227 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12228
12229 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012230 blockScope->TheDecl->setBlockMissingReturnType(
12231 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012232
Chris Lattner01cf8db2011-07-20 06:58:45 +000012233 SmallVector<ParmVarDecl*, 4> params;
12234 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012235
John McCallc8e321d2016-03-01 02:09:25 +000012236 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12237
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012238 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012239 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012240 if (getDerived().TransformFunctionTypeParams(
12241 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12242 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12243 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012244 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012245 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012246 }
John McCall490112f2011-02-04 18:33:18 +000012247
Eli Friedman34b49062012-01-26 03:00:14 +000012248 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012249 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012250
John McCallc8e321d2016-03-01 02:09:25 +000012251 auto epi = exprFunctionType->getExtProtoInfo();
12252 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12253
Jordan Rose5c382722013-03-08 21:51:21 +000012254 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012255 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012256 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012257
12258 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012259 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012260 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012261
12262 if (!oldBlock->blockMissingReturnType()) {
12263 blockScope->HasImplicitReturnType = false;
12264 blockScope->ReturnType = exprResultType;
12265 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012266
John McCall3882ace2011-01-05 12:14:39 +000012267 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012268 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012269 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012270 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012271 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012272 }
John McCall3882ace2011-01-05 12:14:39 +000012273
John McCall490112f2011-02-04 18:33:18 +000012274#ifndef NDEBUG
12275 // In builds with assertions, make sure that we captured everything we
12276 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012277 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012278 for (const auto &I : oldBlock->captures()) {
12279 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012280
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012281 // Ignore parameter packs.
12282 if (isa<ParmVarDecl>(oldCapture) &&
12283 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12284 continue;
John McCall490112f2011-02-04 18:33:18 +000012285
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012286 VarDecl *newCapture =
12287 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12288 oldCapture));
12289 assert(blockScope->CaptureMap.count(newCapture));
12290 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012291 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012292 }
12293#endif
12294
12295 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012296 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012297}
12298
Mike Stump11289f42009-09-09 15:08:12 +000012299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012300ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012301TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012302 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012303}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012304
12305template<typename Derived>
12306ExprResult
12307TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012308 QualType RetTy = getDerived().TransformType(E->getType());
12309 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012310 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012311 SubExprs.reserve(E->getNumSubExprs());
12312 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12313 SubExprs, &ArgumentChanged))
12314 return ExprError();
12315
12316 if (!getDerived().AlwaysRebuild() &&
12317 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012318 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012319
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012320 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012321 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012322}
Chad Rosier1dcde962012-08-08 18:46:20 +000012323
Douglas Gregora16548e2009-08-11 05:31:07 +000012324//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012325// Type reconstruction
12326//===----------------------------------------------------------------------===//
12327
Mike Stump11289f42009-09-09 15:08:12 +000012328template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012329QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12330 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012331 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012332 getDerived().getBaseEntity());
12333}
12334
Mike Stump11289f42009-09-09 15:08:12 +000012335template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012336QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12337 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012338 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012339 getDerived().getBaseEntity());
12340}
12341
Mike Stump11289f42009-09-09 15:08:12 +000012342template<typename Derived>
12343QualType
John McCall70dd5f62009-10-30 00:06:24 +000012344TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12345 bool WrittenAsLValue,
12346 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012347 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012348 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012349}
12350
12351template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012352QualType
John McCall70dd5f62009-10-30 00:06:24 +000012353TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12354 QualType ClassType,
12355 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012356 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12357 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012358}
12359
12360template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012361QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12362 const ObjCTypeParamDecl *Decl,
12363 SourceLocation ProtocolLAngleLoc,
12364 ArrayRef<ObjCProtocolDecl *> Protocols,
12365 ArrayRef<SourceLocation> ProtocolLocs,
12366 SourceLocation ProtocolRAngleLoc) {
12367 return SemaRef.BuildObjCTypeParamType(Decl,
12368 ProtocolLAngleLoc, Protocols,
12369 ProtocolLocs, ProtocolRAngleLoc,
12370 /*FailOnError=*/true);
12371}
12372
12373template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012374QualType TreeTransform<Derived>::RebuildObjCObjectType(
12375 QualType BaseType,
12376 SourceLocation Loc,
12377 SourceLocation TypeArgsLAngleLoc,
12378 ArrayRef<TypeSourceInfo *> TypeArgs,
12379 SourceLocation TypeArgsRAngleLoc,
12380 SourceLocation ProtocolLAngleLoc,
12381 ArrayRef<ObjCProtocolDecl *> Protocols,
12382 ArrayRef<SourceLocation> ProtocolLocs,
12383 SourceLocation ProtocolRAngleLoc) {
12384 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12385 TypeArgs, TypeArgsRAngleLoc,
12386 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12387 ProtocolRAngleLoc,
12388 /*FailOnError=*/true);
12389}
12390
12391template<typename Derived>
12392QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12393 QualType PointeeType,
12394 SourceLocation Star) {
12395 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12396}
12397
12398template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012399QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012400TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12401 ArrayType::ArraySizeModifier SizeMod,
12402 const llvm::APInt *Size,
12403 Expr *SizeExpr,
12404 unsigned IndexTypeQuals,
12405 SourceRange BracketsRange) {
12406 if (SizeExpr || !Size)
12407 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12408 IndexTypeQuals, BracketsRange,
12409 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012410
12411 QualType Types[] = {
12412 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12413 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12414 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012415 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012416 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012417 QualType SizeType;
12418 for (unsigned I = 0; I != NumTypes; ++I)
12419 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12420 SizeType = Types[I];
12421 break;
12422 }
Mike Stump11289f42009-09-09 15:08:12 +000012423
Eli Friedman9562f392012-01-25 23:20:27 +000012424 // Note that we can return a VariableArrayType here in the case where
12425 // the element type was a dependent VariableArrayType.
12426 IntegerLiteral *ArraySize
12427 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12428 /*FIXME*/BracketsRange.getBegin());
12429 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012430 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012431 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012432}
Mike Stump11289f42009-09-09 15:08:12 +000012433
Douglas Gregord6ff3322009-08-04 16:50:30 +000012434template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012435QualType
12436TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012437 ArrayType::ArraySizeModifier SizeMod,
12438 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012439 unsigned IndexTypeQuals,
12440 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012441 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012442 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012443}
12444
12445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012446QualType
Mike Stump11289f42009-09-09 15:08:12 +000012447TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012448 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012449 unsigned IndexTypeQuals,
12450 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012451 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012452 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012453}
Mike Stump11289f42009-09-09 15:08:12 +000012454
Douglas Gregord6ff3322009-08-04 16:50:30 +000012455template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012456QualType
12457TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012458 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012459 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012460 unsigned IndexTypeQuals,
12461 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012462 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012463 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012464 IndexTypeQuals, BracketsRange);
12465}
12466
12467template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012468QualType
12469TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012470 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012471 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012472 unsigned IndexTypeQuals,
12473 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012474 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012475 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012476 IndexTypeQuals, BracketsRange);
12477}
12478
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012479template <typename Derived>
12480QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12481 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12482 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12483 AttributeLoc);
12484}
12485
12486template <typename Derived>
12487QualType
12488TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12489 unsigned NumElements,
12490 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012491 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012492 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012493}
Mike Stump11289f42009-09-09 15:08:12 +000012494
Erich Keanef702b022018-07-13 19:46:04 +000012495template <typename Derived>
12496QualType TreeTransform<Derived>::RebuildDependentVectorType(
12497 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
12498 VectorType::VectorKind VecKind) {
12499 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
12500}
12501
Douglas Gregord6ff3322009-08-04 16:50:30 +000012502template<typename Derived>
12503QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12504 unsigned NumElements,
12505 SourceLocation AttributeLoc) {
12506 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12507 NumElements, true);
12508 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012509 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12510 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012511 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012512}
Mike Stump11289f42009-09-09 15:08:12 +000012513
Douglas Gregord6ff3322009-08-04 16:50:30 +000012514template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012515QualType
12516TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012517 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012518 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012519 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012520}
Mike Stump11289f42009-09-09 15:08:12 +000012521
Douglas Gregord6ff3322009-08-04 16:50:30 +000012522template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012523QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12524 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012525 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012526 const FunctionProtoType::ExtProtoInfo &EPI) {
12527 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012528 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012529 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012530 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012531}
Mike Stump11289f42009-09-09 15:08:12 +000012532
Douglas Gregord6ff3322009-08-04 16:50:30 +000012533template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012534QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12535 return SemaRef.Context.getFunctionNoProtoType(T);
12536}
12537
12538template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012539QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12540 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012541 assert(D && "no decl found");
12542 if (D->isInvalidDecl()) return QualType();
12543
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012544 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012545 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012546 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12547 // A valid resolved using typename pack expansion decl can have multiple
12548 // UsingDecls, but they must each have exactly one type, and it must be
12549 // the same type in every case. But we must have at least one expansion!
12550 if (UPD->expansions().empty()) {
12551 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12552 << UPD->isCXXClassMember() << UPD;
12553 return QualType();
12554 }
12555
12556 // We might still have some unresolved types. Try to pick a resolved type
12557 // if we can. The final instantiation will check that the remaining
12558 // unresolved types instantiate to the type we pick.
12559 QualType FallbackT;
12560 QualType T;
12561 for (auto *E : UPD->expansions()) {
12562 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12563 if (ThisT.isNull())
12564 continue;
12565 else if (ThisT->getAs<UnresolvedUsingType>())
12566 FallbackT = ThisT;
12567 else if (T.isNull())
12568 T = ThisT;
12569 else
12570 assert(getSema().Context.hasSameType(ThisT, T) &&
12571 "mismatched resolved types in using pack expansion");
12572 }
12573 return T.isNull() ? FallbackT : T;
12574 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012575 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012576 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12577
12578 // A valid resolved using typename decl points to exactly one type decl.
12579 assert(++Using->shadow_begin() == Using->shadow_end());
12580 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012581 } else {
12582 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12583 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12584 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12585 }
12586
12587 return SemaRef.Context.getTypeDeclType(Ty);
12588}
12589
12590template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012591QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12592 SourceLocation Loc) {
12593 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012594}
12595
12596template<typename Derived>
12597QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12598 return SemaRef.Context.getTypeOfType(Underlying);
12599}
12600
12601template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012602QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12603 SourceLocation Loc) {
12604 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012605}
12606
12607template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012608QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12609 UnaryTransformType::UTTKind UKind,
12610 SourceLocation Loc) {
12611 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12612}
12613
12614template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012615QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012616 TemplateName Template,
12617 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012618 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012619 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012620}
Mike Stump11289f42009-09-09 15:08:12 +000012621
Douglas Gregor1135c352009-08-06 05:28:30 +000012622template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012623QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12624 SourceLocation KWLoc) {
12625 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12626}
12627
12628template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012629QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012630 SourceLocation KWLoc,
12631 bool isReadPipe) {
12632 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12633 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012634}
12635
12636template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012637TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012638TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012639 bool TemplateKW,
12640 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012641 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012642 Template);
12643}
12644
12645template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012646TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012647TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012648 SourceLocation TemplateKWLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +000012649 const IdentifierInfo &Name,
12650 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012651 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012652 NamedDecl *FirstQualifierInScope,
12653 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012654 UnqualifiedId TemplateName;
12655 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012656 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012657 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012658 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012659 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012660 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012661 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012662 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012663}
Mike Stump11289f42009-09-09 15:08:12 +000012664
Douglas Gregora16548e2009-08-11 05:31:07 +000012665template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012666TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012667TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Richard Smith79810042018-05-11 02:43:08 +000012668 SourceLocation TemplateKWLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012669 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012670 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012671 QualType ObjectType,
12672 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012673 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012674 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012675 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012676 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +000012677 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012678 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012679 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012680 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012681 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012682 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012683 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012684}
Chad Rosier1dcde962012-08-08 18:46:20 +000012685
Douglas Gregor71395fa2009-11-04 00:56:37 +000012686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012687ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012688TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12689 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012690 Expr *OrigCallee,
12691 Expr *First,
12692 Expr *Second) {
12693 Expr *Callee = OrigCallee->IgnoreParenCasts();
12694 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012695
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012696 if (First->getObjectKind() == OK_ObjCProperty) {
12697 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12698 if (BinaryOperator::isAssignmentOp(Opc))
12699 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12700 First, Second);
12701 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12702 if (Result.isInvalid())
12703 return ExprError();
12704 First = Result.get();
12705 }
12706
12707 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12708 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12709 if (Result.isInvalid())
12710 return ExprError();
12711 Second = Result.get();
12712 }
12713
Douglas Gregora16548e2009-08-11 05:31:07 +000012714 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012715 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012716 if (!First->getType()->isOverloadableType() &&
12717 !Second->getType()->isOverloadableType())
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012718 return getSema().CreateBuiltinArraySubscriptExpr(
12719 First, Callee->getBeginLoc(), Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012720 } else if (Op == OO_Arrow) {
12721 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012722 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12723 } else if (Second == nullptr || isPostIncDec) {
Richard Smithcc4ad952018-07-22 05:21:47 +000012724 if (!First->getType()->isOverloadableType() ||
12725 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
12726 // The argument is not of overloadable type, or this is an expression
12727 // of the form &Class::member, so try to create a built-in unary
12728 // operation.
John McCalle3027922010-08-25 11:45:40 +000012729 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012730 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012731
John McCallb268a282010-08-23 23:25:46 +000012732 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012733 }
12734 } else {
John McCallb268a282010-08-23 23:25:46 +000012735 if (!First->getType()->isOverloadableType() &&
12736 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012737 // Neither of the arguments is an overloadable type, so try to
12738 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012739 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012740 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012741 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012742 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012743 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012744
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012745 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012746 }
12747 }
Mike Stump11289f42009-09-09 15:08:12 +000012748
12749 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012750 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012751 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012752 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012753
John McCallb268a282010-08-23 23:25:46 +000012754 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012755 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012756 // If the overload could not be resolved in the template definition
12757 // (because we had a dependent argument), ADL is performed as part of
12758 // template instantiation.
12759 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012760 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012761 // If we've resolved this to a particular non-member function, just call
12762 // that function. If we resolved it to a member function,
12763 // CreateOverloaded* will find that function for us.
12764 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12765 if (!isa<CXXMethodDecl>(ND))
12766 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012767 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012768 }
Mike Stump11289f42009-09-09 15:08:12 +000012769
Douglas Gregora16548e2009-08-11 05:31:07 +000012770 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012771 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012772 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012773
Douglas Gregora16548e2009-08-11 05:31:07 +000012774 // Create the overloaded operator invocation for unary operators.
12775 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012776 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012777 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012778 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12779 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012780 }
Mike Stump11289f42009-09-09 15:08:12 +000012781
Douglas Gregore9d62932011-07-15 16:25:15 +000012782 if (Op == OO_Subscript) {
12783 SourceLocation LBrace;
12784 SourceLocation RBrace;
12785
12786 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012787 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012788 LBrace = SourceLocation::getFromRawEncoding(
12789 NameLoc.CXXOperatorName.BeginOpNameLoc);
12790 RBrace = SourceLocation::getFromRawEncoding(
12791 NameLoc.CXXOperatorName.EndOpNameLoc);
12792 } else {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012793 LBrace = Callee->getBeginLoc();
12794 RBrace = OpLoc;
Douglas Gregore9d62932011-07-15 16:25:15 +000012795 }
12796
12797 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12798 First, Second);
12799 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012800
Douglas Gregora16548e2009-08-11 05:31:07 +000012801 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012802 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012803 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12804 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012805 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012806 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012807
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012808 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012809}
Mike Stump11289f42009-09-09 15:08:12 +000012810
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012811template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012812ExprResult
John McCallb268a282010-08-23 23:25:46 +000012813TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012814 SourceLocation OperatorLoc,
12815 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012816 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012817 TypeSourceInfo *ScopeType,
12818 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012819 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012820 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012821 QualType BaseType = Base->getType();
12822 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012823 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012824 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012825 !BaseType->getAs<PointerType>()->getPointeeType()
12826 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012827 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012828 return SemaRef.BuildPseudoDestructorExpr(
12829 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12830 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012831 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012832
Douglas Gregor678f90d2010-02-25 01:56:36 +000012833 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012834 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12835 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12836 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12837 NameInfo.setNamedTypeInfo(DestroyedType);
12838
Richard Smith8e4a3862012-05-15 06:15:11 +000012839 // The scope type is now known to be a valid nested name specifier
12840 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012841 if (ScopeType) {
12842 if (!ScopeType->getType()->getAs<TagType>()) {
12843 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12844 diag::err_expected_class_or_namespace)
12845 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12846 return ExprError();
12847 }
12848 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12849 CCLoc);
12850 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012851
Abramo Bagnara7945c982012-01-27 09:46:47 +000012852 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012853 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012854 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012855 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012856 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012857 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012858 /*TemplateArgs*/ nullptr,
12859 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012860}
12861
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012862template<typename Derived>
12863StmtResult
12864TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Stephen Kellyf2ceec42018-08-09 21:08:08 +000012865 SourceLocation Loc = S->getBeginLoc();
Alexey Bataev9959db52014-05-06 10:08:46 +000012866 CapturedDecl *CD = S->getCapturedDecl();
12867 unsigned NumParams = CD->getNumParams();
12868 unsigned ContextParamPos = CD->getContextParamPosition();
12869 SmallVector<Sema::CapturedParamNameType, 4> Params;
12870 for (unsigned I = 0; I < NumParams; ++I) {
12871 if (I != ContextParamPos) {
12872 Params.push_back(
12873 std::make_pair(
12874 CD->getParam(I)->getName(),
12875 getDerived().TransformType(CD->getParam(I)->getType())));
12876 } else {
12877 Params.push_back(std::make_pair(StringRef(), QualType()));
12878 }
12879 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012880 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012881 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012882 StmtResult Body;
12883 {
12884 Sema::CompoundScopeRAII CompoundScope(getSema());
12885 Body = getDerived().TransformStmt(S->getCapturedStmt());
12886 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012887
12888 if (Body.isInvalid()) {
12889 getSema().ActOnCapturedRegionError();
12890 return StmtError();
12891 }
12892
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012893 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012894}
12895
Douglas Gregord6ff3322009-08-04 16:50:30 +000012896} // end namespace clang
12897
Hans Wennborg59dbe862015-09-29 20:56:43 +000012898#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H