blob: 693b5c088acc12327741bebd125e198f9bfa1a23 [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//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Eric Fiselierbee782b2017-04-03 19:21:00 +000017#include "CoroutineStmtBuilder.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000020#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000021#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000022#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000023#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000025#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000029#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000030#include "clang/Sema/Designator.h"
31#include "clang/Sema/Lookup.h"
32#include "clang/Sema/Ownership.h"
33#include "clang/Sema/ParsedTemplate.h"
34#include "clang/Sema/ScopeInfo.h"
35#include "clang/Sema/SemaDiagnostic.h"
36#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000037#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000038#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000039#include <algorithm>
40
41namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000042using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregord6ff3322009-08-04 16:50:30 +000044/// \brief A semantic tree transformation that allows one to transform one
45/// abstract syntax tree into another.
46///
Mike Stump11289f42009-09-09 15:08:12 +000047/// A new tree transformation is defined by creating a new subclass \c X of
48/// \c TreeTransform<X> and then overriding certain operations to provide
49/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000050/// instantiation is implemented as a tree transformation where the
51/// transformation of TemplateTypeParmType nodes involves substituting the
52/// template arguments for their corresponding template parameters; a similar
53/// transformation is performed for non-type template parameters and
54/// template template parameters.
55///
56/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000057/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000058/// override any of the transformation or rebuild operators by providing an
59/// operation with the same signature as the default implementation. The
60/// overridding function should not be virtual.
61///
62/// Semantic tree transformations are split into two stages, either of which
63/// can be replaced by a subclass. The "transform" step transforms an AST node
64/// or the parts of an AST node using the various transformation functions,
65/// then passes the pieces on to the "rebuild" step, which constructs a new AST
66/// node of the appropriate kind from the pieces. The default transformation
67/// routines recursively transform the operands to composite AST nodes (e.g.,
68/// the pointee type of a PointerType node) and, if any of those operand nodes
69/// were changed by the transformation, invokes the rebuild operation to create
70/// a new AST node.
71///
Mike Stump11289f42009-09-09 15:08:12 +000072/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000073/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000074/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000075/// TransformTemplateName(), or TransformTemplateArgument() with entirely
76/// new implementations.
77///
78/// For more fine-grained transformations, subclasses can replace any of the
79/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000080/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000082/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000083/// parameters. Additionally, subclasses can override the \c RebuildXXX
84/// functions to control how AST nodes are rebuilt when their operands change.
85/// By default, \c TreeTransform will invoke semantic analysis to rebuild
86/// AST nodes. However, certain other tree transformations (e.g, cloning) may
87/// be able to use more efficient rebuild steps.
88///
89/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000090/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000091/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
92/// operands have not changed (\c AlwaysRebuild()), and customize the
93/// default locations and entity names used for type-checking
94/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000095template<typename Derived>
96class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000097 /// \brief Private RAII object that helps us forget and then re-remember
98 /// the template argument corresponding to a partially-substituted parameter
99 /// pack.
100 class ForgetPartiallySubstitutedPackRAII {
101 Derived &Self;
102 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000103
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000104 public:
105 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
106 Old = Self.ForgetPartiallySubstitutedPack();
107 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000108
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000109 ~ForgetPartiallySubstitutedPackRAII() {
110 Self.RememberPartiallySubstitutedPack(Old);
111 }
112 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114protected:
115 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000116
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000117 /// \brief The set of local declarations that have been transformed, for
118 /// cases where we are forced to build new declarations within the transformer
119 /// rather than in the subclass (e.g., lambda closure types).
120 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000121
Mike Stump11289f42009-09-09 15:08:12 +0000122public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000124 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000125
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// \brief Retrieves a reference to the derived class.
127 Derived &getDerived() { return static_cast<Derived&>(*this); }
128
129 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000130 const Derived &getDerived() const {
131 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 }
133
John McCalldadc5752010-08-24 06:29:42 +0000134 static inline ExprResult Owned(Expr *E) { return E; }
135 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000136
Douglas Gregord6ff3322009-08-04 16:50:30 +0000137 /// \brief Retrieves a reference to the semantic analysis object used for
138 /// this tree transform.
139 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Whether the transformation should always rebuild AST nodes, even
142 /// if none of the children have changed.
143 ///
144 /// Subclasses may override this function to specify when the transformation
145 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000146 ///
147 /// We must always rebuild all AST nodes when performing variadic template
148 /// pack expansion, in order to avoid violating the AST invariant that each
149 /// statement node appears at most once in its containing declaration.
150 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000151
Douglas Gregord6ff3322009-08-04 16:50:30 +0000152 /// \brief Returns the location of the entity being transformed, if that
153 /// information was not available elsewhere in the AST.
154 ///
Mike Stump11289f42009-09-09 15:08:12 +0000155 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000156 /// provide an alternative implementation that provides better location
157 /// information.
158 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregord6ff3322009-08-04 16:50:30 +0000160 /// \brief Returns the name of the entity being transformed, if that
161 /// information was not available elsewhere in the AST.
162 ///
163 /// By default, returns an empty name. Subclasses can provide an alternative
164 /// implementation with a more precise name.
165 DeclarationName getBaseEntity() { return DeclarationName(); }
166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 /// \brief Sets the "base" location and entity when that
168 /// information is known based on another transformation.
169 ///
170 /// By default, the source location and entity are ignored. Subclasses can
171 /// override this function to provide a customized implementation.
172 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000173
Douglas Gregora16548e2009-08-11 05:31:07 +0000174 /// \brief RAII object that temporarily sets the base location and entity
175 /// used for reporting diagnostics in types.
176 class TemporaryBase {
177 TreeTransform &Self;
178 SourceLocation OldLocation;
179 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000180
Douglas Gregora16548e2009-08-11 05:31:07 +0000181 public:
182 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000183 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000184 OldLocation = Self.getDerived().getBaseLocation();
185 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000186
Douglas Gregora518d5b2011-01-25 17:51:48 +0000187 if (Location.isValid())
188 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000189 }
Mike Stump11289f42009-09-09 15:08:12 +0000190
Douglas Gregora16548e2009-08-11 05:31:07 +0000191 ~TemporaryBase() {
192 Self.getDerived().setBase(OldLocation, OldEntity);
193 }
194 };
Mike Stump11289f42009-09-09 15:08:12 +0000195
196 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000197 /// transformed.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000200 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000201 /// not change. For example, template instantiation need not traverse
202 /// non-dependent types.
203 bool AlreadyTransformed(QualType T) {
204 return T.isNull();
205 }
206
Douglas Gregord196a582009-12-14 19:27:10 +0000207 /// \brief Determine whether the given call argument should be dropped, e.g.,
208 /// because it is a default argument.
209 ///
210 /// Subclasses can provide an alternative implementation of this routine to
211 /// determine which kinds of call arguments get dropped. By default,
212 /// CXXDefaultArgument nodes are dropped (prior to transformation).
213 bool DropCallArgument(Expr *E) {
214 return E->isDefaultArgument();
215 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000216
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000217 /// \brief Determine whether we should expand a pack expansion with the
218 /// given set of parameter packs into separate arguments by repeatedly
219 /// transforming the pattern.
220 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000221 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000222 /// Subclasses can override this routine to provide different behavior.
223 ///
224 /// \param EllipsisLoc The location of the ellipsis that identifies the
225 /// pack expansion.
226 ///
227 /// \param PatternRange The source range that covers the entire pattern of
228 /// the pack expansion.
229 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000230 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000231 /// pattern.
232 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000233 /// \param ShouldExpand Will be set to \c true if the transformer should
234 /// expand the corresponding pack expansions into separate arguments. When
235 /// set, \c NumExpansions must also be set.
236 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000237 /// \param RetainExpansion Whether the caller should add an unexpanded
238 /// pack expansion after all of the expanded arguments. This is used
239 /// when extending explicitly-specified template argument packs per
240 /// C++0x [temp.arg.explicit]p9.
241 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000242 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000243 /// the expanded form of the corresponding pack expansion. This is both an
244 /// input and an output parameter, which can be set by the caller if the
245 /// number of expansions is known a priori (e.g., due to a prior substitution)
246 /// and will be set by the callee when the number of expansions is known.
247 /// The callee must set this value when \c ShouldExpand is \c true; it may
248 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000250 /// \returns true if an error occurred (e.g., because the parameter packs
251 /// are to be instantiated with arguments of different lengths), false
252 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000253 /// must be set.
254 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
255 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000256 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000257 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000258 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000259 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000260 ShouldExpand = false;
261 return false;
262 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000263
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000264 /// \brief "Forget" about the partially-substituted pack template argument,
265 /// when performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 TemplateArgument ForgetPartiallySubstitutedPack() {
270 return TemplateArgument();
271 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000272
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000273 /// \brief "Remember" the partially-substituted pack template argument
274 /// after performing an instantiation that must preserve the parameter pack
275 /// use.
276 ///
277 /// This routine is meant to be overridden by the template instantiator.
278 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000279
Douglas Gregorf3010112011-01-07 16:43:16 +0000280 /// \brief Note to the derived class when a function parameter pack is
281 /// being expanded.
282 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000283
Douglas Gregord6ff3322009-08-04 16:50:30 +0000284 /// \brief Transforms the given type into another type.
285 ///
John McCall550e0c22009-10-21 00:40:46 +0000286 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000287 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000288 /// function. This is expensive, but we don't mind, because
289 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000290 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 ///
292 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000293 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000294
John McCall550e0c22009-10-21 00:40:46 +0000295 /// \brief Transforms the given type-with-location into a new
296 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000297 ///
John McCall550e0c22009-10-21 00:40:46 +0000298 /// By default, this routine transforms a type by delegating to the
299 /// appropriate TransformXXXType to build a new type. Subclasses
300 /// may override this function (to take over all type
301 /// transformations) or some set of the TransformXXXType functions
302 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000303 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000304
305 /// \brief Transform the given type-with-location into a new
306 /// type, collecting location information in the given builder
307 /// as necessary.
308 ///
John McCall31f82722010-11-12 08:19:04 +0000309 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000310
Richard Smithee579842017-01-30 20:39:26 +0000311 /// \brief Transform a type that is permitted to produce a
312 /// DeducedTemplateSpecializationType.
313 ///
314 /// This is used in the (relatively rare) contexts where it is acceptable
315 /// for transformation to produce a class template type with deduced
316 /// template arguments.
317 /// @{
318 QualType TransformTypeWithDeducedTST(QualType T);
319 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
320 /// @}
321
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000322 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000323 ///
Mike Stump11289f42009-09-09 15:08:12 +0000324 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000325 /// appropriate TransformXXXStmt function to transform a specific kind of
326 /// statement or the TransformExpr() function to transform an expression.
327 /// Subclasses may override this function to transform statements using some
328 /// other mechanism.
329 ///
330 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000331 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000332
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000333 /// \brief Transform the given statement.
334 ///
335 /// By default, this routine transforms a statement by delegating to the
336 /// appropriate TransformOMPXXXClause function to transform a specific kind
337 /// of clause. Subclasses may override this function to transform statements
338 /// using some other mechanism.
339 ///
340 /// \returns the transformed OpenMP clause.
341 OMPClause *TransformOMPClause(OMPClause *S);
342
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000343 /// \brief Transform the given attribute.
344 ///
345 /// By default, this routine transforms a statement by delegating to the
346 /// appropriate TransformXXXAttr function to transform a specific kind
347 /// of attribute. Subclasses may override this function to transform
348 /// attributed statements using some other mechanism.
349 ///
350 /// \returns the transformed attribute
351 const Attr *TransformAttr(const Attr *S);
352
353/// \brief Transform the specified attribute.
354///
355/// Subclasses should override the transformation of attributes with a pragma
356/// spelling to transform expressions stored within the attribute.
357///
358/// \returns the transformed attribute.
359#define ATTR(X)
360#define PRAGMA_SPELLING_ATTR(X) \
361 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
362#include "clang/Basic/AttrList.inc"
363
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000364 /// \brief Transform the given expression.
365 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000366 /// By default, this routine transforms an expression by delegating to the
367 /// appropriate TransformXXXExpr function to build a new expression.
368 /// Subclasses may override this function to transform expressions using some
369 /// other mechanism.
370 ///
371 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000372 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Richard Smithd59b8322012-12-19 01:39:02 +0000374 /// \brief Transform the given initializer.
375 ///
376 /// By default, this routine transforms an initializer by stripping off the
377 /// semantic nodes added by initialization, then passing the result to
378 /// TransformExpr or TransformExprs.
379 ///
380 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000381 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000382
Douglas Gregora3efea12011-01-03 19:04:46 +0000383 /// \brief Transform the given list of expressions.
384 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000385 /// This routine transforms a list of expressions by invoking
386 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000387 /// support for variadic templates by expanding any pack expansions (if the
388 /// derived class permits such expansion) along the way. When pack expansions
389 /// are present, the number of outputs may not equal the number of inputs.
390 ///
391 /// \param Inputs The set of expressions to be transformed.
392 ///
393 /// \param NumInputs The number of expressions in \c Inputs.
394 ///
395 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000396 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000397 /// be.
398 ///
399 /// \param Outputs The transformed input expressions will be added to this
400 /// vector.
401 ///
402 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
403 /// due to transformation.
404 ///
405 /// \returns true if an error occurred, false otherwise.
Craig Topper99d23532015-12-24 23:58:29 +0000406 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000407 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000408 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 /// \brief Transform the given declaration, which is referenced from a type
411 /// or expression.
412 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000413 /// By default, acts as the identity function on declarations, unless the
414 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000415 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000416 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000417 llvm::DenseMap<Decl *, Decl *>::iterator Known
418 = TransformedLocalDecls.find(D);
419 if (Known != TransformedLocalDecls.end())
420 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000421
422 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000423 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000424
Richard Smith03a4aa32016-06-23 19:02:52 +0000425 /// \brief Transform the specified condition.
426 ///
427 /// By default, this transforms the variable and expression and rebuilds
428 /// the condition.
429 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
430 Expr *Expr,
431 Sema::ConditionKind Kind);
432
Chad Rosier1dcde962012-08-08 18:46:20 +0000433 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000434 /// place them on the new declaration.
435 ///
436 /// By default, this operation does nothing. Subclasses may override this
437 /// behavior to transform attributes.
438 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000439
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000440 /// \brief Note that a local declaration has been transformed by this
441 /// transformer.
442 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000443 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000444 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
445 /// the transformer itself has to transform the declarations. This routine
446 /// can be overridden by a subclass that keeps track of such mappings.
447 void transformedLocalDecl(Decl *Old, Decl *New) {
448 TransformedLocalDecls[Old] = New;
449 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000450
Douglas Gregorebe10102009-08-20 07:17:43 +0000451 /// \brief Transform the definition of the given declaration.
452 ///
Mike Stump11289f42009-09-09 15:08:12 +0000453 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000454 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000455 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
456 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000457 }
Mike Stump11289f42009-09-09 15:08:12 +0000458
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000459 /// \brief Transform the given declaration, which was the first part of a
460 /// nested-name-specifier in a member access expression.
461 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000462 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000463 /// identifier in a nested-name-specifier of a member access expression, e.g.,
464 /// the \c T in \c x->T::member
465 ///
466 /// By default, invokes TransformDecl() to transform the declaration.
467 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000468 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
469 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000470 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000471
Richard Smith151c4562016-12-20 21:35:28 +0000472 /// Transform the set of declarations in an OverloadExpr.
473 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
474 LookupResult &R);
475
Douglas Gregor14454802011-02-25 02:25:35 +0000476 /// \brief Transform the given nested-name-specifier with source-location
477 /// information.
478 ///
479 /// By default, transforms all of the types and declarations within the
480 /// nested-name-specifier. Subclasses may override this function to provide
481 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000482 NestedNameSpecifierLoc
483 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
484 QualType ObjectType = QualType(),
485 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000486
Douglas Gregorf816bd72009-09-03 22:13:48 +0000487 /// \brief Transform the given declaration name.
488 ///
489 /// By default, transforms the types of conversion function, constructor,
490 /// and destructor names and then (if needed) rebuilds the declaration name.
491 /// Identifiers and selectors are returned unmodified. Sublcasses may
492 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000493 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000494 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000495
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000497 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000498 /// \param SS The nested-name-specifier that qualifies the template
499 /// name. This nested-name-specifier must already have been transformed.
500 ///
501 /// \param Name The template name to transform.
502 ///
503 /// \param NameLoc The source location of the template name.
504 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000505 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000506 /// access expression, this is the type of the object whose member template
507 /// is being referenced.
508 ///
509 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
510 /// also refers to a name within the current (lexical) scope, this is the
511 /// declaration it refers to.
512 ///
513 /// By default, transforms the template name by transforming the declarations
514 /// and nested-name-specifiers that occur within the template name.
515 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000516 TemplateName
517 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
518 SourceLocation NameLoc,
519 QualType ObjectType = QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000520 NamedDecl *FirstQualifierInScope = nullptr,
521 bool AllowInjectedClassName = false);
Douglas Gregor9db53502011-03-02 18:07:45 +0000522
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523 /// \brief Transform the given template argument.
524 ///
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// By default, this operation transforms the type, expression, or
526 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000527 /// new template argument from the transformed result. Subclasses may
528 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000529 ///
530 /// Returns true if there was an error.
531 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000532 TemplateArgumentLoc &Output,
533 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000534
Douglas Gregor62e06f22010-12-20 17:31:10 +0000535 /// \brief Transform the given set of template arguments.
536 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000537 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000538 /// in the input set using \c TransformTemplateArgument(), and appends
539 /// the transformed arguments to the output list.
540 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000541 /// Note that this overload of \c TransformTemplateArguments() is merely
542 /// a convenience function. Subclasses that wish to override this behavior
543 /// should override the iterator-based member template version.
544 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000545 /// \param Inputs The set of template arguments to be transformed.
546 ///
547 /// \param NumInputs The number of template arguments in \p Inputs.
548 ///
549 /// \param Outputs The set of transformed template arguments output by this
550 /// routine.
551 ///
552 /// Returns true if an error occurred.
553 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
554 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000555 TemplateArgumentListInfo &Outputs,
556 bool Uneval = false) {
557 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
558 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000559 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000560
561 /// \brief Transform the given set of template arguments.
562 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000563 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000564 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000565 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000566 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000567 /// \param First An iterator to the first template argument.
568 ///
569 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000570 ///
571 /// \param Outputs The set of transformed template arguments output by this
572 /// routine.
573 ///
574 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000575 template<typename InputIterator>
576 bool TransformTemplateArguments(InputIterator First,
577 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000578 TemplateArgumentListInfo &Outputs,
579 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000580
John McCall0ad16662009-10-29 08:12:44 +0000581 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
582 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
583 TemplateArgumentLoc &ArgLoc);
584
John McCallbcd03502009-12-07 02:54:59 +0000585 /// \brief Fakes up a TypeSourceInfo for a type.
586 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
587 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000588 getDerived().getBaseLocation());
589 }
Mike Stump11289f42009-09-09 15:08:12 +0000590
John McCall550e0c22009-10-21 00:40:46 +0000591#define ABSTRACT_TYPELOC(CLASS, PARENT)
592#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000593 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000594#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000595
Richard Smith2e321552014-11-12 02:00:47 +0000596 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000597 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
598 FunctionProtoTypeLoc TL,
599 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000600 unsigned ThisTypeQuals,
601 Fn TransformExceptionSpec);
602
603 bool TransformExceptionSpec(SourceLocation Loc,
604 FunctionProtoType::ExceptionSpecInfo &ESI,
605 SmallVectorImpl<QualType> &Exceptions,
606 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000607
David Majnemerfad8f482013-10-15 09:33:02 +0000608 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000609
Chad Rosier1dcde962012-08-08 18:46:20 +0000610 QualType
John McCall31f82722010-11-12 08:19:04 +0000611 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
612 TemplateSpecializationTypeLoc TL,
613 TemplateName Template);
614
Chad Rosier1dcde962012-08-08 18:46:20 +0000615 QualType
John McCall31f82722010-11-12 08:19:04 +0000616 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
617 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000618 TemplateName Template,
619 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000620
Nico Weberc153d242014-07-28 00:02:09 +0000621 QualType TransformDependentTemplateSpecializationType(
622 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
623 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000624
John McCall58f10c32010-03-11 09:03:00 +0000625 /// \brief Transforms the parameters of a function type into the
626 /// given vectors.
627 ///
628 /// The result vectors should be kept in sync; null entries in the
629 /// variables vector are acceptable.
630 ///
631 /// Return true on error.
David Majnemer59f77922016-06-24 04:05:48 +0000632 bool TransformFunctionTypeParams(
633 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
634 const QualType *ParamTypes,
635 const FunctionProtoType::ExtParameterInfo *ParamInfos,
636 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
637 Sema::ExtParameterInfoBuilder &PInfos);
John McCall58f10c32010-03-11 09:03:00 +0000638
639 /// \brief Transforms a single function-type parameter. Return null
640 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000641 ///
642 /// \param indexAdjustment - A number to add to the parameter's
643 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000644 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000645 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000646 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000647 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000648
John McCall31f82722010-11-12 08:19:04 +0000649 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000650
John McCalldadc5752010-08-24 06:29:42 +0000651 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
652 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000653
Faisal Vali2cba1332013-10-23 06:44:28 +0000654 TemplateParameterList *TransformTemplateParameterList(
655 TemplateParameterList *TPL) {
656 return TPL;
657 }
658
Richard Smithdb2630f2012-10-21 03:28:35 +0000659 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000660
Richard Smithdb2630f2012-10-21 03:28:35 +0000661 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000662 bool IsAddressOfOperand,
663 TypeSourceInfo **RecoveryTSI);
664
665 ExprResult TransformParenDependentScopeDeclRefExpr(
666 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
667 TypeSourceInfo **RecoveryTSI);
668
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000669 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000670
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000671// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
672// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000673#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000674 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000675 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000676#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000677 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000678 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000679#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000680#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000681
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000682#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000683 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000684 OMPClause *Transform ## Class(Class *S);
685#include "clang/Basic/OpenMPKinds.def"
686
Richard Smithee579842017-01-30 20:39:26 +0000687 /// \brief Build a new qualified type given its unqualified type and type
688 /// qualifiers.
689 ///
690 /// By default, this routine adds type qualifiers only to types that can
691 /// have qualifiers, and silently suppresses those qualifiers that are not
692 /// permitted. Subclasses may override this routine to provide different
693 /// behavior.
694 QualType RebuildQualifiedType(QualType T, SourceLocation Loc,
695 Qualifiers Quals);
696
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 /// \brief Build a new pointer type given its pointee type.
698 ///
699 /// By default, performs semantic analysis when building the pointer type.
700 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000701 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000702
703 /// \brief Build a new block pointer type given its pointee type.
704 ///
Mike Stump11289f42009-09-09 15:08:12 +0000705 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000706 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000707 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000708
John McCall70dd5f62009-10-30 00:06:24 +0000709 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 ///
John McCall70dd5f62009-10-30 00:06:24 +0000711 /// By default, performs semantic analysis when building the
712 /// reference type. Subclasses may override this routine to provide
713 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 ///
John McCall70dd5f62009-10-30 00:06:24 +0000715 /// \param LValue whether the type was written with an lvalue sigil
716 /// or an rvalue sigil.
717 QualType RebuildReferenceType(QualType ReferentType,
718 bool LValue,
719 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000720
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 /// \brief Build a new member pointer type given the pointee type and the
722 /// class type it refers into.
723 ///
724 /// By default, performs semantic analysis when building the member pointer
725 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000726 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
727 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000728
Manman Rene6be26c2016-09-13 17:25:08 +0000729 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
730 SourceLocation ProtocolLAngleLoc,
731 ArrayRef<ObjCProtocolDecl *> Protocols,
732 ArrayRef<SourceLocation> ProtocolLocs,
733 SourceLocation ProtocolRAngleLoc);
734
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000735 /// \brief Build an Objective-C object type.
736 ///
737 /// By default, performs semantic analysis when building the object type.
738 /// Subclasses may override this routine to provide different behavior.
739 QualType RebuildObjCObjectType(QualType BaseType,
740 SourceLocation Loc,
741 SourceLocation TypeArgsLAngleLoc,
742 ArrayRef<TypeSourceInfo *> TypeArgs,
743 SourceLocation TypeArgsRAngleLoc,
744 SourceLocation ProtocolLAngleLoc,
745 ArrayRef<ObjCProtocolDecl *> Protocols,
746 ArrayRef<SourceLocation> ProtocolLocs,
747 SourceLocation ProtocolRAngleLoc);
748
749 /// \brief Build a new Objective-C object pointer type given the pointee type.
750 ///
751 /// By default, directly builds the pointer type, with no additional semantic
752 /// analysis.
753 QualType RebuildObjCObjectPointerType(QualType PointeeType,
754 SourceLocation Star);
755
Douglas Gregord6ff3322009-08-04 16:50:30 +0000756 /// \brief Build a new array type given the element type, size
757 /// modifier, size of the array (if known), size expression, and index type
758 /// qualifiers.
759 ///
760 /// By default, performs semantic analysis when building the array type.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000763 QualType RebuildArrayType(QualType ElementType,
764 ArrayType::ArraySizeModifier SizeMod,
765 const llvm::APInt *Size,
766 Expr *SizeExpr,
767 unsigned IndexTypeQuals,
768 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregord6ff3322009-08-04 16:50:30 +0000770 /// \brief Build a new constant array type given the element type, size
771 /// modifier, (known) size of the array, and index type qualifiers.
772 ///
773 /// By default, performs semantic analysis when building the array type.
774 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000775 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000776 ArrayType::ArraySizeModifier SizeMod,
777 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000778 unsigned IndexTypeQuals,
779 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000780
Douglas Gregord6ff3322009-08-04 16:50:30 +0000781 /// \brief Build a new incomplete array type given the element type, size
782 /// modifier, and index type qualifiers.
783 ///
784 /// By default, performs semantic analysis when building the array type.
785 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000786 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000787 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000788 unsigned IndexTypeQuals,
789 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790
Mike Stump11289f42009-09-09 15:08:12 +0000791 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 /// size modifier, size expression, and index type qualifiers.
793 ///
794 /// By default, performs semantic analysis when building the array type.
795 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000796 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000797 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000798 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000799 unsigned IndexTypeQuals,
800 SourceRange BracketsRange);
801
Mike Stump11289f42009-09-09 15:08:12 +0000802 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000803 /// size modifier, size expression, and index type qualifiers.
804 ///
805 /// By default, performs semantic analysis when building the array type.
806 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000807 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000808 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000809 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000810 unsigned IndexTypeQuals,
811 SourceRange BracketsRange);
812
813 /// \brief Build a new vector type given the element type and
814 /// number of elements.
815 ///
816 /// By default, performs semantic analysis when building the vector type.
817 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000818 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000819 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000820
Douglas Gregord6ff3322009-08-04 16:50:30 +0000821 /// \brief Build a new extended vector type given the element type and
822 /// number of elements.
823 ///
824 /// By default, performs semantic analysis when building the vector type.
825 /// Subclasses may override this routine to provide different behavior.
826 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
827 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000828
829 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000830 /// given the element type and number of elements.
831 ///
832 /// By default, performs semantic analysis when building the vector type.
833 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000834 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000835 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000836 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000837
Douglas Gregord6ff3322009-08-04 16:50:30 +0000838 /// \brief Build a new function type.
839 ///
840 /// By default, performs semantic analysis when building the function type.
841 /// Subclasses may override this routine to provide different behavior.
842 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000843 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000844 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000845
John McCall550e0c22009-10-21 00:40:46 +0000846 /// \brief Build a new unprototyped function type.
847 QualType RebuildFunctionNoProtoType(QualType ResultType);
848
John McCallb96ec562009-12-04 22:46:56 +0000849 /// \brief Rebuild an unresolved typename type, given the decl that
850 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000851 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000852
Douglas Gregord6ff3322009-08-04 16:50:30 +0000853 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000854 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000855 return SemaRef.Context.getTypeDeclType(Typedef);
856 }
857
858 /// \brief Build a new class/struct/union type.
859 QualType RebuildRecordType(RecordDecl *Record) {
860 return SemaRef.Context.getTypeDeclType(Record);
861 }
862
863 /// \brief Build a new Enum type.
864 QualType RebuildEnumType(EnumDecl *Enum) {
865 return SemaRef.Context.getTypeDeclType(Enum);
866 }
John McCallfcc33b02009-09-05 00:15:47 +0000867
Mike Stump11289f42009-09-09 15:08:12 +0000868 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000869 ///
870 /// By default, performs semantic analysis when building the typeof type.
871 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000872 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000873
Mike Stump11289f42009-09-09 15:08:12 +0000874 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000875 ///
876 /// By default, builds a new TypeOfType with the given underlying type.
877 QualType RebuildTypeOfType(QualType Underlying);
878
Alexis Hunte852b102011-05-24 22:41:36 +0000879 /// \brief Build a new unary transform type.
880 QualType RebuildUnaryTransformType(QualType BaseType,
881 UnaryTransformType::UTTKind UKind,
882 SourceLocation Loc);
883
Richard Smith74aeef52013-04-26 16:15:35 +0000884 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885 ///
886 /// By default, performs semantic analysis when building the decltype type.
887 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000888 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000889
Richard Smith74aeef52013-04-26 16:15:35 +0000890 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000891 ///
892 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000893 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000894 // Note, IsDependent is always false here: we implicitly convert an 'auto'
895 // which has been deduced to a dependent type into an undeduced 'auto', so
896 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000897 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000898 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000899 }
900
Richard Smith600b5262017-01-26 20:40:47 +0000901 /// By default, builds a new DeducedTemplateSpecializationType with the given
902 /// deduced type.
903 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
904 QualType Deduced) {
905 return SemaRef.Context.getDeducedTemplateSpecializationType(
906 Template, Deduced, /*IsDependent*/ false);
907 }
908
Douglas Gregord6ff3322009-08-04 16:50:30 +0000909 /// \brief Build a new template specialization type.
910 ///
911 /// By default, performs semantic analysis when building the template
912 /// specialization type. Subclasses may override this routine to provide
913 /// different behavior.
914 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000915 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000916 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000917
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000918 /// \brief Build a new parenthesized type.
919 ///
920 /// By default, builds a new ParenType type from the inner type.
921 /// Subclasses may override this routine to provide different behavior.
922 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000923 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000924 }
925
Douglas Gregord6ff3322009-08-04 16:50:30 +0000926 /// \brief Build a new qualified name type.
927 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000928 /// By default, builds a new ElaboratedType type from the keyword,
929 /// the nested-name-specifier and the named type.
930 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000931 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
932 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000933 NestedNameSpecifierLoc QualifierLoc,
934 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000935 return SemaRef.Context.getElaboratedType(Keyword,
936 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000937 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000938 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000939
940 /// \brief Build a new typename type that refers to a template-id.
941 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 /// By default, builds a new DependentNameType type from the
943 /// nested-name-specifier and the given type. Subclasses may override
944 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000945 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000946 ElaboratedTypeKeyword Keyword,
947 NestedNameSpecifierLoc QualifierLoc,
948 const IdentifierInfo *Name,
949 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000950 TemplateArgumentListInfo &Args,
951 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000952 // Rebuild the template name.
953 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000954 CXXScopeSpec SS;
955 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000956 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000957 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000958 nullptr, AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000959
Douglas Gregora7a795b2011-03-01 20:11:18 +0000960 if (InstName.isNull())
961 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000962
Douglas Gregora7a795b2011-03-01 20:11:18 +0000963 // If it's still dependent, make a dependent specialization.
964 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000965 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
966 QualifierLoc.getNestedNameSpecifier(),
967 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000968 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000969
Douglas Gregora7a795b2011-03-01 20:11:18 +0000970 // Otherwise, make an elaborated type wrapping a non-dependent
971 // specialization.
972 QualType T =
973 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
974 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000975
Craig Topperc3ec1492014-05-26 06:22:03 +0000976 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000977 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000978
979 return SemaRef.Context.getElaboratedType(Keyword,
980 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000981 T);
982 }
983
Douglas Gregord6ff3322009-08-04 16:50:30 +0000984 /// \brief Build a new typename type that refers to an identifier.
985 ///
986 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000987 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000988 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000989 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000990 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000991 NestedNameSpecifierLoc QualifierLoc,
992 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +0000993 SourceLocation IdLoc,
994 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000995 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000996 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000997
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000998 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000999 // If the name is still dependent, just build a new dependent name type.
1000 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001001 return SemaRef.Context.getDependentNameType(Keyword,
1002 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001003 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001004 }
1005
Richard Smithee579842017-01-30 20:39:26 +00001006 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1007 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1008 *Id, IdLoc);
1009 // If a dependent name resolves to a deduced template specialization type,
1010 // check that we're in one of the syntactic contexts permitting it.
1011 if (!DeducedTSTContext) {
1012 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1013 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1014 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1015 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1016 Deduced->getTemplateName())
1017 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1018 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1019 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1020 return QualType();
1021 }
1022 }
1023 return T;
1024 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001025
1026 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1027
Abramo Bagnarad7548482010-05-19 21:37:53 +00001028 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001029 // into a non-dependent elaborated-type-specifier. Find the tag we're
1030 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001031 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001032 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1033 if (!DC)
1034 return QualType();
1035
John McCallbf8c5192010-05-27 06:40:31 +00001036 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1037 return QualType();
1038
Craig Topperc3ec1492014-05-26 06:22:03 +00001039 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001040 SemaRef.LookupQualifiedName(Result, DC);
1041 switch (Result.getResultKind()) {
1042 case LookupResult::NotFound:
1043 case LookupResult::NotFoundInCurrentInstantiation:
1044 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001045
Douglas Gregore677daf2010-03-31 22:19:08 +00001046 case LookupResult::Found:
1047 Tag = Result.getAsSingle<TagDecl>();
1048 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001049
Douglas Gregore677daf2010-03-31 22:19:08 +00001050 case LookupResult::FoundOverloaded:
1051 case LookupResult::FoundUnresolvedValue:
1052 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001053
Douglas Gregore677daf2010-03-31 22:19:08 +00001054 case LookupResult::Ambiguous:
1055 // Let the LookupResult structure handle ambiguities.
1056 return QualType();
1057 }
1058
1059 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001060 // Check where the name exists but isn't a tag type and use that to emit
1061 // better diagnostics.
1062 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1063 SemaRef.LookupQualifiedName(Result, DC);
1064 switch (Result.getResultKind()) {
1065 case LookupResult::Found:
1066 case LookupResult::FoundOverloaded:
1067 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001068 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001069 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1070 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1071 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001072 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1073 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001074 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001075 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001076 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001077 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001078 break;
1079 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001080 return QualType();
1081 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001082
Richard Trieucaa33d32011-06-10 03:11:26 +00001083 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001084 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001085 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001086 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1087 return QualType();
1088 }
1089
1090 // Build the elaborated-type-specifier type.
1091 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001092 return SemaRef.Context.getElaboratedType(Keyword,
1093 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001094 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregor822d0302011-01-12 17:07:58 +00001097 /// \brief Build a new pack expansion type.
1098 ///
1099 /// By default, builds a new PackExpansionType type from the given pattern.
1100 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001101 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001102 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001103 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001104 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001105 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1106 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001107 }
1108
Eli Friedman0dfb8892011-10-06 23:00:33 +00001109 /// \brief Build a new atomic type given its value type.
1110 ///
1111 /// By default, performs semantic analysis when building the atomic type.
1112 /// Subclasses may override this routine to provide different behavior.
1113 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1114
Xiuli Pan9c14e282016-01-09 12:53:17 +00001115 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001116 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1117 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001118
Douglas Gregor71dc5092009-08-06 06:41:21 +00001119 /// \brief Build a new template name given a nested name specifier, a flag
1120 /// indicating whether the "template" keyword was provided, and the template
1121 /// that the template name refers to.
1122 ///
1123 /// By default, builds the new template name directly. Subclasses may override
1124 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001125 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001126 bool TemplateKW,
1127 TemplateDecl *Template);
1128
Douglas Gregor71dc5092009-08-06 06:41:21 +00001129 /// \brief Build a new template name given a nested name specifier and the
1130 /// name that is referred to as a template.
1131 ///
1132 /// By default, performs semantic analysis to determine whether the name can
1133 /// be resolved to a specific template, then builds the appropriate kind of
1134 /// template name. Subclasses may override this routine to provide different
1135 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001136 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1137 const IdentifierInfo &Name,
1138 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001139 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001140 NamedDecl *FirstQualifierInScope,
1141 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001142
Douglas Gregor71395fa2009-11-04 00:56:37 +00001143 /// \brief Build a new template name given a nested name specifier and the
1144 /// overloaded operator name that is referred to as a template.
1145 ///
1146 /// By default, performs semantic analysis to determine whether the name can
1147 /// be resolved to a specific template, then builds the appropriate kind of
1148 /// template name. Subclasses may override this routine to provide different
1149 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001150 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001151 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001152 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00001153 QualType ObjectType,
1154 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001155
1156 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001157 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001158 ///
1159 /// By default, performs semantic analysis to determine whether the name can
1160 /// be resolved to a specific template, then builds the appropriate kind of
1161 /// template name. Subclasses may override this routine to provide different
1162 /// behavior.
1163 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1164 const TemplateArgument &ArgPack) {
1165 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1166 }
1167
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 /// \brief Build a new compound statement.
1169 ///
1170 /// By default, performs semantic analysis to build the new statement.
1171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001172 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001173 MultiStmtArg Statements,
1174 SourceLocation RBraceLoc,
1175 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001176 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001177 IsStmtExpr);
1178 }
1179
1180 /// \brief Build a new case statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001185 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001186 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001187 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001188 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001189 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001190 ColonLoc);
1191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregorebe10102009-08-20 07:17:43 +00001193 /// \brief Attach the body to a new case statement.
1194 ///
1195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001198 getSema().ActOnCaseStmtBody(S, Body);
1199 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 /// \brief Build a new default statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001208 Stmt *SubStmt) {
1209 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001210 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 /// \brief Build a new label statement.
1214 ///
1215 /// By default, performs semantic analysis to build the new statement.
1216 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001217 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1218 SourceLocation ColonLoc, Stmt *SubStmt) {
1219 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001220 }
Mike Stump11289f42009-09-09 15:08:12 +00001221
Richard Smithc202b282012-04-14 00:33:13 +00001222 /// \brief Build a new label statement.
1223 ///
1224 /// By default, performs semantic analysis to build the new statement.
1225 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001226 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1227 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001228 Stmt *SubStmt) {
1229 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1230 }
1231
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 /// \brief Build a new "if" statement.
1233 ///
1234 /// By default, performs semantic analysis to build the new statement.
1235 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001236 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001237 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001238 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001239 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001240 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 /// \brief Start building a new switch statement.
1244 ///
1245 /// By default, performs semantic analysis to build the new statement.
1246 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001247 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001248 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001249 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 /// \brief Attach the body to the switch statement.
1253 ///
1254 /// By default, performs semantic analysis to build the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001256 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001257 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001258 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001259 }
1260
1261 /// \brief Build a new while statement.
1262 ///
1263 /// By default, performs semantic analysis to build the new statement.
1264 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001265 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1266 Sema::ConditionResult Cond, Stmt *Body) {
1267 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001268 }
Mike Stump11289f42009-09-09 15:08:12 +00001269
Douglas Gregorebe10102009-08-20 07:17:43 +00001270 /// \brief Build a new do-while statement.
1271 ///
1272 /// By default, performs semantic analysis to build the new statement.
1273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001274 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001275 SourceLocation WhileLoc, SourceLocation LParenLoc,
1276 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001277 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1278 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001279 }
1280
1281 /// \brief Build a new for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001285 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001286 Stmt *Init, Sema::ConditionResult Cond,
1287 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1288 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001289 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001290 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001291 }
Mike Stump11289f42009-09-09 15:08:12 +00001292
Douglas Gregorebe10102009-08-20 07:17:43 +00001293 /// \brief Build a new goto statement.
1294 ///
1295 /// By default, performs semantic analysis to build the new statement.
1296 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001297 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1298 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001299 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001300 }
1301
1302 /// \brief Build a new indirect goto statement.
1303 ///
1304 /// By default, performs semantic analysis to build the new statement.
1305 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001306 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001307 SourceLocation StarLoc,
1308 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001309 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001310 }
Mike Stump11289f42009-09-09 15:08:12 +00001311
Douglas Gregorebe10102009-08-20 07:17:43 +00001312 /// \brief Build a new return statement.
1313 ///
1314 /// By default, performs semantic analysis to build the new statement.
1315 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001316 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001317 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregorebe10102009-08-20 07:17:43 +00001320 /// \brief Build a new declaration statement.
1321 ///
1322 /// By default, performs semantic analysis to build the new statement.
1323 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001324 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001325 SourceLocation StartLoc, SourceLocation EndLoc) {
1326 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001327 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Anders Carlssonaaeef072010-01-24 05:50:09 +00001330 /// \brief Build a new inline asm statement.
1331 ///
1332 /// By default, performs semantic analysis to build the new statement.
1333 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001334 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1335 bool IsVolatile, unsigned NumOutputs,
1336 unsigned NumInputs, IdentifierInfo **Names,
1337 MultiExprArg Constraints, MultiExprArg Exprs,
1338 Expr *AsmString, MultiExprArg Clobbers,
1339 SourceLocation RParenLoc) {
1340 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1341 NumInputs, Names, Constraints, Exprs,
1342 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001343 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001344
Chad Rosier32503022012-06-11 20:47:18 +00001345 /// \brief Build a new MS style inline asm statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001349 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001350 ArrayRef<Token> AsmToks,
1351 StringRef AsmString,
1352 unsigned NumOutputs, unsigned NumInputs,
1353 ArrayRef<StringRef> Constraints,
1354 ArrayRef<StringRef> Clobbers,
1355 ArrayRef<Expr*> Exprs,
1356 SourceLocation EndLoc) {
1357 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1358 NumOutputs, NumInputs,
1359 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001360 }
1361
Richard Smith9f690bd2015-10-27 06:02:45 +00001362 /// \brief Build a new co_return statement.
1363 ///
1364 /// By default, performs semantic analysis to build the new statement.
1365 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001366 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1367 bool IsImplicit) {
1368 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001369 }
1370
1371 /// \brief Build a new co_await expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001375 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1376 bool IsImplicit) {
1377 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1378 }
1379
1380 /// \brief Build a new co_await expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1385 Expr *Result,
1386 UnresolvedLookupExpr *Lookup) {
1387 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001388 }
1389
1390 /// \brief Build a new co_yield expression.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
1394 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1395 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1396 }
1397
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001398 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1399 return getSema().BuildCoroutineBodyStmt(Args);
1400 }
1401
James Dennett2a4d13c2012-06-15 07:13:21 +00001402 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001406 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001407 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001408 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001409 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001410 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001411 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001412 }
1413
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001414 /// \brief Rebuild an Objective-C exception declaration.
1415 ///
1416 /// By default, performs semantic analysis to build the new declaration.
1417 /// Subclasses may override this routine to provide different behavior.
1418 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1419 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001420 return getSema().BuildObjCExceptionDecl(TInfo, T,
1421 ExceptionDecl->getInnerLocStart(),
1422 ExceptionDecl->getLocation(),
1423 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001425
James Dennett2a4d13c2012-06-15 07:13:21 +00001426 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001427 ///
1428 /// By default, performs semantic analysis to build the new statement.
1429 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001430 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001431 SourceLocation RParenLoc,
1432 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001433 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001434 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001435 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001436 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001437
James Dennett2a4d13c2012-06-15 07:13:21 +00001438 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001439 ///
1440 /// By default, performs semantic analysis to build the new statement.
1441 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001442 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001443 Stmt *Body) {
1444 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001445 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001446
James Dennett2a4d13c2012-06-15 07:13:21 +00001447 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001451 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001452 Expr *Operand) {
1453 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001455
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001456 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001460 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001461 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001462 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001463 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001464 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001465 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001466 return getSema().ActOnOpenMPExecutableDirective(
1467 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001468 }
1469
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001470 /// \brief Build a new OpenMP 'if' clause.
1471 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001472 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001473 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001474 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1475 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001476 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001477 SourceLocation NameModifierLoc,
1478 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001479 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001480 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1481 LParenLoc, NameModifierLoc, ColonLoc,
1482 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001483 }
1484
Alexey Bataev3778b602014-07-17 07:32:53 +00001485 /// \brief Build a new OpenMP 'final' clause.
1486 ///
1487 /// By default, performs semantic analysis to build the new OpenMP clause.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1490 SourceLocation LParenLoc,
1491 SourceLocation EndLoc) {
1492 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1493 EndLoc);
1494 }
1495
Alexey Bataev568a8332014-03-06 06:15:19 +00001496 /// \brief Build a new OpenMP 'num_threads' clause.
1497 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001498 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001499 /// Subclasses may override this routine to provide different behavior.
1500 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1501 SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1505 LParenLoc, EndLoc);
1506 }
1507
Alexey Bataev62c87d22014-03-21 04:51:18 +00001508 /// \brief Build a new OpenMP 'safelen' clause.
1509 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001510 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1516 }
1517
Alexey Bataev66b15b52015-08-21 11:14:16 +00001518 /// \brief Build a new OpenMP 'simdlen' clause.
1519 ///
1520 /// By default, performs semantic analysis to build the new OpenMP clause.
1521 /// Subclasses may override this routine to provide different behavior.
1522 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1523 SourceLocation LParenLoc,
1524 SourceLocation EndLoc) {
1525 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1526 }
1527
Alexander Musman8bd31e62014-05-27 15:12:19 +00001528 /// \brief Build a new OpenMP 'collapse' clause.
1529 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001530 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001531 /// Subclasses may override this routine to provide different behavior.
1532 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1533 SourceLocation LParenLoc,
1534 SourceLocation EndLoc) {
1535 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1536 EndLoc);
1537 }
1538
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001539 /// \brief Build a new OpenMP 'default' clause.
1540 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001541 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001542 /// Subclasses may override this routine to provide different behavior.
1543 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1544 SourceLocation KindKwLoc,
1545 SourceLocation StartLoc,
1546 SourceLocation LParenLoc,
1547 SourceLocation EndLoc) {
1548 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1549 StartLoc, LParenLoc, EndLoc);
1550 }
1551
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001552 /// \brief Build a new OpenMP 'proc_bind' clause.
1553 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001554 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001555 /// Subclasses may override this routine to provide different behavior.
1556 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1557 SourceLocation KindKwLoc,
1558 SourceLocation StartLoc,
1559 SourceLocation LParenLoc,
1560 SourceLocation EndLoc) {
1561 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1562 StartLoc, LParenLoc, EndLoc);
1563 }
1564
Alexey Bataev56dafe82014-06-20 07:16:17 +00001565 /// \brief Build a new OpenMP 'schedule' clause.
1566 ///
1567 /// By default, performs semantic analysis to build the new OpenMP clause.
1568 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001569 OMPClause *RebuildOMPScheduleClause(
1570 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1571 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1572 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1573 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001574 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001575 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1576 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001577 }
1578
Alexey Bataev10e775f2015-07-30 11:36:16 +00001579 /// \brief Build a new OpenMP 'ordered' clause.
1580 ///
1581 /// By default, performs semantic analysis to build the new OpenMP clause.
1582 /// Subclasses may override this routine to provide different behavior.
1583 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1584 SourceLocation EndLoc,
1585 SourceLocation LParenLoc, Expr *Num) {
1586 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1587 }
1588
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001589 /// \brief Build a new OpenMP 'private' clause.
1590 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001591 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001592 /// Subclasses may override this routine to provide different behavior.
1593 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1594 SourceLocation StartLoc,
1595 SourceLocation LParenLoc,
1596 SourceLocation EndLoc) {
1597 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1598 EndLoc);
1599 }
1600
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001601 /// \brief Build a new OpenMP 'firstprivate' clause.
1602 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001603 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1610 EndLoc);
1611 }
1612
Alexander Musman1bb328c2014-06-04 13:06:39 +00001613 /// \brief Build a new OpenMP 'lastprivate' clause.
1614 ///
1615 /// By default, performs semantic analysis to build the new OpenMP clause.
1616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1622 EndLoc);
1623 }
1624
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001625 /// \brief Build a new OpenMP 'shared' clause.
1626 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001627 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001628 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001629 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1634 EndLoc);
1635 }
1636
Alexey Bataevc5e02582014-06-16 07:08:35 +00001637 /// \brief Build a new OpenMP 'reduction' clause.
1638 ///
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
1641 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation ColonLoc,
1645 SourceLocation EndLoc,
1646 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001647 const DeclarationNameInfo &ReductionId,
1648 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001649 return getSema().ActOnOpenMPReductionClause(
1650 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001651 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001652 }
1653
Alexander Musman8dba6642014-04-22 13:09:42 +00001654 /// \brief Build a new OpenMP 'linear' clause.
1655 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001656 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001657 /// Subclasses may override this routine to provide different behavior.
1658 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1659 SourceLocation StartLoc,
1660 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001661 OpenMPLinearClauseKind Modifier,
1662 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001663 SourceLocation ColonLoc,
1664 SourceLocation EndLoc) {
1665 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001666 Modifier, ModifierLoc, ColonLoc,
1667 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001668 }
1669
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001670 /// \brief Build a new OpenMP 'aligned' clause.
1671 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001672 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001673 /// Subclasses may override this routine to provide different behavior.
1674 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1675 SourceLocation StartLoc,
1676 SourceLocation LParenLoc,
1677 SourceLocation ColonLoc,
1678 SourceLocation EndLoc) {
1679 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1680 LParenLoc, ColonLoc, EndLoc);
1681 }
1682
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001683 /// \brief Build a new OpenMP 'copyin' clause.
1684 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001685 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001686 /// Subclasses may override this routine to provide different behavior.
1687 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1688 SourceLocation StartLoc,
1689 SourceLocation LParenLoc,
1690 SourceLocation EndLoc) {
1691 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1692 EndLoc);
1693 }
1694
Alexey Bataevbae9a792014-06-27 10:37:06 +00001695 /// \brief Build a new OpenMP 'copyprivate' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1699 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1700 SourceLocation StartLoc,
1701 SourceLocation LParenLoc,
1702 SourceLocation EndLoc) {
1703 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1704 EndLoc);
1705 }
1706
Alexey Bataev6125da92014-07-21 11:26:11 +00001707 /// \brief Build a new OpenMP 'flush' pseudo clause.
1708 ///
1709 /// By default, performs semantic analysis to build the new OpenMP clause.
1710 /// Subclasses may override this routine to provide different behavior.
1711 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1712 SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
1714 SourceLocation EndLoc) {
1715 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1716 EndLoc);
1717 }
1718
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001719 /// \brief Build a new OpenMP 'depend' pseudo clause.
1720 ///
1721 /// By default, performs semantic analysis to build the new OpenMP clause.
1722 /// Subclasses may override this routine to provide different behavior.
1723 OMPClause *
1724 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1725 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1726 SourceLocation StartLoc, SourceLocation LParenLoc,
1727 SourceLocation EndLoc) {
1728 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1729 StartLoc, LParenLoc, EndLoc);
1730 }
1731
Michael Wonge710d542015-08-07 16:16:36 +00001732 /// \brief Build a new OpenMP 'device' clause.
1733 ///
1734 /// By default, performs semantic analysis to build the new statement.
1735 /// Subclasses may override this routine to provide different behavior.
1736 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1737 SourceLocation LParenLoc,
1738 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001739 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001740 EndLoc);
1741 }
1742
Kelvin Li0bff7af2015-11-23 05:32:03 +00001743 /// \brief Build a new OpenMP 'map' clause.
1744 ///
1745 /// By default, performs semantic analysis to build the new OpenMP clause.
1746 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001747 OMPClause *
1748 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1749 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1750 SourceLocation MapLoc, SourceLocation ColonLoc,
1751 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1752 SourceLocation LParenLoc, SourceLocation EndLoc) {
1753 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1754 IsMapTypeImplicit, MapLoc, ColonLoc,
1755 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001756 }
1757
Kelvin Li099bb8c2015-11-24 20:50:12 +00001758 /// \brief Build a new OpenMP 'num_teams' clause.
1759 ///
1760 /// By default, performs semantic analysis to build the new statement.
1761 /// Subclasses may override this routine to provide different behavior.
1762 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1763 SourceLocation LParenLoc,
1764 SourceLocation EndLoc) {
1765 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1766 EndLoc);
1767 }
1768
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001769 /// \brief Build a new OpenMP 'thread_limit' clause.
1770 ///
1771 /// By default, performs semantic analysis to build the new statement.
1772 /// Subclasses may override this routine to provide different behavior.
1773 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1774 SourceLocation StartLoc,
1775 SourceLocation LParenLoc,
1776 SourceLocation EndLoc) {
1777 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1778 LParenLoc, EndLoc);
1779 }
1780
Alexey Bataeva0569352015-12-01 10:17:31 +00001781 /// \brief Build a new OpenMP 'priority' clause.
1782 ///
1783 /// By default, performs semantic analysis to build the new statement.
1784 /// Subclasses may override this routine to provide different behavior.
1785 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1786 SourceLocation LParenLoc,
1787 SourceLocation EndLoc) {
1788 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1789 EndLoc);
1790 }
1791
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001792 /// \brief Build a new OpenMP 'grainsize' clause.
1793 ///
1794 /// By default, performs semantic analysis to build the new statement.
1795 /// Subclasses may override this routine to provide different behavior.
1796 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1797 SourceLocation LParenLoc,
1798 SourceLocation EndLoc) {
1799 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1800 EndLoc);
1801 }
1802
Alexey Bataev382967a2015-12-08 12:06:20 +00001803 /// \brief Build a new OpenMP 'num_tasks' clause.
1804 ///
1805 /// By default, performs semantic analysis to build the new statement.
1806 /// Subclasses may override this routine to provide different behavior.
1807 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1808 SourceLocation LParenLoc,
1809 SourceLocation EndLoc) {
1810 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1811 EndLoc);
1812 }
1813
Alexey Bataev28c75412015-12-15 08:19:24 +00001814 /// \brief Build a new OpenMP 'hint' clause.
1815 ///
1816 /// By default, performs semantic analysis to build the new statement.
1817 /// Subclasses may override this routine to provide different behavior.
1818 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1819 SourceLocation LParenLoc,
1820 SourceLocation EndLoc) {
1821 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1822 }
1823
Carlo Bertollib4adf552016-01-15 18:50:31 +00001824 /// \brief Build a new OpenMP 'dist_schedule' clause.
1825 ///
1826 /// By default, performs semantic analysis to build the new OpenMP clause.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OMPClause *
1829 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1830 Expr *ChunkSize, SourceLocation StartLoc,
1831 SourceLocation LParenLoc, SourceLocation KindLoc,
1832 SourceLocation CommaLoc, SourceLocation EndLoc) {
1833 return getSema().ActOnOpenMPDistScheduleClause(
1834 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1835 }
1836
Samuel Antao661c0902016-05-26 17:39:58 +00001837 /// \brief Build a new OpenMP 'to' clause.
1838 ///
1839 /// By default, performs semantic analysis to build the new statement.
1840 /// Subclasses may override this routine to provide different behavior.
1841 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1842 SourceLocation StartLoc,
1843 SourceLocation LParenLoc,
1844 SourceLocation EndLoc) {
1845 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1846 }
1847
Samuel Antaoec172c62016-05-26 17:49:04 +00001848 /// \brief Build a new OpenMP 'from' clause.
1849 ///
1850 /// By default, performs semantic analysis to build the new statement.
1851 /// Subclasses may override this routine to provide different behavior.
1852 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1853 SourceLocation StartLoc,
1854 SourceLocation LParenLoc,
1855 SourceLocation EndLoc) {
1856 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1857 EndLoc);
1858 }
1859
Carlo Bertolli2404b172016-07-13 15:37:16 +00001860 /// Build a new OpenMP 'use_device_ptr' clause.
1861 ///
1862 /// By default, performs semantic analysis to build the new OpenMP clause.
1863 /// Subclasses may override this routine to provide different behavior.
1864 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1865 SourceLocation StartLoc,
1866 SourceLocation LParenLoc,
1867 SourceLocation EndLoc) {
1868 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1869 EndLoc);
1870 }
1871
Carlo Bertolli70594e92016-07-13 17:16:49 +00001872 /// Build a new OpenMP 'is_device_ptr' clause.
1873 ///
1874 /// By default, performs semantic analysis to build the new OpenMP clause.
1875 /// Subclasses may override this routine to provide different behavior.
1876 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1877 SourceLocation StartLoc,
1878 SourceLocation LParenLoc,
1879 SourceLocation EndLoc) {
1880 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1881 EndLoc);
1882 }
1883
James Dennett2a4d13c2012-06-15 07:13:21 +00001884 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001885 ///
1886 /// By default, performs semantic analysis to build the new statement.
1887 /// Subclasses may override this routine to provide different behavior.
1888 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1889 Expr *object) {
1890 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1891 }
1892
James Dennett2a4d13c2012-06-15 07:13:21 +00001893 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001894 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001895 /// By default, performs semantic analysis to build the new statement.
1896 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001897 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001898 Expr *Object, Stmt *Body) {
1899 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001900 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001901
James Dennett2a4d13c2012-06-15 07:13:21 +00001902 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001903 ///
1904 /// By default, performs semantic analysis to build the new statement.
1905 /// Subclasses may override this routine to provide different behavior.
1906 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1907 Stmt *Body) {
1908 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1909 }
John McCall53848232011-07-27 01:07:15 +00001910
Douglas Gregorf68a5082010-04-22 23:10:45 +00001911 /// \brief Build a new Objective-C fast enumeration statement.
1912 ///
1913 /// By default, performs semantic analysis to build the new statement.
1914 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001915 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001916 Stmt *Element,
1917 Expr *Collection,
1918 SourceLocation RParenLoc,
1919 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001920 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001921 Element,
John McCallb268a282010-08-23 23:25:46 +00001922 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001923 RParenLoc);
1924 if (ForEachStmt.isInvalid())
1925 return StmtError();
1926
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001927 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001929
Douglas Gregorebe10102009-08-20 07:17:43 +00001930 /// \brief Build a new C++ exception declaration.
1931 ///
1932 /// By default, performs semantic analysis to build the new decaration.
1933 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001934 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001935 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001936 SourceLocation StartLoc,
1937 SourceLocation IdLoc,
1938 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001939 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001940 StartLoc, IdLoc, Id);
1941 if (Var)
1942 getSema().CurContext->addDecl(Var);
1943 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001944 }
1945
1946 /// \brief Build a new C++ catch statement.
1947 ///
1948 /// 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 RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001951 VarDecl *ExceptionDecl,
1952 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001953 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1954 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregorebe10102009-08-20 07:17:43 +00001957 /// \brief Build a new C++ try statement.
1958 ///
1959 /// By default, performs semantic analysis to build the new statement.
1960 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001961 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1962 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001963 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Richard Smith02e85f32011-04-14 22:09:26 +00001966 /// \brief Build a new C++0x range-based for statement.
1967 ///
1968 /// By default, performs semantic analysis to build the new statement.
1969 /// Subclasses may override this routine to provide different behavior.
1970 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001971 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001972 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001973 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001974 Expr *Cond, Expr *Inc,
1975 Stmt *LoopVar,
1976 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001977 // If we've just learned that the range is actually an Objective-C
1978 // collection, treat this as an Objective-C fast enumeration loop.
1979 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1980 if (RangeStmt->isSingleDecl()) {
1981 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001982 if (RangeVar->isInvalidDecl())
1983 return StmtError();
1984
Douglas Gregorf7106af2013-04-08 18:40:13 +00001985 Expr *RangeExpr = RangeVar->getInit();
1986 if (!RangeExpr->isTypeDependent() &&
1987 RangeExpr->getType()->isObjCObjectPointerType())
1988 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1989 RParenLoc);
1990 }
1991 }
1992 }
1993
Richard Smithcfd53b42015-10-22 06:13:50 +00001994 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001995 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00001996 Cond, Inc, LoopVar, RParenLoc,
1997 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001998 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001999
2000 /// \brief Build a new C++0x range-based for statement.
2001 ///
2002 /// By default, performs semantic analysis to build the new statement.
2003 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002004 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002005 bool IsIfExists,
2006 NestedNameSpecifierLoc QualifierLoc,
2007 DeclarationNameInfo NameInfo,
2008 Stmt *Nested) {
2009 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2010 QualifierLoc, NameInfo, Nested);
2011 }
2012
Richard Smith02e85f32011-04-14 22:09:26 +00002013 /// \brief Attach body to a C++0x range-based for statement.
2014 ///
2015 /// By default, performs semantic analysis to finish the new statement.
2016 /// Subclasses may override this routine to provide different behavior.
2017 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2018 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2019 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002020
David Majnemerfad8f482013-10-15 09:33:02 +00002021 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002022 Stmt *TryBlock, Stmt *Handler) {
2023 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002024 }
2025
David Majnemerfad8f482013-10-15 09:33:02 +00002026 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002027 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002028 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002029 }
2030
David Majnemerfad8f482013-10-15 09:33:02 +00002031 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002032 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002033 }
2034
Alexey Bataevec474782014-10-09 08:45:04 +00002035 /// \brief Build a new predefined expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
2039 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2040 PredefinedExpr::IdentType IT) {
2041 return getSema().BuildPredefinedExpr(Loc, IT);
2042 }
2043
Douglas Gregora16548e2009-08-11 05:31:07 +00002044 /// \brief Build a new expression that references a declaration.
2045 ///
2046 /// By default, performs semantic analysis to build the new expression.
2047 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002048 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002049 LookupResult &R,
2050 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002051 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2052 }
2053
2054
2055 /// \brief Build a new expression that references a declaration.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002059 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002060 ValueDecl *VD,
2061 const DeclarationNameInfo &NameInfo,
2062 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002063 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002064 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002065
2066 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002067
2068 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 }
Mike Stump11289f42009-09-09 15:08:12 +00002070
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 /// By default, performs semantic analysis to build the new expression.
2074 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002075 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002077 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 }
2079
Douglas Gregorad8a3362009-09-04 17:36:40 +00002080 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002081 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002085 SourceLocation OperatorLoc,
2086 bool isArrow,
2087 CXXScopeSpec &SS,
2088 TypeSourceInfo *ScopeType,
2089 SourceLocation CCLoc,
2090 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002091 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002092
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002094 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002097 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002098 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002099 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002100 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102
Douglas Gregor882211c2010-04-28 22:16:22 +00002103 /// \brief Build a new builtin offsetof expression.
2104 ///
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 RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002108 TypeSourceInfo *Type,
2109 ArrayRef<Sema::OffsetOfComponent> Components,
2110 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002111 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002112 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002113 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002114
2115 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002116 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002117 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 /// By default, performs semantic analysis to build the new expression.
2119 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002120 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2121 SourceLocation OpLoc,
2122 UnaryExprOrTypeTrait ExprKind,
2123 SourceRange R) {
2124 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
2126
Peter Collingbournee190dee2011-03-11 19:24:49 +00002127 /// \brief Build a new sizeof, alignof or vec step expression with an
2128 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002129 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002132 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2133 UnaryExprOrTypeTrait ExprKind,
2134 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002135 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002136 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002139
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002140 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 }
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002144 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002145 /// By default, performs semantic analysis to build the new expression.
2146 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002147 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002148 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002149 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002151 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002152 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 RBracketLoc);
2154 }
2155
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002156 /// \brief Build a new array section expression.
2157 ///
2158 /// By default, performs semantic analysis to build the new expression.
2159 /// Subclasses may override this routine to provide different behavior.
2160 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2161 Expr *LowerBound,
2162 SourceLocation ColonLoc, Expr *Length,
2163 SourceLocation RBracketLoc) {
2164 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2165 ColonLoc, Length, RBracketLoc);
2166 }
2167
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002169 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// By default, performs semantic analysis to build the new expression.
2171 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002172 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002174 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002175 Expr *ExecConfig = nullptr) {
2176 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002177 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 }
2179
2180 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002181 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// By default, performs semantic analysis to build the new expression.
2183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002185 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002186 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002187 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002188 const DeclarationNameInfo &MemberNameInfo,
2189 ValueDecl *Member,
2190 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002191 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002192 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002193 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2194 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002195 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002196 // We have a reference to an unnamed field. This is always the
2197 // base of an anonymous struct/union member access, i.e. the
2198 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002199 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002200 assert(Member->getType()->isRecordType() &&
2201 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002202
Richard Smithcab9a7d2011-10-26 19:06:56 +00002203 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002204 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002205 QualifierLoc.getNestedNameSpecifier(),
2206 FoundDecl, Member);
2207 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002208 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002209 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002210 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002211 MemberExpr *ME = new (getSema().Context)
2212 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2213 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002214 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002215 }
Mike Stump11289f42009-09-09 15:08:12 +00002216
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002217 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002218 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002219
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002220 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002221 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002222
John McCall16df1e52010-03-30 21:47:33 +00002223 // FIXME: this involves duplicating earlier analysis in a lot of
2224 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002225 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002226 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002227 R.resolveKind();
2228
John McCallb268a282010-08-23 23:25:46 +00002229 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002230 SS, TemplateKWLoc,
2231 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002232 R, ExplicitTemplateArgs,
2233 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 }
Mike Stump11289f42009-09-09 15:08:12 +00002235
Douglas Gregora16548e2009-08-11 05:31:07 +00002236 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002237 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002241 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002242 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002243 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002244 }
2245
2246 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002247 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002248 /// By default, performs semantic analysis to build the new expression.
2249 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002250 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002251 SourceLocation QuestionLoc,
2252 Expr *LHS,
2253 SourceLocation ColonLoc,
2254 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002255 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2256 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 }
2258
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002261 /// By default, performs semantic analysis to build the new expression.
2262 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002263 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002264 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002265 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002266 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002267 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002268 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002269 }
Mike Stump11289f42009-09-09 15:08:12 +00002270
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002272 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002273 /// By default, performs semantic analysis to build the new expression.
2274 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002275 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002276 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002278 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002279 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002280 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002281 }
Mike Stump11289f42009-09-09 15:08:12 +00002282
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002284 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 /// By default, performs semantic analysis to build the new expression.
2286 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002287 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 SourceLocation OpLoc,
2289 SourceLocation AccessorLoc,
2290 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002291
John McCall10eae182009-11-30 22:42:35 +00002292 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002293 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002294 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002295 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002296 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002297 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002298 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002299 /* TemplateArgs */ nullptr,
2300 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
Mike Stump11289f42009-09-09 15:08:12 +00002302
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002304 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// By default, performs semantic analysis to build the new expression.
2306 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002307 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002308 MultiExprArg Inits,
2309 SourceLocation RBraceLoc,
2310 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002311 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002312 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002313 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002314 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002315
Douglas Gregord3d93062009-11-09 17:16:50 +00002316 // Patch in the result type we were given, which may have been computed
2317 // when the initial InitListExpr was built.
2318 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2319 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002320 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 }
Mike Stump11289f42009-09-09 15:08:12 +00002322
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002324 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002325 /// By default, performs semantic analysis to build the new expression.
2326 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002327 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002328 MultiExprArg ArrayExprs,
2329 SourceLocation EqualOrColonLoc,
2330 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002331 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002332 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002333 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002334 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002335 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002337
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002338 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002339 }
Mike Stump11289f42009-09-09 15:08:12 +00002340
Douglas Gregora16548e2009-08-11 05:31:07 +00002341 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 /// By default, builds the implicit value initialization without performing
2344 /// any semantic analysis. Subclasses may override this routine to provide
2345 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002346 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002347 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 }
Mike Stump11289f42009-09-09 15:08:12 +00002349
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002351 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 /// By default, performs semantic analysis to build the new expression.
2353 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002355 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002356 SourceLocation RParenLoc) {
2357 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002358 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002359 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002360 }
2361
2362 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002363 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 /// By default, performs semantic analysis to build the new expression.
2365 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002366 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002367 MultiExprArg SubExprs,
2368 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002369 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 }
Mike Stump11289f42009-09-09 15:08:12 +00002371
Douglas Gregora16548e2009-08-11 05:31:07 +00002372 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002373 ///
2374 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 /// rather than attempting to map the label statement itself.
2376 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002377 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002378 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002379 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002380 }
Mike Stump11289f42009-09-09 15:08:12 +00002381
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002383 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 /// By default, performs semantic analysis to build the new expression.
2385 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002386 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002387 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002389 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 /// \brief Build a new __builtin_choose_expr expression.
2393 ///
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002396 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002397 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 SourceLocation RParenLoc) {
2399 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002400 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 RParenLoc);
2402 }
Mike Stump11289f42009-09-09 15:08:12 +00002403
Peter Collingbourne91147592011-04-15 00:35:48 +00002404 /// \brief Build a new generic selection expression.
2405 ///
2406 /// By default, performs semantic analysis to build the new expression.
2407 /// Subclasses may override this routine to provide different behavior.
2408 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2409 SourceLocation DefaultLoc,
2410 SourceLocation RParenLoc,
2411 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002412 ArrayRef<TypeSourceInfo *> Types,
2413 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002414 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002415 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002416 }
2417
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 /// \brief Build a new overloaded operator call expression.
2419 ///
2420 /// By default, performs semantic analysis to build the new expression.
2421 /// The semantic analysis provides the behavior of template instantiation,
2422 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002423 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 /// argument-dependent lookup, etc. Subclasses may override this routine to
2425 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002426 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002428 Expr *Callee,
2429 Expr *First,
2430 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002431
2432 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 /// reinterpret_cast.
2434 ///
2435 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002436 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002438 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002439 Stmt::StmtClass Class,
2440 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002441 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002442 SourceLocation RAngleLoc,
2443 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002444 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 SourceLocation RParenLoc) {
2446 switch (Class) {
2447 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002448 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002449 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002450 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002451
2452 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002453 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002454 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002455 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002456
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002458 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002459 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002460 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002461 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002462
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002464 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002465 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002466 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002467
Douglas Gregora16548e2009-08-11 05:31:07 +00002468 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002469 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002470 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002471 }
Mike Stump11289f42009-09-09 15:08:12 +00002472
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 /// \brief Build a new C++ static_cast expression.
2474 ///
2475 /// By default, performs semantic analysis to build the new expression.
2476 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002477 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002479 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002480 SourceLocation RAngleLoc,
2481 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002482 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002483 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002484 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002485 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002486 SourceRange(LAngleLoc, RAngleLoc),
2487 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
2489
2490 /// \brief Build a new C++ dynamic_cast expression.
2491 ///
2492 /// By default, performs semantic analysis to build the new expression.
2493 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002494 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002496 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 SourceLocation RAngleLoc,
2498 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002499 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002500 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002501 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002502 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002503 SourceRange(LAngleLoc, RAngleLoc),
2504 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002505 }
2506
2507 /// \brief Build a new C++ reinterpret_cast expression.
2508 ///
2509 /// By default, performs semantic analysis to build the new expression.
2510 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002511 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002512 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002513 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 SourceLocation RAngleLoc,
2515 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002516 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002517 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002518 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002519 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002520 SourceRange(LAngleLoc, RAngleLoc),
2521 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002522 }
2523
2524 /// \brief Build a new C++ const_cast expression.
2525 ///
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 RebuildCXXConstCastExpr(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_const_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 }
Mike Stump11289f42009-09-09 15:08:12 +00002540
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 /// \brief Build a new C++ functional-style cast expression.
2542 ///
2543 /// By default, performs semantic analysis to build the new expression.
2544 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002545 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2546 SourceLocation LParenLoc,
2547 Expr *Sub,
2548 SourceLocation RParenLoc) {
2549 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002550 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002551 RParenLoc);
2552 }
Mike Stump11289f42009-09-09 15:08:12 +00002553
Douglas Gregora16548e2009-08-11 05:31:07 +00002554 /// \brief Build a new C++ typeid(type) expression.
2555 ///
2556 /// By default, performs semantic analysis to build the new expression.
2557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002558 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002559 SourceLocation TypeidLoc,
2560 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002562 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002563 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 }
Mike Stump11289f42009-09-09 15:08:12 +00002565
Francois Pichet9f4f2072010-09-08 12:20:18 +00002566
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 /// \brief Build a new C++ typeid(expr) expression.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002571 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002572 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002573 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002574 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002575 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002576 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002577 }
2578
Francois Pichet9f4f2072010-09-08 12:20:18 +00002579 /// \brief Build a new C++ __uuidof(type) expression.
2580 ///
2581 /// By default, performs semantic analysis to build the new expression.
2582 /// Subclasses may override this routine to provide different behavior.
2583 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2584 SourceLocation TypeidLoc,
2585 TypeSourceInfo *Operand,
2586 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002587 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002588 RParenLoc);
2589 }
2590
2591 /// \brief Build a new C++ __uuidof(expr) expression.
2592 ///
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
2595 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2596 SourceLocation TypeidLoc,
2597 Expr *Operand,
2598 SourceLocation RParenLoc) {
2599 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2600 RParenLoc);
2601 }
2602
Douglas Gregora16548e2009-08-11 05:31:07 +00002603 /// \brief Build a new C++ "this" expression.
2604 ///
2605 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002606 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002607 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002608 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002609 QualType ThisType,
2610 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002611 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002612 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002613 }
2614
2615 /// \brief Build a new C++ throw expression.
2616 ///
2617 /// By default, performs semantic analysis to build the new expression.
2618 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002619 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2620 bool IsThrownVariableInScope) {
2621 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002622 }
2623
2624 /// \brief Build a new C++ default-argument expression.
2625 ///
2626 /// By default, builds a new default-argument expression, which does not
2627 /// require any semantic analysis. Subclasses may override this routine to
2628 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002629 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002630 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002631 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002632 }
2633
Richard Smith852c9db2013-04-20 22:23:05 +00002634 /// \brief Build a new C++11 default-initialization expression.
2635 ///
2636 /// By default, builds a new default field initialization expression, which
2637 /// does not require any semantic analysis. Subclasses may override this
2638 /// routine to provide different behavior.
2639 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2640 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002641 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002642 }
2643
Douglas Gregora16548e2009-08-11 05:31:07 +00002644 /// \brief Build a new C++ zero-initialization expression.
2645 ///
2646 /// By default, performs semantic analysis to build the new expression.
2647 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002648 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2649 SourceLocation LParenLoc,
2650 SourceLocation RParenLoc) {
2651 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002652 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002653 }
Mike Stump11289f42009-09-09 15:08:12 +00002654
Douglas Gregora16548e2009-08-11 05:31:07 +00002655 /// \brief Build a new C++ "new" expression.
2656 ///
2657 /// By default, performs semantic analysis to build the new expression.
2658 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002659 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002660 bool UseGlobal,
2661 SourceLocation PlacementLParen,
2662 MultiExprArg PlacementArgs,
2663 SourceLocation PlacementRParen,
2664 SourceRange TypeIdParens,
2665 QualType AllocatedType,
2666 TypeSourceInfo *AllocatedTypeInfo,
2667 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002668 SourceRange DirectInitRange,
2669 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002670 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002672 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002674 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002675 AllocatedType,
2676 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002677 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002678 DirectInitRange,
2679 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002680 }
Mike Stump11289f42009-09-09 15:08:12 +00002681
Douglas Gregora16548e2009-08-11 05:31:07 +00002682 /// \brief Build a new C++ "delete" expression.
2683 ///
2684 /// By default, performs semantic analysis to build the new expression.
2685 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002686 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002687 bool IsGlobalDelete,
2688 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002689 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002691 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002692 }
Mike Stump11289f42009-09-09 15:08:12 +00002693
Douglas Gregor29c42f22012-02-24 07:38:34 +00002694 /// \brief Build a new type trait expression.
2695 ///
2696 /// By default, performs semantic analysis to build the new expression.
2697 /// Subclasses may override this routine to provide different behavior.
2698 ExprResult RebuildTypeTrait(TypeTrait Trait,
2699 SourceLocation StartLoc,
2700 ArrayRef<TypeSourceInfo *> Args,
2701 SourceLocation RParenLoc) {
2702 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2703 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002704
John Wiegley6242b6a2011-04-28 00:16:57 +00002705 /// \brief Build a new array type trait expression.
2706 ///
2707 /// By default, performs semantic analysis to build the new expression.
2708 /// Subclasses may override this routine to provide different behavior.
2709 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2710 SourceLocation StartLoc,
2711 TypeSourceInfo *TSInfo,
2712 Expr *DimExpr,
2713 SourceLocation RParenLoc) {
2714 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2715 }
2716
John Wiegleyf9f65842011-04-25 06:54:41 +00002717 /// \brief Build a new expression trait expression.
2718 ///
2719 /// By default, performs semantic analysis to build the new expression.
2720 /// Subclasses may override this routine to provide different behavior.
2721 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2722 SourceLocation StartLoc,
2723 Expr *Queried,
2724 SourceLocation RParenLoc) {
2725 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2726 }
2727
Mike Stump11289f42009-09-09 15:08:12 +00002728 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 /// expression.
2730 ///
2731 /// By default, performs semantic analysis to build the new expression.
2732 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002733 ExprResult RebuildDependentScopeDeclRefExpr(
2734 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002735 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002736 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002737 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002738 bool IsAddressOfOperand,
2739 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002740 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002741 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002742
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002743 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002744 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2745 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002746
Reid Kleckner32506ed2014-06-12 23:03:48 +00002747 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002748 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002749 }
2750
2751 /// \brief Build a new template-id expression.
2752 ///
2753 /// By default, performs semantic analysis to build the new expression.
2754 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002755 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002756 SourceLocation TemplateKWLoc,
2757 LookupResult &R,
2758 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002759 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002760 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2761 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002762 }
2763
2764 /// \brief Build a new object-construction expression.
2765 ///
2766 /// By default, performs semantic analysis to build the new expression.
2767 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002768 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002769 SourceLocation Loc,
2770 CXXConstructorDecl *Constructor,
2771 bool IsElidable,
2772 MultiExprArg Args,
2773 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002774 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002775 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002776 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002777 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002778 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002779 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002780 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002781 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002782 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002783
Richard Smithc83bf822016-06-10 00:58:19 +00002784 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002785 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002786 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002787 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002788 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002789 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002790 RequiresZeroInit, ConstructKind,
2791 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002792 }
2793
Richard Smith5179eb72016-06-28 19:03:57 +00002794 /// \brief Build a new implicit construction via inherited constructor
2795 /// expression.
2796 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2797 CXXConstructorDecl *Constructor,
2798 bool ConstructsVBase,
2799 bool InheritedFromVBase) {
2800 return new (getSema().Context) CXXInheritedCtorInitExpr(
2801 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2802 }
2803
Douglas Gregora16548e2009-08-11 05:31:07 +00002804 /// \brief Build a new object-construction expression.
2805 ///
2806 /// By default, performs semantic analysis to build the new expression.
2807 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002808 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2809 SourceLocation LParenLoc,
2810 MultiExprArg Args,
2811 SourceLocation RParenLoc) {
2812 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002813 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002814 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002815 RParenLoc);
2816 }
2817
2818 /// \brief Build a new object-construction expression.
2819 ///
2820 /// By default, performs semantic analysis to build the new expression.
2821 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002822 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2823 SourceLocation LParenLoc,
2824 MultiExprArg Args,
2825 SourceLocation RParenLoc) {
2826 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002827 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002828 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002829 RParenLoc);
2830 }
Mike Stump11289f42009-09-09 15:08:12 +00002831
Douglas Gregora16548e2009-08-11 05:31:07 +00002832 /// \brief Build a new member reference expression.
2833 ///
2834 /// By default, performs semantic analysis to build the new expression.
2835 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002836 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002837 QualType BaseType,
2838 bool IsArrow,
2839 SourceLocation OperatorLoc,
2840 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002841 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002842 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002843 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002844 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002845 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002846 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002847
John McCallb268a282010-08-23 23:25:46 +00002848 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002849 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002850 SS, TemplateKWLoc,
2851 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002852 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002853 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002854 }
2855
John McCall10eae182009-11-30 22:42:35 +00002856 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002857 ///
2858 /// By default, performs semantic analysis to build the new expression.
2859 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002860 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2861 SourceLocation OperatorLoc,
2862 bool IsArrow,
2863 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002864 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002865 NamedDecl *FirstQualifierInScope,
2866 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002867 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002868 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002869 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002870
John McCallb268a282010-08-23 23:25:46 +00002871 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002872 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002873 SS, TemplateKWLoc,
2874 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002875 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002876 }
Mike Stump11289f42009-09-09 15:08:12 +00002877
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002878 /// \brief Build a new noexcept expression.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
2882 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2883 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2884 }
2885
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002886 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002887 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2888 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002889 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002890 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002891 Optional<unsigned> Length,
2892 ArrayRef<TemplateArgument> PartialArgs) {
2893 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2894 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002895 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002896
Patrick Beard0caa3942012-04-19 00:25:12 +00002897 /// \brief Build a new Objective-C boxed expression.
2898 ///
2899 /// By default, performs semantic analysis to build the new expression.
2900 /// Subclasses may override this routine to provide different behavior.
2901 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2902 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2903 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002904
Ted Kremeneke65b0862012-03-06 20:05:56 +00002905 /// \brief Build a new Objective-C array literal.
2906 ///
2907 /// By default, performs semantic analysis to build the new expression.
2908 /// Subclasses may override this routine to provide different behavior.
2909 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2910 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002911 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002912 MultiExprArg(Elements, NumElements));
2913 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002914
2915 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002916 Expr *Base, Expr *Key,
2917 ObjCMethodDecl *getterMethod,
2918 ObjCMethodDecl *setterMethod) {
2919 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2920 getterMethod, setterMethod);
2921 }
2922
2923 /// \brief Build a new Objective-C dictionary literal.
2924 ///
2925 /// By default, performs semantic analysis to build the new expression.
2926 /// Subclasses may override this routine to provide different behavior.
2927 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002928 MutableArrayRef<ObjCDictionaryElement> Elements) {
2929 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002930 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002931
James Dennett2a4d13c2012-06-15 07:13:21 +00002932 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002933 ///
2934 /// By default, performs semantic analysis to build the new expression.
2935 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002936 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002937 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002938 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002939 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002940 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002941
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002942 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002943 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002944 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002945 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002946 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002947 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002948 MultiExprArg Args,
2949 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002950 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2951 ReceiverTypeInfo->getType(),
2952 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002953 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002954 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002955 }
2956
2957 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002958 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002959 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002960 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002961 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002962 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002963 MultiExprArg Args,
2964 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002965 return SemaRef.BuildInstanceMessage(Receiver,
2966 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002967 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002968 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002969 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002970 }
2971
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002972 /// \brief Build a new Objective-C instance/class message to 'super'.
2973 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2974 Selector Sel,
2975 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002976 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002977 ObjCMethodDecl *Method,
2978 SourceLocation LBracLoc,
2979 MultiExprArg Args,
2980 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002981 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002982 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002983 SuperLoc,
2984 Sel, Method, LBracLoc, SelectorLocs,
2985 RBracLoc, Args)
2986 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002987 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002988 SuperLoc,
2989 Sel, Method, LBracLoc, SelectorLocs,
2990 RBracLoc, Args);
2991
2992
2993 }
2994
Douglas Gregord51d90d2010-04-26 20:11:03 +00002995 /// \brief Build a new Objective-C ivar reference expression.
2996 ///
2997 /// By default, performs semantic analysis to build the new expression.
2998 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002999 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003000 SourceLocation IvarLoc,
3001 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003002 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003003 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003004 ExprResult Result = getSema().BuildMemberReferenceExpr(
3005 BaseArg, BaseArg->getType(),
3006 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3007 /*FirstQualifierInScope=*/nullptr, NameInfo,
3008 /*TemplateArgs=*/nullptr,
3009 /*S=*/nullptr);
3010 if (IsFreeIvar && Result.isUsable())
3011 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3012 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003013 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003014
3015 /// \brief Build a new Objective-C property reference expression.
3016 ///
3017 /// By default, performs semantic analysis to build the new expression.
3018 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003019 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003020 ObjCPropertyDecl *Property,
3021 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003022 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003023 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3024 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3025 /*FIXME:*/PropertyLoc,
3026 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003027 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003028 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003029 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003030 /*TemplateArgs=*/nullptr,
3031 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003033
John McCallb7bd14f2010-12-02 01:19:52 +00003034 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003035 ///
3036 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003037 /// Subclasses may override this routine to provide different behavior.
3038 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3039 ObjCMethodDecl *Getter,
3040 ObjCMethodDecl *Setter,
3041 SourceLocation PropertyLoc) {
3042 // Since these expressions can only be value-dependent, we do not
3043 // need to perform semantic analysis again.
3044 return Owned(
3045 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3046 VK_LValue, OK_ObjCProperty,
3047 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003048 }
3049
Douglas Gregord51d90d2010-04-26 20:11:03 +00003050 /// \brief Build a new Objective-C "isa" expression.
3051 ///
3052 /// By default, performs semantic analysis to build the new expression.
3053 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003054 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003055 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003056 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003057 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3058 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003059 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003060 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003061 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003062 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003063 /*TemplateArgs=*/nullptr,
3064 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003066
Douglas Gregora16548e2009-08-11 05:31:07 +00003067 /// \brief Build a new shuffle vector expression.
3068 ///
3069 /// By default, performs semantic analysis to build the new expression.
3070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003071 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003072 MultiExprArg SubExprs,
3073 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003074 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003075 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003076 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3077 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3078 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003079 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003080
Douglas Gregora16548e2009-08-11 05:31:07 +00003081 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003082 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003083 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3084 SemaRef.Context.BuiltinFnTy,
3085 VK_RValue, BuiltinLoc);
3086 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3087 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003088 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003089
3090 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003091 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003092 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003093 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003094
Douglas Gregora16548e2009-08-11 05:31:07 +00003095 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003096 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003097 }
John McCall31f82722010-11-12 08:19:04 +00003098
Hal Finkelc4d7c822013-09-18 03:29:45 +00003099 /// \brief Build a new convert vector expression.
3100 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3101 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3102 SourceLocation RParenLoc) {
3103 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3104 BuiltinLoc, RParenLoc);
3105 }
3106
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003107 /// \brief Build a new template argument pack expansion.
3108 ///
3109 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003110 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003111 /// different behavior.
3112 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003113 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003114 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003115 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003116 case TemplateArgument::Expression: {
3117 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003118 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3119 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003120 if (Result.isInvalid())
3121 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003122
Douglas Gregor98318c22011-01-03 21:37:45 +00003123 return TemplateArgumentLoc(Result.get(), Result.get());
3124 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003125
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003126 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003127 return TemplateArgumentLoc(TemplateArgument(
3128 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003129 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003130 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003131 Pattern.getTemplateNameLoc(),
3132 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003133
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003134 case TemplateArgument::Null:
3135 case TemplateArgument::Integral:
3136 case TemplateArgument::Declaration:
3137 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003138 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003139 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003140 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003141
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003142 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003143 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003144 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003145 EllipsisLoc,
3146 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003147 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3148 Expansion);
3149 break;
3150 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003151
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003152 return TemplateArgumentLoc();
3153 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003154
Douglas Gregor968f23a2011-01-03 19:31:53 +00003155 /// \brief Build a new expression pack expansion.
3156 ///
3157 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003158 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003159 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003160 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003161 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003162 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003163 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003164
Richard Smith0f0af192014-11-08 05:07:16 +00003165 /// \brief Build a new C++1z fold-expression.
3166 ///
3167 /// By default, performs semantic analysis in order to build a new fold
3168 /// expression.
3169 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3170 BinaryOperatorKind Operator,
3171 SourceLocation EllipsisLoc, Expr *RHS,
3172 SourceLocation RParenLoc) {
3173 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3174 RHS, RParenLoc);
3175 }
3176
3177 /// \brief Build an empty C++1z fold-expression with the given operator.
3178 ///
3179 /// By default, produces the fallback value for the fold-expression, or
3180 /// produce an error if there is no fallback value.
3181 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3182 BinaryOperatorKind Operator) {
3183 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3184 }
3185
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003186 /// \brief Build a new atomic operation expression.
3187 ///
3188 /// By default, performs semantic analysis to build the new expression.
3189 /// Subclasses may override this routine to provide different behavior.
3190 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3191 MultiExprArg SubExprs,
3192 QualType RetTy,
3193 AtomicExpr::AtomicOp Op,
3194 SourceLocation RParenLoc) {
3195 // Just create the expression; there is not any interesting semantic
3196 // analysis here because we can't actually build an AtomicExpr until
3197 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003198 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003199 RParenLoc);
3200 }
3201
John McCall31f82722010-11-12 08:19:04 +00003202private:
Douglas Gregor14454802011-02-25 02:25:35 +00003203 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3204 QualType ObjectType,
3205 NamedDecl *FirstQualifierInScope,
3206 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003207
3208 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3209 QualType ObjectType,
3210 NamedDecl *FirstQualifierInScope,
3211 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003212
3213 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3214 NamedDecl *FirstQualifierInScope,
3215 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003216
3217 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3218 DependentNameTypeLoc TL,
3219 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003220};
Douglas Gregora16548e2009-08-11 05:31:07 +00003221
Douglas Gregorebe10102009-08-20 07:17:43 +00003222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003223StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003224 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003225 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003226
Douglas Gregorebe10102009-08-20 07:17:43 +00003227 switch (S->getStmtClass()) {
3228 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003229
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 // Transform individual statement nodes
3231#define STMT(Node, Parent) \
3232 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003233#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003234#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003235#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 // Transform expressions by calling TransformExpr.
3238#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003239#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003240#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003241#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 {
John McCalldadc5752010-08-24 06:29:42 +00003243 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003244 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003245 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003246
Richard Smith945f8d32013-01-14 22:39:08 +00003247 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 }
Mike Stump11289f42009-09-09 15:08:12 +00003249 }
3250
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003251 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003252}
Mike Stump11289f42009-09-09 15:08:12 +00003253
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003254template<typename Derived>
3255OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3256 if (!S)
3257 return S;
3258
3259 switch (S->getClauseKind()) {
3260 default: break;
3261 // Transform individual clause nodes
3262#define OPENMP_CLAUSE(Name, Class) \
3263 case OMPC_ ## Name : \
3264 return getDerived().Transform ## Class(cast<Class>(S));
3265#include "clang/Basic/OpenMPKinds.def"
3266 }
3267
3268 return S;
3269}
3270
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregore922c772009-08-04 22:27:00 +00003272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003273ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003274 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003275 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003276
3277 switch (E->getStmtClass()) {
3278 case Stmt::NoStmtClass: break;
3279#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003280#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003281#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003282 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003283#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003284 }
3285
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003286 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003287}
3288
3289template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003290ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003291 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003292 // Initializers are instantiated like expressions, except that various outer
3293 // layers are stripped.
3294 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003295 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003296
3297 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3298 Init = ExprTemp->getSubExpr();
3299
Richard Smith410306b2016-12-12 02:53:20 +00003300 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3301 Init = AIL->getCommonExpr();
3302
Richard Smithe6ca4752013-05-30 22:40:16 +00003303 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3304 Init = MTE->GetTemporaryExpr();
3305
Richard Smithd59b8322012-12-19 01:39:02 +00003306 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3307 Init = Binder->getSubExpr();
3308
3309 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3310 Init = ICE->getSubExprAsWritten();
3311
Richard Smithcc1b96d2013-06-12 22:31:48 +00003312 if (CXXStdInitializerListExpr *ILE =
3313 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003314 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003315
Richard Smithc6abd962014-07-25 01:12:44 +00003316 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003317 // InitListExprs. Other forms of copy-initialization will be a no-op if
3318 // the initializer is already the right type.
3319 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003320 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003321 return getDerived().TransformExpr(Init);
3322
3323 // Revert value-initialization back to empty parens.
3324 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3325 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003326 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003327 Parens.getEnd());
3328 }
3329
3330 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3331 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003332 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003333 SourceLocation());
3334
3335 // Revert initialization by constructor back to a parenthesized or braced list
3336 // of expressions. Any other form of initializer can just be reused directly.
3337 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003338 return getDerived().TransformExpr(Init);
3339
Richard Smithf8adcdc2014-07-17 05:12:35 +00003340 // If the initialization implicitly converted an initializer list to a
3341 // std::initializer_list object, unwrap the std::initializer_list too.
3342 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003343 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003344
Richard Smithd59b8322012-12-19 01:39:02 +00003345 SmallVector<Expr*, 8> NewArgs;
3346 bool ArgChanged = false;
3347 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003348 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003349 return ExprError();
3350
3351 // If this was list initialization, revert to list form.
3352 if (Construct->isListInitialization())
3353 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3354 Construct->getLocEnd(),
3355 Construct->getType());
3356
Richard Smithd59b8322012-12-19 01:39:02 +00003357 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003358 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003359 if (Parens.isInvalid()) {
3360 // This was a variable declaration's initialization for which no initializer
3361 // was specified.
3362 assert(NewArgs.empty() &&
3363 "no parens or braces but have direct init with arguments?");
3364 return ExprEmpty();
3365 }
Richard Smithd59b8322012-12-19 01:39:02 +00003366 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3367 Parens.getEnd());
3368}
3369
3370template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003371bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003372 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003373 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003374 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003375 bool *ArgChanged) {
3376 for (unsigned I = 0; I != NumInputs; ++I) {
3377 // If requested, drop call arguments that need to be dropped.
3378 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3379 if (ArgChanged)
3380 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003381
Douglas Gregora3efea12011-01-03 19:04:46 +00003382 break;
3383 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003384
Douglas Gregor968f23a2011-01-03 19:31:53 +00003385 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3386 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Chris Lattner01cf8db2011-07-20 06:58:45 +00003388 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003389 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3390 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003391
Douglas Gregor968f23a2011-01-03 19:31:53 +00003392 // Determine whether the set of unexpanded parameter packs can and should
3393 // be expanded.
3394 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003395 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003396 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3397 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003398 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3399 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003400 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003401 Expand, RetainExpansion,
3402 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003403 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003404
Douglas Gregor968f23a2011-01-03 19:31:53 +00003405 if (!Expand) {
3406 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003407 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003408 // expansion.
3409 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3410 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3411 if (OutPattern.isInvalid())
3412 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
3414 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003415 Expansion->getEllipsisLoc(),
3416 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003417 if (Out.isInvalid())
3418 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003419
Douglas Gregor968f23a2011-01-03 19:31:53 +00003420 if (ArgChanged)
3421 *ArgChanged = true;
3422 Outputs.push_back(Out.get());
3423 continue;
3424 }
John McCall542e7c62011-07-06 07:30:07 +00003425
3426 // Record right away that the argument was changed. This needs
3427 // to happen even if the array expands to nothing.
3428 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor968f23a2011-01-03 19:31:53 +00003430 // The transform has determined that we should perform an elementwise
3431 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003432 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003433 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3434 ExprResult Out = getDerived().TransformExpr(Pattern);
3435 if (Out.isInvalid())
3436 return true;
3437
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003438 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003439 Out = getDerived().RebuildPackExpansion(
3440 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003441 if (Out.isInvalid())
3442 return true;
3443 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
Douglas Gregor968f23a2011-01-03 19:31:53 +00003445 Outputs.push_back(Out.get());
3446 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Richard Smith9467be42014-06-06 17:33:35 +00003448 // If we're supposed to retain a pack expansion, do so by temporarily
3449 // forgetting the partially-substituted parameter pack.
3450 if (RetainExpansion) {
3451 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3452
3453 ExprResult Out = getDerived().TransformExpr(Pattern);
3454 if (Out.isInvalid())
3455 return true;
3456
3457 Out = getDerived().RebuildPackExpansion(
3458 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3459 if (Out.isInvalid())
3460 return true;
3461
3462 Outputs.push_back(Out.get());
3463 }
3464
Douglas Gregor968f23a2011-01-03 19:31:53 +00003465 continue;
3466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003467
Richard Smithd59b8322012-12-19 01:39:02 +00003468 ExprResult Result =
3469 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3470 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003471 if (Result.isInvalid())
3472 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
Douglas Gregora3efea12011-01-03 19:04:46 +00003474 if (Result.get() != Inputs[I] && ArgChanged)
3475 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003476
3477 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003478 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003479
Douglas Gregora3efea12011-01-03 19:04:46 +00003480 return false;
3481}
3482
Richard Smith03a4aa32016-06-23 19:02:52 +00003483template <typename Derived>
3484Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3485 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3486 if (Var) {
3487 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3488 getDerived().TransformDefinition(Var->getLocation(), Var));
3489
3490 if (!ConditionVar)
3491 return Sema::ConditionError();
3492
3493 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3494 }
3495
3496 if (Expr) {
3497 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3498
3499 if (CondExpr.isInvalid())
3500 return Sema::ConditionError();
3501
3502 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3503 }
3504
3505 return Sema::ConditionResult();
3506}
3507
Douglas Gregora3efea12011-01-03 19:04:46 +00003508template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003509NestedNameSpecifierLoc
3510TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3511 NestedNameSpecifierLoc NNS,
3512 QualType ObjectType,
3513 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003514 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003515 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003516 Qualifier = Qualifier.getPrefix())
3517 Qualifiers.push_back(Qualifier);
3518
3519 CXXScopeSpec SS;
3520 while (!Qualifiers.empty()) {
3521 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3522 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003523
Douglas Gregor14454802011-02-25 02:25:35 +00003524 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003525 case NestedNameSpecifier::Identifier: {
3526 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3527 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3528 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3529 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003530 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003531 }
Douglas Gregor14454802011-02-25 02:25:35 +00003532 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003533
Douglas Gregor14454802011-02-25 02:25:35 +00003534 case NestedNameSpecifier::Namespace: {
3535 NamespaceDecl *NS
3536 = cast_or_null<NamespaceDecl>(
3537 getDerived().TransformDecl(
3538 Q.getLocalBeginLoc(),
3539 QNNS->getAsNamespace()));
3540 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3541 break;
3542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregor14454802011-02-25 02:25:35 +00003544 case NestedNameSpecifier::NamespaceAlias: {
3545 NamespaceAliasDecl *Alias
3546 = cast_or_null<NamespaceAliasDecl>(
3547 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3548 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003549 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003550 Q.getLocalEndLoc());
3551 break;
3552 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003553
Douglas Gregor14454802011-02-25 02:25:35 +00003554 case NestedNameSpecifier::Global:
3555 // There is no meaningful transformation that one could perform on the
3556 // global scope.
3557 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3558 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003559
Nikola Smiljanic67860242014-09-26 00:28:20 +00003560 case NestedNameSpecifier::Super: {
3561 CXXRecordDecl *RD =
3562 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3563 SourceLocation(), QNNS->getAsRecordDecl()));
3564 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3565 break;
3566 }
3567
Douglas Gregor14454802011-02-25 02:25:35 +00003568 case NestedNameSpecifier::TypeSpecWithTemplate:
3569 case NestedNameSpecifier::TypeSpec: {
3570 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3571 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003572
Douglas Gregor14454802011-02-25 02:25:35 +00003573 if (!TL)
3574 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003575
Douglas Gregor14454802011-02-25 02:25:35 +00003576 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003577 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003578 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003579 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003580 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003581 if (TL.getType()->isEnumeralType())
3582 SemaRef.Diag(TL.getBeginLoc(),
3583 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003584 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3585 Q.getLocalEndLoc());
3586 break;
3587 }
Richard Trieude756fb2011-05-07 01:36:37 +00003588 // If the nested-name-specifier is an invalid type def, don't emit an
3589 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003590 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3591 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003592 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003593 << TL.getType() << SS.getRange();
3594 }
Douglas Gregor14454802011-02-25 02:25:35 +00003595 return NestedNameSpecifierLoc();
3596 }
Douglas Gregore16af532011-02-28 18:50:33 +00003597 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003598
Douglas Gregore16af532011-02-28 18:50:33 +00003599 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003600 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003601 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Douglas Gregor14454802011-02-25 02:25:35 +00003604 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003605 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003606 !getDerived().AlwaysRebuild())
3607 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
3609 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003610 // nested-name-specifier, do so.
3611 if (SS.location_size() == NNS.getDataLength() &&
3612 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3613 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3614
3615 // Allocate new nested-name-specifier location information.
3616 return SS.getWithLocInContext(SemaRef.Context);
3617}
3618
3619template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003620DeclarationNameInfo
3621TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003622::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003623 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003624 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003625 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003626
3627 switch (Name.getNameKind()) {
3628 case DeclarationName::Identifier:
3629 case DeclarationName::ObjCZeroArgSelector:
3630 case DeclarationName::ObjCOneArgSelector:
3631 case DeclarationName::ObjCMultiArgSelector:
3632 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003633 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003634 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003635 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003636
Richard Smith35845152017-02-07 01:37:30 +00003637 case DeclarationName::CXXDeductionGuideName: {
3638 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3639 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3640 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3641 if (!NewTemplate)
3642 return DeclarationNameInfo();
3643
3644 DeclarationNameInfo NewNameInfo(NameInfo);
3645 NewNameInfo.setName(
3646 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3647 return NewNameInfo;
3648 }
3649
Douglas Gregorf816bd72009-09-03 22:13:48 +00003650 case DeclarationName::CXXConstructorName:
3651 case DeclarationName::CXXDestructorName:
3652 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003653 TypeSourceInfo *NewTInfo;
3654 CanQualType NewCanTy;
3655 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003656 NewTInfo = getDerived().TransformType(OldTInfo);
3657 if (!NewTInfo)
3658 return DeclarationNameInfo();
3659 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003660 }
3661 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003662 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003663 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003664 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003665 if (NewT.isNull())
3666 return DeclarationNameInfo();
3667 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3668 }
Mike Stump11289f42009-09-09 15:08:12 +00003669
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003670 DeclarationName NewName
3671 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3672 NewCanTy);
3673 DeclarationNameInfo NewNameInfo(NameInfo);
3674 NewNameInfo.setName(NewName);
3675 NewNameInfo.setNamedTypeInfo(NewTInfo);
3676 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003677 }
Mike Stump11289f42009-09-09 15:08:12 +00003678 }
3679
David Blaikie83d382b2011-09-23 05:06:16 +00003680 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003681}
3682
3683template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003684TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003685TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3686 TemplateName Name,
3687 SourceLocation NameLoc,
3688 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003689 NamedDecl *FirstQualifierInScope,
3690 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003691 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3692 TemplateDecl *Template = QTN->getTemplateDecl();
3693 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003694
Douglas Gregor9db53502011-03-02 18:07:45 +00003695 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003696 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003697 Template));
3698 if (!TransTemplate)
3699 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
Douglas Gregor9db53502011-03-02 18:07:45 +00003701 if (!getDerived().AlwaysRebuild() &&
3702 SS.getScopeRep() == QTN->getQualifier() &&
3703 TransTemplate == Template)
3704 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregor9db53502011-03-02 18:07:45 +00003706 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3707 TransTemplate);
3708 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003709
Douglas Gregor9db53502011-03-02 18:07:45 +00003710 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3711 if (SS.getScopeRep()) {
3712 // These apply to the scope specifier, not the template.
3713 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003714 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003715 }
3716
Douglas Gregor9db53502011-03-02 18:07:45 +00003717 if (!getDerived().AlwaysRebuild() &&
3718 SS.getScopeRep() == DTN->getQualifier() &&
3719 ObjectType.isNull())
3720 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003721
Douglas Gregor9db53502011-03-02 18:07:45 +00003722 if (DTN->isIdentifier()) {
3723 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003724 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003725 NameLoc,
3726 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003727 FirstQualifierInScope,
3728 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003729 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003730
Douglas Gregor9db53502011-03-02 18:07:45 +00003731 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003732 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003734
Douglas Gregor9db53502011-03-02 18:07:45 +00003735 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3736 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003737 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003738 Template));
3739 if (!TransTemplate)
3740 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003741
Douglas Gregor9db53502011-03-02 18:07:45 +00003742 if (!getDerived().AlwaysRebuild() &&
3743 TransTemplate == Template)
3744 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003745
Douglas Gregor9db53502011-03-02 18:07:45 +00003746 return TemplateName(TransTemplate);
3747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Douglas Gregor9db53502011-03-02 18:07:45 +00003749 if (SubstTemplateTemplateParmPackStorage *SubstPack
3750 = Name.getAsSubstTemplateTemplateParmPack()) {
3751 TemplateTemplateParmDecl *TransParam
3752 = cast_or_null<TemplateTemplateParmDecl>(
3753 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3754 if (!TransParam)
3755 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003756
Douglas Gregor9db53502011-03-02 18:07:45 +00003757 if (!getDerived().AlwaysRebuild() &&
3758 TransParam == SubstPack->getParameterPack())
3759 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003760
3761 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003762 SubstPack->getArgumentPack());
3763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor9db53502011-03-02 18:07:45 +00003765 // These should be getting filtered out before they reach the AST.
3766 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003767}
3768
3769template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003770void TreeTransform<Derived>::InventTemplateArgumentLoc(
3771 const TemplateArgument &Arg,
3772 TemplateArgumentLoc &Output) {
3773 SourceLocation Loc = getDerived().getBaseLocation();
3774 switch (Arg.getKind()) {
3775 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003776 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003777 break;
3778
3779 case TemplateArgument::Type:
3780 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003781 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
John McCall0ad16662009-10-29 08:12:44 +00003783 break;
3784
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003785 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003786 case TemplateArgument::TemplateExpansion: {
3787 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003788 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003789 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3790 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3791 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3792 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003793
Douglas Gregor9d802122011-03-02 17:09:35 +00003794 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003795 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003796 Builder.getWithLocInContext(SemaRef.Context),
3797 Loc);
3798 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003799 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003800 Builder.getWithLocInContext(SemaRef.Context),
3801 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003802
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003803 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003804 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003805
John McCall0ad16662009-10-29 08:12:44 +00003806 case TemplateArgument::Expression:
3807 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3808 break;
3809
3810 case TemplateArgument::Declaration:
3811 case TemplateArgument::Integral:
3812 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003813 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003814 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003815 break;
3816 }
3817}
3818
3819template<typename Derived>
3820bool TreeTransform<Derived>::TransformTemplateArgument(
3821 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003822 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003823 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003824 switch (Arg.getKind()) {
3825 case TemplateArgument::Null:
3826 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003827 case TemplateArgument::Pack:
3828 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003829 case TemplateArgument::NullPtr:
3830 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregore922c772009-08-04 22:27:00 +00003832 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003833 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003834 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003835 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003836
3837 DI = getDerived().TransformType(DI);
3838 if (!DI) return true;
3839
3840 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3841 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003842 }
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003844 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003845 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3846 if (QualifierLoc) {
3847 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3848 if (!QualifierLoc)
3849 return true;
3850 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003851
Douglas Gregordf846d12011-03-02 18:46:51 +00003852 CXXScopeSpec SS;
3853 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003854 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003855 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3856 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003857 if (Template.isNull())
3858 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003859
Douglas Gregor9d802122011-03-02 17:09:35 +00003860 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003861 Input.getTemplateNameLoc());
3862 return false;
3863 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003864
3865 case TemplateArgument::TemplateExpansion:
3866 llvm_unreachable("Caller should expand pack expansions");
3867
Douglas Gregore922c772009-08-04 22:27:00 +00003868 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003869 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003870 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003871 getSema(), Uneval
3872 ? Sema::ExpressionEvaluationContext::Unevaluated
3873 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003874
John McCall0ad16662009-10-29 08:12:44 +00003875 Expr *InputExpr = Input.getSourceExpression();
3876 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3877
Chris Lattnercdb591a2011-04-25 20:37:58 +00003878 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003879 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003880 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003881 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003882 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003883 }
Douglas Gregore922c772009-08-04 22:27:00 +00003884 }
Mike Stump11289f42009-09-09 15:08:12 +00003885
Douglas Gregore922c772009-08-04 22:27:00 +00003886 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003887 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003888}
3889
Douglas Gregorfe921a72010-12-20 23:36:19 +00003890/// \brief Iterator adaptor that invents template argument location information
3891/// for each of the template arguments in its underlying iterator.
3892template<typename Derived, typename InputIterator>
3893class TemplateArgumentLocInventIterator {
3894 TreeTransform<Derived> &Self;
3895 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003896
Douglas Gregorfe921a72010-12-20 23:36:19 +00003897public:
3898 typedef TemplateArgumentLoc value_type;
3899 typedef TemplateArgumentLoc reference;
3900 typedef typename std::iterator_traits<InputIterator>::difference_type
3901 difference_type;
3902 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003903
Douglas Gregorfe921a72010-12-20 23:36:19 +00003904 class pointer {
3905 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003906
Douglas Gregorfe921a72010-12-20 23:36:19 +00003907 public:
3908 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003909
Douglas Gregorfe921a72010-12-20 23:36:19 +00003910 const TemplateArgumentLoc *operator->() const { return &Arg; }
3911 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003912
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003913 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregorfe921a72010-12-20 23:36:19 +00003915 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3916 InputIterator Iter)
3917 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003918
Douglas Gregorfe921a72010-12-20 23:36:19 +00003919 TemplateArgumentLocInventIterator &operator++() {
3920 ++Iter;
3921 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003922 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003923
Douglas Gregorfe921a72010-12-20 23:36:19 +00003924 TemplateArgumentLocInventIterator operator++(int) {
3925 TemplateArgumentLocInventIterator Old(*this);
3926 ++(*this);
3927 return Old;
3928 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregorfe921a72010-12-20 23:36:19 +00003930 reference operator*() const {
3931 TemplateArgumentLoc Result;
3932 Self.InventTemplateArgumentLoc(*Iter, Result);
3933 return Result;
3934 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003935
Douglas Gregorfe921a72010-12-20 23:36:19 +00003936 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003937
Douglas Gregorfe921a72010-12-20 23:36:19 +00003938 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3939 const TemplateArgumentLocInventIterator &Y) {
3940 return X.Iter == Y.Iter;
3941 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003942
Douglas Gregorfe921a72010-12-20 23:36:19 +00003943 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3944 const TemplateArgumentLocInventIterator &Y) {
3945 return X.Iter != Y.Iter;
3946 }
3947};
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregor42cafa82010-12-20 17:42:22 +00003949template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003950template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003951bool TreeTransform<Derived>::TransformTemplateArguments(
3952 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3953 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003954 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003955 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003956 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003958 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3959 // Unpack argument packs, which we translate them into separate
3960 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003961 // FIXME: We could do much better if we could guarantee that the
3962 // TemplateArgumentLocInfo for the pack expansion would be usable for
3963 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003964 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003965 TemplateArgument::pack_iterator>
3966 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003967 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003968 In.getArgument().pack_begin()),
3969 PackLocIterator(*this,
3970 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003971 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003972 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003973
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003974 continue;
3975 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003976
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003977 if (In.getArgument().isPackExpansion()) {
3978 // We have a pack expansion, for which we will be substituting into
3979 // the pattern.
3980 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003981 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003982 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003983 = getSema().getTemplateArgumentPackExpansionPattern(
3984 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003985
Chris Lattner01cf8db2011-07-20 06:58:45 +00003986 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003987 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3988 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003989
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003990 // Determine whether the set of unexpanded parameter packs can and should
3991 // be expanded.
3992 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003993 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003994 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003995 if (getDerived().TryExpandParameterPacks(Ellipsis,
3996 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003997 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003998 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003999 RetainExpansion,
4000 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004001 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004002
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004003 if (!Expand) {
4004 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004005 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004006 // expansion.
4007 TemplateArgumentLoc OutPattern;
4008 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004009 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004010 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004011
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004012 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4013 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004014 if (Out.getArgument().isNull())
4015 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004016
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004017 Outputs.addArgument(Out);
4018 continue;
4019 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004020
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004021 // The transform has determined that we should perform an elementwise
4022 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004023 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4025
Richard Smithd784e682015-09-23 21:41:42 +00004026 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004027 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004028
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004029 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004030 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4031 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004032 if (Out.getArgument().isNull())
4033 return true;
4034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004035
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004036 Outputs.addArgument(Out);
4037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Douglas Gregor48d24112011-01-10 20:53:55 +00004039 // If we're supposed to retain a pack expansion, do so by temporarily
4040 // forgetting the partially-substituted parameter pack.
4041 if (RetainExpansion) {
4042 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004043
Richard Smithd784e682015-09-23 21:41:42 +00004044 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004045 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004047 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4048 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004049 if (Out.getArgument().isNull())
4050 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004051
Douglas Gregor48d24112011-01-10 20:53:55 +00004052 Outputs.addArgument(Out);
4053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004054
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004055 continue;
4056 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004057
4058 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004059 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004060 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004061
Douglas Gregor42cafa82010-12-20 17:42:22 +00004062 Outputs.addArgument(Out);
4063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
Douglas Gregor42cafa82010-12-20 17:42:22 +00004065 return false;
4066
4067}
4068
Douglas Gregord6ff3322009-08-04 16:50:30 +00004069//===----------------------------------------------------------------------===//
4070// Type transformation
4071//===----------------------------------------------------------------------===//
4072
4073template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004074QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075 if (getDerived().AlreadyTransformed(T))
4076 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004077
John McCall550e0c22009-10-21 00:40:46 +00004078 // Temporary workaround. All of these transformations should
4079 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004080 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4081 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004082
John McCall31f82722010-11-12 08:19:04 +00004083 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004084
John McCall550e0c22009-10-21 00:40:46 +00004085 if (!NewDI)
4086 return QualType();
4087
4088 return NewDI->getType();
4089}
4090
4091template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004092TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004093 // Refine the base location to the type's location.
4094 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4095 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004096 if (getDerived().AlreadyTransformed(DI->getType()))
4097 return DI;
4098
4099 TypeLocBuilder TLB;
4100
4101 TypeLoc TL = DI->getTypeLoc();
4102 TLB.reserve(TL.getFullDataSize());
4103
John McCall31f82722010-11-12 08:19:04 +00004104 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004105 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004106 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004107
John McCallbcd03502009-12-07 02:54:59 +00004108 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004109}
4110
4111template<typename Derived>
4112QualType
John McCall31f82722010-11-12 08:19:04 +00004113TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004114 switch (T.getTypeLocClass()) {
4115#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004116#define TYPELOC(CLASS, PARENT) \
4117 case TypeLoc::CLASS: \
4118 return getDerived().Transform##CLASS##Type(TLB, \
4119 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004120#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004121 }
Mike Stump11289f42009-09-09 15:08:12 +00004122
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004123 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004124}
4125
Richard Smithee579842017-01-30 20:39:26 +00004126template<typename Derived>
4127QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4128 if (!isa<DependentNameType>(T))
4129 return TransformType(T);
4130
4131 if (getDerived().AlreadyTransformed(T))
4132 return T;
4133 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4134 getDerived().getBaseLocation());
4135 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4136 return NewDI ? NewDI->getType() : QualType();
4137}
4138
4139template<typename Derived>
4140TypeSourceInfo *
4141TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4142 if (!isa<DependentNameType>(DI->getType()))
4143 return TransformType(DI);
4144
4145 // Refine the base location to the type's location.
4146 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4147 getDerived().getBaseEntity());
4148 if (getDerived().AlreadyTransformed(DI->getType()))
4149 return DI;
4150
4151 TypeLocBuilder TLB;
4152
4153 TypeLoc TL = DI->getTypeLoc();
4154 TLB.reserve(TL.getFullDataSize());
4155
4156 Qualifiers Quals;
4157 auto QTL = TL.getAs<QualifiedTypeLoc>();
4158 if (QTL)
4159 TL = QTL.getUnqualifiedLoc();
4160
4161 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4162
4163 QualType Result = getDerived().TransformDependentNameType(
4164 TLB, DNTL, /*DeducedTSTContext*/true);
4165 if (Result.isNull())
4166 return nullptr;
4167
4168 if (QTL) {
4169 Result = getDerived().RebuildQualifiedType(
4170 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4171 TLB.TypeWasModifiedSafely(Result);
4172 }
4173
4174 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4175}
4176
John McCall550e0c22009-10-21 00:40:46 +00004177template<typename Derived>
4178QualType
4179TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004180 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004181 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004182
John McCall31f82722010-11-12 08:19:04 +00004183 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004184 if (Result.isNull())
4185 return QualType();
4186
Richard Smithee579842017-01-30 20:39:26 +00004187 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4188
4189 // RebuildQualifiedType might have updated the type, but not in a way
4190 // that invalidates the TypeLoc. (There's no location information for
4191 // qualifiers.)
4192 TLB.TypeWasModifiedSafely(Result);
4193
4194 return Result;
4195}
4196
4197template<typename Derived>
4198QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4199 SourceLocation Loc,
4200 Qualifiers Quals) {
4201 // C++ [dcl.fct]p7:
4202 // [When] adding cv-qualifications on top of the function type [...] the
4203 // cv-qualifiers are ignored.
4204 // C++ [dcl.ref]p1:
4205 // when the cv-qualifiers are introduced through the use of a typedef-name
4206 // or decltype-specifier [...] the cv-qualifiers are ignored.
4207 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4208 // applied to a reference type.
4209 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4210 if (T->isFunctionType() || T->isReferenceType())
4211 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004212
John McCall31168b02011-06-15 23:02:42 +00004213 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004214 // resulting type.
4215 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004216 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004217 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004218 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004219 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004220 // A lifetime qualifier applied to a substituted template parameter
4221 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004222 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004223 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004224 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004225 QualType Replacement = SubstTypeParam->getReplacementType();
4226 Qualifiers Qs = Replacement.getQualifiers();
4227 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004228 Replacement = SemaRef.Context.getQualifiedType(
4229 Replacement.getUnqualifiedType(), Qs);
4230 T = SemaRef.Context.getSubstTemplateTypeParmType(
4231 SubstTypeParam->getReplacedParameter(), Replacement);
4232 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004233 // 'auto' types behave the same way as template parameters.
4234 QualType Deduced = AutoTy->getDeducedType();
4235 Qualifiers Qs = Deduced.getQualifiers();
4236 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004237 Deduced =
4238 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4239 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4240 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004241 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004242 // Otherwise, complain about the addition of a qualifier to an
4243 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004244 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4245 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004246 Quals.removeObjCLifetime();
4247 }
4248 }
4249 }
John McCall550e0c22009-10-21 00:40:46 +00004250
Richard Smithee579842017-01-30 20:39:26 +00004251 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004252}
4253
Douglas Gregor14454802011-02-25 02:25:35 +00004254template<typename Derived>
4255TypeLoc
4256TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4257 QualType ObjectType,
4258 NamedDecl *UnqualLookup,
4259 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004260 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004261 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004262
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004263 TypeSourceInfo *TSI =
4264 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4265 if (TSI)
4266 return TSI->getTypeLoc();
4267 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004268}
4269
Douglas Gregor579c15f2011-03-02 18:32:08 +00004270template<typename Derived>
4271TypeSourceInfo *
4272TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4273 QualType ObjectType,
4274 NamedDecl *UnqualLookup,
4275 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004276 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004277 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004278
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004279 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4280 UnqualLookup, SS);
4281}
4282
4283template <typename Derived>
4284TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4285 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4286 CXXScopeSpec &SS) {
4287 QualType T = TL.getType();
4288 assert(!getDerived().AlreadyTransformed(T));
4289
Douglas Gregor579c15f2011-03-02 18:32:08 +00004290 TypeLocBuilder TLB;
4291 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004292
Douglas Gregor579c15f2011-03-02 18:32:08 +00004293 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004294 TemplateSpecializationTypeLoc SpecTL =
4295 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Richard Smithfd3dae02017-01-20 00:20:39 +00004297 TemplateName Template = getDerived().TransformTemplateName(
4298 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4299 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004300 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004301 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004302
4303 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004304 Template);
4305 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004306 DependentTemplateSpecializationTypeLoc SpecTL =
4307 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004308
Douglas Gregor579c15f2011-03-02 18:32:08 +00004309 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004310 = getDerived().RebuildTemplateName(SS,
4311 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004312 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004313 ObjectType, UnqualLookup,
4314 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004315 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004316 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004317
4318 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004319 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004320 Template,
4321 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004322 } else {
4323 // Nothing special needs to be done for these.
4324 Result = getDerived().TransformType(TLB, TL);
4325 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
4327 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004328 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Douglas Gregor579c15f2011-03-02 18:32:08 +00004330 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4331}
4332
John McCall550e0c22009-10-21 00:40:46 +00004333template <class TyLoc> static inline
4334QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4335 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4336 NewT.setNameLoc(T.getNameLoc());
4337 return T.getType();
4338}
4339
John McCall550e0c22009-10-21 00:40:46 +00004340template<typename Derived>
4341QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004342 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004343 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4344 NewT.setBuiltinLoc(T.getBuiltinLoc());
4345 if (T.needsExtraLocalData())
4346 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4347 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregord6ff3322009-08-04 16:50:30 +00004350template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004351QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004352 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004353 // FIXME: recurse?
4354 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004355}
Mike Stump11289f42009-09-09 15:08:12 +00004356
Reid Kleckner0503a872013-12-05 01:23:43 +00004357template <typename Derived>
4358QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4359 AdjustedTypeLoc TL) {
4360 // Adjustments applied during transformation are handled elsewhere.
4361 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4362}
4363
Douglas Gregord6ff3322009-08-04 16:50:30 +00004364template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004365QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4366 DecayedTypeLoc TL) {
4367 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4368 if (OriginalType.isNull())
4369 return QualType();
4370
4371 QualType Result = TL.getType();
4372 if (getDerived().AlwaysRebuild() ||
4373 OriginalType != TL.getOriginalLoc().getType())
4374 Result = SemaRef.Context.getDecayedType(OriginalType);
4375 TLB.push<DecayedTypeLoc>(Result);
4376 // Nothing to set for DecayedTypeLoc.
4377 return Result;
4378}
4379
4380template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004381QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004382 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004383 QualType PointeeType
4384 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004385 if (PointeeType.isNull())
4386 return QualType();
4387
4388 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004389 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004390 // A dependent pointer type 'T *' has is being transformed such
4391 // that an Objective-C class type is being replaced for 'T'. The
4392 // resulting pointer type is an ObjCObjectPointerType, not a
4393 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004394 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004395
John McCall8b07ec22010-05-15 11:32:37 +00004396 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4397 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004398 return Result;
4399 }
John McCall31f82722010-11-12 08:19:04 +00004400
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004401 if (getDerived().AlwaysRebuild() ||
4402 PointeeType != TL.getPointeeLoc().getType()) {
4403 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4404 if (Result.isNull())
4405 return QualType();
4406 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004407
John McCall31168b02011-06-15 23:02:42 +00004408 // Objective-C ARC can add lifetime qualifiers to the type that we're
4409 // pointing to.
4410 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004411
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004412 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4413 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004414 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
4417template<typename Derived>
4418QualType
John McCall550e0c22009-10-21 00:40:46 +00004419TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004420 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004421 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004422 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4423 if (PointeeType.isNull())
4424 return QualType();
4425
4426 QualType Result = TL.getType();
4427 if (getDerived().AlwaysRebuild() ||
4428 PointeeType != TL.getPointeeLoc().getType()) {
4429 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004430 TL.getSigilLoc());
4431 if (Result.isNull())
4432 return QualType();
4433 }
4434
Douglas Gregor049211a2010-04-22 16:50:51 +00004435 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004436 NewT.setSigilLoc(TL.getSigilLoc());
4437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004438}
4439
John McCall70dd5f62009-10-30 00:06:24 +00004440/// Transforms a reference type. Note that somewhat paradoxically we
4441/// don't care whether the type itself is an l-value type or an r-value
4442/// type; we only care if the type was *written* as an l-value type
4443/// or an r-value type.
4444template<typename Derived>
4445QualType
4446TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004447 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004448 const ReferenceType *T = TL.getTypePtr();
4449
4450 // Note that this works with the pointee-as-written.
4451 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4452 if (PointeeType.isNull())
4453 return QualType();
4454
4455 QualType Result = TL.getType();
4456 if (getDerived().AlwaysRebuild() ||
4457 PointeeType != T->getPointeeTypeAsWritten()) {
4458 Result = getDerived().RebuildReferenceType(PointeeType,
4459 T->isSpelledAsLValue(),
4460 TL.getSigilLoc());
4461 if (Result.isNull())
4462 return QualType();
4463 }
4464
John McCall31168b02011-06-15 23:02:42 +00004465 // Objective-C ARC can add lifetime qualifiers to the type that we're
4466 // referring to.
4467 TLB.TypeWasModifiedSafely(
4468 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4469
John McCall70dd5f62009-10-30 00:06:24 +00004470 // r-value references can be rebuilt as l-value references.
4471 ReferenceTypeLoc NewTL;
4472 if (isa<LValueReferenceType>(Result))
4473 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4474 else
4475 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4476 NewTL.setSigilLoc(TL.getSigilLoc());
4477
4478 return Result;
4479}
4480
Mike Stump11289f42009-09-09 15:08:12 +00004481template<typename Derived>
4482QualType
John McCall550e0c22009-10-21 00:40:46 +00004483TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004484 LValueReferenceTypeLoc TL) {
4485 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004486}
4487
Mike Stump11289f42009-09-09 15:08:12 +00004488template<typename Derived>
4489QualType
John McCall550e0c22009-10-21 00:40:46 +00004490TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004491 RValueReferenceTypeLoc TL) {
4492 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004493}
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregord6ff3322009-08-04 16:50:30 +00004495template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004496QualType
John McCall550e0c22009-10-21 00:40:46 +00004497TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004498 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004499 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004500 if (PointeeType.isNull())
4501 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004502
Abramo Bagnara509357842011-03-05 14:42:21 +00004503 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004504 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004505 if (OldClsTInfo) {
4506 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4507 if (!NewClsTInfo)
4508 return QualType();
4509 }
4510
4511 const MemberPointerType *T = TL.getTypePtr();
4512 QualType OldClsType = QualType(T->getClass(), 0);
4513 QualType NewClsType;
4514 if (NewClsTInfo)
4515 NewClsType = NewClsTInfo->getType();
4516 else {
4517 NewClsType = getDerived().TransformType(OldClsType);
4518 if (NewClsType.isNull())
4519 return QualType();
4520 }
Mike Stump11289f42009-09-09 15:08:12 +00004521
John McCall550e0c22009-10-21 00:40:46 +00004522 QualType Result = TL.getType();
4523 if (getDerived().AlwaysRebuild() ||
4524 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004525 NewClsType != OldClsType) {
4526 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004527 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004528 if (Result.isNull())
4529 return QualType();
4530 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004531
Reid Kleckner0503a872013-12-05 01:23:43 +00004532 // If we had to adjust the pointee type when building a member pointer, make
4533 // sure to push TypeLoc info for it.
4534 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4535 if (MPT && PointeeType != MPT->getPointeeType()) {
4536 assert(isa<AdjustedType>(MPT->getPointeeType()));
4537 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4538 }
4539
John McCall550e0c22009-10-21 00:40:46 +00004540 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4541 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004542 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004543
4544 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004545}
4546
Mike Stump11289f42009-09-09 15:08:12 +00004547template<typename Derived>
4548QualType
John McCall550e0c22009-10-21 00:40:46 +00004549TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004550 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004551 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004552 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004553 if (ElementType.isNull())
4554 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004555
John McCall550e0c22009-10-21 00:40:46 +00004556 QualType Result = TL.getType();
4557 if (getDerived().AlwaysRebuild() ||
4558 ElementType != T->getElementType()) {
4559 Result = getDerived().RebuildConstantArrayType(ElementType,
4560 T->getSizeModifier(),
4561 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004562 T->getIndexTypeCVRQualifiers(),
4563 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004564 if (Result.isNull())
4565 return QualType();
4566 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004567
4568 // We might have either a ConstantArrayType or a VariableArrayType now:
4569 // a ConstantArrayType is allowed to have an element type which is a
4570 // VariableArrayType if the type is dependent. Fortunately, all array
4571 // types have the same location layout.
4572 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004573 NewTL.setLBracketLoc(TL.getLBracketLoc());
4574 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004575
John McCall550e0c22009-10-21 00:40:46 +00004576 Expr *Size = TL.getSizeExpr();
4577 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004578 EnterExpressionEvaluationContext Unevaluated(
4579 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004580 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4581 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004582 }
4583 NewTL.setSizeExpr(Size);
4584
4585 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586}
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregord6ff3322009-08-04 16:50:30 +00004588template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004589QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004590 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004591 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004592 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004594 if (ElementType.isNull())
4595 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004596
John McCall550e0c22009-10-21 00:40:46 +00004597 QualType Result = TL.getType();
4598 if (getDerived().AlwaysRebuild() ||
4599 ElementType != T->getElementType()) {
4600 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004601 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004602 T->getIndexTypeCVRQualifiers(),
4603 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004604 if (Result.isNull())
4605 return QualType();
4606 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004607
John McCall550e0c22009-10-21 00:40:46 +00004608 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4609 NewTL.setLBracketLoc(TL.getLBracketLoc());
4610 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004611 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004612
4613 return Result;
4614}
4615
4616template<typename Derived>
4617QualType
4618TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004619 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004620 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004621 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4622 if (ElementType.isNull())
4623 return QualType();
4624
Tim Shenb34d0ef2017-02-14 23:46:37 +00004625 ExprResult SizeResult;
4626 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004627 EnterExpressionEvaluationContext Context(
4628 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004629 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4630 }
4631 if (SizeResult.isInvalid())
4632 return QualType();
4633 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004634 if (SizeResult.isInvalid())
4635 return QualType();
4636
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004637 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004638
4639 QualType Result = TL.getType();
4640 if (getDerived().AlwaysRebuild() ||
4641 ElementType != T->getElementType() ||
4642 Size != T->getSizeExpr()) {
4643 Result = getDerived().RebuildVariableArrayType(ElementType,
4644 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004645 Size,
John McCall550e0c22009-10-21 00:40:46 +00004646 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004647 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004648 if (Result.isNull())
4649 return QualType();
4650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004651
Serge Pavlov774c6d02014-02-06 03:49:11 +00004652 // We might have constant size array now, but fortunately it has the same
4653 // location layout.
4654 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004655 NewTL.setLBracketLoc(TL.getLBracketLoc());
4656 NewTL.setRBracketLoc(TL.getRBracketLoc());
4657 NewTL.setSizeExpr(Size);
4658
4659 return Result;
4660}
4661
4662template<typename Derived>
4663QualType
4664TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004665 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004666 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004667 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4668 if (ElementType.isNull())
4669 return QualType();
4670
Richard Smith764d2fe2011-12-20 02:08:33 +00004671 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004672 EnterExpressionEvaluationContext Unevaluated(
4673 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004674
John McCall33ddac02011-01-19 10:06:00 +00004675 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4676 Expr *origSize = TL.getSizeExpr();
4677 if (!origSize) origSize = T->getSizeExpr();
4678
4679 ExprResult sizeResult
4680 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004681 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004682 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004683 return QualType();
4684
John McCall33ddac02011-01-19 10:06:00 +00004685 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004686
4687 QualType Result = TL.getType();
4688 if (getDerived().AlwaysRebuild() ||
4689 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004690 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004691 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4692 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004693 size,
John McCall550e0c22009-10-21 00:40:46 +00004694 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004695 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004696 if (Result.isNull())
4697 return QualType();
4698 }
John McCall550e0c22009-10-21 00:40:46 +00004699
4700 // We might have any sort of array type now, but fortunately they
4701 // all have the same location layout.
4702 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4703 NewTL.setLBracketLoc(TL.getLBracketLoc());
4704 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004705 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004706
4707 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004708}
Mike Stump11289f42009-09-09 15:08:12 +00004709
4710template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004711QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004712 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004713 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004714 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004715
4716 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004717 QualType ElementType = getDerived().TransformType(T->getElementType());
4718 if (ElementType.isNull())
4719 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004720
Richard Smith764d2fe2011-12-20 02:08:33 +00004721 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004722 EnterExpressionEvaluationContext Unevaluated(
4723 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004724
John McCalldadc5752010-08-24 06:29:42 +00004725 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004726 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004727 if (Size.isInvalid())
4728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004729
John McCall550e0c22009-10-21 00:40:46 +00004730 QualType Result = TL.getType();
4731 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004732 ElementType != T->getElementType() ||
4733 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004734 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004735 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004736 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004737 if (Result.isNull())
4738 return QualType();
4739 }
John McCall550e0c22009-10-21 00:40:46 +00004740
4741 // Result might be dependent or not.
4742 if (isa<DependentSizedExtVectorType>(Result)) {
4743 DependentSizedExtVectorTypeLoc NewTL
4744 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4745 NewTL.setNameLoc(TL.getNameLoc());
4746 } else {
4747 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4748 NewTL.setNameLoc(TL.getNameLoc());
4749 }
4750
4751 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004752}
Mike Stump11289f42009-09-09 15:08:12 +00004753
4754template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004755QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004756 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004757 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004758 QualType ElementType = getDerived().TransformType(T->getElementType());
4759 if (ElementType.isNull())
4760 return QualType();
4761
John McCall550e0c22009-10-21 00:40:46 +00004762 QualType Result = TL.getType();
4763 if (getDerived().AlwaysRebuild() ||
4764 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004765 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004766 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004767 if (Result.isNull())
4768 return QualType();
4769 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004770
John McCall550e0c22009-10-21 00:40:46 +00004771 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4772 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004773
John McCall550e0c22009-10-21 00:40:46 +00004774 return Result;
4775}
4776
4777template<typename Derived>
4778QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004779 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004780 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004781 QualType ElementType = getDerived().TransformType(T->getElementType());
4782 if (ElementType.isNull())
4783 return QualType();
4784
4785 QualType Result = TL.getType();
4786 if (getDerived().AlwaysRebuild() ||
4787 ElementType != T->getElementType()) {
4788 Result = getDerived().RebuildExtVectorType(ElementType,
4789 T->getNumElements(),
4790 /*FIXME*/ SourceLocation());
4791 if (Result.isNull())
4792 return QualType();
4793 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004794
John McCall550e0c22009-10-21 00:40:46 +00004795 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4796 NewTL.setNameLoc(TL.getNameLoc());
4797
4798 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004799}
Mike Stump11289f42009-09-09 15:08:12 +00004800
David Blaikie05785d12013-02-20 22:23:23 +00004801template <typename Derived>
4802ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4803 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4804 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004805 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004806 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004807
Douglas Gregor715e4612011-01-14 22:40:04 +00004808 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004809 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004810 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004811 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004812 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004813
Douglas Gregor715e4612011-01-14 22:40:04 +00004814 TypeLocBuilder TLB;
4815 TypeLoc NewTL = OldDI->getTypeLoc();
4816 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004817
4818 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004819 OldExpansionTL.getPatternLoc());
4820 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004821 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004822
4823 Result = RebuildPackExpansionType(Result,
4824 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004825 OldExpansionTL.getEllipsisLoc(),
4826 NumExpansions);
4827 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004828 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004829
Douglas Gregor715e4612011-01-14 22:40:04 +00004830 PackExpansionTypeLoc NewExpansionTL
4831 = TLB.push<PackExpansionTypeLoc>(Result);
4832 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4833 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4834 } else
4835 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004836 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004837 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004838
John McCall8fb0d9d2011-05-01 22:35:37 +00004839 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004840 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004841
4842 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4843 OldParm->getDeclContext(),
4844 OldParm->getInnerLocStart(),
4845 OldParm->getLocation(),
4846 OldParm->getIdentifier(),
4847 NewDI->getType(),
4848 NewDI,
4849 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004850 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004851 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4852 OldParm->getFunctionScopeIndex() + indexAdjustment);
4853 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004854}
4855
David Majnemer59f77922016-06-24 04:05:48 +00004856template <typename Derived>
4857bool TreeTransform<Derived>::TransformFunctionTypeParams(
4858 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4859 const QualType *ParamTypes,
4860 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4861 SmallVectorImpl<QualType> &OutParamTypes,
4862 SmallVectorImpl<ParmVarDecl *> *PVars,
4863 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004864 int indexAdjustment = 0;
4865
David Majnemer59f77922016-06-24 04:05:48 +00004866 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004867 for (unsigned i = 0; i != NumParams; ++i) {
4868 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004869 assert(OldParm->getFunctionScopeIndex() == i);
4870
David Blaikie05785d12013-02-20 22:23:23 +00004871 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004872 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004873 if (OldParm->isParameterPack()) {
4874 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004875 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004876
Douglas Gregor5499af42011-01-05 23:12:31 +00004877 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004878 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004879 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004880 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4881 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004882 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4883
Douglas Gregor5499af42011-01-05 23:12:31 +00004884 // Determine whether we should expand the parameter packs.
4885 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004886 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004887 Optional<unsigned> OrigNumExpansions =
4888 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004889 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004890 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4891 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004892 Unexpanded,
4893 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004894 RetainExpansion,
4895 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004896 return true;
4897 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004898
Douglas Gregor5499af42011-01-05 23:12:31 +00004899 if (ShouldExpand) {
4900 // Expand the function parameter pack into multiple, separate
4901 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004902 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004903 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004904 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004905 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004906 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004907 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004908 OrigNumExpansions,
4909 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004910 if (!NewParm)
4911 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004912
John McCallc8e321d2016-03-01 02:09:25 +00004913 if (ParamInfos)
4914 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004915 OutParamTypes.push_back(NewParm->getType());
4916 if (PVars)
4917 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004918 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004919
4920 // If we're supposed to retain a pack expansion, do so by temporarily
4921 // forgetting the partially-substituted parameter pack.
4922 if (RetainExpansion) {
4923 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004924 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004925 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004926 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004927 OrigNumExpansions,
4928 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004929 if (!NewParm)
4930 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004931
John McCallc8e321d2016-03-01 02:09:25 +00004932 if (ParamInfos)
4933 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004934 OutParamTypes.push_back(NewParm->getType());
4935 if (PVars)
4936 PVars->push_back(NewParm);
4937 }
4938
John McCall8fb0d9d2011-05-01 22:35:37 +00004939 // The next parameter should have the same adjustment as the
4940 // last thing we pushed, but we post-incremented indexAdjustment
4941 // on every push. Also, if we push nothing, the adjustment should
4942 // go down by one.
4943 indexAdjustment--;
4944
Douglas Gregor5499af42011-01-05 23:12:31 +00004945 // We're done with the pack expansion.
4946 continue;
4947 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004948
4949 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004950 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004951 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4952 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004953 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004954 NumExpansions,
4955 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004956 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004957 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004958 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004959 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004960
John McCall58f10c32010-03-11 09:03:00 +00004961 if (!NewParm)
4962 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004963
John McCallc8e321d2016-03-01 02:09:25 +00004964 if (ParamInfos)
4965 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004966 OutParamTypes.push_back(NewParm->getType());
4967 if (PVars)
4968 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004969 continue;
4970 }
John McCall58f10c32010-03-11 09:03:00 +00004971
4972 // Deal with the possibility that we don't have a parameter
4973 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004974 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004975 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004976 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004977 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004978 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004979 = dyn_cast<PackExpansionType>(OldType)) {
4980 // We have a function parameter pack that may need to be expanded.
4981 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004982 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004983 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004984
Douglas Gregor5499af42011-01-05 23:12:31 +00004985 // Determine whether we should expand the parameter packs.
4986 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004987 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004988 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004989 Unexpanded,
4990 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004991 RetainExpansion,
4992 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004993 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004994 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004995
Douglas Gregor5499af42011-01-05 23:12:31 +00004996 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004997 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004998 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004999 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005000 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5001 QualType NewType = getDerived().TransformType(Pattern);
5002 if (NewType.isNull())
5003 return true;
John McCall58f10c32010-03-11 09:03:00 +00005004
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005005 if (NewType->containsUnexpandedParameterPack()) {
5006 NewType =
5007 getSema().getASTContext().getPackExpansionType(NewType, None);
5008
5009 if (NewType.isNull())
5010 return true;
5011 }
5012
John McCallc8e321d2016-03-01 02:09:25 +00005013 if (ParamInfos)
5014 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005015 OutParamTypes.push_back(NewType);
5016 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005017 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005019
Douglas Gregor5499af42011-01-05 23:12:31 +00005020 // We're done with the pack expansion.
5021 continue;
5022 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005023
Douglas Gregor48d24112011-01-10 20:53:55 +00005024 // If we're supposed to retain a pack expansion, do so by temporarily
5025 // forgetting the partially-substituted parameter pack.
5026 if (RetainExpansion) {
5027 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5028 QualType NewType = getDerived().TransformType(Pattern);
5029 if (NewType.isNull())
5030 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005031
John McCallc8e321d2016-03-01 02:09:25 +00005032 if (ParamInfos)
5033 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005034 OutParamTypes.push_back(NewType);
5035 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005036 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005037 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005038
Chad Rosier1dcde962012-08-08 18:46:20 +00005039 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005040 // expansion.
5041 OldType = Expansion->getPattern();
5042 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005043 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5044 NewType = getDerived().TransformType(OldType);
5045 } else {
5046 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005048
Douglas Gregor5499af42011-01-05 23:12:31 +00005049 if (NewType.isNull())
5050 return true;
5051
5052 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005053 NewType = getSema().Context.getPackExpansionType(NewType,
5054 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005055
John McCallc8e321d2016-03-01 02:09:25 +00005056 if (ParamInfos)
5057 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005058 OutParamTypes.push_back(NewType);
5059 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005060 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005061 }
5062
John McCall8fb0d9d2011-05-01 22:35:37 +00005063#ifndef NDEBUG
5064 if (PVars) {
5065 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5066 if (ParmVarDecl *parm = (*PVars)[i])
5067 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005068 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005069#endif
5070
5071 return false;
5072}
John McCall58f10c32010-03-11 09:03:00 +00005073
5074template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005075QualType
John McCall550e0c22009-10-21 00:40:46 +00005076TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005077 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005078 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005079 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005080 return getDerived().TransformFunctionProtoType(
5081 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005082 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5083 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5084 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005085 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005086}
5087
Richard Smith2e321552014-11-12 02:00:47 +00005088template<typename Derived> template<typename Fn>
5089QualType TreeTransform<Derived>::TransformFunctionProtoType(
5090 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5091 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005092
Douglas Gregor4afc2362010-08-31 00:26:14 +00005093 // Transform the parameters and return type.
5094 //
Richard Smithf623c962012-04-17 00:58:00 +00005095 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005096 // When the function has a trailing return type, we instantiate the
5097 // parameters before the return type, since the return type can then refer
5098 // to the parameters themselves (via decltype, sizeof, etc.).
5099 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005100 SmallVector<QualType, 4> ParamTypes;
5101 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005102 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005103 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005104
Douglas Gregor7fb25412010-10-01 18:44:50 +00005105 QualType ResultType;
5106
Richard Smith1226c602012-08-14 22:51:13 +00005107 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005108 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005109 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005110 TL.getTypePtr()->param_type_begin(),
5111 T->getExtParameterInfosOrNull(),
5112 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005113 return QualType();
5114
Douglas Gregor3024f072012-04-16 07:05:22 +00005115 {
5116 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005117 // If a declaration declares a member function or member function
5118 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005119 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005120 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005121 // declarator.
5122 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005123
Alp Toker42a16a62014-01-25 23:51:36 +00005124 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005125 if (ResultType.isNull())
5126 return QualType();
5127 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005128 }
5129 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005130 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005131 if (ResultType.isNull())
5132 return QualType();
5133
Alp Toker9cacbab2014-01-20 20:26:09 +00005134 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005135 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005136 TL.getTypePtr()->param_type_begin(),
5137 T->getExtParameterInfosOrNull(),
5138 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005139 return QualType();
5140 }
5141
Richard Smith2e321552014-11-12 02:00:47 +00005142 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5143
5144 bool EPIChanged = false;
5145 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5146 return QualType();
5147
John McCallc8e321d2016-03-01 02:09:25 +00005148 // Handle extended parameter information.
5149 if (auto NewExtParamInfos =
5150 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5151 if (!EPI.ExtParameterInfos ||
5152 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5153 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5154 EPIChanged = true;
5155 }
5156 EPI.ExtParameterInfos = NewExtParamInfos;
5157 } else if (EPI.ExtParameterInfos) {
5158 EPIChanged = true;
5159 EPI.ExtParameterInfos = nullptr;
5160 }
Richard Smithf623c962012-04-17 00:58:00 +00005161
John McCall550e0c22009-10-21 00:40:46 +00005162 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005163 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005164 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005165 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005166 if (Result.isNull())
5167 return QualType();
5168 }
Mike Stump11289f42009-09-09 15:08:12 +00005169
John McCall550e0c22009-10-21 00:40:46 +00005170 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005171 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005172 NewTL.setLParenLoc(TL.getLParenLoc());
5173 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005174 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005175 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005176 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5177 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005178
5179 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005180}
Mike Stump11289f42009-09-09 15:08:12 +00005181
Douglas Gregord6ff3322009-08-04 16:50:30 +00005182template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005183bool TreeTransform<Derived>::TransformExceptionSpec(
5184 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5185 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5186 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5187
5188 // Instantiate a dynamic noexcept expression, if any.
5189 if (ESI.Type == EST_ComputedNoexcept) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005190 EnterExpressionEvaluationContext Unevaluated(
5191 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005192 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5193 if (NoexceptExpr.isInvalid())
5194 return true;
5195
Richard Smith03a4aa32016-06-23 19:02:52 +00005196 // FIXME: This is bogus, a noexcept expression is not a condition.
5197 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005198 if (NoexceptExpr.isInvalid())
5199 return true;
5200
5201 if (!NoexceptExpr.get()->isValueDependent()) {
5202 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5203 NoexceptExpr.get(), nullptr,
5204 diag::err_noexcept_needs_constant_expression,
5205 /*AllowFold*/false);
5206 if (NoexceptExpr.isInvalid())
5207 return true;
5208 }
5209
5210 if (ESI.NoexceptExpr != NoexceptExpr.get())
5211 Changed = true;
5212 ESI.NoexceptExpr = NoexceptExpr.get();
5213 }
5214
5215 if (ESI.Type != EST_Dynamic)
5216 return false;
5217
5218 // Instantiate a dynamic exception specification's type.
5219 for (QualType T : ESI.Exceptions) {
5220 if (const PackExpansionType *PackExpansion =
5221 T->getAs<PackExpansionType>()) {
5222 Changed = true;
5223
5224 // We have a pack expansion. Instantiate it.
5225 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5226 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5227 Unexpanded);
5228 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5229
5230 // Determine whether the set of unexpanded parameter packs can and
5231 // should
5232 // be expanded.
5233 bool Expand = false;
5234 bool RetainExpansion = false;
5235 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5236 // FIXME: Track the location of the ellipsis (and track source location
5237 // information for the types in the exception specification in general).
5238 if (getDerived().TryExpandParameterPacks(
5239 Loc, SourceRange(), Unexpanded, Expand,
5240 RetainExpansion, NumExpansions))
5241 return true;
5242
5243 if (!Expand) {
5244 // We can't expand this pack expansion into separate arguments yet;
5245 // just substitute into the pattern and create a new pack expansion
5246 // type.
5247 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5248 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5249 if (U.isNull())
5250 return true;
5251
5252 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5253 Exceptions.push_back(U);
5254 continue;
5255 }
5256
5257 // Substitute into the pack expansion pattern for each slice of the
5258 // pack.
5259 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5260 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5261
5262 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5263 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5264 return true;
5265
5266 Exceptions.push_back(U);
5267 }
5268 } else {
5269 QualType U = getDerived().TransformType(T);
5270 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5271 return true;
5272 if (T != U)
5273 Changed = true;
5274
5275 Exceptions.push_back(U);
5276 }
5277 }
5278
5279 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005280 if (ESI.Exceptions.empty())
5281 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005282 return false;
5283}
5284
5285template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005286QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005287 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005288 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005289 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005290 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005291 if (ResultType.isNull())
5292 return QualType();
5293
5294 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005295 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005296 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5297
5298 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005299 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005300 NewTL.setLParenLoc(TL.getLParenLoc());
5301 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005302 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005303
5304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005305}
Mike Stump11289f42009-09-09 15:08:12 +00005306
John McCallb96ec562009-12-04 22:46:56 +00005307template<typename Derived> QualType
5308TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005309 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005310 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005311 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005312 if (!D)
5313 return QualType();
5314
5315 QualType Result = TL.getType();
5316 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005317 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005318 if (Result.isNull())
5319 return QualType();
5320 }
5321
5322 // We might get an arbitrary type spec type back. We should at
5323 // least always get a type spec type, though.
5324 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5325 NewTL.setNameLoc(TL.getNameLoc());
5326
5327 return Result;
5328}
5329
Douglas Gregord6ff3322009-08-04 16:50:30 +00005330template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005331QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005332 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005333 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005334 TypedefNameDecl *Typedef
5335 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5336 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 if (!Typedef)
5338 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall550e0c22009-10-21 00:40:46 +00005340 QualType Result = TL.getType();
5341 if (getDerived().AlwaysRebuild() ||
5342 Typedef != T->getDecl()) {
5343 Result = getDerived().RebuildTypedefType(Typedef);
5344 if (Result.isNull())
5345 return QualType();
5346 }
Mike Stump11289f42009-09-09 15:08:12 +00005347
John McCall550e0c22009-10-21 00:40:46 +00005348 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5349 NewTL.setNameLoc(TL.getNameLoc());
5350
5351 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005352}
Mike Stump11289f42009-09-09 15:08:12 +00005353
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005355QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005356 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005357 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005358 EnterExpressionEvaluationContext Unevaluated(
5359 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5360 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005361
John McCalldadc5752010-08-24 06:29:42 +00005362 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005363 if (E.isInvalid())
5364 return QualType();
5365
Eli Friedmane4f22df2012-02-29 04:03:55 +00005366 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5367 if (E.isInvalid())
5368 return QualType();
5369
John McCall550e0c22009-10-21 00:40:46 +00005370 QualType Result = TL.getType();
5371 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005372 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005373 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005374 if (Result.isNull())
5375 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005376 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005377 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005378
John McCall550e0c22009-10-21 00:40:46 +00005379 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005380 NewTL.setTypeofLoc(TL.getTypeofLoc());
5381 NewTL.setLParenLoc(TL.getLParenLoc());
5382 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005383
5384 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005385}
Mike Stump11289f42009-09-09 15:08:12 +00005386
5387template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005388QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005389 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005390 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5391 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5392 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005393 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005394
John McCall550e0c22009-10-21 00:40:46 +00005395 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005396 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5397 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005398 if (Result.isNull())
5399 return QualType();
5400 }
Mike Stump11289f42009-09-09 15:08:12 +00005401
John McCall550e0c22009-10-21 00:40:46 +00005402 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005403 NewTL.setTypeofLoc(TL.getTypeofLoc());
5404 NewTL.setLParenLoc(TL.getLParenLoc());
5405 NewTL.setRParenLoc(TL.getRParenLoc());
5406 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005407
5408 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005409}
Mike Stump11289f42009-09-09 15:08:12 +00005410
5411template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005412QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005413 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005414 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005415
Douglas Gregore922c772009-08-04 22:27:00 +00005416 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005417 EnterExpressionEvaluationContext Unevaluated(
5418 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5419 /*IsDecltype=*/true);
Mike Stump11289f42009-09-09 15:08:12 +00005420
John McCalldadc5752010-08-24 06:29:42 +00005421 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005422 if (E.isInvalid())
5423 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005424
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005425 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005426 if (E.isInvalid())
5427 return QualType();
5428
John McCall550e0c22009-10-21 00:40:46 +00005429 QualType Result = TL.getType();
5430 if (getDerived().AlwaysRebuild() ||
5431 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005432 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005433 if (Result.isNull())
5434 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005435 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005436 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005437
John McCall550e0c22009-10-21 00:40:46 +00005438 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5439 NewTL.setNameLoc(TL.getNameLoc());
5440
5441 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005442}
5443
5444template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005445QualType TreeTransform<Derived>::TransformUnaryTransformType(
5446 TypeLocBuilder &TLB,
5447 UnaryTransformTypeLoc TL) {
5448 QualType Result = TL.getType();
5449 if (Result->isDependentType()) {
5450 const UnaryTransformType *T = TL.getTypePtr();
5451 QualType NewBase =
5452 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5453 Result = getDerived().RebuildUnaryTransformType(NewBase,
5454 T->getUTTKind(),
5455 TL.getKWLoc());
5456 if (Result.isNull())
5457 return QualType();
5458 }
5459
5460 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5461 NewTL.setKWLoc(TL.getKWLoc());
5462 NewTL.setParensRange(TL.getParensRange());
5463 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5464 return Result;
5465}
5466
5467template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005468QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5469 AutoTypeLoc TL) {
5470 const AutoType *T = TL.getTypePtr();
5471 QualType OldDeduced = T->getDeducedType();
5472 QualType NewDeduced;
5473 if (!OldDeduced.isNull()) {
5474 NewDeduced = getDerived().TransformType(OldDeduced);
5475 if (NewDeduced.isNull())
5476 return QualType();
5477 }
5478
5479 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005480 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5481 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005482 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005483 if (Result.isNull())
5484 return QualType();
5485 }
5486
5487 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5488 NewTL.setNameLoc(TL.getNameLoc());
5489
5490 return Result;
5491}
5492
5493template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005494QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5495 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5496 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5497
5498 CXXScopeSpec SS;
5499 TemplateName TemplateName = getDerived().TransformTemplateName(
5500 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5501 if (TemplateName.isNull())
5502 return QualType();
5503
5504 QualType OldDeduced = T->getDeducedType();
5505 QualType NewDeduced;
5506 if (!OldDeduced.isNull()) {
5507 NewDeduced = getDerived().TransformType(OldDeduced);
5508 if (NewDeduced.isNull())
5509 return QualType();
5510 }
5511
5512 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5513 TemplateName, NewDeduced);
5514 if (Result.isNull())
5515 return QualType();
5516
5517 DeducedTemplateSpecializationTypeLoc NewTL =
5518 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5519 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5520
5521 return Result;
5522}
5523
5524template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005525QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005526 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005527 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005528 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005529 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5530 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005531 if (!Record)
5532 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005533
John McCall550e0c22009-10-21 00:40:46 +00005534 QualType Result = TL.getType();
5535 if (getDerived().AlwaysRebuild() ||
5536 Record != T->getDecl()) {
5537 Result = getDerived().RebuildRecordType(Record);
5538 if (Result.isNull())
5539 return QualType();
5540 }
Mike Stump11289f42009-09-09 15:08:12 +00005541
John McCall550e0c22009-10-21 00:40:46 +00005542 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5543 NewTL.setNameLoc(TL.getNameLoc());
5544
5545 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
5548template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005549QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005550 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005551 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005552 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005553 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5554 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005555 if (!Enum)
5556 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005557
John McCall550e0c22009-10-21 00:40:46 +00005558 QualType Result = TL.getType();
5559 if (getDerived().AlwaysRebuild() ||
5560 Enum != T->getDecl()) {
5561 Result = getDerived().RebuildEnumType(Enum);
5562 if (Result.isNull())
5563 return QualType();
5564 }
Mike Stump11289f42009-09-09 15:08:12 +00005565
John McCall550e0c22009-10-21 00:40:46 +00005566 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5567 NewTL.setNameLoc(TL.getNameLoc());
5568
5569 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570}
John McCallfcc33b02009-09-05 00:15:47 +00005571
John McCalle78aac42010-03-10 03:28:59 +00005572template<typename Derived>
5573QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5574 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005575 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005576 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5577 TL.getTypePtr()->getDecl());
5578 if (!D) return QualType();
5579
5580 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5581 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5582 return T;
5583}
5584
Douglas Gregord6ff3322009-08-04 16:50:30 +00005585template<typename Derived>
5586QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005587 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005588 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005589 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005590}
5591
Mike Stump11289f42009-09-09 15:08:12 +00005592template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005593QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005594 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005595 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005596 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005597
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005598 // Substitute into the replacement type, which itself might involve something
5599 // that needs to be transformed. This only tends to occur with default
5600 // template arguments of template template parameters.
5601 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5602 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5603 if (Replacement.isNull())
5604 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005605
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005606 // Always canonicalize the replacement type.
5607 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5608 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005609 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005610 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005611
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005612 // Propagate type-source information.
5613 SubstTemplateTypeParmTypeLoc NewTL
5614 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5615 NewTL.setNameLoc(TL.getNameLoc());
5616 return Result;
5617
John McCallcebee162009-10-18 09:09:24 +00005618}
5619
5620template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005621QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5622 TypeLocBuilder &TLB,
5623 SubstTemplateTypeParmPackTypeLoc TL) {
5624 return TransformTypeSpecType(TLB, TL);
5625}
5626
5627template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005628QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005629 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005630 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005631 const TemplateSpecializationType *T = TL.getTypePtr();
5632
Douglas Gregordf846d12011-03-02 18:46:51 +00005633 // The nested-name-specifier never matters in a TemplateSpecializationType,
5634 // because we can't have a dependent nested-name-specifier anyway.
5635 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005636 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005637 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5638 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005639 if (Template.isNull())
5640 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005641
John McCall31f82722010-11-12 08:19:04 +00005642 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5643}
5644
Eli Friedman0dfb8892011-10-06 23:00:33 +00005645template<typename Derived>
5646QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5647 AtomicTypeLoc TL) {
5648 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5649 if (ValueType.isNull())
5650 return QualType();
5651
5652 QualType Result = TL.getType();
5653 if (getDerived().AlwaysRebuild() ||
5654 ValueType != TL.getValueLoc().getType()) {
5655 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5656 if (Result.isNull())
5657 return QualType();
5658 }
5659
5660 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5661 NewTL.setKWLoc(TL.getKWLoc());
5662 NewTL.setLParenLoc(TL.getLParenLoc());
5663 NewTL.setRParenLoc(TL.getRParenLoc());
5664
5665 return Result;
5666}
5667
Xiuli Pan9c14e282016-01-09 12:53:17 +00005668template <typename Derived>
5669QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5670 PipeTypeLoc TL) {
5671 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5672 if (ValueType.isNull())
5673 return QualType();
5674
5675 QualType Result = TL.getType();
5676 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005677 const PipeType *PT = Result->getAs<PipeType>();
5678 bool isReadPipe = PT->isReadOnly();
5679 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005680 if (Result.isNull())
5681 return QualType();
5682 }
5683
5684 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5685 NewTL.setKWLoc(TL.getKWLoc());
5686
5687 return Result;
5688}
5689
Chad Rosier1dcde962012-08-08 18:46:20 +00005690 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005691 /// container that provides a \c getArgLoc() member function.
5692 ///
5693 /// This iterator is intended to be used with the iterator form of
5694 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5695 template<typename ArgLocContainer>
5696 class TemplateArgumentLocContainerIterator {
5697 ArgLocContainer *Container;
5698 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005699
Douglas Gregorfe921a72010-12-20 23:36:19 +00005700 public:
5701 typedef TemplateArgumentLoc value_type;
5702 typedef TemplateArgumentLoc reference;
5703 typedef int difference_type;
5704 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005705
Douglas Gregorfe921a72010-12-20 23:36:19 +00005706 class pointer {
5707 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005708
Douglas Gregorfe921a72010-12-20 23:36:19 +00005709 public:
5710 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005711
Douglas Gregorfe921a72010-12-20 23:36:19 +00005712 const TemplateArgumentLoc *operator->() const {
5713 return &Arg;
5714 }
5715 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005716
5717
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005718 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005719
Douglas Gregorfe921a72010-12-20 23:36:19 +00005720 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5721 unsigned Index)
5722 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Douglas Gregorfe921a72010-12-20 23:36:19 +00005724 TemplateArgumentLocContainerIterator &operator++() {
5725 ++Index;
5726 return *this;
5727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005728
Douglas Gregorfe921a72010-12-20 23:36:19 +00005729 TemplateArgumentLocContainerIterator operator++(int) {
5730 TemplateArgumentLocContainerIterator Old(*this);
5731 ++(*this);
5732 return Old;
5733 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
Douglas Gregorfe921a72010-12-20 23:36:19 +00005735 TemplateArgumentLoc operator*() const {
5736 return Container->getArgLoc(Index);
5737 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005738
Douglas Gregorfe921a72010-12-20 23:36:19 +00005739 pointer operator->() const {
5740 return pointer(Container->getArgLoc(Index));
5741 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005742
Douglas Gregorfe921a72010-12-20 23:36:19 +00005743 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005744 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005745 return X.Container == Y.Container && X.Index == Y.Index;
5746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005747
Douglas Gregorfe921a72010-12-20 23:36:19 +00005748 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005749 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005750 return !(X == Y);
5751 }
5752 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005753
5754
John McCall31f82722010-11-12 08:19:04 +00005755template <typename Derived>
5756QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5757 TypeLocBuilder &TLB,
5758 TemplateSpecializationTypeLoc TL,
5759 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005760 TemplateArgumentListInfo NewTemplateArgs;
5761 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5762 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005763 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5764 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005765 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005766 ArgIterator(TL, TL.getNumArgs()),
5767 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005768 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005769
John McCall0ad16662009-10-29 08:12:44 +00005770 // FIXME: maybe don't rebuild if all the template arguments are the same.
5771
5772 QualType Result =
5773 getDerived().RebuildTemplateSpecializationType(Template,
5774 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005775 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005776
5777 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005778 // Specializations of template template parameters are represented as
5779 // TemplateSpecializationTypes, and substitution of type alias templates
5780 // within a dependent context can transform them into
5781 // DependentTemplateSpecializationTypes.
5782 if (isa<DependentTemplateSpecializationType>(Result)) {
5783 DependentTemplateSpecializationTypeLoc NewTL
5784 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005785 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005786 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005787 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005788 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005789 NewTL.setLAngleLoc(TL.getLAngleLoc());
5790 NewTL.setRAngleLoc(TL.getRAngleLoc());
5791 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5792 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5793 return Result;
5794 }
5795
John McCall0ad16662009-10-29 08:12:44 +00005796 TemplateSpecializationTypeLoc NewTL
5797 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005798 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005799 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5800 NewTL.setLAngleLoc(TL.getLAngleLoc());
5801 NewTL.setRAngleLoc(TL.getRAngleLoc());
5802 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5803 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005804 }
Mike Stump11289f42009-09-09 15:08:12 +00005805
John McCall0ad16662009-10-29 08:12:44 +00005806 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005807}
Mike Stump11289f42009-09-09 15:08:12 +00005808
Douglas Gregor5a064722011-02-28 17:23:35 +00005809template <typename Derived>
5810QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5811 TypeLocBuilder &TLB,
5812 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005813 TemplateName Template,
5814 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005815 TemplateArgumentListInfo NewTemplateArgs;
5816 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5817 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5818 typedef TemplateArgumentLocContainerIterator<
5819 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005820 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005821 ArgIterator(TL, TL.getNumArgs()),
5822 NewTemplateArgs))
5823 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005824
Douglas Gregor5a064722011-02-28 17:23:35 +00005825 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
Douglas Gregor5a064722011-02-28 17:23:35 +00005827 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5828 QualType Result
5829 = getSema().Context.getDependentTemplateSpecializationType(
5830 TL.getTypePtr()->getKeyword(),
5831 DTN->getQualifier(),
5832 DTN->getIdentifier(),
5833 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005834
Douglas Gregor5a064722011-02-28 17:23:35 +00005835 DependentTemplateSpecializationTypeLoc NewTL
5836 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005837 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005838 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005839 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005840 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005841 NewTL.setLAngleLoc(TL.getLAngleLoc());
5842 NewTL.setRAngleLoc(TL.getRAngleLoc());
5843 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5844 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5845 return Result;
5846 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005847
5848 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005849 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005850 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005851 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Douglas Gregor5a064722011-02-28 17:23:35 +00005853 if (!Result.isNull()) {
5854 /// FIXME: Wrap this in an elaborated-type-specifier?
5855 TemplateSpecializationTypeLoc NewTL
5856 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005857 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005858 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005859 NewTL.setLAngleLoc(TL.getLAngleLoc());
5860 NewTL.setRAngleLoc(TL.getRAngleLoc());
5861 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5862 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5863 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005864
Douglas Gregor5a064722011-02-28 17:23:35 +00005865 return Result;
5866}
5867
Mike Stump11289f42009-09-09 15:08:12 +00005868template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005869QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005870TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005871 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005872 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005873
Douglas Gregor844cb502011-03-01 18:12:44 +00005874 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005875 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005876 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005877 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005878 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5879 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005880 return QualType();
5881 }
Mike Stump11289f42009-09-09 15:08:12 +00005882
John McCall31f82722010-11-12 08:19:04 +00005883 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5884 if (NamedT.isNull())
5885 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005886
Richard Smith3f1b5d02011-05-05 21:57:07 +00005887 // C++0x [dcl.type.elab]p2:
5888 // If the identifier resolves to a typedef-name or the simple-template-id
5889 // resolves to an alias template specialization, the
5890 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005891 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5892 if (const TemplateSpecializationType *TST =
5893 NamedT->getAs<TemplateSpecializationType>()) {
5894 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005895 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5896 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005897 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005898 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005899 << TAT << Sema::NTK_TypeAliasTemplate
5900 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005901 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5902 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005903 }
5904 }
5905
John McCall550e0c22009-10-21 00:40:46 +00005906 QualType Result = TL.getType();
5907 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005908 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005909 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005910 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005911 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005912 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005913 if (Result.isNull())
5914 return QualType();
5915 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005916
Abramo Bagnara6150c882010-05-11 21:36:43 +00005917 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005918 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005919 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005920 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005921}
Mike Stump11289f42009-09-09 15:08:12 +00005922
5923template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005924QualType TreeTransform<Derived>::TransformAttributedType(
5925 TypeLocBuilder &TLB,
5926 AttributedTypeLoc TL) {
5927 const AttributedType *oldType = TL.getTypePtr();
5928 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5929 if (modifiedType.isNull())
5930 return QualType();
5931
5932 QualType result = TL.getType();
5933
5934 // FIXME: dependent operand expressions?
5935 if (getDerived().AlwaysRebuild() ||
5936 modifiedType != oldType->getModifiedType()) {
5937 // TODO: this is really lame; we should really be rebuilding the
5938 // equivalent type from first principles.
5939 QualType equivalentType
5940 = getDerived().TransformType(oldType->getEquivalentType());
5941 if (equivalentType.isNull())
5942 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005943
5944 // Check whether we can add nullability; it is only represented as
5945 // type sugar, and therefore cannot be diagnosed in any other way.
5946 if (auto nullability = oldType->getImmediateNullability()) {
5947 if (!modifiedType->canHaveNullability()) {
5948 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005949 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005950 return QualType();
5951 }
5952 }
5953
John McCall81904512011-01-06 01:58:22 +00005954 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5955 modifiedType,
5956 equivalentType);
5957 }
5958
5959 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5960 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5961 if (TL.hasAttrOperand())
5962 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5963 if (TL.hasAttrExprOperand())
5964 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5965 else if (TL.hasAttrEnumOperand())
5966 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5967
5968 return result;
5969}
5970
5971template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005972QualType
5973TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5974 ParenTypeLoc TL) {
5975 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5976 if (Inner.isNull())
5977 return QualType();
5978
5979 QualType Result = TL.getType();
5980 if (getDerived().AlwaysRebuild() ||
5981 Inner != TL.getInnerLoc().getType()) {
5982 Result = getDerived().RebuildParenType(Inner);
5983 if (Result.isNull())
5984 return QualType();
5985 }
5986
5987 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5988 NewTL.setLParenLoc(TL.getLParenLoc());
5989 NewTL.setRParenLoc(TL.getRParenLoc());
5990 return Result;
5991}
5992
5993template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00005994QualType TreeTransform<Derived>::TransformDependentNameType(
5995 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
5996 return TransformDependentNameType(TLB, TL, false);
5997}
5998
5999template<typename Derived>
6000QualType TreeTransform<Derived>::TransformDependentNameType(
6001 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006002 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006003
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006004 NestedNameSpecifierLoc QualifierLoc
6005 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6006 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006007 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006008
John McCallc392f372010-06-11 00:33:02 +00006009 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006010 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006011 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006012 QualifierLoc,
6013 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006014 TL.getNameLoc(),
6015 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006016 if (Result.isNull())
6017 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006018
Abramo Bagnarad7548482010-05-19 21:37:53 +00006019 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6020 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006021 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6022
Abramo Bagnarad7548482010-05-19 21:37:53 +00006023 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006024 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006025 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006026 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006027 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006028 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006029 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006030 NewTL.setNameLoc(TL.getNameLoc());
6031 }
John McCall550e0c22009-10-21 00:40:46 +00006032 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregord6ff3322009-08-04 16:50:30 +00006035template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006036QualType TreeTransform<Derived>::
6037 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006038 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006039 NestedNameSpecifierLoc QualifierLoc;
6040 if (TL.getQualifierLoc()) {
6041 QualifierLoc
6042 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6043 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006044 return QualType();
6045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006046
John McCall31f82722010-11-12 08:19:04 +00006047 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006048 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006049}
6050
6051template<typename Derived>
6052QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006053TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6054 DependentTemplateSpecializationTypeLoc TL,
6055 NestedNameSpecifierLoc QualifierLoc) {
6056 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006057
Douglas Gregora7a795b2011-03-01 20:11:18 +00006058 TemplateArgumentListInfo NewTemplateArgs;
6059 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6060 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006061
Douglas Gregora7a795b2011-03-01 20:11:18 +00006062 typedef TemplateArgumentLocContainerIterator<
6063 DependentTemplateSpecializationTypeLoc> ArgIterator;
6064 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6065 ArgIterator(TL, TL.getNumArgs()),
6066 NewTemplateArgs))
6067 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006068
Richard Smithfd3dae02017-01-20 00:20:39 +00006069 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6070 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6071 TL.getTemplateNameLoc(), NewTemplateArgs,
6072 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006073 if (Result.isNull())
6074 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006075
Douglas Gregora7a795b2011-03-01 20:11:18 +00006076 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6077 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006078
Douglas Gregora7a795b2011-03-01 20:11:18 +00006079 // Copy information relevant to the template specialization.
6080 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006081 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006082 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006083 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006084 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6085 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006086 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006087 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006088
Douglas Gregora7a795b2011-03-01 20:11:18 +00006089 // Copy information relevant to the elaborated type.
6090 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006091 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006092 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006093 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6094 DependentTemplateSpecializationTypeLoc SpecTL
6095 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006096 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006097 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006098 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006099 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006100 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6101 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006102 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006103 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006104 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006105 TemplateSpecializationTypeLoc SpecTL
6106 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006107 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006108 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006109 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6110 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006111 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006112 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006113 }
6114 return Result;
6115}
6116
6117template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006118QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6119 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006120 QualType Pattern
6121 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006122 if (Pattern.isNull())
6123 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006124
6125 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006126 if (getDerived().AlwaysRebuild() ||
6127 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006128 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006129 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006130 TL.getEllipsisLoc(),
6131 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006132 if (Result.isNull())
6133 return QualType();
6134 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006135
Douglas Gregor822d0302011-01-12 17:07:58 +00006136 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6137 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6138 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006139}
6140
6141template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006142QualType
6143TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006144 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006145 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006146 TLB.pushFullCopy(TL);
6147 return TL.getType();
6148}
6149
6150template<typename Derived>
6151QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006152TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6153 ObjCTypeParamTypeLoc TL) {
6154 const ObjCTypeParamType *T = TL.getTypePtr();
6155 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6156 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6157 if (!OTP)
6158 return QualType();
6159
6160 QualType Result = TL.getType();
6161 if (getDerived().AlwaysRebuild() ||
6162 OTP != T->getDecl()) {
6163 Result = getDerived().RebuildObjCTypeParamType(OTP,
6164 TL.getProtocolLAngleLoc(),
6165 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6166 TL.getNumProtocols()),
6167 TL.getProtocolLocs(),
6168 TL.getProtocolRAngleLoc());
6169 if (Result.isNull())
6170 return QualType();
6171 }
6172
6173 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6174 if (TL.getNumProtocols()) {
6175 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6176 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6177 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6178 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6179 }
6180 return Result;
6181}
6182
6183template<typename Derived>
6184QualType
John McCall8b07ec22010-05-15 11:32:37 +00006185TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006186 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006187 // Transform base type.
6188 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6189 if (BaseType.isNull())
6190 return QualType();
6191
6192 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6193
6194 // Transform type arguments.
6195 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6196 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6197 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6198 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6199 QualType TypeArg = TypeArgInfo->getType();
6200 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6201 AnyChanged = true;
6202
6203 // We have a pack expansion. Instantiate it.
6204 const auto *PackExpansion = PackExpansionLoc.getType()
6205 ->castAs<PackExpansionType>();
6206 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6207 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6208 Unexpanded);
6209 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6210
6211 // Determine whether the set of unexpanded parameter packs can
6212 // and should be expanded.
6213 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6214 bool Expand = false;
6215 bool RetainExpansion = false;
6216 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6217 if (getDerived().TryExpandParameterPacks(
6218 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6219 Unexpanded, Expand, RetainExpansion, NumExpansions))
6220 return QualType();
6221
6222 if (!Expand) {
6223 // We can't expand this pack expansion into separate arguments yet;
6224 // just substitute into the pattern and create a new pack expansion
6225 // type.
6226 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6227
6228 TypeLocBuilder TypeArgBuilder;
6229 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6230 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6231 PatternLoc);
6232 if (NewPatternType.isNull())
6233 return QualType();
6234
6235 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6236 NewPatternType, NumExpansions);
6237 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6238 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6239 NewTypeArgInfos.push_back(
6240 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6241 continue;
6242 }
6243
6244 // Substitute into the pack expansion pattern for each slice of the
6245 // pack.
6246 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6247 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6248
6249 TypeLocBuilder TypeArgBuilder;
6250 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6251
6252 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6253 PatternLoc);
6254 if (NewTypeArg.isNull())
6255 return QualType();
6256
6257 NewTypeArgInfos.push_back(
6258 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6259 }
6260
6261 continue;
6262 }
6263
6264 TypeLocBuilder TypeArgBuilder;
6265 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6266 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6267 if (NewTypeArg.isNull())
6268 return QualType();
6269
6270 // If nothing changed, just keep the old TypeSourceInfo.
6271 if (NewTypeArg == TypeArg) {
6272 NewTypeArgInfos.push_back(TypeArgInfo);
6273 continue;
6274 }
6275
6276 NewTypeArgInfos.push_back(
6277 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6278 AnyChanged = true;
6279 }
6280
6281 QualType Result = TL.getType();
6282 if (getDerived().AlwaysRebuild() || AnyChanged) {
6283 // Rebuild the type.
6284 Result = getDerived().RebuildObjCObjectType(
6285 BaseType,
6286 TL.getLocStart(),
6287 TL.getTypeArgsLAngleLoc(),
6288 NewTypeArgInfos,
6289 TL.getTypeArgsRAngleLoc(),
6290 TL.getProtocolLAngleLoc(),
6291 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6292 TL.getNumProtocols()),
6293 TL.getProtocolLocs(),
6294 TL.getProtocolRAngleLoc());
6295
6296 if (Result.isNull())
6297 return QualType();
6298 }
6299
6300 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006301 NewT.setHasBaseTypeAsWritten(true);
6302 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6303 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6304 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6305 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6306 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6307 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6308 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6309 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6310 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006311}
Mike Stump11289f42009-09-09 15:08:12 +00006312
6313template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006314QualType
6315TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006316 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006317 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6318 if (PointeeType.isNull())
6319 return QualType();
6320
6321 QualType Result = TL.getType();
6322 if (getDerived().AlwaysRebuild() ||
6323 PointeeType != TL.getPointeeLoc().getType()) {
6324 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6325 TL.getStarLoc());
6326 if (Result.isNull())
6327 return QualType();
6328 }
6329
6330 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6331 NewT.setStarLoc(TL.getStarLoc());
6332 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006333}
6334
Douglas Gregord6ff3322009-08-04 16:50:30 +00006335//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006336// Statement transformation
6337//===----------------------------------------------------------------------===//
6338template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006339StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006340TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006341 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006342}
6343
6344template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006345StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006346TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6347 return getDerived().TransformCompoundStmt(S, false);
6348}
6349
6350template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006351StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006352TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006353 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006354 Sema::CompoundScopeRAII CompoundScope(getSema());
6355
John McCall1ababa62010-08-27 19:56:05 +00006356 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006357 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006358 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006359 for (auto *B : S->body()) {
6360 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006361 if (Result.isInvalid()) {
6362 // Immediately fail if this was a DeclStmt, since it's very
6363 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006364 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006365 return StmtError();
6366
6367 // Otherwise, just keep processing substatements and fail later.
6368 SubStmtInvalid = true;
6369 continue;
6370 }
Mike Stump11289f42009-09-09 15:08:12 +00006371
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006372 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006373 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006374 }
Mike Stump11289f42009-09-09 15:08:12 +00006375
John McCall1ababa62010-08-27 19:56:05 +00006376 if (SubStmtInvalid)
6377 return StmtError();
6378
Douglas Gregorebe10102009-08-20 07:17:43 +00006379 if (!getDerived().AlwaysRebuild() &&
6380 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006381 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006382
6383 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006384 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006385 S->getRBracLoc(),
6386 IsStmtExpr);
6387}
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregorebe10102009-08-20 07:17:43 +00006389template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006390StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006391TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006392 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006393 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006394 EnterExpressionEvaluationContext Unevaluated(
6395 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006396
Eli Friedman06577382009-11-19 03:14:00 +00006397 // Transform the left-hand case value.
6398 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006399 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006400 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006401 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006402
Eli Friedman06577382009-11-19 03:14:00 +00006403 // Transform the right-hand case value (for the GNU case-range extension).
6404 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006405 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006406 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006407 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006408 }
Mike Stump11289f42009-09-09 15:08:12 +00006409
Douglas Gregorebe10102009-08-20 07:17:43 +00006410 // Build the case statement.
6411 // Case statements are always rebuilt so that they will attached to their
6412 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006413 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006414 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006415 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006416 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006417 S->getColonLoc());
6418 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006420
Douglas Gregorebe10102009-08-20 07:17:43 +00006421 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006422 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006423 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006424 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006425
Douglas Gregorebe10102009-08-20 07:17:43 +00006426 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006427 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006428}
6429
6430template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006431StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006432TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006434 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006436 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006437
Douglas Gregorebe10102009-08-20 07:17:43 +00006438 // Default statements are always rebuilt
6439 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006440 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006441}
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregorebe10102009-08-20 07:17:43 +00006443template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006444StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006445TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006446 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006447 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006448 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006449
Chris Lattnercab02a62011-02-17 20:34:02 +00006450 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6451 S->getDecl());
6452 if (!LD)
6453 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006454
6455
Douglas Gregorebe10102009-08-20 07:17:43 +00006456 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006457 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006458 cast<LabelDecl>(LD), SourceLocation(),
6459 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006460}
Mike Stump11289f42009-09-09 15:08:12 +00006461
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006462template <typename Derived>
6463const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6464 if (!R)
6465 return R;
6466
6467 switch (R->getKind()) {
6468// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6469#define ATTR(X)
6470#define PRAGMA_SPELLING_ATTR(X) \
6471 case attr::X: \
6472 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6473#include "clang/Basic/AttrList.inc"
6474 default:
6475 return R;
6476 }
6477}
6478
6479template <typename Derived>
6480StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6481 bool AttrsChanged = false;
6482 SmallVector<const Attr *, 1> Attrs;
6483
6484 // Visit attributes and keep track if any are transformed.
6485 for (const auto *I : S->getAttrs()) {
6486 const Attr *R = getDerived().TransformAttr(I);
6487 AttrsChanged |= (I != R);
6488 Attrs.push_back(R);
6489 }
6490
Richard Smithc202b282012-04-14 00:33:13 +00006491 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6492 if (SubStmt.isInvalid())
6493 return StmtError();
6494
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006495 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006496 return S;
6497
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006498 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006499 SubStmt.get());
6500}
6501
6502template<typename Derived>
6503StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006504TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006505 // Transform the initialization statement
6506 StmtResult Init = getDerived().TransformStmt(S->getInit());
6507 if (Init.isInvalid())
6508 return StmtError();
6509
Douglas Gregorebe10102009-08-20 07:17:43 +00006510 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006511 Sema::ConditionResult Cond = getDerived().TransformCondition(
6512 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006513 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6514 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006515 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006516 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006517
Richard Smithb130fe72016-06-23 19:16:49 +00006518 // If this is a constexpr if, determine which arm we should instantiate.
6519 llvm::Optional<bool> ConstexprConditionValue;
6520 if (S->isConstexpr())
6521 ConstexprConditionValue = Cond.getKnownValue();
6522
Douglas Gregorebe10102009-08-20 07:17:43 +00006523 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006524 StmtResult Then;
6525 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6526 Then = getDerived().TransformStmt(S->getThen());
6527 if (Then.isInvalid())
6528 return StmtError();
6529 } else {
6530 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6531 }
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregorebe10102009-08-20 07:17:43 +00006533 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006534 StmtResult Else;
6535 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6536 Else = getDerived().TransformStmt(S->getElse());
6537 if (Else.isInvalid())
6538 return StmtError();
6539 }
Mike Stump11289f42009-09-09 15:08:12 +00006540
Douglas Gregorebe10102009-08-20 07:17:43 +00006541 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006542 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006543 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006544 Then.get() == S->getThen() &&
6545 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006546 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006547
Richard Smithb130fe72016-06-23 19:16:49 +00006548 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006549 Init.get(), Then.get(), S->getElseLoc(),
6550 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006551}
6552
6553template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006554StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006555TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006556 // Transform the initialization statement
6557 StmtResult Init = getDerived().TransformStmt(S->getInit());
6558 if (Init.isInvalid())
6559 return StmtError();
6560
Douglas Gregorebe10102009-08-20 07:17:43 +00006561 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006562 Sema::ConditionResult Cond = getDerived().TransformCondition(
6563 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6564 Sema::ConditionKind::Switch);
6565 if (Cond.isInvalid())
6566 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006567
Douglas Gregorebe10102009-08-20 07:17:43 +00006568 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006569 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006570 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6571 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006572 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006573 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006574
Douglas Gregorebe10102009-08-20 07:17:43 +00006575 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006576 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006577 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006578 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006579
Douglas Gregorebe10102009-08-20 07:17:43 +00006580 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006581 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6582 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006583}
Mike Stump11289f42009-09-09 15:08:12 +00006584
Douglas Gregorebe10102009-08-20 07:17:43 +00006585template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006586StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006587TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006588 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006589 Sema::ConditionResult Cond = getDerived().TransformCondition(
6590 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6591 Sema::ConditionKind::Boolean);
6592 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006593 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006594
Douglas Gregorebe10102009-08-20 07:17:43 +00006595 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006596 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006597 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006598 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006599
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006601 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006602 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006603 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006604
Richard Smith03a4aa32016-06-23 19:02:52 +00006605 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006606}
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregorebe10102009-08-20 07:17:43 +00006608template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006609StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006610TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006611 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006612 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006614 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006616 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006617 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006618 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006620
Douglas Gregorebe10102009-08-20 07:17:43 +00006621 if (!getDerived().AlwaysRebuild() &&
6622 Cond.get() == S->getCond() &&
6623 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006624 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006625
John McCallb268a282010-08-23 23:25:46 +00006626 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6627 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006628 S->getRParenLoc());
6629}
Mike Stump11289f42009-09-09 15:08:12 +00006630
Douglas Gregorebe10102009-08-20 07:17:43 +00006631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006632StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006633TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006634 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006635 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006636 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006639 // In OpenMP loop region loop control variable must be captured and be
6640 // private. Perform analysis of first part (if any).
6641 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6642 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6643
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006645 Sema::ConditionResult Cond = getDerived().TransformCondition(
6646 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6647 Sema::ConditionKind::Boolean);
6648 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006649 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006650
Douglas Gregorebe10102009-08-20 07:17:43 +00006651 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006652 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006653 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006654 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006655
Richard Smith945f8d32013-01-14 22:39:08 +00006656 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006657 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006658 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006659
Douglas Gregorebe10102009-08-20 07:17:43 +00006660 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006661 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006662 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006663 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregorebe10102009-08-20 07:17:43 +00006665 if (!getDerived().AlwaysRebuild() &&
6666 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006667 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006668 Inc.get() == S->getInc() &&
6669 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006670 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006671
Douglas Gregorebe10102009-08-20 07:17:43 +00006672 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006673 Init.get(), Cond, FullInc,
6674 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006675}
6676
6677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006678StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006679TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006680 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6681 S->getLabel());
6682 if (!LD)
6683 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006684
Douglas Gregorebe10102009-08-20 07:17:43 +00006685 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006686 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006687 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006688}
6689
6690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006691StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006692TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006693 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006694 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006695 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006696 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregorebe10102009-08-20 07:17:43 +00006698 if (!getDerived().AlwaysRebuild() &&
6699 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006700 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006701
6702 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006703 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006704}
6705
6706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006708TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006709 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006710}
Mike Stump11289f42009-09-09 15:08:12 +00006711
Douglas Gregorebe10102009-08-20 07:17:43 +00006712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006713StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006714TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006715 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006716}
Mike Stump11289f42009-09-09 15:08:12 +00006717
Douglas Gregorebe10102009-08-20 07:17:43 +00006718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006719StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006720TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006721 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6722 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006723 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006724 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006725
Mike Stump11289f42009-09-09 15:08:12 +00006726 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006727 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006728 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006729}
Mike Stump11289f42009-09-09 15:08:12 +00006730
Douglas Gregorebe10102009-08-20 07:17:43 +00006731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006732StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006733TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006734 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006735 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006736 for (auto *D : S->decls()) {
6737 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006738 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006739 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006740
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006741 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006742 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006743
Douglas Gregorebe10102009-08-20 07:17:43 +00006744 Decls.push_back(Transformed);
6745 }
Mike Stump11289f42009-09-09 15:08:12 +00006746
Douglas Gregorebe10102009-08-20 07:17:43 +00006747 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006748 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006749
Rafael Espindolaab417692013-07-09 12:05:01 +00006750 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006751}
Mike Stump11289f42009-09-09 15:08:12 +00006752
Douglas Gregorebe10102009-08-20 07:17:43 +00006753template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006754StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006755TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006756
Benjamin Kramerf0623432012-08-23 22:51:59 +00006757 SmallVector<Expr*, 8> Constraints;
6758 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006759 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006760
John McCalldadc5752010-08-24 06:29:42 +00006761 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006762 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006763
6764 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006765
Anders Carlssonaaeef072010-01-24 05:50:09 +00006766 // Go through the outputs.
6767 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006768 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006769
Anders Carlssonaaeef072010-01-24 05:50:09 +00006770 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006771 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006772
Anders Carlssonaaeef072010-01-24 05:50:09 +00006773 // Transform the output expr.
6774 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006775 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006776 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006777 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006778
Anders Carlssonaaeef072010-01-24 05:50:09 +00006779 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
John McCallb268a282010-08-23 23:25:46 +00006781 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006782 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Anders Carlssonaaeef072010-01-24 05:50:09 +00006784 // Go through the inputs.
6785 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006786 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006787
Anders Carlssonaaeef072010-01-24 05:50:09 +00006788 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006789 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006790
Anders Carlssonaaeef072010-01-24 05:50:09 +00006791 // Transform the input expr.
6792 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006793 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006794 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006795 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006796
Anders Carlssonaaeef072010-01-24 05:50:09 +00006797 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006798
John McCallb268a282010-08-23 23:25:46 +00006799 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006801
Anders Carlssonaaeef072010-01-24 05:50:09 +00006802 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006803 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006804
6805 // Go through the clobbers.
6806 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006807 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006808
6809 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006810 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006811 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6812 S->isVolatile(), S->getNumOutputs(),
6813 S->getNumInputs(), Names.data(),
6814 Constraints, Exprs, AsmString.get(),
6815 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006816}
6817
Chad Rosier32503022012-06-11 20:47:18 +00006818template<typename Derived>
6819StmtResult
6820TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006821 ArrayRef<Token> AsmToks =
6822 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006823
John McCallf413f5e2013-05-03 00:10:13 +00006824 bool HadError = false, HadChange = false;
6825
6826 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6827 SmallVector<Expr*, 8> TransformedExprs;
6828 TransformedExprs.reserve(SrcExprs.size());
6829 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6830 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6831 if (!Result.isUsable()) {
6832 HadError = true;
6833 } else {
6834 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006835 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006836 }
6837 }
6838
6839 if (HadError) return StmtError();
6840 if (!HadChange && !getDerived().AlwaysRebuild())
6841 return Owned(S);
6842
Chad Rosierb6f46c12012-08-15 16:53:30 +00006843 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006844 AsmToks, S->getAsmString(),
6845 S->getNumOutputs(), S->getNumInputs(),
6846 S->getAllConstraints(), S->getClobbers(),
6847 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006848}
Douglas Gregorebe10102009-08-20 07:17:43 +00006849
Richard Smith9f690bd2015-10-27 06:02:45 +00006850// C++ Coroutines TS
6851
6852template<typename Derived>
6853StmtResult
6854TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006855 auto *ScopeInfo = SemaRef.getCurFunction();
6856 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006857 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006858 ScopeInfo->NeedsCoroutineSuspends &&
6859 ScopeInfo->CoroutineSuspends.first == nullptr &&
6860 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006861 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006862
6863 // Set that we have (possibly-invalid) suspend points before we do anything
6864 // that may fail.
6865 ScopeInfo->setNeedsCoroutineSuspends(false);
6866
6867 // The new CoroutinePromise object needs to be built and put into the current
6868 // FunctionScopeInfo before any transformations or rebuilding occurs.
Eric Fiselierbee782b2017-04-03 19:21:00 +00006869 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6870 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006871 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006872 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6873 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006874
6875 // Transform the implicit coroutine statements we built during the initial
6876 // parse.
6877 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6878 if (InitSuspend.isInvalid())
6879 return StmtError();
6880 StmtResult FinalSuspend =
6881 getDerived().TransformStmt(S->getFinalSuspendStmt());
6882 if (FinalSuspend.isInvalid())
6883 return StmtError();
6884 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6885 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006886
6887 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6888 if (BodyRes.isInvalid())
6889 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006890
Eric Fiselierbee782b2017-04-03 19:21:00 +00006891 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6892 if (Builder.isInvalid())
6893 return StmtError();
6894
6895 Expr *ReturnObject = S->getReturnValueInit();
6896 assert(ReturnObject && "the return object is expected to be valid");
6897 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6898 /*NoCopyInit*/ false);
6899 if (Res.isInvalid())
6900 return StmtError();
6901 Builder.ReturnValue = Res.get();
6902
6903 if (S->hasDependentPromiseType()) {
6904 assert(!Promise->getType()->isDependentType() &&
6905 "the promise type must no longer be dependent");
6906 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6907 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6908 "these nodes should not have been built yet");
6909 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006910 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006911 } else {
6912 if (auto *OnFallthrough = S->getFallthroughHandler()) {
6913 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6914 if (Res.isInvalid())
6915 return StmtError();
6916 Builder.OnFallthrough = Res.get();
6917 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006918
Eric Fiselierbee782b2017-04-03 19:21:00 +00006919 if (auto *OnException = S->getExceptionHandler()) {
6920 StmtResult Res = getDerived().TransformStmt(OnException);
6921 if (Res.isInvalid())
6922 return StmtError();
6923 Builder.OnException = Res.get();
6924 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006925
Eric Fiselierbee782b2017-04-03 19:21:00 +00006926 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
6927 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
6928 if (Res.isInvalid())
6929 return StmtError();
6930 Builder.ReturnStmtOnAllocFailure = Res.get();
6931 }
6932
6933 // Transform any additional statements we may have already built
6934 assert(S->getAllocate() && S->getDeallocate() &&
6935 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006936 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
6937 if (AllocRes.isInvalid())
6938 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006939 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006940
6941 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
6942 if (DeallocRes.isInvalid())
6943 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006944 Builder.Deallocate = DeallocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006945 }
6946
Eric Fiselierbee782b2017-04-03 19:21:00 +00006947 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00006948}
6949
6950template<typename Derived>
6951StmtResult
6952TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6953 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6954 /*NotCopyInit*/false);
6955 if (Result.isInvalid())
6956 return StmtError();
6957
6958 // Always rebuild; we don't know if this needs to be injected into a new
6959 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006960 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
6961 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00006962}
6963
6964template<typename Derived>
6965ExprResult
6966TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
6967 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
6968 /*NotCopyInit*/false);
6969 if (Result.isInvalid())
6970 return ExprError();
6971
6972 // Always rebuild; we don't know if this needs to be injected into a new
6973 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006974 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
6975 E->isImplicit());
6976}
6977
6978template <typename Derived>
6979ExprResult
6980TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
6981 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
6982 /*NotCopyInit*/ false);
6983 if (OperandResult.isInvalid())
6984 return ExprError();
6985
6986 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
6987 E->getOperatorCoawaitLookup());
6988
6989 if (LookupResult.isInvalid())
6990 return ExprError();
6991
6992 // Always rebuild; we don't know if this needs to be injected into a new
6993 // context or if the promise type has changed.
6994 return getDerived().RebuildDependentCoawaitExpr(
6995 E->getKeywordLoc(), OperandResult.get(),
6996 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00006997}
6998
6999template<typename Derived>
7000ExprResult
7001TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7002 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7003 /*NotCopyInit*/false);
7004 if (Result.isInvalid())
7005 return ExprError();
7006
7007 // Always rebuild; we don't know if this needs to be injected into a new
7008 // context or if the promise type has changed.
7009 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7010}
7011
7012// Objective-C Statements.
7013
Douglas Gregorebe10102009-08-20 07:17:43 +00007014template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007015StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007016TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007017 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007018 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007019 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007020 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007021
Douglas Gregor96c79492010-04-23 22:50:49 +00007022 // Transform the @catch statements (if present).
7023 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007024 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007025 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007026 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007027 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007028 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007029 if (Catch.get() != S->getCatchStmt(I))
7030 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007031 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007032 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007033
Douglas Gregor306de2f2010-04-22 23:59:56 +00007034 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007035 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007036 if (S->getFinallyStmt()) {
7037 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7038 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007039 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007040 }
7041
7042 // If nothing changed, just retain this statement.
7043 if (!getDerived().AlwaysRebuild() &&
7044 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007045 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007046 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007047 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007048
Douglas Gregor306de2f2010-04-22 23:59:56 +00007049 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007050 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007051 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007052}
Mike Stump11289f42009-09-09 15:08:12 +00007053
Douglas Gregorebe10102009-08-20 07:17:43 +00007054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007056TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007057 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007058 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007059 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007060 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007061 if (FromVar->getTypeSourceInfo()) {
7062 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7063 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007064 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007066
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007067 QualType T;
7068 if (TSInfo)
7069 T = TSInfo->getType();
7070 else {
7071 T = getDerived().TransformType(FromVar->getType());
7072 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007073 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007075
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007076 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7077 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007078 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007079 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007080
John McCalldadc5752010-08-24 06:29:42 +00007081 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007082 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007083 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007084
7085 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007086 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007087 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007088}
Mike Stump11289f42009-09-09 15:08:12 +00007089
Douglas Gregorebe10102009-08-20 07:17:43 +00007090template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007091StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007092TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007093 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007094 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007095 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007096 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007097
Douglas Gregor306de2f2010-04-22 23:59:56 +00007098 // If nothing changed, just retain this statement.
7099 if (!getDerived().AlwaysRebuild() &&
7100 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007101 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007102
7103 // Build a new statement.
7104 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007105 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007106}
Mike Stump11289f42009-09-09 15:08:12 +00007107
Douglas Gregorebe10102009-08-20 07:17:43 +00007108template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007109StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007110TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007111 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007112 if (S->getThrowExpr()) {
7113 Operand = getDerived().TransformExpr(S->getThrowExpr());
7114 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007115 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007116 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007117
Douglas Gregor2900c162010-04-22 21:44:01 +00007118 if (!getDerived().AlwaysRebuild() &&
7119 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007120 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007121
John McCallb268a282010-08-23 23:25:46 +00007122 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007123}
Mike Stump11289f42009-09-09 15:08:12 +00007124
Douglas Gregorebe10102009-08-20 07:17:43 +00007125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007126StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007127TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007128 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007129 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007130 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007131 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007132 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007133 Object =
7134 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7135 Object.get());
7136 if (Object.isInvalid())
7137 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007138
Douglas Gregor6148de72010-04-22 22:01:21 +00007139 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007140 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007141 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007142 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007143
Douglas Gregor6148de72010-04-22 22:01:21 +00007144 // If nothing change, just retain the current statement.
7145 if (!getDerived().AlwaysRebuild() &&
7146 Object.get() == S->getSynchExpr() &&
7147 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007148 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007149
7150 // Build a new statement.
7151 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007152 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007153}
7154
7155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007156StmtResult
John McCall31168b02011-06-15 23:02:42 +00007157TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7158 ObjCAutoreleasePoolStmt *S) {
7159 // Transform the body.
7160 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7161 if (Body.isInvalid())
7162 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007163
John McCall31168b02011-06-15 23:02:42 +00007164 // If nothing changed, just retain this statement.
7165 if (!getDerived().AlwaysRebuild() &&
7166 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007167 return S;
John McCall31168b02011-06-15 23:02:42 +00007168
7169 // Build a new statement.
7170 return getDerived().RebuildObjCAutoreleasePoolStmt(
7171 S->getAtLoc(), Body.get());
7172}
7173
7174template<typename Derived>
7175StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007176TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007177 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007178 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007179 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007180 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007181 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007182
Douglas Gregorf68a5082010-04-22 23:10:45 +00007183 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007184 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007185 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007186 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007187
Douglas Gregorf68a5082010-04-22 23:10:45 +00007188 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007189 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007190 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007191 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007192
Douglas Gregorf68a5082010-04-22 23:10:45 +00007193 // If nothing changed, just retain this statement.
7194 if (!getDerived().AlwaysRebuild() &&
7195 Element.get() == S->getElement() &&
7196 Collection.get() == S->getCollection() &&
7197 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007198 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007199
Douglas Gregorf68a5082010-04-22 23:10:45 +00007200 // Build a new statement.
7201 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007202 Element.get(),
7203 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007204 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007205 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007206}
7207
David Majnemer5f7efef2013-10-15 09:50:08 +00007208template <typename Derived>
7209StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007210 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007211 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007212 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7213 TypeSourceInfo *T =
7214 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007215 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007216 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007217
David Majnemer5f7efef2013-10-15 09:50:08 +00007218 Var = getDerived().RebuildExceptionDecl(
7219 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7220 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007221 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007222 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007223 }
Mike Stump11289f42009-09-09 15:08:12 +00007224
Douglas Gregorebe10102009-08-20 07:17:43 +00007225 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007226 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007227 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007228 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007229
David Majnemer5f7efef2013-10-15 09:50:08 +00007230 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007231 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007232 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007233
David Majnemer5f7efef2013-10-15 09:50:08 +00007234 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007235}
Mike Stump11289f42009-09-09 15:08:12 +00007236
David Majnemer5f7efef2013-10-15 09:50:08 +00007237template <typename Derived>
7238StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007239 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007240 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007241 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007242 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregorebe10102009-08-20 07:17:43 +00007244 // Transform the handlers.
7245 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007246 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007247 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007248 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007249 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007250 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007251
Douglas Gregorebe10102009-08-20 07:17:43 +00007252 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007253 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007254 }
Mike Stump11289f42009-09-09 15:08:12 +00007255
David Majnemer5f7efef2013-10-15 09:50:08 +00007256 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007257 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007258 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007259
John McCallb268a282010-08-23 23:25:46 +00007260 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007261 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007262}
Mike Stump11289f42009-09-09 15:08:12 +00007263
Richard Smith02e85f32011-04-14 22:09:26 +00007264template<typename Derived>
7265StmtResult
7266TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7267 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7268 if (Range.isInvalid())
7269 return StmtError();
7270
Richard Smith01694c32016-03-20 10:33:40 +00007271 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7272 if (Begin.isInvalid())
7273 return StmtError();
7274 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7275 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007276 return StmtError();
7277
7278 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7279 if (Cond.isInvalid())
7280 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007281 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007282 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007283 if (Cond.isInvalid())
7284 return StmtError();
7285 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007286 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007287
7288 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7289 if (Inc.isInvalid())
7290 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007291 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007292 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007293
7294 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7295 if (LoopVar.isInvalid())
7296 return StmtError();
7297
7298 StmtResult NewStmt = S;
7299 if (getDerived().AlwaysRebuild() ||
7300 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007301 Begin.get() != S->getBeginStmt() ||
7302 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007303 Cond.get() != S->getCond() ||
7304 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007305 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007306 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007307 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007308 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007309 Begin.get(), End.get(),
7310 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007311 Inc.get(), LoopVar.get(),
7312 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007313 if (NewStmt.isInvalid())
7314 return StmtError();
7315 }
Richard Smith02e85f32011-04-14 22:09:26 +00007316
7317 StmtResult Body = getDerived().TransformStmt(S->getBody());
7318 if (Body.isInvalid())
7319 return StmtError();
7320
7321 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7322 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007323 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007324 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007325 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007326 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007327 Begin.get(), End.get(),
7328 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007329 Inc.get(), LoopVar.get(),
7330 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007331 if (NewStmt.isInvalid())
7332 return StmtError();
7333 }
Richard Smith02e85f32011-04-14 22:09:26 +00007334
7335 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007336 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007337
7338 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7339}
7340
John Wiegley1c0675e2011-04-28 01:08:34 +00007341template<typename Derived>
7342StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007343TreeTransform<Derived>::TransformMSDependentExistsStmt(
7344 MSDependentExistsStmt *S) {
7345 // Transform the nested-name-specifier, if any.
7346 NestedNameSpecifierLoc QualifierLoc;
7347 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007348 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007349 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7350 if (!QualifierLoc)
7351 return StmtError();
7352 }
7353
7354 // Transform the declaration name.
7355 DeclarationNameInfo NameInfo = S->getNameInfo();
7356 if (NameInfo.getName()) {
7357 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7358 if (!NameInfo.getName())
7359 return StmtError();
7360 }
7361
7362 // Check whether anything changed.
7363 if (!getDerived().AlwaysRebuild() &&
7364 QualifierLoc == S->getQualifierLoc() &&
7365 NameInfo.getName() == S->getNameInfo().getName())
7366 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007367
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007368 // Determine whether this name exists, if we can.
7369 CXXScopeSpec SS;
7370 SS.Adopt(QualifierLoc);
7371 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007372 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007373 case Sema::IER_Exists:
7374 if (S->isIfExists())
7375 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007376
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007377 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7378
7379 case Sema::IER_DoesNotExist:
7380 if (S->isIfNotExists())
7381 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007382
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007383 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007384
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007385 case Sema::IER_Dependent:
7386 Dependent = true;
7387 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007388
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007389 case Sema::IER_Error:
7390 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007391 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007392
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007393 // We need to continue with the instantiation, so do so now.
7394 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7395 if (SubStmt.isInvalid())
7396 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007397
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007398 // If we have resolved the name, just transform to the substatement.
7399 if (!Dependent)
7400 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007401
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007402 // The name is still dependent, so build a dependent expression again.
7403 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7404 S->isIfExists(),
7405 QualifierLoc,
7406 NameInfo,
7407 SubStmt.get());
7408}
7409
7410template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007411ExprResult
7412TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7413 NestedNameSpecifierLoc QualifierLoc;
7414 if (E->getQualifierLoc()) {
7415 QualifierLoc
7416 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7417 if (!QualifierLoc)
7418 return ExprError();
7419 }
7420
7421 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7422 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7423 if (!PD)
7424 return ExprError();
7425
7426 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7427 if (Base.isInvalid())
7428 return ExprError();
7429
7430 return new (SemaRef.getASTContext())
7431 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7432 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7433 QualifierLoc, E->getMemberLoc());
7434}
7435
David Majnemerfad8f482013-10-15 09:33:02 +00007436template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007437ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7438 MSPropertySubscriptExpr *E) {
7439 auto BaseRes = getDerived().TransformExpr(E->getBase());
7440 if (BaseRes.isInvalid())
7441 return ExprError();
7442 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7443 if (IdxRes.isInvalid())
7444 return ExprError();
7445
7446 if (!getDerived().AlwaysRebuild() &&
7447 BaseRes.get() == E->getBase() &&
7448 IdxRes.get() == E->getIdx())
7449 return E;
7450
7451 return getDerived().RebuildArraySubscriptExpr(
7452 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7453}
7454
7455template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007456StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007457 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007458 if (TryBlock.isInvalid())
7459 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007460
7461 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007462 if (Handler.isInvalid())
7463 return StmtError();
7464
David Majnemerfad8f482013-10-15 09:33:02 +00007465 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7466 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007467 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007468
Warren Huntf6be4cb2014-07-25 20:52:51 +00007469 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7470 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007471}
7472
David Majnemerfad8f482013-10-15 09:33:02 +00007473template <typename Derived>
7474StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007475 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007476 if (Block.isInvalid())
7477 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007478
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007479 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007480}
7481
David Majnemerfad8f482013-10-15 09:33:02 +00007482template <typename Derived>
7483StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007484 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007485 if (FilterExpr.isInvalid())
7486 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007487
David Majnemer7e755502013-10-15 09:30:14 +00007488 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007489 if (Block.isInvalid())
7490 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007491
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007492 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7493 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007494}
7495
David Majnemerfad8f482013-10-15 09:33:02 +00007496template <typename Derived>
7497StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7498 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007499 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7500 else
7501 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7502}
7503
Nico Weber9b982072014-07-07 00:12:30 +00007504template<typename Derived>
7505StmtResult
7506TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7507 return S;
7508}
7509
Alexander Musman64d33f12014-06-04 07:53:32 +00007510//===----------------------------------------------------------------------===//
7511// OpenMP directive transformation
7512//===----------------------------------------------------------------------===//
7513template <typename Derived>
7514StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7515 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007516
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007517 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007518 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007519 ArrayRef<OMPClause *> Clauses = D->clauses();
7520 TClauses.reserve(Clauses.size());
7521 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7522 I != E; ++I) {
7523 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007524 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007525 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007526 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007527 if (Clause)
7528 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007529 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007530 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007531 }
7532 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007533 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007534 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007535 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7536 /*CurScope=*/nullptr);
7537 StmtResult Body;
7538 {
7539 Sema::CompoundScopeRAII CompoundScope(getSema());
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007540 int ThisCaptureLevel =
7541 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7542 Stmt *CS = D->getAssociatedStmt();
7543 while (--ThisCaptureLevel >= 0)
7544 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7545 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007546 }
7547 AssociatedStmt =
7548 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007549 if (AssociatedStmt.isInvalid()) {
7550 return StmtError();
7551 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007552 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007553 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007554 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007555 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007556
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007557 // Transform directive name for 'omp critical' directive.
7558 DeclarationNameInfo DirName;
7559 if (D->getDirectiveKind() == OMPD_critical) {
7560 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7561 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7562 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007563 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7564 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7565 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007566 } else if (D->getDirectiveKind() == OMPD_cancel) {
7567 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007568 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007569
Alexander Musman64d33f12014-06-04 07:53:32 +00007570 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007571 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7572 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007573}
7574
Alexander Musman64d33f12014-06-04 07:53:32 +00007575template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007576StmtResult
7577TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7578 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007579 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7580 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007581 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7582 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7583 return Res;
7584}
7585
Alexander Musman64d33f12014-06-04 07:53:32 +00007586template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007587StmtResult
7588TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7589 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007590 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7591 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007592 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7593 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007594 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007595}
7596
Alexey Bataevf29276e2014-06-18 04:14:57 +00007597template <typename Derived>
7598StmtResult
7599TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7600 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007601 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7602 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007603 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7604 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7605 return Res;
7606}
7607
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007608template <typename Derived>
7609StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007610TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7611 DeclarationNameInfo DirName;
7612 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7613 D->getLocStart());
7614 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7615 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7616 return Res;
7617}
7618
7619template <typename Derived>
7620StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007621TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7622 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007623 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7624 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007625 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7626 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7627 return Res;
7628}
7629
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007630template <typename Derived>
7631StmtResult
7632TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7633 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007634 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7635 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007636 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7637 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7638 return Res;
7639}
7640
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007641template <typename Derived>
7642StmtResult
7643TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7644 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007645 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7646 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7649 return Res;
7650}
7651
Alexey Bataev4acb8592014-07-07 13:01:15 +00007652template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007653StmtResult
7654TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7655 DeclarationNameInfo DirName;
7656 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7657 D->getLocStart());
7658 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7659 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7660 return Res;
7661}
7662
7663template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007664StmtResult
7665TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7666 getDerived().getSema().StartOpenMPDSABlock(
7667 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7668 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7669 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7670 return Res;
7671}
7672
7673template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007674StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7675 OMPParallelForDirective *D) {
7676 DeclarationNameInfo DirName;
7677 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7678 nullptr, D->getLocStart());
7679 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7680 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7681 return Res;
7682}
7683
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007684template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007685StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7686 OMPParallelForSimdDirective *D) {
7687 DeclarationNameInfo DirName;
7688 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7689 nullptr, D->getLocStart());
7690 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7691 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7692 return Res;
7693}
7694
7695template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007696StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7697 OMPParallelSectionsDirective *D) {
7698 DeclarationNameInfo DirName;
7699 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7700 nullptr, D->getLocStart());
7701 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7702 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7703 return Res;
7704}
7705
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007706template <typename Derived>
7707StmtResult
7708TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7709 DeclarationNameInfo DirName;
7710 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7711 D->getLocStart());
7712 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7713 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7714 return Res;
7715}
7716
Alexey Bataev68446b72014-07-18 07:47:19 +00007717template <typename Derived>
7718StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7719 OMPTaskyieldDirective *D) {
7720 DeclarationNameInfo DirName;
7721 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7722 D->getLocStart());
7723 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7724 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7725 return Res;
7726}
7727
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007728template <typename Derived>
7729StmtResult
7730TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7731 DeclarationNameInfo DirName;
7732 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7733 D->getLocStart());
7734 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7735 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7736 return Res;
7737}
7738
Alexey Bataev2df347a2014-07-18 10:17:07 +00007739template <typename Derived>
7740StmtResult
7741TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7742 DeclarationNameInfo DirName;
7743 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7744 D->getLocStart());
7745 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7746 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7747 return Res;
7748}
7749
Alexey Bataev6125da92014-07-21 11:26:11 +00007750template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007751StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7752 OMPTaskgroupDirective *D) {
7753 DeclarationNameInfo DirName;
7754 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7755 D->getLocStart());
7756 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7757 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7758 return Res;
7759}
7760
7761template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007762StmtResult
7763TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7764 DeclarationNameInfo DirName;
7765 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7766 D->getLocStart());
7767 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7768 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769 return Res;
7770}
7771
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007772template <typename Derived>
7773StmtResult
7774TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7775 DeclarationNameInfo DirName;
7776 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7777 D->getLocStart());
7778 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7780 return Res;
7781}
7782
Alexey Bataev0162e452014-07-22 10:10:35 +00007783template <typename Derived>
7784StmtResult
7785TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7786 DeclarationNameInfo DirName;
7787 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7788 D->getLocStart());
7789 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7790 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7791 return Res;
7792}
7793
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007794template <typename Derived>
7795StmtResult
7796TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7797 DeclarationNameInfo DirName;
7798 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7799 D->getLocStart());
7800 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7801 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7802 return Res;
7803}
7804
Alexey Bataev13314bf2014-10-09 04:18:56 +00007805template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007806StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7807 OMPTargetDataDirective *D) {
7808 DeclarationNameInfo DirName;
7809 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7810 D->getLocStart());
7811 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7812 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7813 return Res;
7814}
7815
7816template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007817StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7818 OMPTargetEnterDataDirective *D) {
7819 DeclarationNameInfo DirName;
7820 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7821 nullptr, D->getLocStart());
7822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7824 return Res;
7825}
7826
7827template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007828StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7829 OMPTargetExitDataDirective *D) {
7830 DeclarationNameInfo DirName;
7831 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7832 nullptr, D->getLocStart());
7833 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7834 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7835 return Res;
7836}
7837
7838template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007839StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7840 OMPTargetParallelDirective *D) {
7841 DeclarationNameInfo DirName;
7842 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7843 nullptr, D->getLocStart());
7844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7846 return Res;
7847}
7848
7849template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007850StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7851 OMPTargetParallelForDirective *D) {
7852 DeclarationNameInfo DirName;
7853 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7854 nullptr, D->getLocStart());
7855 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7856 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7857 return Res;
7858}
7859
7860template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007861StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7862 OMPTargetUpdateDirective *D) {
7863 DeclarationNameInfo DirName;
7864 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7865 nullptr, D->getLocStart());
7866 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7867 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7868 return Res;
7869}
7870
7871template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007872StmtResult
7873TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7874 DeclarationNameInfo DirName;
7875 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7876 D->getLocStart());
7877 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7878 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7879 return Res;
7880}
7881
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007882template <typename Derived>
7883StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7884 OMPCancellationPointDirective *D) {
7885 DeclarationNameInfo DirName;
7886 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7887 nullptr, D->getLocStart());
7888 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7889 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7890 return Res;
7891}
7892
Alexey Bataev80909872015-07-02 11:25:17 +00007893template <typename Derived>
7894StmtResult
7895TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7896 DeclarationNameInfo DirName;
7897 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7898 D->getLocStart());
7899 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7900 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7901 return Res;
7902}
7903
Alexey Bataev49f6e782015-12-01 04:18:41 +00007904template <typename Derived>
7905StmtResult
7906TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7907 DeclarationNameInfo DirName;
7908 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7909 D->getLocStart());
7910 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7912 return Res;
7913}
7914
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007915template <typename Derived>
7916StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7917 OMPTaskLoopSimdDirective *D) {
7918 DeclarationNameInfo DirName;
7919 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7920 nullptr, D->getLocStart());
7921 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7923 return Res;
7924}
7925
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007926template <typename Derived>
7927StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7928 OMPDistributeDirective *D) {
7929 DeclarationNameInfo DirName;
7930 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7931 D->getLocStart());
7932 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7933 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7934 return Res;
7935}
7936
Carlo Bertolli9925f152016-06-27 14:55:37 +00007937template <typename Derived>
7938StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7939 OMPDistributeParallelForDirective *D) {
7940 DeclarationNameInfo DirName;
7941 getDerived().getSema().StartOpenMPDSABlock(
7942 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7945 return Res;
7946}
7947
Kelvin Li4a39add2016-07-05 05:00:15 +00007948template <typename Derived>
7949StmtResult
7950TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7951 OMPDistributeParallelForSimdDirective *D) {
7952 DeclarationNameInfo DirName;
7953 getDerived().getSema().StartOpenMPDSABlock(
7954 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7956 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7957 return Res;
7958}
7959
Kelvin Li787f3fc2016-07-06 04:45:38 +00007960template <typename Derived>
7961StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7962 OMPDistributeSimdDirective *D) {
7963 DeclarationNameInfo DirName;
7964 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7965 nullptr, D->getLocStart());
7966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7967 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7968 return Res;
7969}
7970
Kelvin Lia579b912016-07-14 02:54:56 +00007971template <typename Derived>
7972StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
7973 OMPTargetParallelForSimdDirective *D) {
7974 DeclarationNameInfo DirName;
7975 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
7976 DirName, nullptr,
7977 D->getLocStart());
7978 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7979 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7980 return Res;
7981}
7982
Kelvin Li986330c2016-07-20 22:57:10 +00007983template <typename Derived>
7984StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
7985 OMPTargetSimdDirective *D) {
7986 DeclarationNameInfo DirName;
7987 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
7988 D->getLocStart());
7989 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7990 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7991 return Res;
7992}
7993
Kelvin Li02532872016-08-05 14:37:37 +00007994template <typename Derived>
7995StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
7996 OMPTeamsDistributeDirective *D) {
7997 DeclarationNameInfo DirName;
7998 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
7999 nullptr, D->getLocStart());
8000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8001 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8002 return Res;
8003}
8004
Kelvin Li4e325f72016-10-25 12:50:55 +00008005template <typename Derived>
8006StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8007 OMPTeamsDistributeSimdDirective *D) {
8008 DeclarationNameInfo DirName;
8009 getDerived().getSema().StartOpenMPDSABlock(
8010 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8013 return Res;
8014}
8015
Kelvin Li579e41c2016-11-30 23:51:03 +00008016template <typename Derived>
8017StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8018 OMPTeamsDistributeParallelForSimdDirective *D) {
8019 DeclarationNameInfo DirName;
8020 getDerived().getSema().StartOpenMPDSABlock(
8021 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8024 return Res;
8025}
8026
Kelvin Li7ade93f2016-12-09 03:24:30 +00008027template <typename Derived>
8028StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8029 OMPTeamsDistributeParallelForDirective *D) {
8030 DeclarationNameInfo DirName;
8031 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8032 DirName, nullptr, D->getLocStart());
8033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8034 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8035 return Res;
8036}
8037
Kelvin Libf594a52016-12-17 05:48:59 +00008038template <typename Derived>
8039StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8040 OMPTargetTeamsDirective *D) {
8041 DeclarationNameInfo DirName;
8042 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8043 nullptr, D->getLocStart());
8044 auto Res = getDerived().TransformOMPExecutableDirective(D);
8045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8046 return Res;
8047}
Kelvin Li579e41c2016-11-30 23:51:03 +00008048
Kelvin Li83c451e2016-12-25 04:52:54 +00008049template <typename Derived>
8050StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8051 OMPTargetTeamsDistributeDirective *D) {
8052 DeclarationNameInfo DirName;
8053 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8054 DirName, nullptr, D->getLocStart());
8055 auto Res = getDerived().TransformOMPExecutableDirective(D);
8056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8057 return Res;
8058}
8059
Kelvin Li80e8f562016-12-29 22:16:30 +00008060template <typename Derived>
8061StmtResult
8062TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8063 OMPTargetTeamsDistributeParallelForDirective *D) {
8064 DeclarationNameInfo DirName;
8065 getDerived().getSema().StartOpenMPDSABlock(
8066 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8067 D->getLocStart());
8068 auto Res = getDerived().TransformOMPExecutableDirective(D);
8069 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8070 return Res;
8071}
8072
Kelvin Li1851df52017-01-03 05:23:48 +00008073template <typename Derived>
8074StmtResult TreeTransform<Derived>::
8075 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8076 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8077 DeclarationNameInfo DirName;
8078 getDerived().getSema().StartOpenMPDSABlock(
8079 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8080 D->getLocStart());
8081 auto Res = getDerived().TransformOMPExecutableDirective(D);
8082 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8083 return Res;
8084}
8085
Kelvin Lida681182017-01-10 18:08:18 +00008086template <typename Derived>
8087StmtResult
8088TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8089 OMPTargetTeamsDistributeSimdDirective *D) {
8090 DeclarationNameInfo DirName;
8091 getDerived().getSema().StartOpenMPDSABlock(
8092 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8093 auto Res = getDerived().TransformOMPExecutableDirective(D);
8094 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8095 return Res;
8096}
8097
Kelvin Li1851df52017-01-03 05:23:48 +00008098
Alexander Musman64d33f12014-06-04 07:53:32 +00008099//===----------------------------------------------------------------------===//
8100// OpenMP clause transformation
8101//===----------------------------------------------------------------------===//
8102template <typename Derived>
8103OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008104 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8105 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008106 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008107 return getDerived().RebuildOMPIfClause(
8108 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8109 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008110}
8111
Alexander Musman64d33f12014-06-04 07:53:32 +00008112template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008113OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8114 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8115 if (Cond.isInvalid())
8116 return nullptr;
8117 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8118 C->getLParenLoc(), C->getLocEnd());
8119}
8120
8121template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008122OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008123TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8124 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8125 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008126 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008127 return getDerived().RebuildOMPNumThreadsClause(
8128 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00008129}
8130
Alexey Bataev62c87d22014-03-21 04:51:18 +00008131template <typename Derived>
8132OMPClause *
8133TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8134 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8135 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008136 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008137 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008138 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008139}
8140
Alexander Musman8bd31e62014-05-27 15:12:19 +00008141template <typename Derived>
8142OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008143TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8144 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8145 if (E.isInvalid())
8146 return nullptr;
8147 return getDerived().RebuildOMPSimdlenClause(
8148 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8149}
8150
8151template <typename Derived>
8152OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008153TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8154 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8155 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008156 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008157 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008158 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008159}
8160
Alexander Musman64d33f12014-06-04 07:53:32 +00008161template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008162OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008163TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008164 return getDerived().RebuildOMPDefaultClause(
8165 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8166 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008167}
8168
Alexander Musman64d33f12014-06-04 07:53:32 +00008169template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008170OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008171TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008172 return getDerived().RebuildOMPProcBindClause(
8173 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8174 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008175}
8176
Alexander Musman64d33f12014-06-04 07:53:32 +00008177template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008178OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008179TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8180 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8181 if (E.isInvalid())
8182 return nullptr;
8183 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008184 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008185 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008186 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008187 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8188}
8189
8190template <typename Derived>
8191OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008192TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008193 ExprResult E;
8194 if (auto *Num = C->getNumForLoops()) {
8195 E = getDerived().TransformExpr(Num);
8196 if (E.isInvalid())
8197 return nullptr;
8198 }
8199 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8200 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008201}
8202
8203template <typename Derived>
8204OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008205TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8206 // No need to rebuild this clause, no template-dependent parameters.
8207 return C;
8208}
8209
8210template <typename Derived>
8211OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008212TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8213 // No need to rebuild this clause, no template-dependent parameters.
8214 return C;
8215}
8216
8217template <typename Derived>
8218OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008219TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8220 // No need to rebuild this clause, no template-dependent parameters.
8221 return C;
8222}
8223
8224template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008225OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8226 // No need to rebuild this clause, no template-dependent parameters.
8227 return C;
8228}
8229
8230template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008231OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8232 // No need to rebuild this clause, no template-dependent parameters.
8233 return C;
8234}
8235
8236template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008237OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008238TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8239 // No need to rebuild this clause, no template-dependent parameters.
8240 return C;
8241}
8242
8243template <typename Derived>
8244OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008245TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8246 // No need to rebuild this clause, no template-dependent parameters.
8247 return C;
8248}
8249
8250template <typename Derived>
8251OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008252TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8253 // No need to rebuild this clause, no template-dependent parameters.
8254 return C;
8255}
8256
8257template <typename Derived>
8258OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008259TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8260 // No need to rebuild this clause, no template-dependent parameters.
8261 return C;
8262}
8263
8264template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008265OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8266 // No need to rebuild this clause, no template-dependent parameters.
8267 return C;
8268}
8269
8270template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008271OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008272TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8273 // No need to rebuild this clause, no template-dependent parameters.
8274 return C;
8275}
8276
8277template <typename Derived>
8278OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008279TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008280 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008281 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008282 for (auto *VE : C->varlists()) {
8283 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008284 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008285 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008286 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008287 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008288 return getDerived().RebuildOMPPrivateClause(
8289 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008290}
8291
Alexander Musman64d33f12014-06-04 07:53:32 +00008292template <typename Derived>
8293OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8294 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008295 llvm::SmallVector<Expr *, 16> Vars;
8296 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008297 for (auto *VE : C->varlists()) {
8298 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008299 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008300 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008301 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008302 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008303 return getDerived().RebuildOMPFirstprivateClause(
8304 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008305}
8306
Alexander Musman64d33f12014-06-04 07:53:32 +00008307template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008308OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008309TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8310 llvm::SmallVector<Expr *, 16> Vars;
8311 Vars.reserve(C->varlist_size());
8312 for (auto *VE : C->varlists()) {
8313 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8314 if (EVar.isInvalid())
8315 return nullptr;
8316 Vars.push_back(EVar.get());
8317 }
8318 return getDerived().RebuildOMPLastprivateClause(
8319 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8320}
8321
8322template <typename Derived>
8323OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008324TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8325 llvm::SmallVector<Expr *, 16> Vars;
8326 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008327 for (auto *VE : C->varlists()) {
8328 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008329 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008330 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008331 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008332 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008333 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8334 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008335}
8336
Alexander Musman64d33f12014-06-04 07:53:32 +00008337template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008338OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008339TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8340 llvm::SmallVector<Expr *, 16> Vars;
8341 Vars.reserve(C->varlist_size());
8342 for (auto *VE : C->varlists()) {
8343 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8344 if (EVar.isInvalid())
8345 return nullptr;
8346 Vars.push_back(EVar.get());
8347 }
8348 CXXScopeSpec ReductionIdScopeSpec;
8349 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8350
8351 DeclarationNameInfo NameInfo = C->getNameInfo();
8352 if (NameInfo.getName()) {
8353 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8354 if (!NameInfo.getName())
8355 return nullptr;
8356 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008357 // Build a list of all UDR decls with the same names ranged by the Scopes.
8358 // The Scope boundary is a duplication of the previous decl.
8359 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8360 for (auto *E : C->reduction_ops()) {
8361 // Transform all the decls.
8362 if (E) {
8363 auto *ULE = cast<UnresolvedLookupExpr>(E);
8364 UnresolvedSet<8> Decls;
8365 for (auto *D : ULE->decls()) {
8366 NamedDecl *InstD =
8367 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8368 Decls.addDecl(InstD, InstD->getAccess());
8369 }
8370 UnresolvedReductions.push_back(
8371 UnresolvedLookupExpr::Create(
8372 SemaRef.Context, /*NamingClass=*/nullptr,
8373 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8374 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8375 Decls.begin(), Decls.end()));
8376 } else
8377 UnresolvedReductions.push_back(nullptr);
8378 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008379 return getDerived().RebuildOMPReductionClause(
8380 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008381 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008382}
8383
8384template <typename Derived>
8385OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008386TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8387 llvm::SmallVector<Expr *, 16> Vars;
8388 Vars.reserve(C->varlist_size());
8389 for (auto *VE : C->varlists()) {
8390 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8391 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008392 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008393 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008394 }
8395 ExprResult Step = getDerived().TransformExpr(C->getStep());
8396 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008397 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008398 return getDerived().RebuildOMPLinearClause(
8399 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8400 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008401}
8402
Alexander Musman64d33f12014-06-04 07:53:32 +00008403template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008404OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008405TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8406 llvm::SmallVector<Expr *, 16> Vars;
8407 Vars.reserve(C->varlist_size());
8408 for (auto *VE : C->varlists()) {
8409 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8410 if (EVar.isInvalid())
8411 return nullptr;
8412 Vars.push_back(EVar.get());
8413 }
8414 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8415 if (Alignment.isInvalid())
8416 return nullptr;
8417 return getDerived().RebuildOMPAlignedClause(
8418 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8419 C->getColonLoc(), C->getLocEnd());
8420}
8421
Alexander Musman64d33f12014-06-04 07:53:32 +00008422template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008423OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008424TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8425 llvm::SmallVector<Expr *, 16> Vars;
8426 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008427 for (auto *VE : C->varlists()) {
8428 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008429 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008430 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008431 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008432 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008433 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8434 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008435}
8436
Alexey Bataevbae9a792014-06-27 10:37:06 +00008437template <typename Derived>
8438OMPClause *
8439TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8440 llvm::SmallVector<Expr *, 16> Vars;
8441 Vars.reserve(C->varlist_size());
8442 for (auto *VE : C->varlists()) {
8443 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8444 if (EVar.isInvalid())
8445 return nullptr;
8446 Vars.push_back(EVar.get());
8447 }
8448 return getDerived().RebuildOMPCopyprivateClause(
8449 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8450}
8451
Alexey Bataev6125da92014-07-21 11:26:11 +00008452template <typename Derived>
8453OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8454 llvm::SmallVector<Expr *, 16> Vars;
8455 Vars.reserve(C->varlist_size());
8456 for (auto *VE : C->varlists()) {
8457 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8458 if (EVar.isInvalid())
8459 return nullptr;
8460 Vars.push_back(EVar.get());
8461 }
8462 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8463 C->getLParenLoc(), C->getLocEnd());
8464}
8465
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008466template <typename Derived>
8467OMPClause *
8468TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8469 llvm::SmallVector<Expr *, 16> Vars;
8470 Vars.reserve(C->varlist_size());
8471 for (auto *VE : C->varlists()) {
8472 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8473 if (EVar.isInvalid())
8474 return nullptr;
8475 Vars.push_back(EVar.get());
8476 }
8477 return getDerived().RebuildOMPDependClause(
8478 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8479 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8480}
8481
Michael Wonge710d542015-08-07 16:16:36 +00008482template <typename Derived>
8483OMPClause *
8484TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8485 ExprResult E = getDerived().TransformExpr(C->getDevice());
8486 if (E.isInvalid())
8487 return nullptr;
8488 return getDerived().RebuildOMPDeviceClause(
8489 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8490}
8491
Kelvin Li0bff7af2015-11-23 05:32:03 +00008492template <typename Derived>
8493OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8494 llvm::SmallVector<Expr *, 16> Vars;
8495 Vars.reserve(C->varlist_size());
8496 for (auto *VE : C->varlists()) {
8497 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8498 if (EVar.isInvalid())
8499 return nullptr;
8500 Vars.push_back(EVar.get());
8501 }
8502 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008503 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8504 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8505 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008506}
8507
Kelvin Li099bb8c2015-11-24 20:50:12 +00008508template <typename Derived>
8509OMPClause *
8510TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8511 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8512 if (E.isInvalid())
8513 return nullptr;
8514 return getDerived().RebuildOMPNumTeamsClause(
8515 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8516}
8517
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008518template <typename Derived>
8519OMPClause *
8520TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8521 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8522 if (E.isInvalid())
8523 return nullptr;
8524 return getDerived().RebuildOMPThreadLimitClause(
8525 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8526}
8527
Alexey Bataeva0569352015-12-01 10:17:31 +00008528template <typename Derived>
8529OMPClause *
8530TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8531 ExprResult E = getDerived().TransformExpr(C->getPriority());
8532 if (E.isInvalid())
8533 return nullptr;
8534 return getDerived().RebuildOMPPriorityClause(
8535 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8536}
8537
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008538template <typename Derived>
8539OMPClause *
8540TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8541 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8542 if (E.isInvalid())
8543 return nullptr;
8544 return getDerived().RebuildOMPGrainsizeClause(
8545 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8546}
8547
Alexey Bataev382967a2015-12-08 12:06:20 +00008548template <typename Derived>
8549OMPClause *
8550TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8551 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8552 if (E.isInvalid())
8553 return nullptr;
8554 return getDerived().RebuildOMPNumTasksClause(
8555 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8556}
8557
Alexey Bataev28c75412015-12-15 08:19:24 +00008558template <typename Derived>
8559OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8560 ExprResult E = getDerived().TransformExpr(C->getHint());
8561 if (E.isInvalid())
8562 return nullptr;
8563 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8564 C->getLParenLoc(), C->getLocEnd());
8565}
8566
Carlo Bertollib4adf552016-01-15 18:50:31 +00008567template <typename Derived>
8568OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8569 OMPDistScheduleClause *C) {
8570 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8571 if (E.isInvalid())
8572 return nullptr;
8573 return getDerived().RebuildOMPDistScheduleClause(
8574 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8575 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8576}
8577
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008578template <typename Derived>
8579OMPClause *
8580TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8581 return C;
8582}
8583
Samuel Antao661c0902016-05-26 17:39:58 +00008584template <typename Derived>
8585OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8586 llvm::SmallVector<Expr *, 16> Vars;
8587 Vars.reserve(C->varlist_size());
8588 for (auto *VE : C->varlists()) {
8589 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8590 if (EVar.isInvalid())
8591 return 0;
8592 Vars.push_back(EVar.get());
8593 }
8594 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8595 C->getLParenLoc(), C->getLocEnd());
8596}
8597
Samuel Antaoec172c62016-05-26 17:49:04 +00008598template <typename Derived>
8599OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8600 llvm::SmallVector<Expr *, 16> Vars;
8601 Vars.reserve(C->varlist_size());
8602 for (auto *VE : C->varlists()) {
8603 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8604 if (EVar.isInvalid())
8605 return 0;
8606 Vars.push_back(EVar.get());
8607 }
8608 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8609 C->getLParenLoc(), C->getLocEnd());
8610}
8611
Carlo Bertolli2404b172016-07-13 15:37:16 +00008612template <typename Derived>
8613OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8614 OMPUseDevicePtrClause *C) {
8615 llvm::SmallVector<Expr *, 16> Vars;
8616 Vars.reserve(C->varlist_size());
8617 for (auto *VE : C->varlists()) {
8618 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8619 if (EVar.isInvalid())
8620 return nullptr;
8621 Vars.push_back(EVar.get());
8622 }
8623 return getDerived().RebuildOMPUseDevicePtrClause(
8624 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8625}
8626
Carlo Bertolli70594e92016-07-13 17:16:49 +00008627template <typename Derived>
8628OMPClause *
8629TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8630 llvm::SmallVector<Expr *, 16> Vars;
8631 Vars.reserve(C->varlist_size());
8632 for (auto *VE : C->varlists()) {
8633 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8634 if (EVar.isInvalid())
8635 return nullptr;
8636 Vars.push_back(EVar.get());
8637 }
8638 return getDerived().RebuildOMPIsDevicePtrClause(
8639 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8640}
8641
Douglas Gregorebe10102009-08-20 07:17:43 +00008642//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008643// Expression transformation
8644//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008647TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008648 if (!E->isTypeDependent())
8649 return E;
8650
8651 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8652 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008653}
Mike Stump11289f42009-09-09 15:08:12 +00008654
8655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008657TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008658 NestedNameSpecifierLoc QualifierLoc;
8659 if (E->getQualifierLoc()) {
8660 QualifierLoc
8661 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8662 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008663 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008664 }
John McCallce546572009-12-08 09:08:17 +00008665
8666 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008667 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8668 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008669 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008671
John McCall815039a2010-08-17 21:27:17 +00008672 DeclarationNameInfo NameInfo = E->getNameInfo();
8673 if (NameInfo.getName()) {
8674 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8675 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008676 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008677 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008678
8679 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008680 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008681 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008682 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008683 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008684
8685 // Mark it referenced in the new context regardless.
8686 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008687 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008688
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008689 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008690 }
John McCallce546572009-12-08 09:08:17 +00008691
Craig Topperc3ec1492014-05-26 06:22:03 +00008692 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008693 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008694 TemplateArgs = &TransArgs;
8695 TransArgs.setLAngleLoc(E->getLAngleLoc());
8696 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008697 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8698 E->getNumTemplateArgs(),
8699 TransArgs))
8700 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008701 }
8702
Chad Rosier1dcde962012-08-08 18:46:20 +00008703 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008704 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008705}
Mike Stump11289f42009-09-09 15:08:12 +00008706
Douglas Gregora16548e2009-08-11 05:31:07 +00008707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008708ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008709TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008710 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008711}
Mike Stump11289f42009-09-09 15:08:12 +00008712
Douglas Gregora16548e2009-08-11 05:31:07 +00008713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008715TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008716 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008717}
Mike Stump11289f42009-09-09 15:08:12 +00008718
Douglas Gregora16548e2009-08-11 05:31:07 +00008719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008721TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008722 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008723}
Mike Stump11289f42009-09-09 15:08:12 +00008724
Douglas Gregora16548e2009-08-11 05:31:07 +00008725template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008726ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008727TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008728 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008729}
Mike Stump11289f42009-09-09 15:08:12 +00008730
Douglas Gregora16548e2009-08-11 05:31:07 +00008731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008733TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008734 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008735}
8736
8737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008738ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008739TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008740 if (FunctionDecl *FD = E->getDirectCallee())
8741 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008742 return SemaRef.MaybeBindToTemporary(E);
8743}
8744
8745template<typename Derived>
8746ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008747TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8748 ExprResult ControllingExpr =
8749 getDerived().TransformExpr(E->getControllingExpr());
8750 if (ControllingExpr.isInvalid())
8751 return ExprError();
8752
Chris Lattner01cf8db2011-07-20 06:58:45 +00008753 SmallVector<Expr *, 4> AssocExprs;
8754 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008755 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8756 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8757 if (TS) {
8758 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8759 if (!AssocType)
8760 return ExprError();
8761 AssocTypes.push_back(AssocType);
8762 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008763 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008764 }
8765
8766 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8767 if (AssocExpr.isInvalid())
8768 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008769 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008770 }
8771
8772 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8773 E->getDefaultLoc(),
8774 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008775 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008776 AssocTypes,
8777 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008778}
8779
8780template<typename Derived>
8781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008782TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008783 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008784 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008786
Douglas Gregora16548e2009-08-11 05:31:07 +00008787 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008788 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008789
John McCallb268a282010-08-23 23:25:46 +00008790 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008791 E->getRParen());
8792}
8793
Richard Smithdb2630f2012-10-21 03:28:35 +00008794/// \brief The operand of a unary address-of operator has special rules: it's
8795/// allowed to refer to a non-static member of a class even if there's no 'this'
8796/// object available.
8797template<typename Derived>
8798ExprResult
8799TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8800 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008801 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008802 else
8803 return getDerived().TransformExpr(E);
8804}
8805
Mike Stump11289f42009-09-09 15:08:12 +00008806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008808TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008809 ExprResult SubExpr;
8810 if (E->getOpcode() == UO_AddrOf)
8811 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8812 else
8813 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008814 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008815 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008816
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008818 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008819
Douglas Gregora16548e2009-08-11 05:31:07 +00008820 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8821 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008822 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008823}
Mike Stump11289f42009-09-09 15:08:12 +00008824
Douglas Gregora16548e2009-08-11 05:31:07 +00008825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008826ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008827TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8828 // Transform the type.
8829 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8830 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008831 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008832
Douglas Gregor882211c2010-04-28 22:16:22 +00008833 // Transform all of the components into components similar to what the
8834 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008835 // FIXME: It would be slightly more efficient in the non-dependent case to
8836 // just map FieldDecls, rather than requiring the rebuilder to look for
8837 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008838 // template code that we don't care.
8839 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008840 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008841 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008842 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008843 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008844 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008845 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008846 Comp.LocStart = ON.getSourceRange().getBegin();
8847 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008848 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008849 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008850 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008851 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008852 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008853 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008854
Douglas Gregor882211c2010-04-28 22:16:22 +00008855 ExprChanged = ExprChanged || Index.get() != FromIndex;
8856 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008857 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008858 break;
8859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008860
James Y Knight7281c352015-12-29 22:31:18 +00008861 case OffsetOfNode::Field:
8862 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008863 Comp.isBrackets = false;
8864 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008865 if (!Comp.U.IdentInfo)
8866 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008867
Douglas Gregor882211c2010-04-28 22:16:22 +00008868 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008869
James Y Knight7281c352015-12-29 22:31:18 +00008870 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008871 // Will be recomputed during the rebuild.
8872 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008874
Douglas Gregor882211c2010-04-28 22:16:22 +00008875 Components.push_back(Comp);
8876 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008877
Douglas Gregor882211c2010-04-28 22:16:22 +00008878 // If nothing changed, retain the existing expression.
8879 if (!getDerived().AlwaysRebuild() &&
8880 Type == E->getTypeSourceInfo() &&
8881 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008882 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008883
Douglas Gregor882211c2010-04-28 22:16:22 +00008884 // Build a new offsetof expression.
8885 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008886 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008887}
8888
8889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008890ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008891TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008892 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008893 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008894 return E;
John McCall8d69a212010-11-15 23:31:06 +00008895}
8896
8897template<typename Derived>
8898ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008899TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8900 return E;
8901}
8902
8903template<typename Derived>
8904ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008905TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008906 // Rebuild the syntactic form. The original syntactic form has
8907 // opaque-value expressions in it, so strip those away and rebuild
8908 // the result. This is a really awful way of doing this, but the
8909 // better solution (rebuilding the semantic expressions and
8910 // rebinding OVEs as necessary) doesn't work; we'd need
8911 // TreeTransform to not strip away implicit conversions.
8912 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8913 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008914 if (result.isInvalid()) return ExprError();
8915
8916 // If that gives us a pseudo-object result back, the pseudo-object
8917 // expression must have been an lvalue-to-rvalue conversion which we
8918 // should reapply.
8919 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008920 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008921
8922 return result;
8923}
8924
8925template<typename Derived>
8926ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00008927TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
8928 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008929 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00008930 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00008931
John McCallbcd03502009-12-07 02:54:59 +00008932 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00008933 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008934 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008935
John McCall4c98fd82009-11-04 07:28:41 +00008936 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008937 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008938
Peter Collingbournee190dee2011-03-11 19:24:49 +00008939 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
8940 E->getKind(),
8941 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008942 }
Mike Stump11289f42009-09-09 15:08:12 +00008943
Eli Friedmane4f22df2012-02-29 04:03:55 +00008944 // C++0x [expr.sizeof]p1:
8945 // The operand is either an expression, which is an unevaluated operand
8946 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00008947 EnterExpressionEvaluationContext Unevaluated(
8948 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
8949 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008950
Reid Kleckner32506ed2014-06-12 23:03:48 +00008951 // Try to recover if we have something like sizeof(T::X) where X is a type.
8952 // Notably, there must be *exactly* one set of parens if X is a type.
8953 TypeSourceInfo *RecoveryTSI = nullptr;
8954 ExprResult SubExpr;
8955 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
8956 if (auto *DRE =
8957 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
8958 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
8959 PE, DRE, false, &RecoveryTSI);
8960 else
8961 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
8962
8963 if (RecoveryTSI) {
8964 return getDerived().RebuildUnaryExprOrTypeTrait(
8965 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
8966 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00008967 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008968
Eli Friedmane4f22df2012-02-29 04:03:55 +00008969 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008970 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008971
Peter Collingbournee190dee2011-03-11 19:24:49 +00008972 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
8973 E->getOperatorLoc(),
8974 E->getKind(),
8975 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00008976}
Mike Stump11289f42009-09-09 15:08:12 +00008977
Douglas Gregora16548e2009-08-11 05:31:07 +00008978template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008979ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008980TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008981 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008982 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008983 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008984
John McCalldadc5752010-08-24 06:29:42 +00008985 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008986 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008987 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008988
8989
Douglas Gregora16548e2009-08-11 05:31:07 +00008990 if (!getDerived().AlwaysRebuild() &&
8991 LHS.get() == E->getLHS() &&
8992 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008993 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008994
John McCallb268a282010-08-23 23:25:46 +00008995 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008996 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008997 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008998 E->getRBracketLoc());
8999}
Mike Stump11289f42009-09-09 15:08:12 +00009000
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009001template <typename Derived>
9002ExprResult
9003TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9004 ExprResult Base = getDerived().TransformExpr(E->getBase());
9005 if (Base.isInvalid())
9006 return ExprError();
9007
9008 ExprResult LowerBound;
9009 if (E->getLowerBound()) {
9010 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9011 if (LowerBound.isInvalid())
9012 return ExprError();
9013 }
9014
9015 ExprResult Length;
9016 if (E->getLength()) {
9017 Length = getDerived().TransformExpr(E->getLength());
9018 if (Length.isInvalid())
9019 return ExprError();
9020 }
9021
9022 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9023 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9024 return E;
9025
9026 return getDerived().RebuildOMPArraySectionExpr(
9027 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9028 Length.get(), E->getRBracketLoc());
9029}
9030
Mike Stump11289f42009-09-09 15:08:12 +00009031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009033TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009034 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009035 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009036 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009037 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009038
9039 // Transform arguments.
9040 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009041 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009042 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009043 &ArgChanged))
9044 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009045
Douglas Gregora16548e2009-08-11 05:31:07 +00009046 if (!getDerived().AlwaysRebuild() &&
9047 Callee.get() == E->getCallee() &&
9048 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009049 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009050
Douglas Gregora16548e2009-08-11 05:31:07 +00009051 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009052 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009053 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009054 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009055 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009056 E->getRParenLoc());
9057}
Mike Stump11289f42009-09-09 15:08:12 +00009058
9059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009061TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009062 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009063 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009065
Douglas Gregorea972d32011-02-28 21:54:11 +00009066 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009067 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009068 QualifierLoc
9069 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009070
Douglas Gregorea972d32011-02-28 21:54:11 +00009071 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009072 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009073 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009074 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009075
Eli Friedman2cfcef62009-12-04 06:40:45 +00009076 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009077 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9078 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009079 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009080 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009081
John McCall16df1e52010-03-30 21:47:33 +00009082 NamedDecl *FoundDecl = E->getFoundDecl();
9083 if (FoundDecl == E->getMemberDecl()) {
9084 FoundDecl = Member;
9085 } else {
9086 FoundDecl = cast_or_null<NamedDecl>(
9087 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9088 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009089 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009090 }
9091
Douglas Gregora16548e2009-08-11 05:31:07 +00009092 if (!getDerived().AlwaysRebuild() &&
9093 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009094 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009095 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009096 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009097 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009098
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009099 // Mark it referenced in the new context regardless.
9100 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009101 SemaRef.MarkMemberReferenced(E);
9102
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009103 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009104 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009105
John McCall6b51f282009-11-23 01:53:49 +00009106 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009107 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009108 TransArgs.setLAngleLoc(E->getLAngleLoc());
9109 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009110 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9111 E->getNumTemplateArgs(),
9112 TransArgs))
9113 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009114 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009115
Douglas Gregora16548e2009-08-11 05:31:07 +00009116 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009117 SourceLocation FakeOperatorLoc =
9118 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009119
John McCall38836f02010-01-15 08:34:02 +00009120 // FIXME: to do this check properly, we will need to preserve the
9121 // first-qualifier-in-scope here, just in case we had a dependent
9122 // base (and therefore couldn't do the check) and a
9123 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009124 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009125 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9126 if (MemberNameInfo.getName()) {
9127 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9128 if (!MemberNameInfo.getName())
9129 return ExprError();
9130 }
John McCall38836f02010-01-15 08:34:02 +00009131
John McCallb268a282010-08-23 23:25:46 +00009132 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009133 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009134 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009135 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009136 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009137 Member,
John McCall16df1e52010-03-30 21:47:33 +00009138 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009139 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009140 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009141 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009142}
Mike Stump11289f42009-09-09 15:08:12 +00009143
Douglas Gregora16548e2009-08-11 05:31:07 +00009144template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009145ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009146TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009147 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009148 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009149 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009150
John McCalldadc5752010-08-24 06:29:42 +00009151 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009152 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009154
Douglas Gregora16548e2009-08-11 05:31:07 +00009155 if (!getDerived().AlwaysRebuild() &&
9156 LHS.get() == E->getLHS() &&
9157 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009158 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009159
Lang Hames5de91cc2012-10-02 04:45:10 +00009160 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009161 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009162
Douglas Gregora16548e2009-08-11 05:31:07 +00009163 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009164 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009165}
9166
Mike Stump11289f42009-09-09 15:08:12 +00009167template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009168ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009169TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009170 CompoundAssignOperator *E) {
9171 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009172}
Mike Stump11289f42009-09-09 15:08:12 +00009173
Douglas Gregora16548e2009-08-11 05:31:07 +00009174template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009175ExprResult TreeTransform<Derived>::
9176TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9177 // Just rebuild the common and RHS expressions and see whether we
9178 // get any changes.
9179
9180 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9181 if (commonExpr.isInvalid())
9182 return ExprError();
9183
9184 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9185 if (rhs.isInvalid())
9186 return ExprError();
9187
9188 if (!getDerived().AlwaysRebuild() &&
9189 commonExpr.get() == e->getCommon() &&
9190 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009191 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009192
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009193 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009194 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009195 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009196 e->getColonLoc(),
9197 rhs.get());
9198}
9199
9200template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009201ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009202TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009203 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009204 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009205 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009206
John McCalldadc5752010-08-24 06:29:42 +00009207 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009208 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009210
John McCalldadc5752010-08-24 06:29:42 +00009211 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009212 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009213 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009214
Douglas Gregora16548e2009-08-11 05:31:07 +00009215 if (!getDerived().AlwaysRebuild() &&
9216 Cond.get() == E->getCond() &&
9217 LHS.get() == E->getLHS() &&
9218 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009219 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009220
John McCallb268a282010-08-23 23:25:46 +00009221 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009222 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009223 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009224 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009225 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009226}
Mike Stump11289f42009-09-09 15:08:12 +00009227
9228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009230TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009231 // Implicit casts are eliminated during transformation, since they
9232 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009233 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009234}
Mike Stump11289f42009-09-09 15:08:12 +00009235
Douglas Gregora16548e2009-08-11 05:31:07 +00009236template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009237ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009238TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009239 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9240 if (!Type)
9241 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009242
John McCalldadc5752010-08-24 06:29:42 +00009243 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009244 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009245 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009246 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009247
Douglas Gregora16548e2009-08-11 05:31:07 +00009248 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009249 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009250 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009251 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009252
John McCall97513962010-01-15 18:39:57 +00009253 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009254 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009255 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009256 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009257}
Mike Stump11289f42009-09-09 15:08:12 +00009258
Douglas Gregora16548e2009-08-11 05:31:07 +00009259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009260ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009261TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009262 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9263 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9264 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009266
John McCalldadc5752010-08-24 06:29:42 +00009267 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009268 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009269 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009270
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009272 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009273 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009274 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009275
John McCall5d7aa7f2010-01-19 22:33:45 +00009276 // Note: the expression type doesn't necessarily match the
9277 // type-as-written, but that's okay, because it should always be
9278 // derivable from the initializer.
9279
John McCalle15bbff2010-01-18 19:35:47 +00009280 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009281 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009282 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009283}
Mike Stump11289f42009-09-09 15:08:12 +00009284
Douglas Gregora16548e2009-08-11 05:31:07 +00009285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009286ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009287TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009288 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009289 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009290 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009291
Douglas Gregora16548e2009-08-11 05:31:07 +00009292 if (!getDerived().AlwaysRebuild() &&
9293 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009294 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009295
Douglas Gregora16548e2009-08-11 05:31:07 +00009296 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009297 SourceLocation FakeOperatorLoc =
9298 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009299 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009300 E->getAccessorLoc(),
9301 E->getAccessor());
9302}
Mike Stump11289f42009-09-09 15:08:12 +00009303
Douglas Gregora16548e2009-08-11 05:31:07 +00009304template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009305ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009306TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009307 if (InitListExpr *Syntactic = E->getSyntacticForm())
9308 E = Syntactic;
9309
Douglas Gregora16548e2009-08-11 05:31:07 +00009310 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009311
Benjamin Kramerf0623432012-08-23 22:51:59 +00009312 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009313 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009314 Inits, &InitChanged))
9315 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009316
Richard Smith520449d2015-02-05 06:15:50 +00009317 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9318 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9319 // in some cases. We can't reuse it in general, because the syntactic and
9320 // semantic forms are linked, and we can't know that semantic form will
9321 // match even if the syntactic form does.
9322 }
Mike Stump11289f42009-09-09 15:08:12 +00009323
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009324 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00009325 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00009326}
Mike Stump11289f42009-09-09 15:08:12 +00009327
Douglas Gregora16548e2009-08-11 05:31:07 +00009328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009329ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009330TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009331 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009332
Douglas Gregorebe10102009-08-20 07:17:43 +00009333 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009334 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009335 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009337
Douglas Gregorebe10102009-08-20 07:17:43 +00009338 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009339 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009340 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009341 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9342 if (D.isFieldDesignator()) {
9343 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9344 D.getDotLoc(),
9345 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009346 if (D.getField()) {
9347 FieldDecl *Field = cast_or_null<FieldDecl>(
9348 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9349 if (Field != D.getField())
9350 // Rebuild the expression when the transformed FieldDecl is
9351 // different to the already assigned FieldDecl.
9352 ExprChanged = true;
9353 } else {
9354 // Ensure that the designator expression is rebuilt when there isn't
9355 // a resolved FieldDecl in the designator as we don't want to assign
9356 // a FieldDecl to a pattern designator that will be instantiated again.
9357 ExprChanged = true;
9358 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009359 continue;
9360 }
Mike Stump11289f42009-09-09 15:08:12 +00009361
David Majnemerf7e36092016-06-23 00:15:04 +00009362 if (D.isArrayDesignator()) {
9363 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009364 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009366
David Majnemerf7e36092016-06-23 00:15:04 +00009367 Desig.AddDesignator(
9368 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009369
David Majnemerf7e36092016-06-23 00:15:04 +00009370 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009371 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009372 continue;
9373 }
Mike Stump11289f42009-09-09 15:08:12 +00009374
David Majnemerf7e36092016-06-23 00:15:04 +00009375 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009376 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009377 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009378 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009379 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009380
David Majnemerf7e36092016-06-23 00:15:04 +00009381 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009382 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009384
9385 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009386 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009387 D.getLBracketLoc(),
9388 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009389
David Majnemerf7e36092016-06-23 00:15:04 +00009390 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9391 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009392
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009393 ArrayExprs.push_back(Start.get());
9394 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009395 }
Mike Stump11289f42009-09-09 15:08:12 +00009396
Douglas Gregora16548e2009-08-11 05:31:07 +00009397 if (!getDerived().AlwaysRebuild() &&
9398 Init.get() == E->getInit() &&
9399 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009400 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009401
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009402 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009403 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009404 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009405}
Mike Stump11289f42009-09-09 15:08:12 +00009406
Yunzhong Gaocb779302015-06-10 00:27:52 +00009407// Seems that if TransformInitListExpr() only works on the syntactic form of an
9408// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9409template<typename Derived>
9410ExprResult
9411TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9412 DesignatedInitUpdateExpr *E) {
9413 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9414 "initializer");
9415 return ExprError();
9416}
9417
9418template<typename Derived>
9419ExprResult
9420TreeTransform<Derived>::TransformNoInitExpr(
9421 NoInitExpr *E) {
9422 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9423 return ExprError();
9424}
9425
Douglas Gregora16548e2009-08-11 05:31:07 +00009426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009427ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009428TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9429 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9430 return ExprError();
9431}
9432
9433template<typename Derived>
9434ExprResult
9435TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9436 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9437 return ExprError();
9438}
9439
9440template<typename Derived>
9441ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009442TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009443 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009444 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009445
Douglas Gregor3da3c062009-10-28 00:29:27 +00009446 // FIXME: Will we ever have proper type location here? Will we actually
9447 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009448 QualType T = getDerived().TransformType(E->getType());
9449 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009450 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009451
Douglas Gregora16548e2009-08-11 05:31:07 +00009452 if (!getDerived().AlwaysRebuild() &&
9453 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009454 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009455
Douglas Gregora16548e2009-08-11 05:31:07 +00009456 return getDerived().RebuildImplicitValueInitExpr(T);
9457}
Mike Stump11289f42009-09-09 15:08:12 +00009458
Douglas Gregora16548e2009-08-11 05:31:07 +00009459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009461TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009462 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9463 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009464 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009465
John McCalldadc5752010-08-24 06:29:42 +00009466 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009467 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009469
Douglas Gregora16548e2009-08-11 05:31:07 +00009470 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009471 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009472 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009473 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009474
John McCallb268a282010-08-23 23:25:46 +00009475 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009476 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009477}
9478
9479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009481TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009482 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009483 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009484 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9485 &ArgumentChanged))
9486 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009487
Douglas Gregora16548e2009-08-11 05:31:07 +00009488 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009489 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009490 E->getRParenLoc());
9491}
Mike Stump11289f42009-09-09 15:08:12 +00009492
Douglas Gregora16548e2009-08-11 05:31:07 +00009493/// \brief Transform an address-of-label expression.
9494///
9495/// By default, the transformation of an address-of-label expression always
9496/// rebuilds the expression, so that the label identifier can be resolved to
9497/// the corresponding label statement by semantic analysis.
9498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009500TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009501 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9502 E->getLabel());
9503 if (!LD)
9504 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009505
Douglas Gregora16548e2009-08-11 05:31:07 +00009506 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009507 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009508}
Mike Stump11289f42009-09-09 15:08:12 +00009509
9510template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009511ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009512TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009513 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009514 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009515 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009516 if (SubStmt.isInvalid()) {
9517 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009518 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009519 }
Mike Stump11289f42009-09-09 15:08:12 +00009520
Douglas Gregora16548e2009-08-11 05:31:07 +00009521 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009522 SubStmt.get() == E->getSubStmt()) {
9523 // Calling this an 'error' is unintuitive, but it does the right thing.
9524 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009525 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009526 }
Mike Stump11289f42009-09-09 15:08:12 +00009527
9528 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009529 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009530 E->getRParenLoc());
9531}
Mike Stump11289f42009-09-09 15:08:12 +00009532
Douglas Gregora16548e2009-08-11 05:31:07 +00009533template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009534ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009535TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009536 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009537 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009538 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009539
John McCalldadc5752010-08-24 06:29:42 +00009540 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009541 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009542 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009543
John McCalldadc5752010-08-24 06:29:42 +00009544 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009545 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009546 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009547
Douglas Gregora16548e2009-08-11 05:31:07 +00009548 if (!getDerived().AlwaysRebuild() &&
9549 Cond.get() == E->getCond() &&
9550 LHS.get() == E->getLHS() &&
9551 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009552 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009553
Douglas Gregora16548e2009-08-11 05:31:07 +00009554 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009555 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009556 E->getRParenLoc());
9557}
Mike Stump11289f42009-09-09 15:08:12 +00009558
Douglas Gregora16548e2009-08-11 05:31:07 +00009559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009561TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009562 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009563}
9564
9565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009567TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009568 switch (E->getOperator()) {
9569 case OO_New:
9570 case OO_Delete:
9571 case OO_Array_New:
9572 case OO_Array_Delete:
9573 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009574
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009575 case OO_Call: {
9576 // This is a call to an object's operator().
9577 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9578
9579 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009580 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009581 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009582 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009583
9584 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009585 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9586 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009587
9588 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009589 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009590 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009591 Args))
9592 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009593
John McCallb268a282010-08-23 23:25:46 +00009594 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009595 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009596 E->getLocEnd());
9597 }
9598
9599#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9600 case OO_##Name:
9601#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9602#include "clang/Basic/OperatorKinds.def"
9603 case OO_Subscript:
9604 // Handled below.
9605 break;
9606
9607 case OO_Conditional:
9608 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009609
9610 case OO_None:
9611 case NUM_OVERLOADED_OPERATORS:
9612 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009613 }
9614
John McCalldadc5752010-08-24 06:29:42 +00009615 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009616 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009617 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009618
Richard Smithdb2630f2012-10-21 03:28:35 +00009619 ExprResult First;
9620 if (E->getOperator() == OO_Amp)
9621 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9622 else
9623 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009624 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009625 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009626
John McCalldadc5752010-08-24 06:29:42 +00009627 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009628 if (E->getNumArgs() == 2) {
9629 Second = getDerived().TransformExpr(E->getArg(1));
9630 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009631 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009632 }
Mike Stump11289f42009-09-09 15:08:12 +00009633
Douglas Gregora16548e2009-08-11 05:31:07 +00009634 if (!getDerived().AlwaysRebuild() &&
9635 Callee.get() == E->getCallee() &&
9636 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009637 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009638 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009639
Lang Hames5de91cc2012-10-02 04:45:10 +00009640 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009641 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009642
Douglas Gregora16548e2009-08-11 05:31:07 +00009643 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9644 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009645 Callee.get(),
9646 First.get(),
9647 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009648}
Mike Stump11289f42009-09-09 15:08:12 +00009649
Douglas Gregora16548e2009-08-11 05:31:07 +00009650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009652TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9653 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009654}
Mike Stump11289f42009-09-09 15:08:12 +00009655
Douglas Gregora16548e2009-08-11 05:31:07 +00009656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009657ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009658TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9659 // Transform the callee.
9660 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9661 if (Callee.isInvalid())
9662 return ExprError();
9663
9664 // Transform exec config.
9665 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9666 if (EC.isInvalid())
9667 return ExprError();
9668
9669 // Transform arguments.
9670 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009671 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009672 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009673 &ArgChanged))
9674 return ExprError();
9675
9676 if (!getDerived().AlwaysRebuild() &&
9677 Callee.get() == E->getCallee() &&
9678 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009679 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009680
9681 // FIXME: Wrong source location information for the '('.
9682 SourceLocation FakeLParenLoc
9683 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9684 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009685 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009686 E->getRParenLoc(), EC.get());
9687}
9688
9689template<typename Derived>
9690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009691TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009692 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9693 if (!Type)
9694 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009695
John McCalldadc5752010-08-24 06:29:42 +00009696 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009697 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009698 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009699 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009700
Douglas Gregora16548e2009-08-11 05:31:07 +00009701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009702 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009703 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009704 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009705 return getDerived().RebuildCXXNamedCastExpr(
9706 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9707 Type, E->getAngleBrackets().getEnd(),
9708 // FIXME. this should be '(' location
9709 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009710}
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregora16548e2009-08-11 05:31:07 +00009712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009714TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9715 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009716}
Mike Stump11289f42009-09-09 15:08:12 +00009717
9718template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009719ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009720TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9721 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009722}
9723
Douglas Gregora16548e2009-08-11 05:31:07 +00009724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009725ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009726TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009727 CXXReinterpretCastExpr *E) {
9728 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009729}
Mike Stump11289f42009-09-09 15:08:12 +00009730
Douglas Gregora16548e2009-08-11 05:31:07 +00009731template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009732ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009733TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9734 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009735}
Mike Stump11289f42009-09-09 15:08:12 +00009736
Douglas Gregora16548e2009-08-11 05:31:07 +00009737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009738ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009739TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009740 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009741 TypeSourceInfo *Type =
9742 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009743 if (!Type)
9744 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009745
John McCalldadc5752010-08-24 06:29:42 +00009746 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009747 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009748 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009749 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009750
Douglas Gregora16548e2009-08-11 05:31:07 +00009751 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009752 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009754 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009755
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009756 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009757 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009758 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009759 E->getRParenLoc());
9760}
Mike Stump11289f42009-09-09 15:08:12 +00009761
Douglas Gregora16548e2009-08-11 05:31:07 +00009762template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009763ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009764TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009765 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009766 TypeSourceInfo *TInfo
9767 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9768 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009769 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009770
Douglas Gregora16548e2009-08-11 05:31:07 +00009771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009772 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009773 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009774
Douglas Gregor9da64192010-04-26 22:37:10 +00009775 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9776 E->getLocStart(),
9777 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009778 E->getLocEnd());
9779 }
Mike Stump11289f42009-09-09 15:08:12 +00009780
Eli Friedman456f0182012-01-20 01:26:23 +00009781 // We don't know whether the subexpression is potentially evaluated until
9782 // after we perform semantic analysis. We speculatively assume it is
9783 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009784 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +00009785 EnterExpressionEvaluationContext Unevaluated(
9786 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9787 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009788
John McCalldadc5752010-08-24 06:29:42 +00009789 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009790 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009791 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009792
Douglas Gregora16548e2009-08-11 05:31:07 +00009793 if (!getDerived().AlwaysRebuild() &&
9794 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009795 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009796
Douglas Gregor9da64192010-04-26 22:37:10 +00009797 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9798 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009799 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009800 E->getLocEnd());
9801}
9802
9803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009804ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009805TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9806 if (E->isTypeOperand()) {
9807 TypeSourceInfo *TInfo
9808 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9809 if (!TInfo)
9810 return ExprError();
9811
9812 if (!getDerived().AlwaysRebuild() &&
9813 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009814 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009815
Douglas Gregor69735112011-03-06 17:40:41 +00009816 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009817 E->getLocStart(),
9818 TInfo,
9819 E->getLocEnd());
9820 }
9821
Faisal Valid143a0c2017-04-01 21:30:49 +00009822 EnterExpressionEvaluationContext Unevaluated(
9823 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +00009824
9825 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9826 if (SubExpr.isInvalid())
9827 return ExprError();
9828
9829 if (!getDerived().AlwaysRebuild() &&
9830 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009831 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009832
9833 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9834 E->getLocStart(),
9835 SubExpr.get(),
9836 E->getLocEnd());
9837}
9838
9839template<typename Derived>
9840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009841TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009842 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009843}
Mike Stump11289f42009-09-09 15:08:12 +00009844
Douglas Gregora16548e2009-08-11 05:31:07 +00009845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009846ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009847TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009848 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009849 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009850}
Mike Stump11289f42009-09-09 15:08:12 +00009851
Douglas Gregora16548e2009-08-11 05:31:07 +00009852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009854TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009855 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009856
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009857 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9858 // Make sure that we capture 'this'.
9859 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009860 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009861 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009862
Douglas Gregorb15af892010-01-07 23:12:05 +00009863 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009864}
Mike Stump11289f42009-09-09 15:08:12 +00009865
Douglas Gregora16548e2009-08-11 05:31:07 +00009866template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009867ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009868TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009869 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009870 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009871 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009872
Douglas Gregora16548e2009-08-11 05:31:07 +00009873 if (!getDerived().AlwaysRebuild() &&
9874 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009875 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009876
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009877 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9878 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009879}
Mike Stump11289f42009-09-09 15:08:12 +00009880
Douglas Gregora16548e2009-08-11 05:31:07 +00009881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009883TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009884 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009885 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9886 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009887 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009889
Chandler Carruth794da4c2010-02-08 06:42:49 +00009890 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009891 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009892 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009893
Douglas Gregor033f6752009-12-23 23:03:06 +00009894 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009895}
Mike Stump11289f42009-09-09 15:08:12 +00009896
Douglas Gregora16548e2009-08-11 05:31:07 +00009897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009898ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009899TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9900 FieldDecl *Field
9901 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9902 E->getField()));
9903 if (!Field)
9904 return ExprError();
9905
9906 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009907 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009908
9909 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9910}
9911
9912template<typename Derived>
9913ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009914TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9915 CXXScalarValueInitExpr *E) {
9916 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9917 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009918 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009919
Douglas Gregora16548e2009-08-11 05:31:07 +00009920 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009921 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009922 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009923
Chad Rosier1dcde962012-08-08 18:46:20 +00009924 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00009925 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00009926 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009927}
Mike Stump11289f42009-09-09 15:08:12 +00009928
Douglas Gregora16548e2009-08-11 05:31:07 +00009929template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009930ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009931TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009932 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +00009933 TypeSourceInfo *AllocTypeInfo =
9934 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +00009935 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009936 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009937
Douglas Gregora16548e2009-08-11 05:31:07 +00009938 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00009939 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00009940 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009941 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009942
Douglas Gregora16548e2009-08-11 05:31:07 +00009943 // Transform the placement arguments (if any).
9944 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009945 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00009946 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00009947 E->getNumPlacementArgs(), true,
9948 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00009949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009950
Sebastian Redl6047f072012-02-16 12:22:20 +00009951 // Transform the initializer (if any).
9952 Expr *OldInit = E->getInitializer();
9953 ExprResult NewInit;
9954 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00009955 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00009956 if (NewInit.isInvalid())
9957 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009958
Sebastian Redl6047f072012-02-16 12:22:20 +00009959 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00009960 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009961 if (E->getOperatorNew()) {
9962 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009963 getDerived().TransformDecl(E->getLocStart(),
9964 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009965 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00009966 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009967 }
9968
Craig Topperc3ec1492014-05-26 06:22:03 +00009969 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00009970 if (E->getOperatorDelete()) {
9971 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009972 getDerived().TransformDecl(E->getLocStart(),
9973 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00009974 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00009975 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00009976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009977
Douglas Gregora16548e2009-08-11 05:31:07 +00009978 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00009979 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009980 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00009981 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00009982 OperatorNew == E->getOperatorNew() &&
9983 OperatorDelete == E->getOperatorDelete() &&
9984 !ArgumentChanged) {
9985 // Mark any declarations we need as referenced.
9986 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00009987 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009988 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00009989 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00009990 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00009991
Sebastian Redl6047f072012-02-16 12:22:20 +00009992 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00009993 QualType ElementType
9994 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
9995 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
9996 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
9997 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00009998 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00009999 }
10000 }
10001 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010002
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010003 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010004 }
Mike Stump11289f42009-09-09 15:08:12 +000010005
Douglas Gregor0744ef62010-09-07 21:49:58 +000010006 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010007 if (!ArraySize.get()) {
10008 // If no array size was specified, but the new expression was
10009 // instantiated with an array type (e.g., "new T" where T is
10010 // instantiated with "int[4]"), extract the outer bound from the
10011 // array type as our array size. We do this with constant and
10012 // dependently-sized array types.
10013 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10014 if (!ArrayT) {
10015 // Do nothing
10016 } else if (const ConstantArrayType *ConsArrayT
10017 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010018 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10019 SemaRef.Context.getSizeType(),
10020 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010021 AllocType = ConsArrayT->getElementType();
10022 } else if (const DependentSizedArrayType *DepArrayT
10023 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10024 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010025 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010026 AllocType = DepArrayT->getElementType();
10027 }
10028 }
10029 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010030
Douglas Gregora16548e2009-08-11 05:31:07 +000010031 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10032 E->isGlobalNew(),
10033 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010034 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010035 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010036 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010037 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010038 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010039 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010040 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010041 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010042}
Mike Stump11289f42009-09-09 15:08:12 +000010043
Douglas Gregora16548e2009-08-11 05:31:07 +000010044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010046TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010047 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010048 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010049 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010050
Douglas Gregord2d9da02010-02-26 00:38:10 +000010051 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010052 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010053 if (E->getOperatorDelete()) {
10054 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010055 getDerived().TransformDecl(E->getLocStart(),
10056 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010057 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010058 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010059 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010060
Douglas Gregora16548e2009-08-11 05:31:07 +000010061 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010062 Operand.get() == E->getArgument() &&
10063 OperatorDelete == E->getOperatorDelete()) {
10064 // Mark any declarations we need as referenced.
10065 // FIXME: instantiation-specific.
10066 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010067 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010068
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010069 if (!E->getArgument()->isTypeDependent()) {
10070 QualType Destroyed = SemaRef.Context.getBaseElementType(
10071 E->getDestroyedType());
10072 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10073 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010074 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010075 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010076 }
10077 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010078
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010079 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010080 }
Mike Stump11289f42009-09-09 15:08:12 +000010081
Douglas Gregora16548e2009-08-11 05:31:07 +000010082 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10083 E->isGlobalDelete(),
10084 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010085 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010086}
Mike Stump11289f42009-09-09 15:08:12 +000010087
Douglas Gregora16548e2009-08-11 05:31:07 +000010088template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010089ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010090TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010091 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010092 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010093 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010094 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010095
John McCallba7bf592010-08-24 05:47:05 +000010096 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010097 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010098 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010099 E->getOperatorLoc(),
10100 E->isArrow()? tok::arrow : tok::period,
10101 ObjectTypePtr,
10102 MayBePseudoDestructor);
10103 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010104 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010105
John McCallba7bf592010-08-24 05:47:05 +000010106 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010107 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10108 if (QualifierLoc) {
10109 QualifierLoc
10110 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10111 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010112 return ExprError();
10113 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010114 CXXScopeSpec SS;
10115 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010116
Douglas Gregor678f90d2010-02-25 01:56:36 +000010117 PseudoDestructorTypeStorage Destroyed;
10118 if (E->getDestroyedTypeInfo()) {
10119 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010120 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010121 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010122 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010123 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010124 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010125 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010126 // We aren't likely to be able to resolve the identifier down to a type
10127 // now anyway, so just retain the identifier.
10128 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10129 E->getDestroyedTypeLoc());
10130 } else {
10131 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010132 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010133 *E->getDestroyedTypeIdentifier(),
10134 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010135 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010136 SS, ObjectTypePtr,
10137 false);
10138 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010139 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010140
Douglas Gregor678f90d2010-02-25 01:56:36 +000010141 Destroyed
10142 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10143 E->getDestroyedTypeLoc());
10144 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010145
Craig Topperc3ec1492014-05-26 06:22:03 +000010146 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010147 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010148 CXXScopeSpec EmptySS;
10149 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010150 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010151 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010152 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010153 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010154
John McCallb268a282010-08-23 23:25:46 +000010155 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010156 E->getOperatorLoc(),
10157 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010158 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010159 ScopeTypeInfo,
10160 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010161 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010162 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010163}
Mike Stump11289f42009-09-09 15:08:12 +000010164
Richard Smith151c4562016-12-20 21:35:28 +000010165template <typename Derived>
10166bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10167 bool RequiresADL,
10168 LookupResult &R) {
10169 // Transform all the decls.
10170 bool AllEmptyPacks = true;
10171 for (auto *OldD : Old->decls()) {
10172 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10173 if (!InstD) {
10174 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10175 // This can happen because of dependent hiding.
10176 if (isa<UsingShadowDecl>(OldD))
10177 continue;
10178 else {
10179 R.clear();
10180 return true;
10181 }
10182 }
10183
10184 // Expand using pack declarations.
10185 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10186 ArrayRef<NamedDecl*> Decls = SingleDecl;
10187 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10188 Decls = UPD->expansions();
10189
10190 // Expand using declarations.
10191 for (auto *D : Decls) {
10192 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10193 for (auto *SD : UD->shadows())
10194 R.addDecl(SD);
10195 } else {
10196 R.addDecl(D);
10197 }
10198 }
10199
10200 AllEmptyPacks &= Decls.empty();
10201 };
10202
10203 // C++ [temp.res]/8.4.2:
10204 // The program is ill-formed, no diagnostic required, if [...] lookup for
10205 // a name in the template definition found a using-declaration, but the
10206 // lookup in the corresponding scope in the instantiation odoes not find
10207 // any declarations because the using-declaration was a pack expansion and
10208 // the corresponding pack is empty
10209 if (AllEmptyPacks && !RequiresADL) {
10210 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10211 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10212 return true;
10213 }
10214
10215 // Resolve a kind, but don't do any further analysis. If it's
10216 // ambiguous, the callee needs to deal with it.
10217 R.resolveKind();
10218 return false;
10219}
10220
Douglas Gregorad8a3362009-09-04 17:36:40 +000010221template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010222ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010223TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010224 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010225 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10226 Sema::LookupOrdinaryName);
10227
Richard Smith151c4562016-12-20 21:35:28 +000010228 // Transform the declaration set.
10229 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10230 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010231
10232 // Rebuild the nested-name qualifier, if present.
10233 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010234 if (Old->getQualifierLoc()) {
10235 NestedNameSpecifierLoc QualifierLoc
10236 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10237 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010239
Douglas Gregor0da1d432011-02-28 20:01:57 +000010240 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010241 }
10242
Douglas Gregor9262f472010-04-27 18:19:34 +000010243 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010244 CXXRecordDecl *NamingClass
10245 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10246 Old->getNameLoc(),
10247 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010248 if (!NamingClass) {
10249 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010250 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010251 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010252
Douglas Gregorda7be082010-04-27 16:10:10 +000010253 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010254 }
10255
Abramo Bagnara7945c982012-01-27 09:46:47 +000010256 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10257
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010258 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010259 // it's a normal declaration name or member reference.
10260 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10261 NamedDecl *D = R.getAsSingle<NamedDecl>();
10262 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10263 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10264 // give a good diagnostic.
10265 if (D && D->isCXXInstanceMember()) {
10266 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10267 /*TemplateArgs=*/nullptr,
10268 /*Scope=*/nullptr);
10269 }
10270
John McCalle66edc12009-11-24 19:00:30 +000010271 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010272 }
John McCalle66edc12009-11-24 19:00:30 +000010273
10274 // If we have template arguments, rebuild them, then rebuild the
10275 // templateid expression.
10276 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010277 if (Old->hasExplicitTemplateArgs() &&
10278 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010279 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010280 TransArgs)) {
10281 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010282 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010283 }
John McCalle66edc12009-11-24 19:00:30 +000010284
Abramo Bagnara7945c982012-01-27 09:46:47 +000010285 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010286 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010287}
Mike Stump11289f42009-09-09 15:08:12 +000010288
Douglas Gregora16548e2009-08-11 05:31:07 +000010289template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010290ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010291TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10292 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010293 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010294 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10295 TypeSourceInfo *From = E->getArg(I);
10296 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010297 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010298 TypeLocBuilder TLB;
10299 TLB.reserve(FromTL.getFullDataSize());
10300 QualType To = getDerived().TransformType(TLB, FromTL);
10301 if (To.isNull())
10302 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010303
Douglas Gregor29c42f22012-02-24 07:38:34 +000010304 if (To == From->getType())
10305 Args.push_back(From);
10306 else {
10307 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10308 ArgChanged = true;
10309 }
10310 continue;
10311 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010312
Douglas Gregor29c42f22012-02-24 07:38:34 +000010313 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010314
Douglas Gregor29c42f22012-02-24 07:38:34 +000010315 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010316 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010317 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10318 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10319 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010320
Douglas Gregor29c42f22012-02-24 07:38:34 +000010321 // Determine whether the set of unexpanded parameter packs can and should
10322 // be expanded.
10323 bool Expand = true;
10324 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010325 Optional<unsigned> OrigNumExpansions =
10326 ExpansionTL.getTypePtr()->getNumExpansions();
10327 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010328 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10329 PatternTL.getSourceRange(),
10330 Unexpanded,
10331 Expand, RetainExpansion,
10332 NumExpansions))
10333 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010334
Douglas Gregor29c42f22012-02-24 07:38:34 +000010335 if (!Expand) {
10336 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010337 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010338 // expansion.
10339 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010340
Douglas Gregor29c42f22012-02-24 07:38:34 +000010341 TypeLocBuilder TLB;
10342 TLB.reserve(From->getTypeLoc().getFullDataSize());
10343
10344 QualType To = getDerived().TransformType(TLB, PatternTL);
10345 if (To.isNull())
10346 return ExprError();
10347
Chad Rosier1dcde962012-08-08 18:46:20 +000010348 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010349 PatternTL.getSourceRange(),
10350 ExpansionTL.getEllipsisLoc(),
10351 NumExpansions);
10352 if (To.isNull())
10353 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010354
Douglas Gregor29c42f22012-02-24 07:38:34 +000010355 PackExpansionTypeLoc ToExpansionTL
10356 = TLB.push<PackExpansionTypeLoc>(To);
10357 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10358 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10359 continue;
10360 }
10361
10362 // Expand the pack expansion by substituting for each argument in the
10363 // pack(s).
10364 for (unsigned I = 0; I != *NumExpansions; ++I) {
10365 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10366 TypeLocBuilder TLB;
10367 TLB.reserve(PatternTL.getFullDataSize());
10368 QualType To = getDerived().TransformType(TLB, PatternTL);
10369 if (To.isNull())
10370 return ExprError();
10371
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010372 if (To->containsUnexpandedParameterPack()) {
10373 To = getDerived().RebuildPackExpansionType(To,
10374 PatternTL.getSourceRange(),
10375 ExpansionTL.getEllipsisLoc(),
10376 NumExpansions);
10377 if (To.isNull())
10378 return ExprError();
10379
10380 PackExpansionTypeLoc ToExpansionTL
10381 = TLB.push<PackExpansionTypeLoc>(To);
10382 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10383 }
10384
Douglas Gregor29c42f22012-02-24 07:38:34 +000010385 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10386 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010387
Douglas Gregor29c42f22012-02-24 07:38:34 +000010388 if (!RetainExpansion)
10389 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010390
Douglas Gregor29c42f22012-02-24 07:38:34 +000010391 // If we're supposed to retain a pack expansion, do so by temporarily
10392 // forgetting the partially-substituted parameter pack.
10393 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10394
10395 TypeLocBuilder TLB;
10396 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010397
Douglas Gregor29c42f22012-02-24 07:38:34 +000010398 QualType To = getDerived().TransformType(TLB, PatternTL);
10399 if (To.isNull())
10400 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010401
10402 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010403 PatternTL.getSourceRange(),
10404 ExpansionTL.getEllipsisLoc(),
10405 NumExpansions);
10406 if (To.isNull())
10407 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010408
Douglas Gregor29c42f22012-02-24 07:38:34 +000010409 PackExpansionTypeLoc ToExpansionTL
10410 = TLB.push<PackExpansionTypeLoc>(To);
10411 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10412 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10413 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010414
Douglas Gregor29c42f22012-02-24 07:38:34 +000010415 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010416 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010417
10418 return getDerived().RebuildTypeTrait(E->getTrait(),
10419 E->getLocStart(),
10420 Args,
10421 E->getLocEnd());
10422}
10423
10424template<typename Derived>
10425ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010426TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10427 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10428 if (!T)
10429 return ExprError();
10430
10431 if (!getDerived().AlwaysRebuild() &&
10432 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010433 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010434
10435 ExprResult SubExpr;
10436 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010437 EnterExpressionEvaluationContext Unevaluated(
10438 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010439 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10440 if (SubExpr.isInvalid())
10441 return ExprError();
10442
10443 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010444 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010445 }
10446
10447 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10448 E->getLocStart(),
10449 T,
10450 SubExpr.get(),
10451 E->getLocEnd());
10452}
10453
10454template<typename Derived>
10455ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010456TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10457 ExprResult SubExpr;
10458 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010459 EnterExpressionEvaluationContext Unevaluated(
10460 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010461 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10462 if (SubExpr.isInvalid())
10463 return ExprError();
10464
10465 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010466 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010467 }
10468
10469 return getDerived().RebuildExpressionTrait(
10470 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10471}
10472
Reid Kleckner32506ed2014-06-12 23:03:48 +000010473template <typename Derived>
10474ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10475 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10476 TypeSourceInfo **RecoveryTSI) {
10477 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10478 DRE, AddrTaken, RecoveryTSI);
10479
10480 // Propagate both errors and recovered types, which return ExprEmpty.
10481 if (!NewDRE.isUsable())
10482 return NewDRE;
10483
10484 // We got an expr, wrap it up in parens.
10485 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10486 return PE;
10487 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10488 PE->getRParen());
10489}
10490
10491template <typename Derived>
10492ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10493 DependentScopeDeclRefExpr *E) {
10494 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10495 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010496}
10497
10498template<typename Derived>
10499ExprResult
10500TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10501 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010502 bool IsAddressOfOperand,
10503 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010504 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010505 NestedNameSpecifierLoc QualifierLoc
10506 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10507 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010508 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010509 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010510
John McCall31f82722010-11-12 08:19:04 +000010511 // TODO: If this is a conversion-function-id, verify that the
10512 // destination type name (if present) resolves the same way after
10513 // instantiation as it did in the local scope.
10514
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010515 DeclarationNameInfo NameInfo
10516 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10517 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010518 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010519
John McCalle66edc12009-11-24 19:00:30 +000010520 if (!E->hasExplicitTemplateArgs()) {
10521 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010522 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010523 // Note: it is sufficient to compare the Name component of NameInfo:
10524 // if name has not changed, DNLoc has not changed either.
10525 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010526 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010527
Reid Kleckner32506ed2014-06-12 23:03:48 +000010528 return getDerived().RebuildDependentScopeDeclRefExpr(
10529 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10530 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010531 }
John McCall6b51f282009-11-23 01:53:49 +000010532
10533 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010534 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10535 E->getNumTemplateArgs(),
10536 TransArgs))
10537 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010538
Reid Kleckner32506ed2014-06-12 23:03:48 +000010539 return getDerived().RebuildDependentScopeDeclRefExpr(
10540 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10541 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010542}
10543
10544template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010545ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010546TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010547 // CXXConstructExprs other than for list-initialization and
10548 // CXXTemporaryObjectExpr are always implicit, so when we have
10549 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010550 if ((E->getNumArgs() == 1 ||
10551 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010552 (!getDerived().DropCallArgument(E->getArg(0))) &&
10553 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010554 return getDerived().TransformExpr(E->getArg(0));
10555
Douglas Gregora16548e2009-08-11 05:31:07 +000010556 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10557
10558 QualType T = getDerived().TransformType(E->getType());
10559 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010560 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010561
10562 CXXConstructorDecl *Constructor
10563 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010564 getDerived().TransformDecl(E->getLocStart(),
10565 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010566 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010568
Douglas Gregora16548e2009-08-11 05:31:07 +000010569 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010570 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010571 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010572 &ArgumentChanged))
10573 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010574
Douglas Gregora16548e2009-08-11 05:31:07 +000010575 if (!getDerived().AlwaysRebuild() &&
10576 T == E->getType() &&
10577 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010578 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010579 // Mark the constructor as referenced.
10580 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010581 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010582 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010583 }
Mike Stump11289f42009-09-09 15:08:12 +000010584
Douglas Gregordb121ba2009-12-14 16:27:04 +000010585 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010586 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010587 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010588 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010589 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010590 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010591 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010592 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010593 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010594}
Mike Stump11289f42009-09-09 15:08:12 +000010595
Richard Smith5179eb72016-06-28 19:03:57 +000010596template<typename Derived>
10597ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10598 CXXInheritedCtorInitExpr *E) {
10599 QualType T = getDerived().TransformType(E->getType());
10600 if (T.isNull())
10601 return ExprError();
10602
10603 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10604 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10605 if (!Constructor)
10606 return ExprError();
10607
10608 if (!getDerived().AlwaysRebuild() &&
10609 T == E->getType() &&
10610 Constructor == E->getConstructor()) {
10611 // Mark the constructor as referenced.
10612 // FIXME: Instantiation-specific
10613 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10614 return E;
10615 }
10616
10617 return getDerived().RebuildCXXInheritedCtorInitExpr(
10618 T, E->getLocation(), Constructor,
10619 E->constructsVBase(), E->inheritedFromVBase());
10620}
10621
Douglas Gregora16548e2009-08-11 05:31:07 +000010622/// \brief Transform a C++ temporary-binding expression.
10623///
Douglas Gregor363b1512009-12-24 18:51:59 +000010624/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10625/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010627ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010628TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010629 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010630}
Mike Stump11289f42009-09-09 15:08:12 +000010631
John McCall5d413782010-12-06 08:20:24 +000010632/// \brief Transform a C++ expression that contains cleanups that should
10633/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010634///
John McCall5d413782010-12-06 08:20:24 +000010635/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010636/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010638ExprResult
John McCall5d413782010-12-06 08:20:24 +000010639TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010640 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010641}
Mike Stump11289f42009-09-09 15:08:12 +000010642
Douglas Gregora16548e2009-08-11 05:31:07 +000010643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010644ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010645TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010646 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010647 TypeSourceInfo *T =
10648 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010649 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010651
Douglas Gregora16548e2009-08-11 05:31:07 +000010652 CXXConstructorDecl *Constructor
10653 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010654 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010655 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010656 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010657 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010658
Douglas Gregora16548e2009-08-11 05:31:07 +000010659 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010660 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010661 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010662 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010663 &ArgumentChanged))
10664 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010665
Douglas Gregora16548e2009-08-11 05:31:07 +000010666 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010667 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010668 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010669 !ArgumentChanged) {
10670 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010671 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010672 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010673 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010674
Richard Smithd59b8322012-12-19 01:39:02 +000010675 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010676 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10677 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010678 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010679 E->getLocEnd());
10680}
Mike Stump11289f42009-09-09 15:08:12 +000010681
Douglas Gregora16548e2009-08-11 05:31:07 +000010682template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010683ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010684TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010685 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010686 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010687 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010688 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10689 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010690 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010691 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010692 CEnd = E->capture_end();
10693 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010694 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010695 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010696 EnterExpressionEvaluationContext EEEC(
10697 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010698 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10699 C->getCapturedVar()->getInit(),
10700 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010701
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010702 if (NewExprInitResult.isInvalid())
10703 return ExprError();
10704 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010705
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010706 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010707 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010708 getSema().buildLambdaInitCaptureInitialization(
10709 C->getLocation(), OldVD->getType()->isReferenceType(),
10710 OldVD->getIdentifier(),
10711 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010712 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010713 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10714 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010715 }
10716
Faisal Vali2cba1332013-10-23 06:44:28 +000010717 // Transform the template parameters, and add them to the current
10718 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010719 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010720 E->getTemplateParameterList());
10721
Richard Smith01014ce2014-11-20 23:53:14 +000010722 // Transform the type of the original lambda's call operator.
10723 // The transformation MUST be done in the CurrentInstantiationScope since
10724 // it introduces a mapping of the original to the newly created
10725 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010726 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010727 {
10728 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10729 FunctionProtoTypeLoc OldCallOpFPTL =
10730 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010731
10732 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010733 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010734 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010735 QualType NewCallOpType = TransformFunctionProtoType(
10736 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010737 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10738 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10739 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010740 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010741 if (NewCallOpType.isNull())
10742 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010743 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10744 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010745 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010746
Richard Smithc38498f2015-04-27 21:27:54 +000010747 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10748 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10749 LSI->GLTemplateParameterList = TPL;
10750
Eli Friedmand564afb2012-09-19 01:18:11 +000010751 // Create the local class that will describe the lambda.
10752 CXXRecordDecl *Class
10753 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010754 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010755 /*KnownDependent=*/false,
10756 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010757 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10758
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010759 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010760 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10761 Class, E->getIntroducerRange(), NewCallOpTSI,
10762 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010763 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10764 E->getCallOperator()->isConstexpr());
10765
Faisal Vali2cba1332013-10-23 06:44:28 +000010766 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010767
Akira Hatanaka402818462016-12-16 21:16:57 +000010768 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10769 I != NumParams; ++I) {
10770 auto *P = NewCallOperator->getParamDecl(I);
10771 if (P->hasUninstantiatedDefaultArg()) {
10772 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010773 getSema(),
10774 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010775 ExprResult R = getDerived().TransformExpr(
10776 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10777 P->setDefaultArg(R.get());
10778 }
10779 }
10780
Faisal Vali2cba1332013-10-23 06:44:28 +000010781 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010782 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010783
Douglas Gregorb4328232012-02-14 00:00:48 +000010784 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010785 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010786 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010787
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010788 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010789 getSema().buildLambdaScope(LSI, NewCallOperator,
10790 E->getIntroducerRange(),
10791 E->getCaptureDefault(),
10792 E->getCaptureDefaultLoc(),
10793 E->hasExplicitParameters(),
10794 E->hasExplicitResultType(),
10795 E->isMutable());
10796
10797 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010798
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010799 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010800 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010801 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010802 CEnd = E->capture_end();
10803 C != CEnd; ++C) {
10804 // When we hit the first implicit capture, tell Sema that we've finished
10805 // the list of explicit captures.
10806 if (!FinishedExplicitCaptures && C->isImplicit()) {
10807 getSema().finishLambdaExplicitCaptures(LSI);
10808 FinishedExplicitCaptures = true;
10809 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010810
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010811 // Capturing 'this' is trivial.
10812 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010813 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10814 /*BuildAndDiagnose*/ true, nullptr,
10815 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010816 continue;
10817 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010818 // Captured expression will be recaptured during captured variables
10819 // rebuilding.
10820 if (C->capturesVLAType())
10821 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010822
Richard Smithba71c082013-05-16 06:20:58 +000010823 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010824 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010825 InitCaptureInfoTy InitExprTypePair =
10826 InitCaptureExprsAndTypes[C - E->capture_begin()];
10827 ExprResult Init = InitExprTypePair.first;
10828 QualType InitQualType = InitExprTypePair.second;
10829 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010830 Invalid = true;
10831 continue;
10832 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010833 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010834 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010835 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10836 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010837 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010838 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010839 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010840 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010841 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010842 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010843 continue;
10844 }
10845
10846 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10847
Douglas Gregor3e308b12012-02-14 19:27:52 +000010848 // Determine the capture kind for Sema.
10849 Sema::TryCaptureKind Kind
10850 = C->isImplicit()? Sema::TryCapture_Implicit
10851 : C->getCaptureKind() == LCK_ByCopy
10852 ? Sema::TryCapture_ExplicitByVal
10853 : Sema::TryCapture_ExplicitByRef;
10854 SourceLocation EllipsisLoc;
10855 if (C->isPackExpansion()) {
10856 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10857 bool ShouldExpand = false;
10858 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010859 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010860 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10861 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010862 Unexpanded,
10863 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010864 NumExpansions)) {
10865 Invalid = true;
10866 continue;
10867 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010868
Douglas Gregor3e308b12012-02-14 19:27:52 +000010869 if (ShouldExpand) {
10870 // The transform has determined that we should perform an expansion;
10871 // transform and capture each of the arguments.
10872 // expansion of the pattern. Do so.
10873 VarDecl *Pack = C->getCapturedVar();
10874 for (unsigned I = 0; I != *NumExpansions; ++I) {
10875 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10876 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010877 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010878 Pack));
10879 if (!CapturedVar) {
10880 Invalid = true;
10881 continue;
10882 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010883
Douglas Gregor3e308b12012-02-14 19:27:52 +000010884 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010885 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10886 }
Richard Smith9467be42014-06-06 17:33:35 +000010887
10888 // FIXME: Retain a pack expansion if RetainExpansion is true.
10889
Douglas Gregor3e308b12012-02-14 19:27:52 +000010890 continue;
10891 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010892
Douglas Gregor3e308b12012-02-14 19:27:52 +000010893 EllipsisLoc = C->getEllipsisLoc();
10894 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010895
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010896 // Transform the captured variable.
10897 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010898 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010899 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010900 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010901 Invalid = true;
10902 continue;
10903 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010904
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010905 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010906 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10907 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010908 }
10909 if (!FinishedExplicitCaptures)
10910 getSema().finishLambdaExplicitCaptures(LSI);
10911
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010912 // Enter a new evaluation context to insulate the lambda from any
10913 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000010914 getSema().PushExpressionEvaluationContext(
10915 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010916
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010917 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010918 StmtResult Body =
10919 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10920
10921 // ActOnLambda* will pop the function scope for us.
10922 FuncScopeCleanup.disable();
10923
Douglas Gregorb4328232012-02-14 00:00:48 +000010924 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000010925 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000010926 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000010927 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000010928 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000010929 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000010930
Richard Smithc38498f2015-04-27 21:27:54 +000010931 // Copy the LSI before ActOnFinishFunctionBody removes it.
10932 // FIXME: This is dumb. Store the lambda information somewhere that outlives
10933 // the call operator.
10934 auto LSICopy = *LSI;
10935 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
10936 /*IsInstantiation*/ true);
10937 SavedContext.pop();
10938
10939 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
10940 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000010941}
10942
10943template<typename Derived>
10944ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010945TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010946 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010947 TypeSourceInfo *T =
10948 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010949 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010950 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010951
Douglas Gregora16548e2009-08-11 05:31:07 +000010952 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010953 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010954 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000010955 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010956 &ArgumentChanged))
10957 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010958
Douglas Gregora16548e2009-08-11 05:31:07 +000010959 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010960 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010961 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010962 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010963
Douglas Gregora16548e2009-08-11 05:31:07 +000010964 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000010965 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000010966 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010967 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010968 E->getRParenLoc());
10969}
Mike Stump11289f42009-09-09 15:08:12 +000010970
Douglas Gregora16548e2009-08-11 05:31:07 +000010971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010972ExprResult
John McCall8cd78132009-11-19 22:55:06 +000010973TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010974 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010975 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000010976 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000010977 Expr *OldBase;
10978 QualType BaseType;
10979 QualType ObjectType;
10980 if (!E->isImplicitAccess()) {
10981 OldBase = E->getBase();
10982 Base = getDerived().TransformExpr(OldBase);
10983 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010985
John McCall2d74de92009-12-01 22:10:20 +000010986 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000010987 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000010988 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010989 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000010990 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000010991 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000010992 ObjectTy,
10993 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000010994 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010995 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000010996
John McCallba7bf592010-08-24 05:47:05 +000010997 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000010998 BaseType = ((Expr*) Base.get())->getType();
10999 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011000 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011001 BaseType = getDerived().TransformType(E->getBaseType());
11002 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11003 }
Mike Stump11289f42009-09-09 15:08:12 +000011004
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011005 // Transform the first part of the nested-name-specifier that qualifies
11006 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011007 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011008 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011009 E->getFirstQualifierFoundInScope(),
11010 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011011
Douglas Gregore16af532011-02-28 18:50:33 +000011012 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011013 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011014 QualifierLoc
11015 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11016 ObjectType,
11017 FirstQualifierInScope);
11018 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011019 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011020 }
Mike Stump11289f42009-09-09 15:08:12 +000011021
Abramo Bagnara7945c982012-01-27 09:46:47 +000011022 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11023
John McCall31f82722010-11-12 08:19:04 +000011024 // TODO: If this is a conversion-function-id, verify that the
11025 // destination type name (if present) resolves the same way after
11026 // instantiation as it did in the local scope.
11027
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011028 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011029 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011030 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011031 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011032
John McCall2d74de92009-12-01 22:10:20 +000011033 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011034 // This is a reference to a member without an explicitly-specified
11035 // template argument list. Optimize for this common case.
11036 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011037 Base.get() == OldBase &&
11038 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011039 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011040 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011041 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011042 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011043
John McCallb268a282010-08-23 23:25:46 +000011044 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011045 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011046 E->isArrow(),
11047 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011048 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011049 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011050 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011051 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011052 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011053 }
11054
John McCall6b51f282009-11-23 01:53:49 +000011055 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011056 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11057 E->getNumTemplateArgs(),
11058 TransArgs))
11059 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011060
John McCallb268a282010-08-23 23:25:46 +000011061 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011062 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011063 E->isArrow(),
11064 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011065 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011066 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011067 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011068 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011069 &TransArgs);
11070}
11071
11072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011073ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011074TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011075 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011076 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011077 QualType BaseType;
11078 if (!Old->isImplicitAccess()) {
11079 Base = getDerived().TransformExpr(Old->getBase());
11080 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011081 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011082 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011083 Old->isArrow());
11084 if (Base.isInvalid())
11085 return ExprError();
11086 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011087 } else {
11088 BaseType = getDerived().TransformType(Old->getBaseType());
11089 }
John McCall10eae182009-11-30 22:42:35 +000011090
Douglas Gregor0da1d432011-02-28 20:01:57 +000011091 NestedNameSpecifierLoc QualifierLoc;
11092 if (Old->getQualifierLoc()) {
11093 QualifierLoc
11094 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11095 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011096 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011097 }
11098
Abramo Bagnara7945c982012-01-27 09:46:47 +000011099 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11100
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011101 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011102 Sema::LookupOrdinaryName);
11103
Richard Smith151c4562016-12-20 21:35:28 +000011104 // Transform the declaration set.
11105 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11106 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011107
Douglas Gregor9262f472010-04-27 18:19:34 +000011108 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011109 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011110 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011111 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011112 Old->getMemberLoc(),
11113 Old->getNamingClass()));
11114 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011115 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011116
Douglas Gregorda7be082010-04-27 16:10:10 +000011117 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011118 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011119
John McCall10eae182009-11-30 22:42:35 +000011120 TemplateArgumentListInfo TransArgs;
11121 if (Old->hasExplicitTemplateArgs()) {
11122 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11123 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011124 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11125 Old->getNumTemplateArgs(),
11126 TransArgs))
11127 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011128 }
John McCall38836f02010-01-15 08:34:02 +000011129
11130 // FIXME: to do this check properly, we will need to preserve the
11131 // first-qualifier-in-scope here, just in case we had a dependent
11132 // base (and therefore couldn't do the check) and a
11133 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011134 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011135
John McCallb268a282010-08-23 23:25:46 +000011136 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011137 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011138 Old->getOperatorLoc(),
11139 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011140 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011141 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011142 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011143 R,
11144 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011145 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011146}
11147
11148template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011149ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011150TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011151 EnterExpressionEvaluationContext Unevaluated(
11152 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011153 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11154 if (SubExpr.isInvalid())
11155 return ExprError();
11156
11157 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011158 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011159
11160 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11161}
11162
11163template<typename Derived>
11164ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011165TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011166 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11167 if (Pattern.isInvalid())
11168 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011169
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011170 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011171 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011172
Douglas Gregorb8840002011-01-14 21:20:45 +000011173 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11174 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011175}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011176
11177template<typename Derived>
11178ExprResult
11179TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11180 // If E is not value-dependent, then nothing will change when we transform it.
11181 // Note: This is an instantiation-centric view.
11182 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011183 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011184
Faisal Valid143a0c2017-04-01 21:30:49 +000011185 EnterExpressionEvaluationContext Unevaluated(
11186 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011187
Richard Smithd784e682015-09-23 21:41:42 +000011188 ArrayRef<TemplateArgument> PackArgs;
11189 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011190
Richard Smithd784e682015-09-23 21:41:42 +000011191 // Find the argument list to transform.
11192 if (E->isPartiallySubstituted()) {
11193 PackArgs = E->getPartialArguments();
11194 } else if (E->isValueDependent()) {
11195 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11196 bool ShouldExpand = false;
11197 bool RetainExpansion = false;
11198 Optional<unsigned> NumExpansions;
11199 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11200 Unexpanded,
11201 ShouldExpand, RetainExpansion,
11202 NumExpansions))
11203 return ExprError();
11204
11205 // If we need to expand the pack, build a template argument from it and
11206 // expand that.
11207 if (ShouldExpand) {
11208 auto *Pack = E->getPack();
11209 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11210 ArgStorage = getSema().Context.getPackExpansionType(
11211 getSema().Context.getTypeDeclType(TTPD), None);
11212 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11213 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11214 } else {
11215 auto *VD = cast<ValueDecl>(Pack);
11216 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11217 VK_RValue, E->getPackLoc());
11218 if (DRE.isInvalid())
11219 return ExprError();
11220 ArgStorage = new (getSema().Context) PackExpansionExpr(
11221 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11222 }
11223 PackArgs = ArgStorage;
11224 }
11225 }
11226
11227 // If we're not expanding the pack, just transform the decl.
11228 if (!PackArgs.size()) {
11229 auto *Pack = cast_or_null<NamedDecl>(
11230 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011231 if (!Pack)
11232 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011233 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11234 E->getPackLoc(),
11235 E->getRParenLoc(), None, None);
11236 }
11237
Richard Smithc5452ed2016-10-19 22:18:42 +000011238 // Try to compute the result without performing a partial substitution.
11239 Optional<unsigned> Result = 0;
11240 for (const TemplateArgument &Arg : PackArgs) {
11241 if (!Arg.isPackExpansion()) {
11242 Result = *Result + 1;
11243 continue;
11244 }
11245
11246 TemplateArgumentLoc ArgLoc;
11247 InventTemplateArgumentLoc(Arg, ArgLoc);
11248
11249 // Find the pattern of the pack expansion.
11250 SourceLocation Ellipsis;
11251 Optional<unsigned> OrigNumExpansions;
11252 TemplateArgumentLoc Pattern =
11253 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11254 OrigNumExpansions);
11255
11256 // Substitute under the pack expansion. Do not expand the pack (yet).
11257 TemplateArgumentLoc OutPattern;
11258 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11259 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11260 /*Uneval*/ true))
11261 return true;
11262
11263 // See if we can determine the number of arguments from the result.
11264 Optional<unsigned> NumExpansions =
11265 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11266 if (!NumExpansions) {
11267 // No: we must be in an alias template expansion, and we're going to need
11268 // to actually expand the packs.
11269 Result = None;
11270 break;
11271 }
11272
11273 Result = *Result + *NumExpansions;
11274 }
11275
11276 // Common case: we could determine the number of expansions without
11277 // substituting.
11278 if (Result)
11279 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11280 E->getPackLoc(),
11281 E->getRParenLoc(), *Result, None);
11282
Richard Smithd784e682015-09-23 21:41:42 +000011283 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11284 E->getPackLoc());
11285 {
11286 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11287 typedef TemplateArgumentLocInventIterator<
11288 Derived, const TemplateArgument*> PackLocIterator;
11289 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11290 PackLocIterator(*this, PackArgs.end()),
11291 TransformedPackArgs, /*Uneval*/true))
11292 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011293 }
11294
Richard Smithc5452ed2016-10-19 22:18:42 +000011295 // Check whether we managed to fully-expand the pack.
11296 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011297 SmallVector<TemplateArgument, 8> Args;
11298 bool PartialSubstitution = false;
11299 for (auto &Loc : TransformedPackArgs.arguments()) {
11300 Args.push_back(Loc.getArgument());
11301 if (Loc.getArgument().isPackExpansion())
11302 PartialSubstitution = true;
11303 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011304
Richard Smithd784e682015-09-23 21:41:42 +000011305 if (PartialSubstitution)
11306 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11307 E->getPackLoc(),
11308 E->getRParenLoc(), None, Args);
11309
11310 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011311 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011312 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011313}
11314
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011315template<typename Derived>
11316ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011317TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11318 SubstNonTypeTemplateParmPackExpr *E) {
11319 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011320 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011321}
11322
11323template<typename Derived>
11324ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011325TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11326 SubstNonTypeTemplateParmExpr *E) {
11327 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011328 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011329}
11330
11331template<typename Derived>
11332ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011333TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11334 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011335 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011336}
11337
11338template<typename Derived>
11339ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011340TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11341 MaterializeTemporaryExpr *E) {
11342 return getDerived().TransformExpr(E->GetTemporaryExpr());
11343}
Chad Rosier1dcde962012-08-08 18:46:20 +000011344
Douglas Gregorfe314812011-06-21 17:03:29 +000011345template<typename Derived>
11346ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011347TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11348 Expr *Pattern = E->getPattern();
11349
11350 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11351 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11352 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11353
11354 // Determine whether the set of unexpanded parameter packs can and should
11355 // be expanded.
11356 bool Expand = true;
11357 bool RetainExpansion = false;
11358 Optional<unsigned> NumExpansions;
11359 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11360 Pattern->getSourceRange(),
11361 Unexpanded,
11362 Expand, RetainExpansion,
11363 NumExpansions))
11364 return true;
11365
11366 if (!Expand) {
11367 // Do not expand any packs here, just transform and rebuild a fold
11368 // expression.
11369 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11370
11371 ExprResult LHS =
11372 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11373 if (LHS.isInvalid())
11374 return true;
11375
11376 ExprResult RHS =
11377 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11378 if (RHS.isInvalid())
11379 return true;
11380
11381 if (!getDerived().AlwaysRebuild() &&
11382 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11383 return E;
11384
11385 return getDerived().RebuildCXXFoldExpr(
11386 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11387 RHS.get(), E->getLocEnd());
11388 }
11389
11390 // The transform has determined that we should perform an elementwise
11391 // expansion of the pattern. Do so.
11392 ExprResult Result = getDerived().TransformExpr(E->getInit());
11393 if (Result.isInvalid())
11394 return true;
11395 bool LeftFold = E->isLeftFold();
11396
11397 // If we're retaining an expansion for a right fold, it is the innermost
11398 // component and takes the init (if any).
11399 if (!LeftFold && RetainExpansion) {
11400 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11401
11402 ExprResult Out = getDerived().TransformExpr(Pattern);
11403 if (Out.isInvalid())
11404 return true;
11405
11406 Result = getDerived().RebuildCXXFoldExpr(
11407 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11408 Result.get(), E->getLocEnd());
11409 if (Result.isInvalid())
11410 return true;
11411 }
11412
11413 for (unsigned I = 0; I != *NumExpansions; ++I) {
11414 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11415 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11416 ExprResult Out = getDerived().TransformExpr(Pattern);
11417 if (Out.isInvalid())
11418 return true;
11419
11420 if (Out.get()->containsUnexpandedParameterPack()) {
11421 // We still have a pack; retain a pack expansion for this slice.
11422 Result = getDerived().RebuildCXXFoldExpr(
11423 E->getLocStart(),
11424 LeftFold ? Result.get() : Out.get(),
11425 E->getOperator(), E->getEllipsisLoc(),
11426 LeftFold ? Out.get() : Result.get(),
11427 E->getLocEnd());
11428 } else if (Result.isUsable()) {
11429 // We've got down to a single element; build a binary operator.
11430 Result = getDerived().RebuildBinaryOperator(
11431 E->getEllipsisLoc(), E->getOperator(),
11432 LeftFold ? Result.get() : Out.get(),
11433 LeftFold ? Out.get() : Result.get());
11434 } else
11435 Result = Out;
11436
11437 if (Result.isInvalid())
11438 return true;
11439 }
11440
11441 // If we're retaining an expansion for a left fold, it is the outermost
11442 // component and takes the complete expansion so far as its init (if any).
11443 if (LeftFold && RetainExpansion) {
11444 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11445
11446 ExprResult Out = getDerived().TransformExpr(Pattern);
11447 if (Out.isInvalid())
11448 return true;
11449
11450 Result = getDerived().RebuildCXXFoldExpr(
11451 E->getLocStart(), Result.get(),
11452 E->getOperator(), E->getEllipsisLoc(),
11453 Out.get(), E->getLocEnd());
11454 if (Result.isInvalid())
11455 return true;
11456 }
11457
11458 // If we had no init and an empty pack, and we're not retaining an expansion,
11459 // then produce a fallback value or error.
11460 if (Result.isUnset())
11461 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11462 E->getOperator());
11463
11464 return Result;
11465}
11466
11467template<typename Derived>
11468ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011469TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11470 CXXStdInitializerListExpr *E) {
11471 return getDerived().TransformExpr(E->getSubExpr());
11472}
11473
11474template<typename Derived>
11475ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011476TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011477 return SemaRef.MaybeBindToTemporary(E);
11478}
11479
11480template<typename Derived>
11481ExprResult
11482TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011483 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011484}
11485
11486template<typename Derived>
11487ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011488TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11489 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11490 if (SubExpr.isInvalid())
11491 return ExprError();
11492
11493 if (!getDerived().AlwaysRebuild() &&
11494 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011495 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011496
11497 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011498}
11499
11500template<typename Derived>
11501ExprResult
11502TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11503 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011504 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011505 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011506 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011507 /*IsCall=*/false, Elements, &ArgChanged))
11508 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011509
Ted Kremeneke65b0862012-03-06 20:05:56 +000011510 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11511 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011512
Ted Kremeneke65b0862012-03-06 20:05:56 +000011513 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11514 Elements.data(),
11515 Elements.size());
11516}
11517
11518template<typename Derived>
11519ExprResult
11520TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011521 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011522 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011523 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011524 bool ArgChanged = false;
11525 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11526 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011527
Ted Kremeneke65b0862012-03-06 20:05:56 +000011528 if (OrigElement.isPackExpansion()) {
11529 // This key/value element is a pack expansion.
11530 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11531 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11532 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11533 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11534
11535 // Determine whether the set of unexpanded parameter packs can
11536 // and should be expanded.
11537 bool Expand = true;
11538 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011539 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11540 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011541 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11542 OrigElement.Value->getLocEnd());
11543 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11544 PatternRange,
11545 Unexpanded,
11546 Expand, RetainExpansion,
11547 NumExpansions))
11548 return ExprError();
11549
11550 if (!Expand) {
11551 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011552 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011553 // expansion.
11554 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11555 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11556 if (Key.isInvalid())
11557 return ExprError();
11558
11559 if (Key.get() != OrigElement.Key)
11560 ArgChanged = true;
11561
11562 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11563 if (Value.isInvalid())
11564 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011565
Ted Kremeneke65b0862012-03-06 20:05:56 +000011566 if (Value.get() != OrigElement.Value)
11567 ArgChanged = true;
11568
Chad Rosier1dcde962012-08-08 18:46:20 +000011569 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011570 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11571 };
11572 Elements.push_back(Expansion);
11573 continue;
11574 }
11575
11576 // Record right away that the argument was changed. This needs
11577 // to happen even if the array expands to nothing.
11578 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011579
Ted Kremeneke65b0862012-03-06 20:05:56 +000011580 // The transform has determined that we should perform an elementwise
11581 // expansion of the pattern. Do so.
11582 for (unsigned I = 0; I != *NumExpansions; ++I) {
11583 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11584 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11585 if (Key.isInvalid())
11586 return ExprError();
11587
11588 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11589 if (Value.isInvalid())
11590 return ExprError();
11591
Chad Rosier1dcde962012-08-08 18:46:20 +000011592 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011593 Key.get(), Value.get(), SourceLocation(), NumExpansions
11594 };
11595
11596 // If any unexpanded parameter packs remain, we still have a
11597 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011598 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011599 if (Key.get()->containsUnexpandedParameterPack() ||
11600 Value.get()->containsUnexpandedParameterPack())
11601 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011602
Ted Kremeneke65b0862012-03-06 20:05:56 +000011603 Elements.push_back(Element);
11604 }
11605
Richard Smith9467be42014-06-06 17:33:35 +000011606 // FIXME: Retain a pack expansion if RetainExpansion is true.
11607
Ted Kremeneke65b0862012-03-06 20:05:56 +000011608 // We've finished with this pack expansion.
11609 continue;
11610 }
11611
11612 // Transform and check key.
11613 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11614 if (Key.isInvalid())
11615 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011616
Ted Kremeneke65b0862012-03-06 20:05:56 +000011617 if (Key.get() != OrigElement.Key)
11618 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011619
Ted Kremeneke65b0862012-03-06 20:05:56 +000011620 // Transform and check value.
11621 ExprResult Value
11622 = getDerived().TransformExpr(OrigElement.Value);
11623 if (Value.isInvalid())
11624 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011625
Ted Kremeneke65b0862012-03-06 20:05:56 +000011626 if (Value.get() != OrigElement.Value)
11627 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011628
11629 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011630 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011631 };
11632 Elements.push_back(Element);
11633 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011634
Ted Kremeneke65b0862012-03-06 20:05:56 +000011635 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11636 return SemaRef.MaybeBindToTemporary(E);
11637
11638 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011639 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011640}
11641
Mike Stump11289f42009-09-09 15:08:12 +000011642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011644TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011645 TypeSourceInfo *EncodedTypeInfo
11646 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11647 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011649
Douglas Gregora16548e2009-08-11 05:31:07 +000011650 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011651 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011652 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011653
11654 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011655 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011656 E->getRParenLoc());
11657}
Mike Stump11289f42009-09-09 15:08:12 +000011658
Douglas Gregora16548e2009-08-11 05:31:07 +000011659template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011660ExprResult TreeTransform<Derived>::
11661TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011662 // This is a kind of implicit conversion, and it needs to get dropped
11663 // and recomputed for the same general reasons that ImplicitCastExprs
11664 // do, as well a more specific one: this expression is only valid when
11665 // it appears *immediately* as an argument expression.
11666 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011667}
11668
11669template<typename Derived>
11670ExprResult TreeTransform<Derived>::
11671TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011672 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011673 = getDerived().TransformType(E->getTypeInfoAsWritten());
11674 if (!TSInfo)
11675 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011676
John McCall31168b02011-06-15 23:02:42 +000011677 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011678 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011679 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011680
John McCall31168b02011-06-15 23:02:42 +000011681 if (!getDerived().AlwaysRebuild() &&
11682 TSInfo == E->getTypeInfoAsWritten() &&
11683 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011684 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011685
John McCall31168b02011-06-15 23:02:42 +000011686 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011687 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011688 Result.get());
11689}
11690
Erik Pilkington29099de2016-07-16 00:35:23 +000011691template <typename Derived>
11692ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11693 ObjCAvailabilityCheckExpr *E) {
11694 return E;
11695}
11696
John McCall31168b02011-06-15 23:02:42 +000011697template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011698ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011699TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011700 // Transform arguments.
11701 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011702 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011703 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011704 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011705 &ArgChanged))
11706 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011707
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011708 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11709 // Class message: transform the receiver type.
11710 TypeSourceInfo *ReceiverTypeInfo
11711 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11712 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011713 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011714
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011715 // If nothing changed, just retain the existing message send.
11716 if (!getDerived().AlwaysRebuild() &&
11717 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011718 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011719
11720 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011721 SmallVector<SourceLocation, 16> SelLocs;
11722 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011723 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11724 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011725 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011726 E->getMethodDecl(),
11727 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011728 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011729 E->getRightLoc());
11730 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011731 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11732 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011733 if (!E->getMethodDecl())
11734 return ExprError();
11735
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011736 // Build a new class message send to 'super'.
11737 SmallVector<SourceLocation, 16> SelLocs;
11738 E->getSelectorLocs(SelLocs);
11739 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11740 E->getSelector(),
11741 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011742 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011743 E->getMethodDecl(),
11744 E->getLeftLoc(),
11745 Args,
11746 E->getRightLoc());
11747 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011748
11749 // Instance message: transform the receiver
11750 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11751 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011752 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011753 = getDerived().TransformExpr(E->getInstanceReceiver());
11754 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011755 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011756
11757 // If nothing changed, just retain the existing message send.
11758 if (!getDerived().AlwaysRebuild() &&
11759 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011760 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011761
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011762 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011763 SmallVector<SourceLocation, 16> SelLocs;
11764 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011765 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011766 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011767 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011768 E->getMethodDecl(),
11769 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011770 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011771 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011772}
11773
Mike Stump11289f42009-09-09 15:08:12 +000011774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011776TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011777 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011778}
11779
Mike Stump11289f42009-09-09 15:08:12 +000011780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011782TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011783 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011784}
11785
Mike Stump11289f42009-09-09 15:08:12 +000011786template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011787ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011788TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011789 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011790 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011791 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011792 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011793
11794 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011795
Douglas Gregord51d90d2010-04-26 20:11:03 +000011796 // If nothing changed, just retain the existing expression.
11797 if (!getDerived().AlwaysRebuild() &&
11798 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011799 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011800
John McCallb268a282010-08-23 23:25:46 +000011801 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011802 E->getLocation(),
11803 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011804}
11805
Mike Stump11289f42009-09-09 15:08:12 +000011806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011808TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011809 // 'super' and types never change. Property never changes. Just
11810 // retain the existing expression.
11811 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011812 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011813
Douglas Gregor9faee212010-04-26 20:47:02 +000011814 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011815 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011816 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011818
Douglas Gregor9faee212010-04-26 20:47:02 +000011819 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011820
Douglas Gregor9faee212010-04-26 20:47:02 +000011821 // If nothing changed, just retain the existing expression.
11822 if (!getDerived().AlwaysRebuild() &&
11823 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011824 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011825
John McCallb7bd14f2010-12-02 01:19:52 +000011826 if (E->isExplicitProperty())
11827 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11828 E->getExplicitProperty(),
11829 E->getLocation());
11830
11831 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011832 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011833 E->getImplicitPropertyGetter(),
11834 E->getImplicitPropertySetter(),
11835 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011836}
11837
Mike Stump11289f42009-09-09 15:08:12 +000011838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011839ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011840TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11841 // Transform the base expression.
11842 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11843 if (Base.isInvalid())
11844 return ExprError();
11845
11846 // Transform the key expression.
11847 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11848 if (Key.isInvalid())
11849 return ExprError();
11850
11851 // If nothing changed, just retain the existing expression.
11852 if (!getDerived().AlwaysRebuild() &&
11853 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011854 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011855
Chad Rosier1dcde962012-08-08 18:46:20 +000011856 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011857 Base.get(), Key.get(),
11858 E->getAtIndexMethodDecl(),
11859 E->setAtIndexMethodDecl());
11860}
11861
11862template<typename Derived>
11863ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011864TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011865 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011866 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011867 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011868 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011869
Douglas Gregord51d90d2010-04-26 20:11:03 +000011870 // If nothing changed, just retain the existing expression.
11871 if (!getDerived().AlwaysRebuild() &&
11872 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011873 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011874
John McCallb268a282010-08-23 23:25:46 +000011875 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011876 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011877 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011878}
11879
Mike Stump11289f42009-09-09 15:08:12 +000011880template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011881ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011882TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011883 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011884 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011885 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011886 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011887 SubExprs, &ArgumentChanged))
11888 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011889
Douglas Gregora16548e2009-08-11 05:31:07 +000011890 if (!getDerived().AlwaysRebuild() &&
11891 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011892 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011893
Douglas Gregora16548e2009-08-11 05:31:07 +000011894 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011895 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011896 E->getRParenLoc());
11897}
11898
Mike Stump11289f42009-09-09 15:08:12 +000011899template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011900ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011901TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11902 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11903 if (SrcExpr.isInvalid())
11904 return ExprError();
11905
11906 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11907 if (!Type)
11908 return ExprError();
11909
11910 if (!getDerived().AlwaysRebuild() &&
11911 Type == E->getTypeSourceInfo() &&
11912 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011913 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011914
11915 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11916 SrcExpr.get(), Type,
11917 E->getRParenLoc());
11918}
11919
11920template<typename Derived>
11921ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011922TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000011923 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000011924
Craig Topperc3ec1492014-05-26 06:22:03 +000011925 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000011926 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
11927
11928 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000011929 blockScope->TheDecl->setBlockMissingReturnType(
11930 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000011931
Chris Lattner01cf8db2011-07-20 06:58:45 +000011932 SmallVector<ParmVarDecl*, 4> params;
11933 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000011934
John McCallc8e321d2016-03-01 02:09:25 +000011935 const FunctionProtoType *exprFunctionType = E->getFunctionType();
11936
Fariborz Jahanian1babe772010-07-09 18:44:02 +000011937 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000011938 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000011939 if (getDerived().TransformFunctionTypeParams(
11940 E->getCaretLocation(), oldBlock->parameters(), nullptr,
11941 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
11942 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011943 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011944 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011945 }
John McCall490112f2011-02-04 18:33:18 +000011946
Eli Friedman34b49062012-01-26 03:00:14 +000011947 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000011948 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000011949
John McCallc8e321d2016-03-01 02:09:25 +000011950 auto epi = exprFunctionType->getExtProtoInfo();
11951 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
11952
Jordan Rose5c382722013-03-08 21:51:21 +000011953 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000011954 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000011955 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000011956
11957 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000011958 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000011959 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000011960
11961 if (!oldBlock->blockMissingReturnType()) {
11962 blockScope->HasImplicitReturnType = false;
11963 blockScope->ReturnType = exprResultType;
11964 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011965
John McCall3882ace2011-01-05 12:14:39 +000011966 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000011967 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011968 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000011969 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000011970 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000011971 }
John McCall3882ace2011-01-05 12:14:39 +000011972
John McCall490112f2011-02-04 18:33:18 +000011973#ifndef NDEBUG
11974 // In builds with assertions, make sure that we captured everything we
11975 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011976 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000011977 for (const auto &I : oldBlock->captures()) {
11978 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000011979
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011980 // Ignore parameter packs.
11981 if (isa<ParmVarDecl>(oldCapture) &&
11982 cast<ParmVarDecl>(oldCapture)->isParameterPack())
11983 continue;
John McCall490112f2011-02-04 18:33:18 +000011984
Douglas Gregor4385d8b2011-05-20 15:32:55 +000011985 VarDecl *newCapture =
11986 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
11987 oldCapture));
11988 assert(blockScope->CaptureMap.count(newCapture));
11989 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000011990 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000011991 }
11992#endif
11993
11994 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000011995 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000011996}
11997
Mike Stump11289f42009-09-09 15:08:12 +000011998template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011999ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012000TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012001 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012002}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012003
12004template<typename Derived>
12005ExprResult
12006TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012007 QualType RetTy = getDerived().TransformType(E->getType());
12008 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012009 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012010 SubExprs.reserve(E->getNumSubExprs());
12011 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12012 SubExprs, &ArgumentChanged))
12013 return ExprError();
12014
12015 if (!getDerived().AlwaysRebuild() &&
12016 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012017 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012018
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012019 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012020 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012021}
Chad Rosier1dcde962012-08-08 18:46:20 +000012022
Douglas Gregora16548e2009-08-11 05:31:07 +000012023//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012024// Type reconstruction
12025//===----------------------------------------------------------------------===//
12026
Mike Stump11289f42009-09-09 15:08:12 +000012027template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012028QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12029 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012030 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012031 getDerived().getBaseEntity());
12032}
12033
Mike Stump11289f42009-09-09 15:08:12 +000012034template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012035QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12036 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012037 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012038 getDerived().getBaseEntity());
12039}
12040
Mike Stump11289f42009-09-09 15:08:12 +000012041template<typename Derived>
12042QualType
John McCall70dd5f62009-10-30 00:06:24 +000012043TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12044 bool WrittenAsLValue,
12045 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012046 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012047 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012048}
12049
12050template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012051QualType
John McCall70dd5f62009-10-30 00:06:24 +000012052TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12053 QualType ClassType,
12054 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012055 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12056 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012057}
12058
12059template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012060QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12061 const ObjCTypeParamDecl *Decl,
12062 SourceLocation ProtocolLAngleLoc,
12063 ArrayRef<ObjCProtocolDecl *> Protocols,
12064 ArrayRef<SourceLocation> ProtocolLocs,
12065 SourceLocation ProtocolRAngleLoc) {
12066 return SemaRef.BuildObjCTypeParamType(Decl,
12067 ProtocolLAngleLoc, Protocols,
12068 ProtocolLocs, ProtocolRAngleLoc,
12069 /*FailOnError=*/true);
12070}
12071
12072template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012073QualType TreeTransform<Derived>::RebuildObjCObjectType(
12074 QualType BaseType,
12075 SourceLocation Loc,
12076 SourceLocation TypeArgsLAngleLoc,
12077 ArrayRef<TypeSourceInfo *> TypeArgs,
12078 SourceLocation TypeArgsRAngleLoc,
12079 SourceLocation ProtocolLAngleLoc,
12080 ArrayRef<ObjCProtocolDecl *> Protocols,
12081 ArrayRef<SourceLocation> ProtocolLocs,
12082 SourceLocation ProtocolRAngleLoc) {
12083 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12084 TypeArgs, TypeArgsRAngleLoc,
12085 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12086 ProtocolRAngleLoc,
12087 /*FailOnError=*/true);
12088}
12089
12090template<typename Derived>
12091QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12092 QualType PointeeType,
12093 SourceLocation Star) {
12094 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12095}
12096
12097template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012098QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012099TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12100 ArrayType::ArraySizeModifier SizeMod,
12101 const llvm::APInt *Size,
12102 Expr *SizeExpr,
12103 unsigned IndexTypeQuals,
12104 SourceRange BracketsRange) {
12105 if (SizeExpr || !Size)
12106 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12107 IndexTypeQuals, BracketsRange,
12108 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012109
12110 QualType Types[] = {
12111 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12112 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12113 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012114 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012115 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012116 QualType SizeType;
12117 for (unsigned I = 0; I != NumTypes; ++I)
12118 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12119 SizeType = Types[I];
12120 break;
12121 }
Mike Stump11289f42009-09-09 15:08:12 +000012122
Eli Friedman9562f392012-01-25 23:20:27 +000012123 // Note that we can return a VariableArrayType here in the case where
12124 // the element type was a dependent VariableArrayType.
12125 IntegerLiteral *ArraySize
12126 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12127 /*FIXME*/BracketsRange.getBegin());
12128 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012129 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012130 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012131}
Mike Stump11289f42009-09-09 15:08:12 +000012132
Douglas Gregord6ff3322009-08-04 16:50:30 +000012133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012134QualType
12135TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012136 ArrayType::ArraySizeModifier SizeMod,
12137 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012138 unsigned IndexTypeQuals,
12139 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012140 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012141 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012142}
12143
12144template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012145QualType
Mike Stump11289f42009-09-09 15:08:12 +000012146TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012147 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012148 unsigned IndexTypeQuals,
12149 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012150 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012151 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012152}
Mike Stump11289f42009-09-09 15:08:12 +000012153
Douglas Gregord6ff3322009-08-04 16:50:30 +000012154template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012155QualType
12156TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012157 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012158 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012159 unsigned IndexTypeQuals,
12160 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012161 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012162 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012163 IndexTypeQuals, BracketsRange);
12164}
12165
12166template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012167QualType
12168TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012169 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012170 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012171 unsigned IndexTypeQuals,
12172 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012173 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012174 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012175 IndexTypeQuals, BracketsRange);
12176}
12177
12178template<typename Derived>
12179QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000012180 unsigned NumElements,
12181 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012182 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012183 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012184}
Mike Stump11289f42009-09-09 15:08:12 +000012185
Douglas Gregord6ff3322009-08-04 16:50:30 +000012186template<typename Derived>
12187QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12188 unsigned NumElements,
12189 SourceLocation AttributeLoc) {
12190 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12191 NumElements, true);
12192 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012193 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12194 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012195 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012196}
Mike Stump11289f42009-09-09 15:08:12 +000012197
Douglas Gregord6ff3322009-08-04 16:50:30 +000012198template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012199QualType
12200TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012201 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012202 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012203 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012204}
Mike Stump11289f42009-09-09 15:08:12 +000012205
Douglas Gregord6ff3322009-08-04 16:50:30 +000012206template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012207QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12208 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012209 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012210 const FunctionProtoType::ExtProtoInfo &EPI) {
12211 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012212 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012213 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012214 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012215}
Mike Stump11289f42009-09-09 15:08:12 +000012216
Douglas Gregord6ff3322009-08-04 16:50:30 +000012217template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012218QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12219 return SemaRef.Context.getFunctionNoProtoType(T);
12220}
12221
12222template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012223QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12224 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012225 assert(D && "no decl found");
12226 if (D->isInvalidDecl()) return QualType();
12227
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012228 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012229 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012230 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12231 // A valid resolved using typename pack expansion decl can have multiple
12232 // UsingDecls, but they must each have exactly one type, and it must be
12233 // the same type in every case. But we must have at least one expansion!
12234 if (UPD->expansions().empty()) {
12235 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12236 << UPD->isCXXClassMember() << UPD;
12237 return QualType();
12238 }
12239
12240 // We might still have some unresolved types. Try to pick a resolved type
12241 // if we can. The final instantiation will check that the remaining
12242 // unresolved types instantiate to the type we pick.
12243 QualType FallbackT;
12244 QualType T;
12245 for (auto *E : UPD->expansions()) {
12246 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12247 if (ThisT.isNull())
12248 continue;
12249 else if (ThisT->getAs<UnresolvedUsingType>())
12250 FallbackT = ThisT;
12251 else if (T.isNull())
12252 T = ThisT;
12253 else
12254 assert(getSema().Context.hasSameType(ThisT, T) &&
12255 "mismatched resolved types in using pack expansion");
12256 }
12257 return T.isNull() ? FallbackT : T;
12258 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012259 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012260 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12261
12262 // A valid resolved using typename decl points to exactly one type decl.
12263 assert(++Using->shadow_begin() == Using->shadow_end());
12264 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012265 } else {
12266 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12267 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12268 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12269 }
12270
12271 return SemaRef.Context.getTypeDeclType(Ty);
12272}
12273
12274template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012275QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12276 SourceLocation Loc) {
12277 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012278}
12279
12280template<typename Derived>
12281QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12282 return SemaRef.Context.getTypeOfType(Underlying);
12283}
12284
12285template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012286QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12287 SourceLocation Loc) {
12288 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012289}
12290
12291template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012292QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12293 UnaryTransformType::UTTKind UKind,
12294 SourceLocation Loc) {
12295 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12296}
12297
12298template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012299QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012300 TemplateName Template,
12301 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012302 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012303 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012304}
Mike Stump11289f42009-09-09 15:08:12 +000012305
Douglas Gregor1135c352009-08-06 05:28:30 +000012306template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012307QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12308 SourceLocation KWLoc) {
12309 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12310}
12311
12312template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012313QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012314 SourceLocation KWLoc,
12315 bool isReadPipe) {
12316 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12317 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012318}
12319
12320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012321TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012322TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012323 bool TemplateKW,
12324 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012325 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012326 Template);
12327}
12328
12329template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012330TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012331TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12332 const IdentifierInfo &Name,
12333 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012334 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012335 NamedDecl *FirstQualifierInScope,
12336 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012337 UnqualifiedId TemplateName;
12338 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012339 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012340 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012341 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012342 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012343 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012344 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012345 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012346 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012347}
Mike Stump11289f42009-09-09 15:08:12 +000012348
Douglas Gregora16548e2009-08-11 05:31:07 +000012349template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012350TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012351TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012352 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012353 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012354 QualType ObjectType,
12355 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012356 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012357 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012358 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012359 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012360 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012361 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012362 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012363 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012364 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012365 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012366 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012367 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012368}
Chad Rosier1dcde962012-08-08 18:46:20 +000012369
Douglas Gregor71395fa2009-11-04 00:56:37 +000012370template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012371ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012372TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12373 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012374 Expr *OrigCallee,
12375 Expr *First,
12376 Expr *Second) {
12377 Expr *Callee = OrigCallee->IgnoreParenCasts();
12378 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012379
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012380 if (First->getObjectKind() == OK_ObjCProperty) {
12381 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12382 if (BinaryOperator::isAssignmentOp(Opc))
12383 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12384 First, Second);
12385 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12386 if (Result.isInvalid())
12387 return ExprError();
12388 First = Result.get();
12389 }
12390
12391 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12392 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12393 if (Result.isInvalid())
12394 return ExprError();
12395 Second = Result.get();
12396 }
12397
Douglas Gregora16548e2009-08-11 05:31:07 +000012398 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012399 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012400 if (!First->getType()->isOverloadableType() &&
12401 !Second->getType()->isOverloadableType())
12402 return getSema().CreateBuiltinArraySubscriptExpr(First,
12403 Callee->getLocStart(),
12404 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012405 } else if (Op == OO_Arrow) {
12406 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012407 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12408 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012409 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012410 // The argument is not of overloadable type, so try to create a
12411 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012412 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012413 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012414
John McCallb268a282010-08-23 23:25:46 +000012415 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012416 }
12417 } else {
John McCallb268a282010-08-23 23:25:46 +000012418 if (!First->getType()->isOverloadableType() &&
12419 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012420 // Neither of the arguments is an overloadable type, so try to
12421 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012422 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012423 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012424 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012425 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012427
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012428 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012429 }
12430 }
Mike Stump11289f42009-09-09 15:08:12 +000012431
12432 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012433 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012434 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012435
John McCallb268a282010-08-23 23:25:46 +000012436 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012437 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012438 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012439 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012440 // If we've resolved this to a particular non-member function, just call
12441 // that function. If we resolved it to a member function,
12442 // CreateOverloaded* will find that function for us.
12443 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12444 if (!isa<CXXMethodDecl>(ND))
12445 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012446 }
Mike Stump11289f42009-09-09 15:08:12 +000012447
Douglas Gregora16548e2009-08-11 05:31:07 +000012448 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012449 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012450 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012451
Douglas Gregora16548e2009-08-11 05:31:07 +000012452 // Create the overloaded operator invocation for unary operators.
12453 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012454 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012455 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012456 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012457 }
Mike Stump11289f42009-09-09 15:08:12 +000012458
Douglas Gregore9d62932011-07-15 16:25:15 +000012459 if (Op == OO_Subscript) {
12460 SourceLocation LBrace;
12461 SourceLocation RBrace;
12462
12463 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012464 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012465 LBrace = SourceLocation::getFromRawEncoding(
12466 NameLoc.CXXOperatorName.BeginOpNameLoc);
12467 RBrace = SourceLocation::getFromRawEncoding(
12468 NameLoc.CXXOperatorName.EndOpNameLoc);
12469 } else {
12470 LBrace = Callee->getLocStart();
12471 RBrace = OpLoc;
12472 }
12473
12474 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12475 First, Second);
12476 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012477
Douglas Gregora16548e2009-08-11 05:31:07 +000012478 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012479 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012480 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012481 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12482 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012483 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012484
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012485 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012486}
Mike Stump11289f42009-09-09 15:08:12 +000012487
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012488template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012489ExprResult
John McCallb268a282010-08-23 23:25:46 +000012490TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012491 SourceLocation OperatorLoc,
12492 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012493 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012494 TypeSourceInfo *ScopeType,
12495 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012496 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012497 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012498 QualType BaseType = Base->getType();
12499 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012500 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012501 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012502 !BaseType->getAs<PointerType>()->getPointeeType()
12503 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012504 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012505 return SemaRef.BuildPseudoDestructorExpr(
12506 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12507 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012508 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012509
Douglas Gregor678f90d2010-02-25 01:56:36 +000012510 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012511 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12512 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12513 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12514 NameInfo.setNamedTypeInfo(DestroyedType);
12515
Richard Smith8e4a3862012-05-15 06:15:11 +000012516 // The scope type is now known to be a valid nested name specifier
12517 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012518 if (ScopeType) {
12519 if (!ScopeType->getType()->getAs<TagType>()) {
12520 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12521 diag::err_expected_class_or_namespace)
12522 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12523 return ExprError();
12524 }
12525 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12526 CCLoc);
12527 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012528
Abramo Bagnara7945c982012-01-27 09:46:47 +000012529 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012530 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012531 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012532 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012533 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012534 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012535 /*TemplateArgs*/ nullptr,
12536 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012537}
12538
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012539template<typename Derived>
12540StmtResult
12541TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012542 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012543 CapturedDecl *CD = S->getCapturedDecl();
12544 unsigned NumParams = CD->getNumParams();
12545 unsigned ContextParamPos = CD->getContextParamPosition();
12546 SmallVector<Sema::CapturedParamNameType, 4> Params;
12547 for (unsigned I = 0; I < NumParams; ++I) {
12548 if (I != ContextParamPos) {
12549 Params.push_back(
12550 std::make_pair(
12551 CD->getParam(I)->getName(),
12552 getDerived().TransformType(CD->getParam(I)->getType())));
12553 } else {
12554 Params.push_back(std::make_pair(StringRef(), QualType()));
12555 }
12556 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012557 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012558 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012559 StmtResult Body;
12560 {
12561 Sema::CompoundScopeRAII CompoundScope(getSema());
12562 Body = getDerived().TransformStmt(S->getCapturedStmt());
12563 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012564
12565 if (Body.isInvalid()) {
12566 getSema().ActOnCapturedRegionError();
12567 return StmtError();
12568 }
12569
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012570 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012571}
12572
Douglas Gregord6ff3322009-08-04 16:50:30 +000012573} // end namespace clang
12574
Hans Wennborg59dbe862015-09-29 20:56:43 +000012575#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H