blob: 91da9f88c59b8cbe2b3548987c53d62549ee5fa2 [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
Alexey Bataev169d96a2017-07-18 20:17:46 +00001654 /// Build a new OpenMP 'task_reduction' clause.
1655 ///
1656 /// By default, performs semantic analysis to build the new statement.
1657 /// Subclasses may override this routine to provide different behavior.
1658 OMPClause *RebuildOMPTaskReductionClause(
1659 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1660 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1661 CXXScopeSpec &ReductionIdScopeSpec,
1662 const DeclarationNameInfo &ReductionId,
1663 ArrayRef<Expr *> UnresolvedReductions) {
1664 return getSema().ActOnOpenMPTaskReductionClause(
1665 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1666 ReductionId, UnresolvedReductions);
1667 }
1668
Alexander Musman8dba6642014-04-22 13:09:42 +00001669 /// \brief Build a new OpenMP 'linear' clause.
1670 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001671 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001672 /// Subclasses may override this routine to provide different behavior.
1673 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1674 SourceLocation StartLoc,
1675 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001676 OpenMPLinearClauseKind Modifier,
1677 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001678 SourceLocation ColonLoc,
1679 SourceLocation EndLoc) {
1680 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001681 Modifier, ModifierLoc, ColonLoc,
1682 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001683 }
1684
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001685 /// \brief Build a new OpenMP 'aligned' clause.
1686 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001687 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001688 /// Subclasses may override this routine to provide different behavior.
1689 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1690 SourceLocation StartLoc,
1691 SourceLocation LParenLoc,
1692 SourceLocation ColonLoc,
1693 SourceLocation EndLoc) {
1694 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1695 LParenLoc, ColonLoc, EndLoc);
1696 }
1697
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001698 /// \brief Build a new OpenMP 'copyin' clause.
1699 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001700 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001701 /// Subclasses may override this routine to provide different behavior.
1702 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1703 SourceLocation StartLoc,
1704 SourceLocation LParenLoc,
1705 SourceLocation EndLoc) {
1706 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1707 EndLoc);
1708 }
1709
Alexey Bataevbae9a792014-06-27 10:37:06 +00001710 /// \brief Build a new OpenMP 'copyprivate' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1714 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1715 SourceLocation StartLoc,
1716 SourceLocation LParenLoc,
1717 SourceLocation EndLoc) {
1718 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1719 EndLoc);
1720 }
1721
Alexey Bataev6125da92014-07-21 11:26:11 +00001722 /// \brief Build a new OpenMP 'flush' pseudo clause.
1723 ///
1724 /// By default, performs semantic analysis to build the new OpenMP clause.
1725 /// Subclasses may override this routine to provide different behavior.
1726 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1727 SourceLocation StartLoc,
1728 SourceLocation LParenLoc,
1729 SourceLocation EndLoc) {
1730 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1731 EndLoc);
1732 }
1733
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001734 /// \brief Build a new OpenMP 'depend' pseudo clause.
1735 ///
1736 /// By default, performs semantic analysis to build the new OpenMP clause.
1737 /// Subclasses may override this routine to provide different behavior.
1738 OMPClause *
1739 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1740 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1741 SourceLocation StartLoc, SourceLocation LParenLoc,
1742 SourceLocation EndLoc) {
1743 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1744 StartLoc, LParenLoc, EndLoc);
1745 }
1746
Michael Wonge710d542015-08-07 16:16:36 +00001747 /// \brief Build a new OpenMP 'device' clause.
1748 ///
1749 /// By default, performs semantic analysis to build the new statement.
1750 /// Subclasses may override this routine to provide different behavior.
1751 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1752 SourceLocation LParenLoc,
1753 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001754 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001755 EndLoc);
1756 }
1757
Kelvin Li0bff7af2015-11-23 05:32:03 +00001758 /// \brief Build a new OpenMP 'map' clause.
1759 ///
1760 /// By default, performs semantic analysis to build the new OpenMP clause.
1761 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001762 OMPClause *
1763 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1764 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1765 SourceLocation MapLoc, SourceLocation ColonLoc,
1766 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1767 SourceLocation LParenLoc, SourceLocation EndLoc) {
1768 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1769 IsMapTypeImplicit, MapLoc, ColonLoc,
1770 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001771 }
1772
Kelvin Li099bb8c2015-11-24 20:50:12 +00001773 /// \brief Build a new OpenMP 'num_teams' clause.
1774 ///
1775 /// By default, performs semantic analysis to build the new statement.
1776 /// Subclasses may override this routine to provide different behavior.
1777 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1778 SourceLocation LParenLoc,
1779 SourceLocation EndLoc) {
1780 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1781 EndLoc);
1782 }
1783
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001784 /// \brief Build a new OpenMP 'thread_limit' clause.
1785 ///
1786 /// By default, performs semantic analysis to build the new statement.
1787 /// Subclasses may override this routine to provide different behavior.
1788 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1789 SourceLocation StartLoc,
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1793 LParenLoc, EndLoc);
1794 }
1795
Alexey Bataeva0569352015-12-01 10:17:31 +00001796 /// \brief Build a new OpenMP 'priority' clause.
1797 ///
1798 /// By default, performs semantic analysis to build the new statement.
1799 /// Subclasses may override this routine to provide different behavior.
1800 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1801 SourceLocation LParenLoc,
1802 SourceLocation EndLoc) {
1803 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1804 EndLoc);
1805 }
1806
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001807 /// \brief Build a new OpenMP 'grainsize' clause.
1808 ///
1809 /// By default, performs semantic analysis to build the new statement.
1810 /// Subclasses may override this routine to provide different behavior.
1811 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1812 SourceLocation LParenLoc,
1813 SourceLocation EndLoc) {
1814 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1815 EndLoc);
1816 }
1817
Alexey Bataev382967a2015-12-08 12:06:20 +00001818 /// \brief Build a new OpenMP 'num_tasks' clause.
1819 ///
1820 /// By default, performs semantic analysis to build the new statement.
1821 /// Subclasses may override this routine to provide different behavior.
1822 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1823 SourceLocation LParenLoc,
1824 SourceLocation EndLoc) {
1825 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1826 EndLoc);
1827 }
1828
Alexey Bataev28c75412015-12-15 08:19:24 +00001829 /// \brief Build a new OpenMP 'hint' clause.
1830 ///
1831 /// By default, performs semantic analysis to build the new statement.
1832 /// Subclasses may override this routine to provide different behavior.
1833 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1834 SourceLocation LParenLoc,
1835 SourceLocation EndLoc) {
1836 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1837 }
1838
Carlo Bertollib4adf552016-01-15 18:50:31 +00001839 /// \brief Build a new OpenMP 'dist_schedule' clause.
1840 ///
1841 /// By default, performs semantic analysis to build the new OpenMP clause.
1842 /// Subclasses may override this routine to provide different behavior.
1843 OMPClause *
1844 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1845 Expr *ChunkSize, SourceLocation StartLoc,
1846 SourceLocation LParenLoc, SourceLocation KindLoc,
1847 SourceLocation CommaLoc, SourceLocation EndLoc) {
1848 return getSema().ActOnOpenMPDistScheduleClause(
1849 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1850 }
1851
Samuel Antao661c0902016-05-26 17:39:58 +00001852 /// \brief Build a new OpenMP 'to' clause.
1853 ///
1854 /// By default, performs semantic analysis to build the new statement.
1855 /// Subclasses may override this routine to provide different behavior.
1856 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1857 SourceLocation StartLoc,
1858 SourceLocation LParenLoc,
1859 SourceLocation EndLoc) {
1860 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1861 }
1862
Samuel Antaoec172c62016-05-26 17:49:04 +00001863 /// \brief Build a new OpenMP 'from' clause.
1864 ///
1865 /// By default, performs semantic analysis to build the new statement.
1866 /// Subclasses may override this routine to provide different behavior.
1867 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1868 SourceLocation StartLoc,
1869 SourceLocation LParenLoc,
1870 SourceLocation EndLoc) {
1871 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1872 EndLoc);
1873 }
1874
Carlo Bertolli2404b172016-07-13 15:37:16 +00001875 /// Build a new OpenMP 'use_device_ptr' clause.
1876 ///
1877 /// By default, performs semantic analysis to build the new OpenMP clause.
1878 /// Subclasses may override this routine to provide different behavior.
1879 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1880 SourceLocation StartLoc,
1881 SourceLocation LParenLoc,
1882 SourceLocation EndLoc) {
1883 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1884 EndLoc);
1885 }
1886
Carlo Bertolli70594e92016-07-13 17:16:49 +00001887 /// Build a new OpenMP 'is_device_ptr' clause.
1888 ///
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1891 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1892 SourceLocation StartLoc,
1893 SourceLocation LParenLoc,
1894 SourceLocation EndLoc) {
1895 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1896 EndLoc);
1897 }
1898
James Dennett2a4d13c2012-06-15 07:13:21 +00001899 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001900 ///
1901 /// By default, performs semantic analysis to build the new statement.
1902 /// Subclasses may override this routine to provide different behavior.
1903 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1904 Expr *object) {
1905 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1906 }
1907
James Dennett2a4d13c2012-06-15 07:13:21 +00001908 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001909 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001910 /// By default, performs semantic analysis to build the new statement.
1911 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001912 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001913 Expr *Object, Stmt *Body) {
1914 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001915 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001916
James Dennett2a4d13c2012-06-15 07:13:21 +00001917 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001918 ///
1919 /// By default, performs semantic analysis to build the new statement.
1920 /// Subclasses may override this routine to provide different behavior.
1921 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1922 Stmt *Body) {
1923 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1924 }
John McCall53848232011-07-27 01:07:15 +00001925
Douglas Gregorf68a5082010-04-22 23:10:45 +00001926 /// \brief Build a new Objective-C fast enumeration statement.
1927 ///
1928 /// By default, performs semantic analysis to build the new statement.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001931 Stmt *Element,
1932 Expr *Collection,
1933 SourceLocation RParenLoc,
1934 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001935 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001936 Element,
John McCallb268a282010-08-23 23:25:46 +00001937 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001938 RParenLoc);
1939 if (ForEachStmt.isInvalid())
1940 return StmtError();
1941
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001942 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001943 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001944
Douglas Gregorebe10102009-08-20 07:17:43 +00001945 /// \brief Build a new C++ exception declaration.
1946 ///
1947 /// By default, performs semantic analysis to build the new decaration.
1948 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001949 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001950 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001951 SourceLocation StartLoc,
1952 SourceLocation IdLoc,
1953 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001954 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001955 StartLoc, IdLoc, Id);
1956 if (Var)
1957 getSema().CurContext->addDecl(Var);
1958 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001959 }
1960
1961 /// \brief Build a new C++ catch statement.
1962 ///
1963 /// By default, performs semantic analysis to build the new statement.
1964 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001965 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001966 VarDecl *ExceptionDecl,
1967 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001968 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1969 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregorebe10102009-08-20 07:17:43 +00001972 /// \brief Build a new C++ try statement.
1973 ///
1974 /// By default, performs semantic analysis to build the new statement.
1975 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001976 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1977 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001978 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001979 }
Mike Stump11289f42009-09-09 15:08:12 +00001980
Richard Smith02e85f32011-04-14 22:09:26 +00001981 /// \brief Build a new C++0x range-based for statement.
1982 ///
1983 /// By default, performs semantic analysis to build the new statement.
1984 /// Subclasses may override this routine to provide different behavior.
1985 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00001986 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00001987 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00001988 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00001989 Expr *Cond, Expr *Inc,
1990 Stmt *LoopVar,
1991 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001992 // If we've just learned that the range is actually an Objective-C
1993 // collection, treat this as an Objective-C fast enumeration loop.
1994 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1995 if (RangeStmt->isSingleDecl()) {
1996 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001997 if (RangeVar->isInvalidDecl())
1998 return StmtError();
1999
Douglas Gregorf7106af2013-04-08 18:40:13 +00002000 Expr *RangeExpr = RangeVar->getInit();
2001 if (!RangeExpr->isTypeDependent() &&
2002 RangeExpr->getType()->isObjCObjectPointerType())
2003 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2004 RParenLoc);
2005 }
2006 }
2007 }
2008
Richard Smithcfd53b42015-10-22 06:13:50 +00002009 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002010 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00002011 Cond, Inc, LoopVar, RParenLoc,
2012 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002013 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002014
2015 /// \brief Build a new C++0x range-based for statement.
2016 ///
2017 /// By default, performs semantic analysis to build the new statement.
2018 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002019 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002020 bool IsIfExists,
2021 NestedNameSpecifierLoc QualifierLoc,
2022 DeclarationNameInfo NameInfo,
2023 Stmt *Nested) {
2024 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2025 QualifierLoc, NameInfo, Nested);
2026 }
2027
Richard Smith02e85f32011-04-14 22:09:26 +00002028 /// \brief Attach body to a C++0x range-based for statement.
2029 ///
2030 /// By default, performs semantic analysis to finish the new statement.
2031 /// Subclasses may override this routine to provide different behavior.
2032 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2033 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2034 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002035
David Majnemerfad8f482013-10-15 09:33:02 +00002036 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002037 Stmt *TryBlock, Stmt *Handler) {
2038 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002039 }
2040
David Majnemerfad8f482013-10-15 09:33:02 +00002041 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002042 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002043 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002044 }
2045
David Majnemerfad8f482013-10-15 09:33:02 +00002046 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002047 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002048 }
2049
Alexey Bataevec474782014-10-09 08:45:04 +00002050 /// \brief Build a new predefined expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
2054 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2055 PredefinedExpr::IdentType IT) {
2056 return getSema().BuildPredefinedExpr(Loc, IT);
2057 }
2058
Douglas Gregora16548e2009-08-11 05:31:07 +00002059 /// \brief Build a new expression that references a declaration.
2060 ///
2061 /// By default, performs semantic analysis to build the new expression.
2062 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002064 LookupResult &R,
2065 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002066 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2067 }
2068
2069
2070 /// \brief Build a new expression that references a declaration.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002074 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002075 ValueDecl *VD,
2076 const DeclarationNameInfo &NameInfo,
2077 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002078 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002079 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002080
2081 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002082
2083 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002090 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002091 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002092 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 }
2094
Douglas Gregorad8a3362009-09-04 17:36:40 +00002095 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002096 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002100 SourceLocation OperatorLoc,
2101 bool isArrow,
2102 CXXScopeSpec &SS,
2103 TypeSourceInfo *ScopeType,
2104 SourceLocation CCLoc,
2105 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002106 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002107
Douglas Gregora16548e2009-08-11 05:31:07 +00002108 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002109 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002113 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002114 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002115 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 }
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregor882211c2010-04-28 22:16:22 +00002118 /// \brief Build a new builtin offsetof expression.
2119 ///
2120 /// By default, performs semantic analysis to build the new expression.
2121 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002122 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002123 TypeSourceInfo *Type,
2124 ArrayRef<Sema::OffsetOfComponent> Components,
2125 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002126 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002127 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002128 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002129
2130 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002131 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002132 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002135 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2136 SourceLocation OpLoc,
2137 UnaryExprOrTypeTrait ExprKind,
2138 SourceRange R) {
2139 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002140 }
2141
Peter Collingbournee190dee2011-03-11 19:24:49 +00002142 /// \brief Build a new sizeof, alignof or vec step expression with an
2143 /// expression argument.
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.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002147 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2148 UnaryExprOrTypeTrait ExprKind,
2149 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002151 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002152 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002153 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002154
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002155 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002156 }
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 /// By default, performs semantic analysis to build the new expression.
2161 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002162 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002164 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002165 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002166 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002167 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 RBracketLoc);
2169 }
2170
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002171 /// \brief Build a new array section expression.
2172 ///
2173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
2175 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2176 Expr *LowerBound,
2177 SourceLocation ColonLoc, Expr *Length,
2178 SourceLocation RBracketLoc) {
2179 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2180 ColonLoc, Length, RBracketLoc);
2181 }
2182
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002184 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 /// By default, performs semantic analysis to build the new expression.
2186 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002187 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002189 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002190 Expr *ExecConfig = nullptr) {
2191 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002192 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 }
2194
2195 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002196 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002200 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002201 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002202 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002203 const DeclarationNameInfo &MemberNameInfo,
2204 ValueDecl *Member,
2205 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002206 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002207 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002208 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2209 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002210 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002211 // We have a reference to an unnamed field. This is always the
2212 // base of an anonymous struct/union member access, i.e. the
2213 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002214 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002215 assert(Member->getType()->isRecordType() &&
2216 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002217
Richard Smithcab9a7d2011-10-26 19:06:56 +00002218 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002219 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002220 QualifierLoc.getNestedNameSpecifier(),
2221 FoundDecl, Member);
2222 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002223 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002224 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002225 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002226 MemberExpr *ME = new (getSema().Context)
2227 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2228 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002229 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002230 }
Mike Stump11289f42009-09-09 15:08:12 +00002231
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002232 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002233 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002234
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002235 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002236 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002237
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002238 if (isArrow && !BaseType->isPointerType())
2239 return ExprError();
2240
John McCall16df1e52010-03-30 21:47:33 +00002241 // FIXME: this involves duplicating earlier analysis in a lot of
2242 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002243 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002244 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002245 R.resolveKind();
2246
John McCallb268a282010-08-23 23:25:46 +00002247 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002248 SS, TemplateKWLoc,
2249 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002250 R, ExplicitTemplateArgs,
2251 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002252 }
Mike Stump11289f42009-09-09 15:08:12 +00002253
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002255 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002256 /// By default, performs semantic analysis to build the new expression.
2257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002258 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002259 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002260 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002261 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 }
2263
2264 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002265 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 /// By default, performs semantic analysis to build the new expression.
2267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002268 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002269 SourceLocation QuestionLoc,
2270 Expr *LHS,
2271 SourceLocation ColonLoc,
2272 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002273 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2274 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 }
2276
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002278 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 /// By default, performs semantic analysis to build the new expression.
2280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002281 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002282 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002283 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002284 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002285 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002286 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 }
Mike Stump11289f42009-09-09 15:08:12 +00002288
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002290 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// By default, performs semantic analysis to build the new expression.
2292 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002293 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002294 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002295 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002296 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002297 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002298 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 }
Mike Stump11289f42009-09-09 15:08:12 +00002300
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002302 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 /// By default, performs semantic analysis to build the new expression.
2304 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 SourceLocation OpLoc,
2307 SourceLocation AccessorLoc,
2308 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002309
John McCall10eae182009-11-30 22:42:35 +00002310 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002311 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002312 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002313 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002314 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002315 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002316 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002317 /* TemplateArgs */ nullptr,
2318 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 }
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregora16548e2009-08-11 05:31:07 +00002321 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002322 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002325 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002326 MultiExprArg Inits,
2327 SourceLocation RBraceLoc,
2328 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002329 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002330 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002331 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002332 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002333
Douglas Gregord3d93062009-11-09 17:16:50 +00002334 // Patch in the result type we were given, which may have been computed
2335 // when the initial InitListExpr was built.
2336 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2337 ILE->setType(ResultTy);
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 designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002343 /// By default, performs semantic analysis to build the new expression.
2344 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002345 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002346 MultiExprArg ArrayExprs,
2347 SourceLocation EqualOrColonLoc,
2348 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002349 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002350 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002352 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002355
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002356 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002357 }
Mike Stump11289f42009-09-09 15:08:12 +00002358
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002360 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 /// By default, builds the implicit value initialization without performing
2362 /// any semantic analysis. Subclasses may override this routine to provide
2363 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002364 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002365 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002366 }
Mike Stump11289f42009-09-09 15:08:12 +00002367
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002369 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002370 /// By default, performs semantic analysis to build the new expression.
2371 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002372 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002373 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002374 SourceLocation RParenLoc) {
2375 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002376 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002377 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 }
2379
2380 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002381 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002382 /// By default, performs semantic analysis to build the new expression.
2383 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002384 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002385 MultiExprArg SubExprs,
2386 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002387 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 }
Mike Stump11289f42009-09-09 15:08:12 +00002389
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002391 ///
2392 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002393 /// rather than attempting to map the label statement itself.
2394 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002395 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002396 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002397 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002401 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002404 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002405 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002407 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 }
Mike Stump11289f42009-09-09 15:08:12 +00002409
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 /// \brief Build a new __builtin_choose_expr expression.
2411 ///
2412 /// By default, performs semantic analysis to build the new expression.
2413 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002414 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002415 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 SourceLocation RParenLoc) {
2417 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002418 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 RParenLoc);
2420 }
Mike Stump11289f42009-09-09 15:08:12 +00002421
Peter Collingbourne91147592011-04-15 00:35:48 +00002422 /// \brief Build a new generic selection expression.
2423 ///
2424 /// By default, performs semantic analysis to build the new expression.
2425 /// Subclasses may override this routine to provide different behavior.
2426 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2427 SourceLocation DefaultLoc,
2428 SourceLocation RParenLoc,
2429 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002430 ArrayRef<TypeSourceInfo *> Types,
2431 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002432 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002433 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002434 }
2435
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 /// \brief Build a new overloaded operator call expression.
2437 ///
2438 /// By default, performs semantic analysis to build the new expression.
2439 /// The semantic analysis provides the behavior of template instantiation,
2440 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002441 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002442 /// argument-dependent lookup, etc. Subclasses may override this routine to
2443 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002444 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002445 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002446 Expr *Callee,
2447 Expr *First,
2448 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002449
2450 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002451 /// reinterpret_cast.
2452 ///
2453 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002454 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002455 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002456 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002457 Stmt::StmtClass Class,
2458 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002459 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 SourceLocation RAngleLoc,
2461 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002462 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 SourceLocation RParenLoc) {
2464 switch (Class) {
2465 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002466 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002467 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002468 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002469
2470 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002471 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002472 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002473 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002474
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002476 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002477 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002478 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002479 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002482 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002483 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002484 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002485
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002487 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002488 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002489 }
Mike Stump11289f42009-09-09 15:08:12 +00002490
Douglas Gregora16548e2009-08-11 05:31:07 +00002491 /// \brief Build a new C++ static_cast expression.
2492 ///
2493 /// By default, performs semantic analysis to build the new expression.
2494 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002495 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002496 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002497 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002498 SourceLocation RAngleLoc,
2499 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002500 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002501 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002502 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002503 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002504 SourceRange(LAngleLoc, RAngleLoc),
2505 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 }
2507
2508 /// \brief Build a new C++ dynamic_cast expression.
2509 ///
2510 /// By default, performs semantic analysis to build the new expression.
2511 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002512 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002513 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002514 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002515 SourceLocation RAngleLoc,
2516 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002517 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002518 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002519 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002520 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002521 SourceRange(LAngleLoc, RAngleLoc),
2522 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002523 }
2524
2525 /// \brief Build a new C++ reinterpret_cast expression.
2526 ///
2527 /// By default, performs semantic analysis to build the new expression.
2528 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002529 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002530 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002531 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002532 SourceLocation RAngleLoc,
2533 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002534 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002535 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002536 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002537 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002538 SourceRange(LAngleLoc, RAngleLoc),
2539 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002540 }
2541
2542 /// \brief Build a new C++ const_cast expression.
2543 ///
2544 /// By default, performs semantic analysis to build the new expression.
2545 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002546 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002547 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002548 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 SourceLocation RAngleLoc,
2550 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002551 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002552 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002553 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002554 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002555 SourceRange(LAngleLoc, RAngleLoc),
2556 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002557 }
Mike Stump11289f42009-09-09 15:08:12 +00002558
Douglas Gregora16548e2009-08-11 05:31:07 +00002559 /// \brief Build a new C++ functional-style cast expression.
2560 ///
2561 /// By default, performs semantic analysis to build the new expression.
2562 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002563 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2564 SourceLocation LParenLoc,
2565 Expr *Sub,
2566 SourceLocation RParenLoc) {
2567 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002568 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002569 RParenLoc);
2570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregora16548e2009-08-11 05:31:07 +00002572 /// \brief Build a new C++ typeid(type) expression.
2573 ///
2574 /// By default, performs semantic analysis to build the new expression.
2575 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002576 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002577 SourceLocation TypeidLoc,
2578 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002580 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002581 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002582 }
Mike Stump11289f42009-09-09 15:08:12 +00002583
Francois Pichet9f4f2072010-09-08 12:20:18 +00002584
Douglas Gregora16548e2009-08-11 05:31:07 +00002585 /// \brief Build a new C++ typeid(expr) expression.
2586 ///
2587 /// By default, performs semantic analysis to build the new expression.
2588 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002589 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002590 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002591 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002592 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002593 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002594 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002595 }
2596
Francois Pichet9f4f2072010-09-08 12:20:18 +00002597 /// \brief Build a new C++ __uuidof(type) expression.
2598 ///
2599 /// By default, performs semantic analysis to build the new expression.
2600 /// Subclasses may override this routine to provide different behavior.
2601 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2602 SourceLocation TypeidLoc,
2603 TypeSourceInfo *Operand,
2604 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002605 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002606 RParenLoc);
2607 }
2608
2609 /// \brief Build a new C++ __uuidof(expr) expression.
2610 ///
2611 /// By default, performs semantic analysis to build the new expression.
2612 /// Subclasses may override this routine to provide different behavior.
2613 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2614 SourceLocation TypeidLoc,
2615 Expr *Operand,
2616 SourceLocation RParenLoc) {
2617 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2618 RParenLoc);
2619 }
2620
Douglas Gregora16548e2009-08-11 05:31:07 +00002621 /// \brief Build a new C++ "this" expression.
2622 ///
2623 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002624 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002625 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002626 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002627 QualType ThisType,
2628 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002629 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002630 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002631 }
2632
2633 /// \brief Build a new C++ throw expression.
2634 ///
2635 /// By default, performs semantic analysis to build the new expression.
2636 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002637 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2638 bool IsThrownVariableInScope) {
2639 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 }
2641
2642 /// \brief Build a new C++ default-argument expression.
2643 ///
2644 /// By default, builds a new default-argument expression, which does not
2645 /// require any semantic analysis. Subclasses may override this routine to
2646 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002647 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002648 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002649 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 }
2651
Richard Smith852c9db2013-04-20 22:23:05 +00002652 /// \brief Build a new C++11 default-initialization expression.
2653 ///
2654 /// By default, builds a new default field initialization expression, which
2655 /// does not require any semantic analysis. Subclasses may override this
2656 /// routine to provide different behavior.
2657 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2658 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002659 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002660 }
2661
Douglas Gregora16548e2009-08-11 05:31:07 +00002662 /// \brief Build a new C++ zero-initialization expression.
2663 ///
2664 /// By default, performs semantic analysis to build the new expression.
2665 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002666 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2667 SourceLocation LParenLoc,
2668 SourceLocation RParenLoc) {
2669 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002670 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002671 }
Mike Stump11289f42009-09-09 15:08:12 +00002672
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 /// \brief Build a new C++ "new" expression.
2674 ///
2675 /// By default, performs semantic analysis to build the new expression.
2676 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002677 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002678 bool UseGlobal,
2679 SourceLocation PlacementLParen,
2680 MultiExprArg PlacementArgs,
2681 SourceLocation PlacementRParen,
2682 SourceRange TypeIdParens,
2683 QualType AllocatedType,
2684 TypeSourceInfo *AllocatedTypeInfo,
2685 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002686 SourceRange DirectInitRange,
2687 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002688 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002689 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002690 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002691 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002692 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002693 AllocatedType,
2694 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002695 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002696 DirectInitRange,
2697 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002698 }
Mike Stump11289f42009-09-09 15:08:12 +00002699
Douglas Gregora16548e2009-08-11 05:31:07 +00002700 /// \brief Build a new C++ "delete" expression.
2701 ///
2702 /// By default, performs semantic analysis to build the new expression.
2703 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002704 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002705 bool IsGlobalDelete,
2706 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002707 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002708 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002709 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002710 }
Mike Stump11289f42009-09-09 15:08:12 +00002711
Douglas Gregor29c42f22012-02-24 07:38:34 +00002712 /// \brief Build a new type trait expression.
2713 ///
2714 /// By default, performs semantic analysis to build the new expression.
2715 /// Subclasses may override this routine to provide different behavior.
2716 ExprResult RebuildTypeTrait(TypeTrait Trait,
2717 SourceLocation StartLoc,
2718 ArrayRef<TypeSourceInfo *> Args,
2719 SourceLocation RParenLoc) {
2720 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2721 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002722
John Wiegley6242b6a2011-04-28 00:16:57 +00002723 /// \brief Build a new array type trait expression.
2724 ///
2725 /// By default, performs semantic analysis to build the new expression.
2726 /// Subclasses may override this routine to provide different behavior.
2727 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2728 SourceLocation StartLoc,
2729 TypeSourceInfo *TSInfo,
2730 Expr *DimExpr,
2731 SourceLocation RParenLoc) {
2732 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2733 }
2734
John Wiegleyf9f65842011-04-25 06:54:41 +00002735 /// \brief Build a new expression trait expression.
2736 ///
2737 /// By default, performs semantic analysis to build the new expression.
2738 /// Subclasses may override this routine to provide different behavior.
2739 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2740 SourceLocation StartLoc,
2741 Expr *Queried,
2742 SourceLocation RParenLoc) {
2743 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2744 }
2745
Mike Stump11289f42009-09-09 15:08:12 +00002746 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002747 /// expression.
2748 ///
2749 /// By default, performs semantic analysis to build the new expression.
2750 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002751 ExprResult RebuildDependentScopeDeclRefExpr(
2752 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002753 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002754 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002755 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002756 bool IsAddressOfOperand,
2757 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002758 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002759 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002760
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002761 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002762 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2763 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002764
Reid Kleckner32506ed2014-06-12 23:03:48 +00002765 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002766 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002767 }
2768
2769 /// \brief Build a new template-id expression.
2770 ///
2771 /// By default, performs semantic analysis to build the new expression.
2772 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002773 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002774 SourceLocation TemplateKWLoc,
2775 LookupResult &R,
2776 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002777 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002778 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2779 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002780 }
2781
2782 /// \brief Build a new object-construction expression.
2783 ///
2784 /// By default, performs semantic analysis to build the new expression.
2785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002786 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002787 SourceLocation Loc,
2788 CXXConstructorDecl *Constructor,
2789 bool IsElidable,
2790 MultiExprArg Args,
2791 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002792 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002793 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002794 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002795 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002796 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002797 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002798 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002799 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002800 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Richard Smithc83bf822016-06-10 00:58:19 +00002802 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002803 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002804 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002805 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002806 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002807 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002808 RequiresZeroInit, ConstructKind,
2809 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002810 }
2811
Richard Smith5179eb72016-06-28 19:03:57 +00002812 /// \brief Build a new implicit construction via inherited constructor
2813 /// expression.
2814 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2815 CXXConstructorDecl *Constructor,
2816 bool ConstructsVBase,
2817 bool InheritedFromVBase) {
2818 return new (getSema().Context) CXXInheritedCtorInitExpr(
2819 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2820 }
2821
Douglas Gregora16548e2009-08-11 05:31:07 +00002822 /// \brief Build a new object-construction expression.
2823 ///
2824 /// By default, performs semantic analysis to build the new expression.
2825 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002826 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2827 SourceLocation LParenLoc,
2828 MultiExprArg Args,
2829 SourceLocation RParenLoc) {
2830 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002831 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002832 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002833 RParenLoc);
2834 }
2835
2836 /// \brief Build a new object-construction expression.
2837 ///
2838 /// By default, performs semantic analysis to build the new expression.
2839 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002840 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2841 SourceLocation LParenLoc,
2842 MultiExprArg Args,
2843 SourceLocation RParenLoc) {
2844 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002845 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002846 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002847 RParenLoc);
2848 }
Mike Stump11289f42009-09-09 15:08:12 +00002849
Douglas Gregora16548e2009-08-11 05:31:07 +00002850 /// \brief Build a new member reference expression.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002854 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002855 QualType BaseType,
2856 bool IsArrow,
2857 SourceLocation OperatorLoc,
2858 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002859 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002860 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002861 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002862 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002863 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002864 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002865
John McCallb268a282010-08-23 23:25:46 +00002866 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002867 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002868 SS, TemplateKWLoc,
2869 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002870 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002871 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002872 }
2873
John McCall10eae182009-11-30 22:42:35 +00002874 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002875 ///
2876 /// By default, performs semantic analysis to build the new expression.
2877 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002878 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2879 SourceLocation OperatorLoc,
2880 bool IsArrow,
2881 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002882 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002883 NamedDecl *FirstQualifierInScope,
2884 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002885 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002886 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002887 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002888
John McCallb268a282010-08-23 23:25:46 +00002889 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002890 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002891 SS, TemplateKWLoc,
2892 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002893 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002894 }
Mike Stump11289f42009-09-09 15:08:12 +00002895
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002896 /// \brief Build a new noexcept expression.
2897 ///
2898 /// By default, performs semantic analysis to build the new expression.
2899 /// Subclasses may override this routine to provide different behavior.
2900 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2901 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2902 }
2903
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002904 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002905 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2906 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002907 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002908 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002909 Optional<unsigned> Length,
2910 ArrayRef<TemplateArgument> PartialArgs) {
2911 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2912 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002913 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002914
Patrick Beard0caa3942012-04-19 00:25:12 +00002915 /// \brief Build a new Objective-C boxed expression.
2916 ///
2917 /// By default, performs semantic analysis to build the new expression.
2918 /// Subclasses may override this routine to provide different behavior.
2919 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2920 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2921 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002922
Ted Kremeneke65b0862012-03-06 20:05:56 +00002923 /// \brief Build a new Objective-C array 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 RebuildObjCArrayLiteral(SourceRange Range,
2928 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002929 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002930 MultiExprArg(Elements, NumElements));
2931 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002932
2933 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002934 Expr *Base, Expr *Key,
2935 ObjCMethodDecl *getterMethod,
2936 ObjCMethodDecl *setterMethod) {
2937 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2938 getterMethod, setterMethod);
2939 }
2940
2941 /// \brief Build a new Objective-C dictionary literal.
2942 ///
2943 /// By default, performs semantic analysis to build the new expression.
2944 /// Subclasses may override this routine to provide different behavior.
2945 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002946 MutableArrayRef<ObjCDictionaryElement> Elements) {
2947 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
James Dennett2a4d13c2012-06-15 07:13:21 +00002950 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002951 ///
2952 /// By default, performs semantic analysis to build the new expression.
2953 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002954 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002955 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002956 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002957 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002958 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002959
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002960 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002961 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002962 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002963 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002964 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002965 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002966 MultiExprArg Args,
2967 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002968 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2969 ReceiverTypeInfo->getType(),
2970 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002971 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002972 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002973 }
2974
2975 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002976 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002977 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002978 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002979 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002980 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002981 MultiExprArg Args,
2982 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002983 return SemaRef.BuildInstanceMessage(Receiver,
2984 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002985 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002986 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002987 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002988 }
2989
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002990 /// \brief Build a new Objective-C instance/class message to 'super'.
2991 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2992 Selector Sel,
2993 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002994 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002995 ObjCMethodDecl *Method,
2996 SourceLocation LBracLoc,
2997 MultiExprArg Args,
2998 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002999 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003000 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003001 SuperLoc,
3002 Sel, Method, LBracLoc, SelectorLocs,
3003 RBracLoc, Args)
3004 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003005 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003006 SuperLoc,
3007 Sel, Method, LBracLoc, SelectorLocs,
3008 RBracLoc, Args);
3009
3010
3011 }
3012
Douglas Gregord51d90d2010-04-26 20:11:03 +00003013 /// \brief Build a new Objective-C ivar reference expression.
3014 ///
3015 /// By default, performs semantic analysis to build the new expression.
3016 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003017 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003018 SourceLocation IvarLoc,
3019 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003020 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003021 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003022 ExprResult Result = getSema().BuildMemberReferenceExpr(
3023 BaseArg, BaseArg->getType(),
3024 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3025 /*FirstQualifierInScope=*/nullptr, NameInfo,
3026 /*TemplateArgs=*/nullptr,
3027 /*S=*/nullptr);
3028 if (IsFreeIvar && Result.isUsable())
3029 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3030 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003031 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003032
3033 /// \brief Build a new Objective-C property reference expression.
3034 ///
3035 /// By default, performs semantic analysis to build the new expression.
3036 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003037 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003038 ObjCPropertyDecl *Property,
3039 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003040 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003041 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3042 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3043 /*FIXME:*/PropertyLoc,
3044 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003045 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003046 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003047 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003048 /*TemplateArgs=*/nullptr,
3049 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003051
John McCallb7bd14f2010-12-02 01:19:52 +00003052 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003053 ///
3054 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003055 /// Subclasses may override this routine to provide different behavior.
3056 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3057 ObjCMethodDecl *Getter,
3058 ObjCMethodDecl *Setter,
3059 SourceLocation PropertyLoc) {
3060 // Since these expressions can only be value-dependent, we do not
3061 // need to perform semantic analysis again.
3062 return Owned(
3063 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3064 VK_LValue, OK_ObjCProperty,
3065 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003066 }
3067
Douglas Gregord51d90d2010-04-26 20:11:03 +00003068 /// \brief Build a new Objective-C "isa" expression.
3069 ///
3070 /// By default, performs semantic analysis to build the new expression.
3071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003072 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003073 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003074 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003075 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3076 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003077 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003078 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003079 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003080 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003081 /*TemplateArgs=*/nullptr,
3082 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003083 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003084
Douglas Gregora16548e2009-08-11 05:31:07 +00003085 /// \brief Build a new shuffle vector expression.
3086 ///
3087 /// By default, performs semantic analysis to build the new expression.
3088 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003089 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003090 MultiExprArg SubExprs,
3091 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003092 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003093 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003094 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3095 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3096 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003097 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003098
Douglas Gregora16548e2009-08-11 05:31:07 +00003099 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003100 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003101 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3102 SemaRef.Context.BuiltinFnTy,
3103 VK_RValue, BuiltinLoc);
3104 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3105 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003106 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003107
3108 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003109 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003110 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003111 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003112
Douglas Gregora16548e2009-08-11 05:31:07 +00003113 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003114 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003115 }
John McCall31f82722010-11-12 08:19:04 +00003116
Hal Finkelc4d7c822013-09-18 03:29:45 +00003117 /// \brief Build a new convert vector expression.
3118 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3119 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3120 SourceLocation RParenLoc) {
3121 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3122 BuiltinLoc, RParenLoc);
3123 }
3124
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003125 /// \brief Build a new template argument pack expansion.
3126 ///
3127 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003128 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003129 /// different behavior.
3130 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003131 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003132 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003133 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003134 case TemplateArgument::Expression: {
3135 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003136 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3137 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003138 if (Result.isInvalid())
3139 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
Douglas Gregor98318c22011-01-03 21:37:45 +00003141 return TemplateArgumentLoc(Result.get(), Result.get());
3142 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003143
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003144 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003145 return TemplateArgumentLoc(TemplateArgument(
3146 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003147 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003148 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003149 Pattern.getTemplateNameLoc(),
3150 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003151
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003152 case TemplateArgument::Null:
3153 case TemplateArgument::Integral:
3154 case TemplateArgument::Declaration:
3155 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003156 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003157 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003158 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003159
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003160 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003161 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003162 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003163 EllipsisLoc,
3164 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003165 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3166 Expansion);
3167 break;
3168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003170 return TemplateArgumentLoc();
3171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003172
Douglas Gregor968f23a2011-01-03 19:31:53 +00003173 /// \brief Build a new expression pack expansion.
3174 ///
3175 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003176 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003177 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003178 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003179 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003180 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003181 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003182
Richard Smith0f0af192014-11-08 05:07:16 +00003183 /// \brief Build a new C++1z fold-expression.
3184 ///
3185 /// By default, performs semantic analysis in order to build a new fold
3186 /// expression.
3187 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3188 BinaryOperatorKind Operator,
3189 SourceLocation EllipsisLoc, Expr *RHS,
3190 SourceLocation RParenLoc) {
3191 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3192 RHS, RParenLoc);
3193 }
3194
3195 /// \brief Build an empty C++1z fold-expression with the given operator.
3196 ///
3197 /// By default, produces the fallback value for the fold-expression, or
3198 /// produce an error if there is no fallback value.
3199 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3200 BinaryOperatorKind Operator) {
3201 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3202 }
3203
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003204 /// \brief Build a new atomic operation expression.
3205 ///
3206 /// By default, performs semantic analysis to build the new expression.
3207 /// Subclasses may override this routine to provide different behavior.
3208 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3209 MultiExprArg SubExprs,
3210 QualType RetTy,
3211 AtomicExpr::AtomicOp Op,
3212 SourceLocation RParenLoc) {
3213 // Just create the expression; there is not any interesting semantic
3214 // analysis here because we can't actually build an AtomicExpr until
3215 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003216 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003217 RParenLoc);
3218 }
3219
John McCall31f82722010-11-12 08:19:04 +00003220private:
Douglas Gregor14454802011-02-25 02:25:35 +00003221 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3222 QualType ObjectType,
3223 NamedDecl *FirstQualifierInScope,
3224 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003225
3226 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3227 QualType ObjectType,
3228 NamedDecl *FirstQualifierInScope,
3229 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003230
3231 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3232 NamedDecl *FirstQualifierInScope,
3233 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003234
3235 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3236 DependentNameTypeLoc TL,
3237 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003238};
Douglas Gregora16548e2009-08-11 05:31:07 +00003239
Douglas Gregorebe10102009-08-20 07:17:43 +00003240template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003241StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003243 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003244
Douglas Gregorebe10102009-08-20 07:17:43 +00003245 switch (S->getStmtClass()) {
3246 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 // Transform individual statement nodes
3249#define STMT(Node, Parent) \
3250 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003251#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003252#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003253#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregorebe10102009-08-20 07:17:43 +00003255 // Transform expressions by calling TransformExpr.
3256#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003257#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003258#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003259#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003260 {
John McCalldadc5752010-08-24 06:29:42 +00003261 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003262 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003263 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003264
Richard Smith945f8d32013-01-14 22:39:08 +00003265 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003266 }
Mike Stump11289f42009-09-09 15:08:12 +00003267 }
3268
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003269 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003270}
Mike Stump11289f42009-09-09 15:08:12 +00003271
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003272template<typename Derived>
3273OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3274 if (!S)
3275 return S;
3276
3277 switch (S->getClauseKind()) {
3278 default: break;
3279 // Transform individual clause nodes
3280#define OPENMP_CLAUSE(Name, Class) \
3281 case OMPC_ ## Name : \
3282 return getDerived().Transform ## Class(cast<Class>(S));
3283#include "clang/Basic/OpenMPKinds.def"
3284 }
3285
3286 return S;
3287}
3288
Mike Stump11289f42009-09-09 15:08:12 +00003289
Douglas Gregore922c772009-08-04 22:27:00 +00003290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003291ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003292 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003293 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003294
3295 switch (E->getStmtClass()) {
3296 case Stmt::NoStmtClass: break;
3297#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003298#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003299#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003300 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003301#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003302 }
3303
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003304 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003305}
3306
3307template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003308ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003309 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003310 // Initializers are instantiated like expressions, except that various outer
3311 // layers are stripped.
3312 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003313 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003314
3315 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3316 Init = ExprTemp->getSubExpr();
3317
Richard Smith410306b2016-12-12 02:53:20 +00003318 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3319 Init = AIL->getCommonExpr();
3320
Richard Smithe6ca4752013-05-30 22:40:16 +00003321 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3322 Init = MTE->GetTemporaryExpr();
3323
Richard Smithd59b8322012-12-19 01:39:02 +00003324 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3325 Init = Binder->getSubExpr();
3326
3327 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3328 Init = ICE->getSubExprAsWritten();
3329
Richard Smithcc1b96d2013-06-12 22:31:48 +00003330 if (CXXStdInitializerListExpr *ILE =
3331 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003332 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003333
Richard Smithc6abd962014-07-25 01:12:44 +00003334 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003335 // InitListExprs. Other forms of copy-initialization will be a no-op if
3336 // the initializer is already the right type.
3337 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003338 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003339 return getDerived().TransformExpr(Init);
3340
3341 // Revert value-initialization back to empty parens.
3342 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3343 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003344 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003345 Parens.getEnd());
3346 }
3347
3348 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3349 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003350 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003351 SourceLocation());
3352
3353 // Revert initialization by constructor back to a parenthesized or braced list
3354 // of expressions. Any other form of initializer can just be reused directly.
3355 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003356 return getDerived().TransformExpr(Init);
3357
Richard Smithf8adcdc2014-07-17 05:12:35 +00003358 // If the initialization implicitly converted an initializer list to a
3359 // std::initializer_list object, unwrap the std::initializer_list too.
3360 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003361 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003362
Richard Smithd59b8322012-12-19 01:39:02 +00003363 SmallVector<Expr*, 8> NewArgs;
3364 bool ArgChanged = false;
3365 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003366 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003367 return ExprError();
3368
3369 // If this was list initialization, revert to list form.
3370 if (Construct->isListInitialization())
3371 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3372 Construct->getLocEnd(),
3373 Construct->getType());
3374
Richard Smithd59b8322012-12-19 01:39:02 +00003375 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003376 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003377 if (Parens.isInvalid()) {
3378 // This was a variable declaration's initialization for which no initializer
3379 // was specified.
3380 assert(NewArgs.empty() &&
3381 "no parens or braces but have direct init with arguments?");
3382 return ExprEmpty();
3383 }
Richard Smithd59b8322012-12-19 01:39:02 +00003384 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3385 Parens.getEnd());
3386}
3387
3388template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003389bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003390 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003391 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003392 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003393 bool *ArgChanged) {
3394 for (unsigned I = 0; I != NumInputs; ++I) {
3395 // If requested, drop call arguments that need to be dropped.
3396 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3397 if (ArgChanged)
3398 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003399
Douglas Gregora3efea12011-01-03 19:04:46 +00003400 break;
3401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor968f23a2011-01-03 19:31:53 +00003403 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3404 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003405
Chris Lattner01cf8db2011-07-20 06:58:45 +00003406 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003407 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3408 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003409
Douglas Gregor968f23a2011-01-03 19:31:53 +00003410 // Determine whether the set of unexpanded parameter packs can and should
3411 // be expanded.
3412 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003413 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003414 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3415 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003416 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3417 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003418 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003419 Expand, RetainExpansion,
3420 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003421 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor968f23a2011-01-03 19:31:53 +00003423 if (!Expand) {
3424 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003425 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003426 // expansion.
3427 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3428 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3429 if (OutPattern.isInvalid())
3430 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003431
3432 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003433 Expansion->getEllipsisLoc(),
3434 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003435 if (Out.isInvalid())
3436 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor968f23a2011-01-03 19:31:53 +00003438 if (ArgChanged)
3439 *ArgChanged = true;
3440 Outputs.push_back(Out.get());
3441 continue;
3442 }
John McCall542e7c62011-07-06 07:30:07 +00003443
3444 // Record right away that the argument was changed. This needs
3445 // to happen even if the array expands to nothing.
3446 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor968f23a2011-01-03 19:31:53 +00003448 // The transform has determined that we should perform an elementwise
3449 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003450 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003451 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3452 ExprResult Out = getDerived().TransformExpr(Pattern);
3453 if (Out.isInvalid())
3454 return true;
3455
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003456 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003457 Out = getDerived().RebuildPackExpansion(
3458 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003459 if (Out.isInvalid())
3460 return true;
3461 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003462
Douglas Gregor968f23a2011-01-03 19:31:53 +00003463 Outputs.push_back(Out.get());
3464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003465
Richard Smith9467be42014-06-06 17:33:35 +00003466 // If we're supposed to retain a pack expansion, do so by temporarily
3467 // forgetting the partially-substituted parameter pack.
3468 if (RetainExpansion) {
3469 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3470
3471 ExprResult Out = getDerived().TransformExpr(Pattern);
3472 if (Out.isInvalid())
3473 return true;
3474
3475 Out = getDerived().RebuildPackExpansion(
3476 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3477 if (Out.isInvalid())
3478 return true;
3479
3480 Outputs.push_back(Out.get());
3481 }
3482
Douglas Gregor968f23a2011-01-03 19:31:53 +00003483 continue;
3484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Richard Smithd59b8322012-12-19 01:39:02 +00003486 ExprResult Result =
3487 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3488 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003489 if (Result.isInvalid())
3490 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003491
Douglas Gregora3efea12011-01-03 19:04:46 +00003492 if (Result.get() != Inputs[I] && ArgChanged)
3493 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
3495 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003496 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003497
Douglas Gregora3efea12011-01-03 19:04:46 +00003498 return false;
3499}
3500
Richard Smith03a4aa32016-06-23 19:02:52 +00003501template <typename Derived>
3502Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3503 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3504 if (Var) {
3505 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3506 getDerived().TransformDefinition(Var->getLocation(), Var));
3507
3508 if (!ConditionVar)
3509 return Sema::ConditionError();
3510
3511 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3512 }
3513
3514 if (Expr) {
3515 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3516
3517 if (CondExpr.isInvalid())
3518 return Sema::ConditionError();
3519
3520 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3521 }
3522
3523 return Sema::ConditionResult();
3524}
3525
Douglas Gregora3efea12011-01-03 19:04:46 +00003526template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003527NestedNameSpecifierLoc
3528TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3529 NestedNameSpecifierLoc NNS,
3530 QualType ObjectType,
3531 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003532 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003533 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003534 Qualifier = Qualifier.getPrefix())
3535 Qualifiers.push_back(Qualifier);
3536
3537 CXXScopeSpec SS;
3538 while (!Qualifiers.empty()) {
3539 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3540 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003541
Douglas Gregor14454802011-02-25 02:25:35 +00003542 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003543 case NestedNameSpecifier::Identifier: {
3544 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3545 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3546 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3547 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003548 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003549 }
Douglas Gregor14454802011-02-25 02:25:35 +00003550 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregor14454802011-02-25 02:25:35 +00003552 case NestedNameSpecifier::Namespace: {
3553 NamespaceDecl *NS
3554 = cast_or_null<NamespaceDecl>(
3555 getDerived().TransformDecl(
3556 Q.getLocalBeginLoc(),
3557 QNNS->getAsNamespace()));
3558 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3559 break;
3560 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003561
Douglas Gregor14454802011-02-25 02:25:35 +00003562 case NestedNameSpecifier::NamespaceAlias: {
3563 NamespaceAliasDecl *Alias
3564 = cast_or_null<NamespaceAliasDecl>(
3565 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3566 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003567 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003568 Q.getLocalEndLoc());
3569 break;
3570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003571
Douglas Gregor14454802011-02-25 02:25:35 +00003572 case NestedNameSpecifier::Global:
3573 // There is no meaningful transformation that one could perform on the
3574 // global scope.
3575 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3576 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Nikola Smiljanic67860242014-09-26 00:28:20 +00003578 case NestedNameSpecifier::Super: {
3579 CXXRecordDecl *RD =
3580 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3581 SourceLocation(), QNNS->getAsRecordDecl()));
3582 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3583 break;
3584 }
3585
Douglas Gregor14454802011-02-25 02:25:35 +00003586 case NestedNameSpecifier::TypeSpecWithTemplate:
3587 case NestedNameSpecifier::TypeSpec: {
3588 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3589 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003590
Douglas Gregor14454802011-02-25 02:25:35 +00003591 if (!TL)
3592 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregor14454802011-02-25 02:25:35 +00003594 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003595 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003596 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003597 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003598 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003599 if (TL.getType()->isEnumeralType())
3600 SemaRef.Diag(TL.getBeginLoc(),
3601 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003602 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3603 Q.getLocalEndLoc());
3604 break;
3605 }
Richard Trieude756fb2011-05-07 01:36:37 +00003606 // If the nested-name-specifier is an invalid type def, don't emit an
3607 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003608 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3609 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003610 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003611 << TL.getType() << SS.getRange();
3612 }
Douglas Gregor14454802011-02-25 02:25:35 +00003613 return NestedNameSpecifierLoc();
3614 }
Douglas Gregore16af532011-02-28 18:50:33 +00003615 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003616
Douglas Gregore16af532011-02-28 18:50:33 +00003617 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003618 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003619 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003620 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003621
Douglas Gregor14454802011-02-25 02:25:35 +00003622 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003623 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003624 !getDerived().AlwaysRebuild())
3625 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
3627 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003628 // nested-name-specifier, do so.
3629 if (SS.location_size() == NNS.getDataLength() &&
3630 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3631 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3632
3633 // Allocate new nested-name-specifier location information.
3634 return SS.getWithLocInContext(SemaRef.Context);
3635}
3636
3637template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003638DeclarationNameInfo
3639TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003640::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003641 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003642 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003643 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003644
3645 switch (Name.getNameKind()) {
3646 case DeclarationName::Identifier:
3647 case DeclarationName::ObjCZeroArgSelector:
3648 case DeclarationName::ObjCOneArgSelector:
3649 case DeclarationName::ObjCMultiArgSelector:
3650 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003651 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003652 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003653 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003654
Richard Smith35845152017-02-07 01:37:30 +00003655 case DeclarationName::CXXDeductionGuideName: {
3656 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3657 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3658 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3659 if (!NewTemplate)
3660 return DeclarationNameInfo();
3661
3662 DeclarationNameInfo NewNameInfo(NameInfo);
3663 NewNameInfo.setName(
3664 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3665 return NewNameInfo;
3666 }
3667
Douglas Gregorf816bd72009-09-03 22:13:48 +00003668 case DeclarationName::CXXConstructorName:
3669 case DeclarationName::CXXDestructorName:
3670 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003671 TypeSourceInfo *NewTInfo;
3672 CanQualType NewCanTy;
3673 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003674 NewTInfo = getDerived().TransformType(OldTInfo);
3675 if (!NewTInfo)
3676 return DeclarationNameInfo();
3677 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003678 }
3679 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003680 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003681 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003682 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003683 if (NewT.isNull())
3684 return DeclarationNameInfo();
3685 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3686 }
Mike Stump11289f42009-09-09 15:08:12 +00003687
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003688 DeclarationName NewName
3689 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3690 NewCanTy);
3691 DeclarationNameInfo NewNameInfo(NameInfo);
3692 NewNameInfo.setName(NewName);
3693 NewNameInfo.setNamedTypeInfo(NewTInfo);
3694 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003695 }
Mike Stump11289f42009-09-09 15:08:12 +00003696 }
3697
David Blaikie83d382b2011-09-23 05:06:16 +00003698 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003699}
3700
3701template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003702TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003703TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3704 TemplateName Name,
3705 SourceLocation NameLoc,
3706 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003707 NamedDecl *FirstQualifierInScope,
3708 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003709 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3710 TemplateDecl *Template = QTN->getTemplateDecl();
3711 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003712
Douglas Gregor9db53502011-03-02 18:07:45 +00003713 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003714 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003715 Template));
3716 if (!TransTemplate)
3717 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Douglas Gregor9db53502011-03-02 18:07:45 +00003719 if (!getDerived().AlwaysRebuild() &&
3720 SS.getScopeRep() == QTN->getQualifier() &&
3721 TransTemplate == Template)
3722 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003723
Douglas Gregor9db53502011-03-02 18:07:45 +00003724 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3725 TransTemplate);
3726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregor9db53502011-03-02 18:07:45 +00003728 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3729 if (SS.getScopeRep()) {
3730 // These apply to the scope specifier, not the template.
3731 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003732 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003733 }
3734
Douglas Gregor9db53502011-03-02 18:07:45 +00003735 if (!getDerived().AlwaysRebuild() &&
3736 SS.getScopeRep() == DTN->getQualifier() &&
3737 ObjectType.isNull())
3738 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
Douglas Gregor9db53502011-03-02 18:07:45 +00003740 if (DTN->isIdentifier()) {
3741 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003742 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003743 NameLoc,
3744 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003745 FirstQualifierInScope,
3746 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003747 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003748
Douglas Gregor9db53502011-03-02 18:07:45 +00003749 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003750 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003752
Douglas Gregor9db53502011-03-02 18:07:45 +00003753 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3754 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003755 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003756 Template));
3757 if (!TransTemplate)
3758 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003759
Douglas Gregor9db53502011-03-02 18:07:45 +00003760 if (!getDerived().AlwaysRebuild() &&
3761 TransTemplate == Template)
3762 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003763
Douglas Gregor9db53502011-03-02 18:07:45 +00003764 return TemplateName(TransTemplate);
3765 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003766
Douglas Gregor9db53502011-03-02 18:07:45 +00003767 if (SubstTemplateTemplateParmPackStorage *SubstPack
3768 = Name.getAsSubstTemplateTemplateParmPack()) {
3769 TemplateTemplateParmDecl *TransParam
3770 = cast_or_null<TemplateTemplateParmDecl>(
3771 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3772 if (!TransParam)
3773 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003774
Douglas Gregor9db53502011-03-02 18:07:45 +00003775 if (!getDerived().AlwaysRebuild() &&
3776 TransParam == SubstPack->getParameterPack())
3777 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003778
3779 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003780 SubstPack->getArgumentPack());
3781 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregor9db53502011-03-02 18:07:45 +00003783 // These should be getting filtered out before they reach the AST.
3784 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003785}
3786
3787template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003788void TreeTransform<Derived>::InventTemplateArgumentLoc(
3789 const TemplateArgument &Arg,
3790 TemplateArgumentLoc &Output) {
3791 SourceLocation Loc = getDerived().getBaseLocation();
3792 switch (Arg.getKind()) {
3793 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003794 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003795 break;
3796
3797 case TemplateArgument::Type:
3798 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003799 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003800
John McCall0ad16662009-10-29 08:12:44 +00003801 break;
3802
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003803 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003804 case TemplateArgument::TemplateExpansion: {
3805 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003806 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003807 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3808 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3809 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3810 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003811
Douglas Gregor9d802122011-03-02 17:09:35 +00003812 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003813 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003814 Builder.getWithLocInContext(SemaRef.Context),
3815 Loc);
3816 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003817 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003818 Builder.getWithLocInContext(SemaRef.Context),
3819 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003820
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003821 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003822 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003823
John McCall0ad16662009-10-29 08:12:44 +00003824 case TemplateArgument::Expression:
3825 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3826 break;
3827
3828 case TemplateArgument::Declaration:
3829 case TemplateArgument::Integral:
3830 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003831 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003832 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003833 break;
3834 }
3835}
3836
3837template<typename Derived>
3838bool TreeTransform<Derived>::TransformTemplateArgument(
3839 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003840 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003841 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003842 switch (Arg.getKind()) {
3843 case TemplateArgument::Null:
3844 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003845 case TemplateArgument::Pack:
3846 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003847 case TemplateArgument::NullPtr:
3848 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003849
Douglas Gregore922c772009-08-04 22:27:00 +00003850 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003851 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003852 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003853 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003854
3855 DI = getDerived().TransformType(DI);
3856 if (!DI) return true;
3857
3858 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3859 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003860 }
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003862 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003863 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3864 if (QualifierLoc) {
3865 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3866 if (!QualifierLoc)
3867 return true;
3868 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003869
Douglas Gregordf846d12011-03-02 18:46:51 +00003870 CXXScopeSpec SS;
3871 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003872 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003873 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3874 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003875 if (Template.isNull())
3876 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003877
Douglas Gregor9d802122011-03-02 17:09:35 +00003878 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003879 Input.getTemplateNameLoc());
3880 return false;
3881 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003882
3883 case TemplateArgument::TemplateExpansion:
3884 llvm_unreachable("Caller should expand pack expansions");
3885
Douglas Gregore922c772009-08-04 22:27:00 +00003886 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003887 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003888 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003889 getSema(), Uneval
3890 ? Sema::ExpressionEvaluationContext::Unevaluated
3891 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003892
John McCall0ad16662009-10-29 08:12:44 +00003893 Expr *InputExpr = Input.getSourceExpression();
3894 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3895
Chris Lattnercdb591a2011-04-25 20:37:58 +00003896 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003897 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003898 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003899 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003900 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003901 }
Douglas Gregore922c772009-08-04 22:27:00 +00003902 }
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregore922c772009-08-04 22:27:00 +00003904 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003905 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003906}
3907
Douglas Gregorfe921a72010-12-20 23:36:19 +00003908/// \brief Iterator adaptor that invents template argument location information
3909/// for each of the template arguments in its underlying iterator.
3910template<typename Derived, typename InputIterator>
3911class TemplateArgumentLocInventIterator {
3912 TreeTransform<Derived> &Self;
3913 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Douglas Gregorfe921a72010-12-20 23:36:19 +00003915public:
3916 typedef TemplateArgumentLoc value_type;
3917 typedef TemplateArgumentLoc reference;
3918 typedef typename std::iterator_traits<InputIterator>::difference_type
3919 difference_type;
3920 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003921
Douglas Gregorfe921a72010-12-20 23:36:19 +00003922 class pointer {
3923 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003924
Douglas Gregorfe921a72010-12-20 23:36:19 +00003925 public:
3926 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003927
Douglas Gregorfe921a72010-12-20 23:36:19 +00003928 const TemplateArgumentLoc *operator->() const { return &Arg; }
3929 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003931 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003932
Douglas Gregorfe921a72010-12-20 23:36:19 +00003933 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3934 InputIterator Iter)
3935 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003936
Douglas Gregorfe921a72010-12-20 23:36:19 +00003937 TemplateArgumentLocInventIterator &operator++() {
3938 ++Iter;
3939 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003940 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003941
Douglas Gregorfe921a72010-12-20 23:36:19 +00003942 TemplateArgumentLocInventIterator operator++(int) {
3943 TemplateArgumentLocInventIterator Old(*this);
3944 ++(*this);
3945 return Old;
3946 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003947
Douglas Gregorfe921a72010-12-20 23:36:19 +00003948 reference operator*() const {
3949 TemplateArgumentLoc Result;
3950 Self.InventTemplateArgumentLoc(*Iter, Result);
3951 return Result;
3952 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003953
Douglas Gregorfe921a72010-12-20 23:36:19 +00003954 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
Douglas Gregorfe921a72010-12-20 23:36:19 +00003956 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3957 const TemplateArgumentLocInventIterator &Y) {
3958 return X.Iter == Y.Iter;
3959 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003960
Douglas Gregorfe921a72010-12-20 23:36:19 +00003961 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3962 const TemplateArgumentLocInventIterator &Y) {
3963 return X.Iter != Y.Iter;
3964 }
3965};
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Douglas Gregor42cafa82010-12-20 17:42:22 +00003967template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003968template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003969bool TreeTransform<Derived>::TransformTemplateArguments(
3970 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3971 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003972 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003973 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003974 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003975
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003976 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3977 // Unpack argument packs, which we translate them into separate
3978 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003979 // FIXME: We could do much better if we could guarantee that the
3980 // TemplateArgumentLocInfo for the pack expansion would be usable for
3981 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003982 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003983 TemplateArgument::pack_iterator>
3984 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003985 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003986 In.getArgument().pack_begin()),
3987 PackLocIterator(*this,
3988 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003989 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003990 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003991
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003992 continue;
3993 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003994
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003995 if (In.getArgument().isPackExpansion()) {
3996 // We have a pack expansion, for which we will be substituting into
3997 // the pattern.
3998 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003999 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004000 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004001 = getSema().getTemplateArgumentPackExpansionPattern(
4002 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004003
Chris Lattner01cf8db2011-07-20 06:58:45 +00004004 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004005 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4006 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004007
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004008 // Determine whether the set of unexpanded parameter packs can and should
4009 // be expanded.
4010 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004011 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004012 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004013 if (getDerived().TryExpandParameterPacks(Ellipsis,
4014 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004015 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004016 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004017 RetainExpansion,
4018 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004019 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004020
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004021 if (!Expand) {
4022 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004023 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004024 // expansion.
4025 TemplateArgumentLoc OutPattern;
4026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004027 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004028 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004029
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004030 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4031 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004032 if (Out.getArgument().isNull())
4033 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004034
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004035 Outputs.addArgument(Out);
4036 continue;
4037 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004038
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004039 // The transform has determined that we should perform an elementwise
4040 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004041 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4043
Richard Smithd784e682015-09-23 21:41:42 +00004044 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004045 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004046
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004047 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004048 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4049 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004050 if (Out.getArgument().isNull())
4051 return true;
4052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004053
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004054 Outputs.addArgument(Out);
4055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004056
Douglas Gregor48d24112011-01-10 20:53:55 +00004057 // If we're supposed to retain a pack expansion, do so by temporarily
4058 // forgetting the partially-substituted parameter pack.
4059 if (RetainExpansion) {
4060 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004061
Richard Smithd784e682015-09-23 21:41:42 +00004062 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004063 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004064
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004065 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4066 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004067 if (Out.getArgument().isNull())
4068 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004069
Douglas Gregor48d24112011-01-10 20:53:55 +00004070 Outputs.addArgument(Out);
4071 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004072
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004073 continue;
4074 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004075
4076 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004077 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004078 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004079
Douglas Gregor42cafa82010-12-20 17:42:22 +00004080 Outputs.addArgument(Out);
4081 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004082
Douglas Gregor42cafa82010-12-20 17:42:22 +00004083 return false;
4084
4085}
4086
Douglas Gregord6ff3322009-08-04 16:50:30 +00004087//===----------------------------------------------------------------------===//
4088// Type transformation
4089//===----------------------------------------------------------------------===//
4090
4091template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004092QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004093 if (getDerived().AlreadyTransformed(T))
4094 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004095
John McCall550e0c22009-10-21 00:40:46 +00004096 // Temporary workaround. All of these transformations should
4097 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004098 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4099 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004100
John McCall31f82722010-11-12 08:19:04 +00004101 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004102
John McCall550e0c22009-10-21 00:40:46 +00004103 if (!NewDI)
4104 return QualType();
4105
4106 return NewDI->getType();
4107}
4108
4109template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004110TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004111 // Refine the base location to the type's location.
4112 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4113 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004114 if (getDerived().AlreadyTransformed(DI->getType()))
4115 return DI;
4116
4117 TypeLocBuilder TLB;
4118
4119 TypeLoc TL = DI->getTypeLoc();
4120 TLB.reserve(TL.getFullDataSize());
4121
John McCall31f82722010-11-12 08:19:04 +00004122 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004123 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004124 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004125
John McCallbcd03502009-12-07 02:54:59 +00004126 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004127}
4128
4129template<typename Derived>
4130QualType
John McCall31f82722010-11-12 08:19:04 +00004131TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004132 switch (T.getTypeLocClass()) {
4133#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004134#define TYPELOC(CLASS, PARENT) \
4135 case TypeLoc::CLASS: \
4136 return getDerived().Transform##CLASS##Type(TLB, \
4137 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004138#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004139 }
Mike Stump11289f42009-09-09 15:08:12 +00004140
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004141 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004142}
4143
Richard Smithee579842017-01-30 20:39:26 +00004144template<typename Derived>
4145QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4146 if (!isa<DependentNameType>(T))
4147 return TransformType(T);
4148
4149 if (getDerived().AlreadyTransformed(T))
4150 return T;
4151 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4152 getDerived().getBaseLocation());
4153 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4154 return NewDI ? NewDI->getType() : QualType();
4155}
4156
4157template<typename Derived>
4158TypeSourceInfo *
4159TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4160 if (!isa<DependentNameType>(DI->getType()))
4161 return TransformType(DI);
4162
4163 // Refine the base location to the type's location.
4164 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4165 getDerived().getBaseEntity());
4166 if (getDerived().AlreadyTransformed(DI->getType()))
4167 return DI;
4168
4169 TypeLocBuilder TLB;
4170
4171 TypeLoc TL = DI->getTypeLoc();
4172 TLB.reserve(TL.getFullDataSize());
4173
4174 Qualifiers Quals;
4175 auto QTL = TL.getAs<QualifiedTypeLoc>();
4176 if (QTL)
4177 TL = QTL.getUnqualifiedLoc();
4178
4179 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4180
4181 QualType Result = getDerived().TransformDependentNameType(
4182 TLB, DNTL, /*DeducedTSTContext*/true);
4183 if (Result.isNull())
4184 return nullptr;
4185
4186 if (QTL) {
4187 Result = getDerived().RebuildQualifiedType(
4188 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4189 TLB.TypeWasModifiedSafely(Result);
4190 }
4191
4192 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4193}
4194
John McCall550e0c22009-10-21 00:40:46 +00004195template<typename Derived>
4196QualType
4197TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004198 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004199 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004200
John McCall31f82722010-11-12 08:19:04 +00004201 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004202 if (Result.isNull())
4203 return QualType();
4204
Richard Smithee579842017-01-30 20:39:26 +00004205 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4206
4207 // RebuildQualifiedType might have updated the type, but not in a way
4208 // that invalidates the TypeLoc. (There's no location information for
4209 // qualifiers.)
4210 TLB.TypeWasModifiedSafely(Result);
4211
4212 return Result;
4213}
4214
4215template<typename Derived>
4216QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4217 SourceLocation Loc,
4218 Qualifiers Quals) {
4219 // C++ [dcl.fct]p7:
4220 // [When] adding cv-qualifications on top of the function type [...] the
4221 // cv-qualifiers are ignored.
4222 // C++ [dcl.ref]p1:
4223 // when the cv-qualifiers are introduced through the use of a typedef-name
4224 // or decltype-specifier [...] the cv-qualifiers are ignored.
4225 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4226 // applied to a reference type.
4227 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4228 if (T->isFunctionType() || T->isReferenceType())
4229 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004230
John McCall31168b02011-06-15 23:02:42 +00004231 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004232 // resulting type.
4233 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004234 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004235 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004236 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004237 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004238 // A lifetime qualifier applied to a substituted template parameter
4239 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004240 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004241 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004242 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004243 QualType Replacement = SubstTypeParam->getReplacementType();
4244 Qualifiers Qs = Replacement.getQualifiers();
4245 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004246 Replacement = SemaRef.Context.getQualifiedType(
4247 Replacement.getUnqualifiedType(), Qs);
4248 T = SemaRef.Context.getSubstTemplateTypeParmType(
4249 SubstTypeParam->getReplacedParameter(), Replacement);
4250 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004251 // 'auto' types behave the same way as template parameters.
4252 QualType Deduced = AutoTy->getDeducedType();
4253 Qualifiers Qs = Deduced.getQualifiers();
4254 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004255 Deduced =
4256 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4257 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4258 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004259 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004260 // Otherwise, complain about the addition of a qualifier to an
4261 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004262 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4263 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004264 Quals.removeObjCLifetime();
4265 }
4266 }
4267 }
John McCall550e0c22009-10-21 00:40:46 +00004268
Richard Smithee579842017-01-30 20:39:26 +00004269 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004270}
4271
Douglas Gregor14454802011-02-25 02:25:35 +00004272template<typename Derived>
4273TypeLoc
4274TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4275 QualType ObjectType,
4276 NamedDecl *UnqualLookup,
4277 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004278 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004279 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004280
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004281 TypeSourceInfo *TSI =
4282 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4283 if (TSI)
4284 return TSI->getTypeLoc();
4285 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004286}
4287
Douglas Gregor579c15f2011-03-02 18:32:08 +00004288template<typename Derived>
4289TypeSourceInfo *
4290TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4291 QualType ObjectType,
4292 NamedDecl *UnqualLookup,
4293 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004294 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004295 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004296
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004297 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4298 UnqualLookup, SS);
4299}
4300
4301template <typename Derived>
4302TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4303 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4304 CXXScopeSpec &SS) {
4305 QualType T = TL.getType();
4306 assert(!getDerived().AlreadyTransformed(T));
4307
Douglas Gregor579c15f2011-03-02 18:32:08 +00004308 TypeLocBuilder TLB;
4309 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004310
Douglas Gregor579c15f2011-03-02 18:32:08 +00004311 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004312 TemplateSpecializationTypeLoc SpecTL =
4313 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004314
Richard Smithfd3dae02017-01-20 00:20:39 +00004315 TemplateName Template = getDerived().TransformTemplateName(
4316 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4317 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00004318 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004319 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004320
4321 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004322 Template);
4323 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004324 DependentTemplateSpecializationTypeLoc SpecTL =
4325 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004326
Douglas Gregor579c15f2011-03-02 18:32:08 +00004327 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004328 = getDerived().RebuildTemplateName(SS,
4329 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004330 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004331 ObjectType, UnqualLookup,
4332 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004333 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004334 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004335
4336 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004337 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004338 Template,
4339 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004340 } else {
4341 // Nothing special needs to be done for these.
4342 Result = getDerived().TransformType(TLB, TL);
4343 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004344
4345 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004346 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004347
Douglas Gregor579c15f2011-03-02 18:32:08 +00004348 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4349}
4350
John McCall550e0c22009-10-21 00:40:46 +00004351template <class TyLoc> static inline
4352QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4353 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4354 NewT.setNameLoc(T.getNameLoc());
4355 return T.getType();
4356}
4357
John McCall550e0c22009-10-21 00:40:46 +00004358template<typename Derived>
4359QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004360 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004361 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4362 NewT.setBuiltinLoc(T.getBuiltinLoc());
4363 if (T.needsExtraLocalData())
4364 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4365 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004366}
Mike Stump11289f42009-09-09 15:08:12 +00004367
Douglas Gregord6ff3322009-08-04 16:50:30 +00004368template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004369QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004370 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004371 // FIXME: recurse?
4372 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004373}
Mike Stump11289f42009-09-09 15:08:12 +00004374
Reid Kleckner0503a872013-12-05 01:23:43 +00004375template <typename Derived>
4376QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4377 AdjustedTypeLoc TL) {
4378 // Adjustments applied during transformation are handled elsewhere.
4379 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4380}
4381
Douglas Gregord6ff3322009-08-04 16:50:30 +00004382template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004383QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4384 DecayedTypeLoc TL) {
4385 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4386 if (OriginalType.isNull())
4387 return QualType();
4388
4389 QualType Result = TL.getType();
4390 if (getDerived().AlwaysRebuild() ||
4391 OriginalType != TL.getOriginalLoc().getType())
4392 Result = SemaRef.Context.getDecayedType(OriginalType);
4393 TLB.push<DecayedTypeLoc>(Result);
4394 // Nothing to set for DecayedTypeLoc.
4395 return Result;
4396}
4397
4398template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004399QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004400 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004401 QualType PointeeType
4402 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004403 if (PointeeType.isNull())
4404 return QualType();
4405
4406 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004407 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004408 // A dependent pointer type 'T *' has is being transformed such
4409 // that an Objective-C class type is being replaced for 'T'. The
4410 // resulting pointer type is an ObjCObjectPointerType, not a
4411 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004412 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004413
John McCall8b07ec22010-05-15 11:32:37 +00004414 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4415 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004416 return Result;
4417 }
John McCall31f82722010-11-12 08:19:04 +00004418
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004419 if (getDerived().AlwaysRebuild() ||
4420 PointeeType != TL.getPointeeLoc().getType()) {
4421 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4422 if (Result.isNull())
4423 return QualType();
4424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004425
John McCall31168b02011-06-15 23:02:42 +00004426 // Objective-C ARC can add lifetime qualifiers to the type that we're
4427 // pointing to.
4428 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004429
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004430 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4431 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004432 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004433}
Mike Stump11289f42009-09-09 15:08:12 +00004434
4435template<typename Derived>
4436QualType
John McCall550e0c22009-10-21 00:40:46 +00004437TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004438 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004439 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004440 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4441 if (PointeeType.isNull())
4442 return QualType();
4443
4444 QualType Result = TL.getType();
4445 if (getDerived().AlwaysRebuild() ||
4446 PointeeType != TL.getPointeeLoc().getType()) {
4447 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004448 TL.getSigilLoc());
4449 if (Result.isNull())
4450 return QualType();
4451 }
4452
Douglas Gregor049211a2010-04-22 16:50:51 +00004453 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004454 NewT.setSigilLoc(TL.getSigilLoc());
4455 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004456}
4457
John McCall70dd5f62009-10-30 00:06:24 +00004458/// Transforms a reference type. Note that somewhat paradoxically we
4459/// don't care whether the type itself is an l-value type or an r-value
4460/// type; we only care if the type was *written* as an l-value type
4461/// or an r-value type.
4462template<typename Derived>
4463QualType
4464TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004465 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004466 const ReferenceType *T = TL.getTypePtr();
4467
4468 // Note that this works with the pointee-as-written.
4469 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4470 if (PointeeType.isNull())
4471 return QualType();
4472
4473 QualType Result = TL.getType();
4474 if (getDerived().AlwaysRebuild() ||
4475 PointeeType != T->getPointeeTypeAsWritten()) {
4476 Result = getDerived().RebuildReferenceType(PointeeType,
4477 T->isSpelledAsLValue(),
4478 TL.getSigilLoc());
4479 if (Result.isNull())
4480 return QualType();
4481 }
4482
John McCall31168b02011-06-15 23:02:42 +00004483 // Objective-C ARC can add lifetime qualifiers to the type that we're
4484 // referring to.
4485 TLB.TypeWasModifiedSafely(
4486 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4487
John McCall70dd5f62009-10-30 00:06:24 +00004488 // r-value references can be rebuilt as l-value references.
4489 ReferenceTypeLoc NewTL;
4490 if (isa<LValueReferenceType>(Result))
4491 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4492 else
4493 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4494 NewTL.setSigilLoc(TL.getSigilLoc());
4495
4496 return Result;
4497}
4498
Mike Stump11289f42009-09-09 15:08:12 +00004499template<typename Derived>
4500QualType
John McCall550e0c22009-10-21 00:40:46 +00004501TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004502 LValueReferenceTypeLoc TL) {
4503 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004504}
4505
Mike Stump11289f42009-09-09 15:08:12 +00004506template<typename Derived>
4507QualType
John McCall550e0c22009-10-21 00:40:46 +00004508TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004509 RValueReferenceTypeLoc TL) {
4510 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004511}
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregord6ff3322009-08-04 16:50:30 +00004513template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004514QualType
John McCall550e0c22009-10-21 00:40:46 +00004515TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004516 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004517 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004518 if (PointeeType.isNull())
4519 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004520
Abramo Bagnara509357842011-03-05 14:42:21 +00004521 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004522 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004523 if (OldClsTInfo) {
4524 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4525 if (!NewClsTInfo)
4526 return QualType();
4527 }
4528
4529 const MemberPointerType *T = TL.getTypePtr();
4530 QualType OldClsType = QualType(T->getClass(), 0);
4531 QualType NewClsType;
4532 if (NewClsTInfo)
4533 NewClsType = NewClsTInfo->getType();
4534 else {
4535 NewClsType = getDerived().TransformType(OldClsType);
4536 if (NewClsType.isNull())
4537 return QualType();
4538 }
Mike Stump11289f42009-09-09 15:08:12 +00004539
John McCall550e0c22009-10-21 00:40:46 +00004540 QualType Result = TL.getType();
4541 if (getDerived().AlwaysRebuild() ||
4542 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004543 NewClsType != OldClsType) {
4544 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004545 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004546 if (Result.isNull())
4547 return QualType();
4548 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004549
Reid Kleckner0503a872013-12-05 01:23:43 +00004550 // If we had to adjust the pointee type when building a member pointer, make
4551 // sure to push TypeLoc info for it.
4552 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4553 if (MPT && PointeeType != MPT->getPointeeType()) {
4554 assert(isa<AdjustedType>(MPT->getPointeeType()));
4555 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4556 }
4557
John McCall550e0c22009-10-21 00:40:46 +00004558 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4559 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004560 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004561
4562 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004563}
4564
Mike Stump11289f42009-09-09 15:08:12 +00004565template<typename Derived>
4566QualType
John McCall550e0c22009-10-21 00:40:46 +00004567TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004568 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004569 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004570 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004571 if (ElementType.isNull())
4572 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004573
John McCall550e0c22009-10-21 00:40:46 +00004574 QualType Result = TL.getType();
4575 if (getDerived().AlwaysRebuild() ||
4576 ElementType != T->getElementType()) {
4577 Result = getDerived().RebuildConstantArrayType(ElementType,
4578 T->getSizeModifier(),
4579 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004580 T->getIndexTypeCVRQualifiers(),
4581 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004582 if (Result.isNull())
4583 return QualType();
4584 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004585
4586 // We might have either a ConstantArrayType or a VariableArrayType now:
4587 // a ConstantArrayType is allowed to have an element type which is a
4588 // VariableArrayType if the type is dependent. Fortunately, all array
4589 // types have the same location layout.
4590 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004591 NewTL.setLBracketLoc(TL.getLBracketLoc());
4592 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004593
John McCall550e0c22009-10-21 00:40:46 +00004594 Expr *Size = TL.getSizeExpr();
4595 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004596 EnterExpressionEvaluationContext Unevaluated(
4597 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004598 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4599 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004600 }
4601 NewTL.setSizeExpr(Size);
4602
4603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004604}
Mike Stump11289f42009-09-09 15:08:12 +00004605
Douglas Gregord6ff3322009-08-04 16:50:30 +00004606template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004607QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004608 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004609 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004610 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004611 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004612 if (ElementType.isNull())
4613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004614
John McCall550e0c22009-10-21 00:40:46 +00004615 QualType Result = TL.getType();
4616 if (getDerived().AlwaysRebuild() ||
4617 ElementType != T->getElementType()) {
4618 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004619 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004620 T->getIndexTypeCVRQualifiers(),
4621 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004622 if (Result.isNull())
4623 return QualType();
4624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004625
John McCall550e0c22009-10-21 00:40:46 +00004626 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4627 NewTL.setLBracketLoc(TL.getLBracketLoc());
4628 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004629 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004630
4631 return Result;
4632}
4633
4634template<typename Derived>
4635QualType
4636TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004637 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004638 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4640 if (ElementType.isNull())
4641 return QualType();
4642
Tim Shenb34d0ef2017-02-14 23:46:37 +00004643 ExprResult SizeResult;
4644 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004645 EnterExpressionEvaluationContext Context(
4646 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004647 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4648 }
4649 if (SizeResult.isInvalid())
4650 return QualType();
4651 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004652 if (SizeResult.isInvalid())
4653 return QualType();
4654
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004655 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004656
4657 QualType Result = TL.getType();
4658 if (getDerived().AlwaysRebuild() ||
4659 ElementType != T->getElementType() ||
4660 Size != T->getSizeExpr()) {
4661 Result = getDerived().RebuildVariableArrayType(ElementType,
4662 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004663 Size,
John McCall550e0c22009-10-21 00:40:46 +00004664 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004665 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004666 if (Result.isNull())
4667 return QualType();
4668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004669
Serge Pavlov774c6d02014-02-06 03:49:11 +00004670 // We might have constant size array now, but fortunately it has the same
4671 // location layout.
4672 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004673 NewTL.setLBracketLoc(TL.getLBracketLoc());
4674 NewTL.setRBracketLoc(TL.getRBracketLoc());
4675 NewTL.setSizeExpr(Size);
4676
4677 return Result;
4678}
4679
4680template<typename Derived>
4681QualType
4682TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004683 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004684 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004685 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4686 if (ElementType.isNull())
4687 return QualType();
4688
Richard Smith764d2fe2011-12-20 02:08:33 +00004689 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004690 EnterExpressionEvaluationContext Unevaluated(
4691 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004692
John McCall33ddac02011-01-19 10:06:00 +00004693 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4694 Expr *origSize = TL.getSizeExpr();
4695 if (!origSize) origSize = T->getSizeExpr();
4696
4697 ExprResult sizeResult
4698 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004699 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004700 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004701 return QualType();
4702
John McCall33ddac02011-01-19 10:06:00 +00004703 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004704
4705 QualType Result = TL.getType();
4706 if (getDerived().AlwaysRebuild() ||
4707 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004708 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004709 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4710 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004711 size,
John McCall550e0c22009-10-21 00:40:46 +00004712 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004713 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004714 if (Result.isNull())
4715 return QualType();
4716 }
John McCall550e0c22009-10-21 00:40:46 +00004717
4718 // We might have any sort of array type now, but fortunately they
4719 // all have the same location layout.
4720 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4721 NewTL.setLBracketLoc(TL.getLBracketLoc());
4722 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004723 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004724
4725 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004726}
Mike Stump11289f42009-09-09 15:08:12 +00004727
4728template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004729QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004730 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004731 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004732 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004733
4734 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004735 QualType ElementType = getDerived().TransformType(T->getElementType());
4736 if (ElementType.isNull())
4737 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004738
Richard Smith764d2fe2011-12-20 02:08:33 +00004739 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004740 EnterExpressionEvaluationContext Unevaluated(
4741 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004742
John McCalldadc5752010-08-24 06:29:42 +00004743 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004744 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004745 if (Size.isInvalid())
4746 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004747
John McCall550e0c22009-10-21 00:40:46 +00004748 QualType Result = TL.getType();
4749 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004750 ElementType != T->getElementType() ||
4751 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004752 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004753 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004754 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004755 if (Result.isNull())
4756 return QualType();
4757 }
John McCall550e0c22009-10-21 00:40:46 +00004758
4759 // Result might be dependent or not.
4760 if (isa<DependentSizedExtVectorType>(Result)) {
4761 DependentSizedExtVectorTypeLoc NewTL
4762 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4763 NewTL.setNameLoc(TL.getNameLoc());
4764 } else {
4765 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4766 NewTL.setNameLoc(TL.getNameLoc());
4767 }
4768
4769 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
4772template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004773QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004774 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004775 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004776 QualType ElementType = getDerived().TransformType(T->getElementType());
4777 if (ElementType.isNull())
4778 return QualType();
4779
John McCall550e0c22009-10-21 00:40:46 +00004780 QualType Result = TL.getType();
4781 if (getDerived().AlwaysRebuild() ||
4782 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004783 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004784 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004785 if (Result.isNull())
4786 return QualType();
4787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004788
John McCall550e0c22009-10-21 00:40:46 +00004789 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4790 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004791
John McCall550e0c22009-10-21 00:40:46 +00004792 return Result;
4793}
4794
4795template<typename Derived>
4796QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004797 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004798 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004799 QualType ElementType = getDerived().TransformType(T->getElementType());
4800 if (ElementType.isNull())
4801 return QualType();
4802
4803 QualType Result = TL.getType();
4804 if (getDerived().AlwaysRebuild() ||
4805 ElementType != T->getElementType()) {
4806 Result = getDerived().RebuildExtVectorType(ElementType,
4807 T->getNumElements(),
4808 /*FIXME*/ SourceLocation());
4809 if (Result.isNull())
4810 return QualType();
4811 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004812
John McCall550e0c22009-10-21 00:40:46 +00004813 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4814 NewTL.setNameLoc(TL.getNameLoc());
4815
4816 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004817}
Mike Stump11289f42009-09-09 15:08:12 +00004818
David Blaikie05785d12013-02-20 22:23:23 +00004819template <typename Derived>
4820ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4821 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4822 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004823 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004824 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004825
Douglas Gregor715e4612011-01-14 22:40:04 +00004826 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004827 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004828 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004829 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004830 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004831
Douglas Gregor715e4612011-01-14 22:40:04 +00004832 TypeLocBuilder TLB;
4833 TypeLoc NewTL = OldDI->getTypeLoc();
4834 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004835
4836 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004837 OldExpansionTL.getPatternLoc());
4838 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004839 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004840
4841 Result = RebuildPackExpansionType(Result,
4842 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004843 OldExpansionTL.getEllipsisLoc(),
4844 NumExpansions);
4845 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004846 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004847
Douglas Gregor715e4612011-01-14 22:40:04 +00004848 PackExpansionTypeLoc NewExpansionTL
4849 = TLB.push<PackExpansionTypeLoc>(Result);
4850 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4851 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4852 } else
4853 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004854 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004855 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004856
John McCall8fb0d9d2011-05-01 22:35:37 +00004857 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004858 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004859
4860 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4861 OldParm->getDeclContext(),
4862 OldParm->getInnerLocStart(),
4863 OldParm->getLocation(),
4864 OldParm->getIdentifier(),
4865 NewDI->getType(),
4866 NewDI,
4867 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004868 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004869 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4870 OldParm->getFunctionScopeIndex() + indexAdjustment);
4871 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004872}
4873
David Majnemer59f77922016-06-24 04:05:48 +00004874template <typename Derived>
4875bool TreeTransform<Derived>::TransformFunctionTypeParams(
4876 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4877 const QualType *ParamTypes,
4878 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4879 SmallVectorImpl<QualType> &OutParamTypes,
4880 SmallVectorImpl<ParmVarDecl *> *PVars,
4881 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004882 int indexAdjustment = 0;
4883
David Majnemer59f77922016-06-24 04:05:48 +00004884 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004885 for (unsigned i = 0; i != NumParams; ++i) {
4886 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004887 assert(OldParm->getFunctionScopeIndex() == i);
4888
David Blaikie05785d12013-02-20 22:23:23 +00004889 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004890 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004891 if (OldParm->isParameterPack()) {
4892 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004893 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004894
Douglas Gregor5499af42011-01-05 23:12:31 +00004895 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004896 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004897 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004898 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4899 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004900 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4901
Douglas Gregor5499af42011-01-05 23:12:31 +00004902 // Determine whether we should expand the parameter packs.
4903 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004904 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004905 Optional<unsigned> OrigNumExpansions =
4906 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004907 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004908 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4909 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004910 Unexpanded,
4911 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004912 RetainExpansion,
4913 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004914 return true;
4915 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004916
Douglas Gregor5499af42011-01-05 23:12:31 +00004917 if (ShouldExpand) {
4918 // Expand the function parameter pack into multiple, separate
4919 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004920 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004921 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004922 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004923 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004924 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004925 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004926 OrigNumExpansions,
4927 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004928 if (!NewParm)
4929 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004930
John McCallc8e321d2016-03-01 02:09:25 +00004931 if (ParamInfos)
4932 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004933 OutParamTypes.push_back(NewParm->getType());
4934 if (PVars)
4935 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004936 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004937
4938 // If we're supposed to retain a pack expansion, do so by temporarily
4939 // forgetting the partially-substituted parameter pack.
4940 if (RetainExpansion) {
4941 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004942 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004943 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004944 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004945 OrigNumExpansions,
4946 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004947 if (!NewParm)
4948 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004949
John McCallc8e321d2016-03-01 02:09:25 +00004950 if (ParamInfos)
4951 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004952 OutParamTypes.push_back(NewParm->getType());
4953 if (PVars)
4954 PVars->push_back(NewParm);
4955 }
4956
John McCall8fb0d9d2011-05-01 22:35:37 +00004957 // The next parameter should have the same adjustment as the
4958 // last thing we pushed, but we post-incremented indexAdjustment
4959 // on every push. Also, if we push nothing, the adjustment should
4960 // go down by one.
4961 indexAdjustment--;
4962
Douglas Gregor5499af42011-01-05 23:12:31 +00004963 // We're done with the pack expansion.
4964 continue;
4965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004966
4967 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004968 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4970 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004971 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004972 NumExpansions,
4973 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004974 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004975 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004976 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004977 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004978
John McCall58f10c32010-03-11 09:03:00 +00004979 if (!NewParm)
4980 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004981
John McCallc8e321d2016-03-01 02:09:25 +00004982 if (ParamInfos)
4983 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004984 OutParamTypes.push_back(NewParm->getType());
4985 if (PVars)
4986 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004987 continue;
4988 }
John McCall58f10c32010-03-11 09:03:00 +00004989
4990 // Deal with the possibility that we don't have a parameter
4991 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004992 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004993 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004994 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004995 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004996 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004997 = dyn_cast<PackExpansionType>(OldType)) {
4998 // We have a function parameter pack that may need to be expanded.
4999 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005000 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005001 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005002
Douglas Gregor5499af42011-01-05 23:12:31 +00005003 // Determine whether we should expand the parameter packs.
5004 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005005 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005006 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005007 Unexpanded,
5008 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005009 RetainExpansion,
5010 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005011 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005012 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005013
Douglas Gregor5499af42011-01-05 23:12:31 +00005014 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005015 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005016 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005017 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005018 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5019 QualType NewType = getDerived().TransformType(Pattern);
5020 if (NewType.isNull())
5021 return true;
John McCall58f10c32010-03-11 09:03:00 +00005022
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005023 if (NewType->containsUnexpandedParameterPack()) {
5024 NewType =
5025 getSema().getASTContext().getPackExpansionType(NewType, None);
5026
5027 if (NewType.isNull())
5028 return true;
5029 }
5030
John McCallc8e321d2016-03-01 02:09:25 +00005031 if (ParamInfos)
5032 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005033 OutParamTypes.push_back(NewType);
5034 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005035 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005037
Douglas Gregor5499af42011-01-05 23:12:31 +00005038 // We're done with the pack expansion.
5039 continue;
5040 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005041
Douglas Gregor48d24112011-01-10 20:53:55 +00005042 // If we're supposed to retain a pack expansion, do so by temporarily
5043 // forgetting the partially-substituted parameter pack.
5044 if (RetainExpansion) {
5045 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5046 QualType NewType = getDerived().TransformType(Pattern);
5047 if (NewType.isNull())
5048 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005049
John McCallc8e321d2016-03-01 02:09:25 +00005050 if (ParamInfos)
5051 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005052 OutParamTypes.push_back(NewType);
5053 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005054 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005055 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005056
Chad Rosier1dcde962012-08-08 18:46:20 +00005057 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005058 // expansion.
5059 OldType = Expansion->getPattern();
5060 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005061 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5062 NewType = getDerived().TransformType(OldType);
5063 } else {
5064 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005066
Douglas Gregor5499af42011-01-05 23:12:31 +00005067 if (NewType.isNull())
5068 return true;
5069
5070 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005071 NewType = getSema().Context.getPackExpansionType(NewType,
5072 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005073
John McCallc8e321d2016-03-01 02:09:25 +00005074 if (ParamInfos)
5075 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005076 OutParamTypes.push_back(NewType);
5077 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005078 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005079 }
5080
John McCall8fb0d9d2011-05-01 22:35:37 +00005081#ifndef NDEBUG
5082 if (PVars) {
5083 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5084 if (ParmVarDecl *parm = (*PVars)[i])
5085 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005086 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005087#endif
5088
5089 return false;
5090}
John McCall58f10c32010-03-11 09:03:00 +00005091
5092template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005093QualType
John McCall550e0c22009-10-21 00:40:46 +00005094TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005095 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005096 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005097 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005098 return getDerived().TransformFunctionProtoType(
5099 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005100 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5101 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5102 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005103 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005104}
5105
Richard Smith2e321552014-11-12 02:00:47 +00005106template<typename Derived> template<typename Fn>
5107QualType TreeTransform<Derived>::TransformFunctionProtoType(
5108 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5109 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005110
Douglas Gregor4afc2362010-08-31 00:26:14 +00005111 // Transform the parameters and return type.
5112 //
Richard Smithf623c962012-04-17 00:58:00 +00005113 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005114 // When the function has a trailing return type, we instantiate the
5115 // parameters before the return type, since the return type can then refer
5116 // to the parameters themselves (via decltype, sizeof, etc.).
5117 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005118 SmallVector<QualType, 4> ParamTypes;
5119 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005120 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005121 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005122
Douglas Gregor7fb25412010-10-01 18:44:50 +00005123 QualType ResultType;
5124
Richard Smith1226c602012-08-14 22:51:13 +00005125 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005126 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005127 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005128 TL.getTypePtr()->param_type_begin(),
5129 T->getExtParameterInfosOrNull(),
5130 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005131 return QualType();
5132
Douglas Gregor3024f072012-04-16 07:05:22 +00005133 {
5134 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005135 // If a declaration declares a member function or member function
5136 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005137 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005138 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005139 // declarator.
5140 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005141
Alp Toker42a16a62014-01-25 23:51:36 +00005142 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005143 if (ResultType.isNull())
5144 return QualType();
5145 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005146 }
5147 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005148 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005149 if (ResultType.isNull())
5150 return QualType();
5151
Alp Toker9cacbab2014-01-20 20:26:09 +00005152 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005153 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005154 TL.getTypePtr()->param_type_begin(),
5155 T->getExtParameterInfosOrNull(),
5156 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005157 return QualType();
5158 }
5159
Richard Smith2e321552014-11-12 02:00:47 +00005160 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5161
5162 bool EPIChanged = false;
5163 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5164 return QualType();
5165
John McCallc8e321d2016-03-01 02:09:25 +00005166 // Handle extended parameter information.
5167 if (auto NewExtParamInfos =
5168 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5169 if (!EPI.ExtParameterInfos ||
5170 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5171 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5172 EPIChanged = true;
5173 }
5174 EPI.ExtParameterInfos = NewExtParamInfos;
5175 } else if (EPI.ExtParameterInfos) {
5176 EPIChanged = true;
5177 EPI.ExtParameterInfos = nullptr;
5178 }
Richard Smithf623c962012-04-17 00:58:00 +00005179
John McCall550e0c22009-10-21 00:40:46 +00005180 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005181 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005182 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005183 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005184 if (Result.isNull())
5185 return QualType();
5186 }
Mike Stump11289f42009-09-09 15:08:12 +00005187
John McCall550e0c22009-10-21 00:40:46 +00005188 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005189 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005190 NewTL.setLParenLoc(TL.getLParenLoc());
5191 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005192 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005193 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005194 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5195 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005196
5197 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005198}
Mike Stump11289f42009-09-09 15:08:12 +00005199
Douglas Gregord6ff3322009-08-04 16:50:30 +00005200template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005201bool TreeTransform<Derived>::TransformExceptionSpec(
5202 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5203 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5204 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5205
5206 // Instantiate a dynamic noexcept expression, if any.
5207 if (ESI.Type == EST_ComputedNoexcept) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005208 EnterExpressionEvaluationContext Unevaluated(
5209 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005210 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5211 if (NoexceptExpr.isInvalid())
5212 return true;
5213
Richard Smith03a4aa32016-06-23 19:02:52 +00005214 // FIXME: This is bogus, a noexcept expression is not a condition.
5215 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005216 if (NoexceptExpr.isInvalid())
5217 return true;
5218
5219 if (!NoexceptExpr.get()->isValueDependent()) {
5220 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5221 NoexceptExpr.get(), nullptr,
5222 diag::err_noexcept_needs_constant_expression,
5223 /*AllowFold*/false);
5224 if (NoexceptExpr.isInvalid())
5225 return true;
5226 }
5227
5228 if (ESI.NoexceptExpr != NoexceptExpr.get())
5229 Changed = true;
5230 ESI.NoexceptExpr = NoexceptExpr.get();
5231 }
5232
5233 if (ESI.Type != EST_Dynamic)
5234 return false;
5235
5236 // Instantiate a dynamic exception specification's type.
5237 for (QualType T : ESI.Exceptions) {
5238 if (const PackExpansionType *PackExpansion =
5239 T->getAs<PackExpansionType>()) {
5240 Changed = true;
5241
5242 // We have a pack expansion. Instantiate it.
5243 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5244 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5245 Unexpanded);
5246 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5247
5248 // Determine whether the set of unexpanded parameter packs can and
5249 // should
5250 // be expanded.
5251 bool Expand = false;
5252 bool RetainExpansion = false;
5253 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5254 // FIXME: Track the location of the ellipsis (and track source location
5255 // information for the types in the exception specification in general).
5256 if (getDerived().TryExpandParameterPacks(
5257 Loc, SourceRange(), Unexpanded, Expand,
5258 RetainExpansion, NumExpansions))
5259 return true;
5260
5261 if (!Expand) {
5262 // We can't expand this pack expansion into separate arguments yet;
5263 // just substitute into the pattern and create a new pack expansion
5264 // type.
5265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5266 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5267 if (U.isNull())
5268 return true;
5269
5270 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5271 Exceptions.push_back(U);
5272 continue;
5273 }
5274
5275 // Substitute into the pack expansion pattern for each slice of the
5276 // pack.
5277 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5279
5280 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5281 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5282 return true;
5283
5284 Exceptions.push_back(U);
5285 }
5286 } else {
5287 QualType U = getDerived().TransformType(T);
5288 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5289 return true;
5290 if (T != U)
5291 Changed = true;
5292
5293 Exceptions.push_back(U);
5294 }
5295 }
5296
5297 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005298 if (ESI.Exceptions.empty())
5299 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005300 return false;
5301}
5302
5303template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005304QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005305 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005306 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005307 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005308 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005309 if (ResultType.isNull())
5310 return QualType();
5311
5312 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005313 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005314 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5315
5316 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005317 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005318 NewTL.setLParenLoc(TL.getLParenLoc());
5319 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005320 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005321
5322 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005323}
Mike Stump11289f42009-09-09 15:08:12 +00005324
John McCallb96ec562009-12-04 22:46:56 +00005325template<typename Derived> QualType
5326TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005327 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005328 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005329 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005330 if (!D)
5331 return QualType();
5332
5333 QualType Result = TL.getType();
5334 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005335 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005336 if (Result.isNull())
5337 return QualType();
5338 }
5339
5340 // We might get an arbitrary type spec type back. We should at
5341 // least always get a type spec type, though.
5342 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5343 NewTL.setNameLoc(TL.getNameLoc());
5344
5345 return Result;
5346}
5347
Douglas Gregord6ff3322009-08-04 16:50:30 +00005348template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005349QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005350 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005351 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005352 TypedefNameDecl *Typedef
5353 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5354 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005355 if (!Typedef)
5356 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005357
John McCall550e0c22009-10-21 00:40:46 +00005358 QualType Result = TL.getType();
5359 if (getDerived().AlwaysRebuild() ||
5360 Typedef != T->getDecl()) {
5361 Result = getDerived().RebuildTypedefType(Typedef);
5362 if (Result.isNull())
5363 return QualType();
5364 }
Mike Stump11289f42009-09-09 15:08:12 +00005365
John McCall550e0c22009-10-21 00:40:46 +00005366 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5367 NewTL.setNameLoc(TL.getNameLoc());
5368
5369 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005370}
Mike Stump11289f42009-09-09 15:08:12 +00005371
Douglas Gregord6ff3322009-08-04 16:50:30 +00005372template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005373QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005374 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005375 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005376 EnterExpressionEvaluationContext Unevaluated(
5377 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5378 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005379
John McCalldadc5752010-08-24 06:29:42 +00005380 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005381 if (E.isInvalid())
5382 return QualType();
5383
Eli Friedmane4f22df2012-02-29 04:03:55 +00005384 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5385 if (E.isInvalid())
5386 return QualType();
5387
John McCall550e0c22009-10-21 00:40:46 +00005388 QualType Result = TL.getType();
5389 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005390 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005391 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005392 if (Result.isNull())
5393 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005394 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005395 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005396
John McCall550e0c22009-10-21 00:40:46 +00005397 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005398 NewTL.setTypeofLoc(TL.getTypeofLoc());
5399 NewTL.setLParenLoc(TL.getLParenLoc());
5400 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005401
5402 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005403}
Mike Stump11289f42009-09-09 15:08:12 +00005404
5405template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005406QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005407 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005408 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5409 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5410 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005411 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005412
John McCall550e0c22009-10-21 00:40:46 +00005413 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005414 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5415 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005416 if (Result.isNull())
5417 return QualType();
5418 }
Mike Stump11289f42009-09-09 15:08:12 +00005419
John McCall550e0c22009-10-21 00:40:46 +00005420 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005421 NewTL.setTypeofLoc(TL.getTypeofLoc());
5422 NewTL.setLParenLoc(TL.getLParenLoc());
5423 NewTL.setRParenLoc(TL.getRParenLoc());
5424 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005425
5426 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
5429template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005430QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005431 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005432 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005433
Douglas Gregore922c772009-08-04 22:27:00 +00005434 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005435 EnterExpressionEvaluationContext Unevaluated(
5436 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5437 /*IsDecltype=*/true);
Mike Stump11289f42009-09-09 15:08:12 +00005438
John McCalldadc5752010-08-24 06:29:42 +00005439 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005440 if (E.isInvalid())
5441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005442
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005443 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005444 if (E.isInvalid())
5445 return QualType();
5446
John McCall550e0c22009-10-21 00:40:46 +00005447 QualType Result = TL.getType();
5448 if (getDerived().AlwaysRebuild() ||
5449 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005450 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005451 if (Result.isNull())
5452 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005453 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005454 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005455
John McCall550e0c22009-10-21 00:40:46 +00005456 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5457 NewTL.setNameLoc(TL.getNameLoc());
5458
5459 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005460}
5461
5462template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005463QualType TreeTransform<Derived>::TransformUnaryTransformType(
5464 TypeLocBuilder &TLB,
5465 UnaryTransformTypeLoc TL) {
5466 QualType Result = TL.getType();
5467 if (Result->isDependentType()) {
5468 const UnaryTransformType *T = TL.getTypePtr();
5469 QualType NewBase =
5470 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5471 Result = getDerived().RebuildUnaryTransformType(NewBase,
5472 T->getUTTKind(),
5473 TL.getKWLoc());
5474 if (Result.isNull())
5475 return QualType();
5476 }
5477
5478 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5479 NewTL.setKWLoc(TL.getKWLoc());
5480 NewTL.setParensRange(TL.getParensRange());
5481 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5482 return Result;
5483}
5484
5485template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005486QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5487 AutoTypeLoc TL) {
5488 const AutoType *T = TL.getTypePtr();
5489 QualType OldDeduced = T->getDeducedType();
5490 QualType NewDeduced;
5491 if (!OldDeduced.isNull()) {
5492 NewDeduced = getDerived().TransformType(OldDeduced);
5493 if (NewDeduced.isNull())
5494 return QualType();
5495 }
5496
5497 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005498 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5499 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005500 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005501 if (Result.isNull())
5502 return QualType();
5503 }
5504
5505 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5506 NewTL.setNameLoc(TL.getNameLoc());
5507
5508 return Result;
5509}
5510
5511template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005512QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5513 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5514 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5515
5516 CXXScopeSpec SS;
5517 TemplateName TemplateName = getDerived().TransformTemplateName(
5518 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5519 if (TemplateName.isNull())
5520 return QualType();
5521
5522 QualType OldDeduced = T->getDeducedType();
5523 QualType NewDeduced;
5524 if (!OldDeduced.isNull()) {
5525 NewDeduced = getDerived().TransformType(OldDeduced);
5526 if (NewDeduced.isNull())
5527 return QualType();
5528 }
5529
5530 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5531 TemplateName, NewDeduced);
5532 if (Result.isNull())
5533 return QualType();
5534
5535 DeducedTemplateSpecializationTypeLoc NewTL =
5536 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5537 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5538
5539 return Result;
5540}
5541
5542template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005543QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005544 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005545 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005546 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005547 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5548 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005549 if (!Record)
5550 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005551
John McCall550e0c22009-10-21 00:40:46 +00005552 QualType Result = TL.getType();
5553 if (getDerived().AlwaysRebuild() ||
5554 Record != T->getDecl()) {
5555 Result = getDerived().RebuildRecordType(Record);
5556 if (Result.isNull())
5557 return QualType();
5558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
John McCall550e0c22009-10-21 00:40:46 +00005560 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5561 NewTL.setNameLoc(TL.getNameLoc());
5562
5563 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005564}
Mike Stump11289f42009-09-09 15:08:12 +00005565
5566template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005567QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005568 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005569 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005570 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005571 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5572 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573 if (!Enum)
5574 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005575
John McCall550e0c22009-10-21 00:40:46 +00005576 QualType Result = TL.getType();
5577 if (getDerived().AlwaysRebuild() ||
5578 Enum != T->getDecl()) {
5579 Result = getDerived().RebuildEnumType(Enum);
5580 if (Result.isNull())
5581 return QualType();
5582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
John McCall550e0c22009-10-21 00:40:46 +00005584 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5585 NewTL.setNameLoc(TL.getNameLoc());
5586
5587 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005588}
John McCallfcc33b02009-09-05 00:15:47 +00005589
John McCalle78aac42010-03-10 03:28:59 +00005590template<typename Derived>
5591QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5592 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005593 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005594 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5595 TL.getTypePtr()->getDecl());
5596 if (!D) return QualType();
5597
5598 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5599 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5600 return T;
5601}
5602
Douglas Gregord6ff3322009-08-04 16:50:30 +00005603template<typename Derived>
5604QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005605 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005606 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005607 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005608}
5609
Mike Stump11289f42009-09-09 15:08:12 +00005610template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005611QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005612 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005613 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005614 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005615
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005616 // Substitute into the replacement type, which itself might involve something
5617 // that needs to be transformed. This only tends to occur with default
5618 // template arguments of template template parameters.
5619 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5620 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5621 if (Replacement.isNull())
5622 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005623
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005624 // Always canonicalize the replacement type.
5625 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5626 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005627 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005628 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005629
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005630 // Propagate type-source information.
5631 SubstTemplateTypeParmTypeLoc NewTL
5632 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5633 NewTL.setNameLoc(TL.getNameLoc());
5634 return Result;
5635
John McCallcebee162009-10-18 09:09:24 +00005636}
5637
5638template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005639QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5640 TypeLocBuilder &TLB,
5641 SubstTemplateTypeParmPackTypeLoc TL) {
5642 return TransformTypeSpecType(TLB, TL);
5643}
5644
5645template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005646QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005647 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005648 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005649 const TemplateSpecializationType *T = TL.getTypePtr();
5650
Douglas Gregordf846d12011-03-02 18:46:51 +00005651 // The nested-name-specifier never matters in a TemplateSpecializationType,
5652 // because we can't have a dependent nested-name-specifier anyway.
5653 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005654 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005655 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5656 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005657 if (Template.isNull())
5658 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005659
John McCall31f82722010-11-12 08:19:04 +00005660 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5661}
5662
Eli Friedman0dfb8892011-10-06 23:00:33 +00005663template<typename Derived>
5664QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5665 AtomicTypeLoc TL) {
5666 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5667 if (ValueType.isNull())
5668 return QualType();
5669
5670 QualType Result = TL.getType();
5671 if (getDerived().AlwaysRebuild() ||
5672 ValueType != TL.getValueLoc().getType()) {
5673 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5674 if (Result.isNull())
5675 return QualType();
5676 }
5677
5678 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5679 NewTL.setKWLoc(TL.getKWLoc());
5680 NewTL.setLParenLoc(TL.getLParenLoc());
5681 NewTL.setRParenLoc(TL.getRParenLoc());
5682
5683 return Result;
5684}
5685
Xiuli Pan9c14e282016-01-09 12:53:17 +00005686template <typename Derived>
5687QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5688 PipeTypeLoc TL) {
5689 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5690 if (ValueType.isNull())
5691 return QualType();
5692
5693 QualType Result = TL.getType();
5694 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005695 const PipeType *PT = Result->getAs<PipeType>();
5696 bool isReadPipe = PT->isReadOnly();
5697 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005698 if (Result.isNull())
5699 return QualType();
5700 }
5701
5702 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5703 NewTL.setKWLoc(TL.getKWLoc());
5704
5705 return Result;
5706}
5707
Chad Rosier1dcde962012-08-08 18:46:20 +00005708 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005709 /// container that provides a \c getArgLoc() member function.
5710 ///
5711 /// This iterator is intended to be used with the iterator form of
5712 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5713 template<typename ArgLocContainer>
5714 class TemplateArgumentLocContainerIterator {
5715 ArgLocContainer *Container;
5716 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005717
Douglas Gregorfe921a72010-12-20 23:36:19 +00005718 public:
5719 typedef TemplateArgumentLoc value_type;
5720 typedef TemplateArgumentLoc reference;
5721 typedef int difference_type;
5722 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005723
Douglas Gregorfe921a72010-12-20 23:36:19 +00005724 class pointer {
5725 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005726
Douglas Gregorfe921a72010-12-20 23:36:19 +00005727 public:
5728 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005729
Douglas Gregorfe921a72010-12-20 23:36:19 +00005730 const TemplateArgumentLoc *operator->() const {
5731 return &Arg;
5732 }
5733 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005734
5735
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005736 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005737
Douglas Gregorfe921a72010-12-20 23:36:19 +00005738 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5739 unsigned Index)
5740 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005741
Douglas Gregorfe921a72010-12-20 23:36:19 +00005742 TemplateArgumentLocContainerIterator &operator++() {
5743 ++Index;
5744 return *this;
5745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005746
Douglas Gregorfe921a72010-12-20 23:36:19 +00005747 TemplateArgumentLocContainerIterator operator++(int) {
5748 TemplateArgumentLocContainerIterator Old(*this);
5749 ++(*this);
5750 return Old;
5751 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005752
Douglas Gregorfe921a72010-12-20 23:36:19 +00005753 TemplateArgumentLoc operator*() const {
5754 return Container->getArgLoc(Index);
5755 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005756
Douglas Gregorfe921a72010-12-20 23:36:19 +00005757 pointer operator->() const {
5758 return pointer(Container->getArgLoc(Index));
5759 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005760
Douglas Gregorfe921a72010-12-20 23:36:19 +00005761 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005762 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005763 return X.Container == Y.Container && X.Index == Y.Index;
5764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005765
Douglas Gregorfe921a72010-12-20 23:36:19 +00005766 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005767 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005768 return !(X == Y);
5769 }
5770 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005771
5772
John McCall31f82722010-11-12 08:19:04 +00005773template <typename Derived>
5774QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5775 TypeLocBuilder &TLB,
5776 TemplateSpecializationTypeLoc TL,
5777 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005778 TemplateArgumentListInfo NewTemplateArgs;
5779 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5780 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005781 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5782 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005783 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005784 ArgIterator(TL, TL.getNumArgs()),
5785 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005786 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005787
John McCall0ad16662009-10-29 08:12:44 +00005788 // FIXME: maybe don't rebuild if all the template arguments are the same.
5789
5790 QualType Result =
5791 getDerived().RebuildTemplateSpecializationType(Template,
5792 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005793 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005794
5795 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005796 // Specializations of template template parameters are represented as
5797 // TemplateSpecializationTypes, and substitution of type alias templates
5798 // within a dependent context can transform them into
5799 // DependentTemplateSpecializationTypes.
5800 if (isa<DependentTemplateSpecializationType>(Result)) {
5801 DependentTemplateSpecializationTypeLoc NewTL
5802 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005803 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005804 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005805 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005806 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005807 NewTL.setLAngleLoc(TL.getLAngleLoc());
5808 NewTL.setRAngleLoc(TL.getRAngleLoc());
5809 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5810 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5811 return Result;
5812 }
5813
John McCall0ad16662009-10-29 08:12:44 +00005814 TemplateSpecializationTypeLoc NewTL
5815 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005816 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005817 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5818 NewTL.setLAngleLoc(TL.getLAngleLoc());
5819 NewTL.setRAngleLoc(TL.getRAngleLoc());
5820 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5821 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005822 }
Mike Stump11289f42009-09-09 15:08:12 +00005823
John McCall0ad16662009-10-29 08:12:44 +00005824 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005825}
Mike Stump11289f42009-09-09 15:08:12 +00005826
Douglas Gregor5a064722011-02-28 17:23:35 +00005827template <typename Derived>
5828QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5829 TypeLocBuilder &TLB,
5830 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005831 TemplateName Template,
5832 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005833 TemplateArgumentListInfo NewTemplateArgs;
5834 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5835 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5836 typedef TemplateArgumentLocContainerIterator<
5837 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005838 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005839 ArgIterator(TL, TL.getNumArgs()),
5840 NewTemplateArgs))
5841 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005842
Douglas Gregor5a064722011-02-28 17:23:35 +00005843 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005844
Douglas Gregor5a064722011-02-28 17:23:35 +00005845 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5846 QualType Result
5847 = getSema().Context.getDependentTemplateSpecializationType(
5848 TL.getTypePtr()->getKeyword(),
5849 DTN->getQualifier(),
5850 DTN->getIdentifier(),
5851 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005852
Douglas Gregor5a064722011-02-28 17:23:35 +00005853 DependentTemplateSpecializationTypeLoc NewTL
5854 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005855 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005856 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
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 return Result;
5864 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005865
5866 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005867 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005868 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005869 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005870
Douglas Gregor5a064722011-02-28 17:23:35 +00005871 if (!Result.isNull()) {
5872 /// FIXME: Wrap this in an elaborated-type-specifier?
5873 TemplateSpecializationTypeLoc NewTL
5874 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005875 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005876 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005877 NewTL.setLAngleLoc(TL.getLAngleLoc());
5878 NewTL.setRAngleLoc(TL.getRAngleLoc());
5879 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5880 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5881 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005882
Douglas Gregor5a064722011-02-28 17:23:35 +00005883 return Result;
5884}
5885
Mike Stump11289f42009-09-09 15:08:12 +00005886template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005887QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005888TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005889 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005890 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005891
Douglas Gregor844cb502011-03-01 18:12:44 +00005892 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005893 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005894 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005895 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005896 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5897 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005898 return QualType();
5899 }
Mike Stump11289f42009-09-09 15:08:12 +00005900
John McCall31f82722010-11-12 08:19:04 +00005901 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5902 if (NamedT.isNull())
5903 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005904
Richard Smith3f1b5d02011-05-05 21:57:07 +00005905 // C++0x [dcl.type.elab]p2:
5906 // If the identifier resolves to a typedef-name or the simple-template-id
5907 // resolves to an alias template specialization, the
5908 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005909 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5910 if (const TemplateSpecializationType *TST =
5911 NamedT->getAs<TemplateSpecializationType>()) {
5912 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005913 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5914 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005915 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005916 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005917 << TAT << Sema::NTK_TypeAliasTemplate
5918 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005919 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5920 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005921 }
5922 }
5923
John McCall550e0c22009-10-21 00:40:46 +00005924 QualType Result = TL.getType();
5925 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005926 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005927 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005928 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005929 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005930 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005931 if (Result.isNull())
5932 return QualType();
5933 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005934
Abramo Bagnara6150c882010-05-11 21:36:43 +00005935 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005936 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005937 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005938 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005939}
Mike Stump11289f42009-09-09 15:08:12 +00005940
5941template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005942QualType TreeTransform<Derived>::TransformAttributedType(
5943 TypeLocBuilder &TLB,
5944 AttributedTypeLoc TL) {
5945 const AttributedType *oldType = TL.getTypePtr();
5946 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5947 if (modifiedType.isNull())
5948 return QualType();
5949
5950 QualType result = TL.getType();
5951
5952 // FIXME: dependent operand expressions?
5953 if (getDerived().AlwaysRebuild() ||
5954 modifiedType != oldType->getModifiedType()) {
5955 // TODO: this is really lame; we should really be rebuilding the
5956 // equivalent type from first principles.
5957 QualType equivalentType
5958 = getDerived().TransformType(oldType->getEquivalentType());
5959 if (equivalentType.isNull())
5960 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005961
5962 // Check whether we can add nullability; it is only represented as
5963 // type sugar, and therefore cannot be diagnosed in any other way.
5964 if (auto nullability = oldType->getImmediateNullability()) {
5965 if (!modifiedType->canHaveNullability()) {
5966 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005967 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005968 return QualType();
5969 }
5970 }
5971
John McCall81904512011-01-06 01:58:22 +00005972 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5973 modifiedType,
5974 equivalentType);
5975 }
5976
5977 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5978 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5979 if (TL.hasAttrOperand())
5980 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5981 if (TL.hasAttrExprOperand())
5982 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5983 else if (TL.hasAttrEnumOperand())
5984 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5985
5986 return result;
5987}
5988
5989template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005990QualType
5991TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5992 ParenTypeLoc TL) {
5993 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5994 if (Inner.isNull())
5995 return QualType();
5996
5997 QualType Result = TL.getType();
5998 if (getDerived().AlwaysRebuild() ||
5999 Inner != TL.getInnerLoc().getType()) {
6000 Result = getDerived().RebuildParenType(Inner);
6001 if (Result.isNull())
6002 return QualType();
6003 }
6004
6005 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6006 NewTL.setLParenLoc(TL.getLParenLoc());
6007 NewTL.setRParenLoc(TL.getRParenLoc());
6008 return Result;
6009}
6010
6011template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006012QualType TreeTransform<Derived>::TransformDependentNameType(
6013 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6014 return TransformDependentNameType(TLB, TL, false);
6015}
6016
6017template<typename Derived>
6018QualType TreeTransform<Derived>::TransformDependentNameType(
6019 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006020 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006021
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006022 NestedNameSpecifierLoc QualifierLoc
6023 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6024 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006025 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006026
John McCallc392f372010-06-11 00:33:02 +00006027 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006028 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006029 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006030 QualifierLoc,
6031 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006032 TL.getNameLoc(),
6033 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006034 if (Result.isNull())
6035 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006036
Abramo Bagnarad7548482010-05-19 21:37:53 +00006037 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6038 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006039 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6040
Abramo Bagnarad7548482010-05-19 21:37:53 +00006041 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006042 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006043 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006044 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006045 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006046 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006047 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006048 NewTL.setNameLoc(TL.getNameLoc());
6049 }
John McCall550e0c22009-10-21 00:40:46 +00006050 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006051}
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregord6ff3322009-08-04 16:50:30 +00006053template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006054QualType TreeTransform<Derived>::
6055 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006056 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006057 NestedNameSpecifierLoc QualifierLoc;
6058 if (TL.getQualifierLoc()) {
6059 QualifierLoc
6060 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6061 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006062 return QualType();
6063 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006064
John McCall31f82722010-11-12 08:19:04 +00006065 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006066 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006067}
6068
6069template<typename Derived>
6070QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006071TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6072 DependentTemplateSpecializationTypeLoc TL,
6073 NestedNameSpecifierLoc QualifierLoc) {
6074 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006075
Douglas Gregora7a795b2011-03-01 20:11:18 +00006076 TemplateArgumentListInfo NewTemplateArgs;
6077 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6078 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006079
Douglas Gregora7a795b2011-03-01 20:11:18 +00006080 typedef TemplateArgumentLocContainerIterator<
6081 DependentTemplateSpecializationTypeLoc> ArgIterator;
6082 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6083 ArgIterator(TL, TL.getNumArgs()),
6084 NewTemplateArgs))
6085 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006086
Richard Smithfd3dae02017-01-20 00:20:39 +00006087 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6088 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6089 TL.getTemplateNameLoc(), NewTemplateArgs,
6090 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006091 if (Result.isNull())
6092 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006093
Douglas Gregora7a795b2011-03-01 20:11:18 +00006094 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6095 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006096
Douglas Gregora7a795b2011-03-01 20:11:18 +00006097 // Copy information relevant to the template specialization.
6098 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006099 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006100 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006101 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006102 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6103 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006104 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006105 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006106
Douglas Gregora7a795b2011-03-01 20:11:18 +00006107 // Copy information relevant to the elaborated type.
6108 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006109 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006110 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006111 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6112 DependentTemplateSpecializationTypeLoc SpecTL
6113 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006114 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006115 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006116 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006117 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006118 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6119 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006120 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006121 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006122 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006123 TemplateSpecializationTypeLoc SpecTL
6124 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006125 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006126 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006127 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6128 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006129 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006130 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006131 }
6132 return Result;
6133}
6134
6135template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006136QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6137 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006138 QualType Pattern
6139 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006140 if (Pattern.isNull())
6141 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006142
6143 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006144 if (getDerived().AlwaysRebuild() ||
6145 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006146 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006147 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006148 TL.getEllipsisLoc(),
6149 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006150 if (Result.isNull())
6151 return QualType();
6152 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006153
Douglas Gregor822d0302011-01-12 17:07:58 +00006154 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6155 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6156 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006157}
6158
6159template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006160QualType
6161TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006162 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006163 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006164 TLB.pushFullCopy(TL);
6165 return TL.getType();
6166}
6167
6168template<typename Derived>
6169QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006170TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6171 ObjCTypeParamTypeLoc TL) {
6172 const ObjCTypeParamType *T = TL.getTypePtr();
6173 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6174 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6175 if (!OTP)
6176 return QualType();
6177
6178 QualType Result = TL.getType();
6179 if (getDerived().AlwaysRebuild() ||
6180 OTP != T->getDecl()) {
6181 Result = getDerived().RebuildObjCTypeParamType(OTP,
6182 TL.getProtocolLAngleLoc(),
6183 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6184 TL.getNumProtocols()),
6185 TL.getProtocolLocs(),
6186 TL.getProtocolRAngleLoc());
6187 if (Result.isNull())
6188 return QualType();
6189 }
6190
6191 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6192 if (TL.getNumProtocols()) {
6193 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6194 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6195 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6196 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6197 }
6198 return Result;
6199}
6200
6201template<typename Derived>
6202QualType
John McCall8b07ec22010-05-15 11:32:37 +00006203TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006204 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006205 // Transform base type.
6206 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6207 if (BaseType.isNull())
6208 return QualType();
6209
6210 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6211
6212 // Transform type arguments.
6213 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6214 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6215 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6216 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6217 QualType TypeArg = TypeArgInfo->getType();
6218 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6219 AnyChanged = true;
6220
6221 // We have a pack expansion. Instantiate it.
6222 const auto *PackExpansion = PackExpansionLoc.getType()
6223 ->castAs<PackExpansionType>();
6224 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6225 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6226 Unexpanded);
6227 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6228
6229 // Determine whether the set of unexpanded parameter packs can
6230 // and should be expanded.
6231 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6232 bool Expand = false;
6233 bool RetainExpansion = false;
6234 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6235 if (getDerived().TryExpandParameterPacks(
6236 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6237 Unexpanded, Expand, RetainExpansion, NumExpansions))
6238 return QualType();
6239
6240 if (!Expand) {
6241 // We can't expand this pack expansion into separate arguments yet;
6242 // just substitute into the pattern and create a new pack expansion
6243 // type.
6244 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6245
6246 TypeLocBuilder TypeArgBuilder;
6247 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6248 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6249 PatternLoc);
6250 if (NewPatternType.isNull())
6251 return QualType();
6252
6253 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6254 NewPatternType, NumExpansions);
6255 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6256 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6257 NewTypeArgInfos.push_back(
6258 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6259 continue;
6260 }
6261
6262 // Substitute into the pack expansion pattern for each slice of the
6263 // pack.
6264 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6266
6267 TypeLocBuilder TypeArgBuilder;
6268 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6269
6270 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6271 PatternLoc);
6272 if (NewTypeArg.isNull())
6273 return QualType();
6274
6275 NewTypeArgInfos.push_back(
6276 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6277 }
6278
6279 continue;
6280 }
6281
6282 TypeLocBuilder TypeArgBuilder;
6283 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6284 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6285 if (NewTypeArg.isNull())
6286 return QualType();
6287
6288 // If nothing changed, just keep the old TypeSourceInfo.
6289 if (NewTypeArg == TypeArg) {
6290 NewTypeArgInfos.push_back(TypeArgInfo);
6291 continue;
6292 }
6293
6294 NewTypeArgInfos.push_back(
6295 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6296 AnyChanged = true;
6297 }
6298
6299 QualType Result = TL.getType();
6300 if (getDerived().AlwaysRebuild() || AnyChanged) {
6301 // Rebuild the type.
6302 Result = getDerived().RebuildObjCObjectType(
6303 BaseType,
6304 TL.getLocStart(),
6305 TL.getTypeArgsLAngleLoc(),
6306 NewTypeArgInfos,
6307 TL.getTypeArgsRAngleLoc(),
6308 TL.getProtocolLAngleLoc(),
6309 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6310 TL.getNumProtocols()),
6311 TL.getProtocolLocs(),
6312 TL.getProtocolRAngleLoc());
6313
6314 if (Result.isNull())
6315 return QualType();
6316 }
6317
6318 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006319 NewT.setHasBaseTypeAsWritten(true);
6320 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6321 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6322 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6323 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6324 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6325 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6326 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6327 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6328 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006329}
Mike Stump11289f42009-09-09 15:08:12 +00006330
6331template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006332QualType
6333TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006334 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006335 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6336 if (PointeeType.isNull())
6337 return QualType();
6338
6339 QualType Result = TL.getType();
6340 if (getDerived().AlwaysRebuild() ||
6341 PointeeType != TL.getPointeeLoc().getType()) {
6342 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6343 TL.getStarLoc());
6344 if (Result.isNull())
6345 return QualType();
6346 }
6347
6348 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6349 NewT.setStarLoc(TL.getStarLoc());
6350 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006351}
6352
Douglas Gregord6ff3322009-08-04 16:50:30 +00006353//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006354// Statement transformation
6355//===----------------------------------------------------------------------===//
6356template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006357StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006358TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006359 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006360}
6361
6362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006363StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006364TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6365 return getDerived().TransformCompoundStmt(S, false);
6366}
6367
6368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006369StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006370TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006371 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006372 Sema::CompoundScopeRAII CompoundScope(getSema());
6373
John McCall1ababa62010-08-27 19:56:05 +00006374 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006375 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006376 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006377 for (auto *B : S->body()) {
6378 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006379 if (Result.isInvalid()) {
6380 // Immediately fail if this was a DeclStmt, since it's very
6381 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006382 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006383 return StmtError();
6384
6385 // Otherwise, just keep processing substatements and fail later.
6386 SubStmtInvalid = true;
6387 continue;
6388 }
Mike Stump11289f42009-09-09 15:08:12 +00006389
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006390 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006391 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006392 }
Mike Stump11289f42009-09-09 15:08:12 +00006393
John McCall1ababa62010-08-27 19:56:05 +00006394 if (SubStmtInvalid)
6395 return StmtError();
6396
Douglas Gregorebe10102009-08-20 07:17:43 +00006397 if (!getDerived().AlwaysRebuild() &&
6398 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006399 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006400
6401 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006402 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006403 S->getRBracLoc(),
6404 IsStmtExpr);
6405}
Mike Stump11289f42009-09-09 15:08:12 +00006406
Douglas Gregorebe10102009-08-20 07:17:43 +00006407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006408StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006409TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006410 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006411 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006412 EnterExpressionEvaluationContext Unevaluated(
6413 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006414
Eli Friedman06577382009-11-19 03:14:00 +00006415 // Transform the left-hand case value.
6416 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006417 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006418 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006420
Eli Friedman06577382009-11-19 03:14:00 +00006421 // Transform the right-hand case value (for the GNU case-range extension).
6422 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006423 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006424 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006425 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006426 }
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregorebe10102009-08-20 07:17:43 +00006428 // Build the case statement.
6429 // Case statements are always rebuilt so that they will attached to their
6430 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006431 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006432 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006433 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006434 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006435 S->getColonLoc());
6436 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006437 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006438
Douglas Gregorebe10102009-08-20 07:17:43 +00006439 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006440 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006441 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006442 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006445 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006446}
6447
6448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006449StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006450TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006451 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006452 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006453 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006454 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006455
Douglas Gregorebe10102009-08-20 07:17:43 +00006456 // Default statements are always rebuilt
6457 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006458 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006459}
Mike Stump11289f42009-09-09 15:08:12 +00006460
Douglas Gregorebe10102009-08-20 07:17:43 +00006461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006462StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006463TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006464 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006465 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006466 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006467
Chris Lattnercab02a62011-02-17 20:34:02 +00006468 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6469 S->getDecl());
6470 if (!LD)
6471 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006472
6473
Douglas Gregorebe10102009-08-20 07:17:43 +00006474 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006475 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006476 cast<LabelDecl>(LD), SourceLocation(),
6477 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006480template <typename Derived>
6481const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6482 if (!R)
6483 return R;
6484
6485 switch (R->getKind()) {
6486// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6487#define ATTR(X)
6488#define PRAGMA_SPELLING_ATTR(X) \
6489 case attr::X: \
6490 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6491#include "clang/Basic/AttrList.inc"
6492 default:
6493 return R;
6494 }
6495}
6496
6497template <typename Derived>
6498StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6499 bool AttrsChanged = false;
6500 SmallVector<const Attr *, 1> Attrs;
6501
6502 // Visit attributes and keep track if any are transformed.
6503 for (const auto *I : S->getAttrs()) {
6504 const Attr *R = getDerived().TransformAttr(I);
6505 AttrsChanged |= (I != R);
6506 Attrs.push_back(R);
6507 }
6508
Richard Smithc202b282012-04-14 00:33:13 +00006509 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6510 if (SubStmt.isInvalid())
6511 return StmtError();
6512
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006513 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006514 return S;
6515
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006516 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006517 SubStmt.get());
6518}
6519
6520template<typename Derived>
6521StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006522TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006523 // Transform the initialization statement
6524 StmtResult Init = getDerived().TransformStmt(S->getInit());
6525 if (Init.isInvalid())
6526 return StmtError();
6527
Douglas Gregorebe10102009-08-20 07:17:43 +00006528 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006529 Sema::ConditionResult Cond = getDerived().TransformCondition(
6530 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006531 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6532 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006533 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006534 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006535
Richard Smithb130fe72016-06-23 19:16:49 +00006536 // If this is a constexpr if, determine which arm we should instantiate.
6537 llvm::Optional<bool> ConstexprConditionValue;
6538 if (S->isConstexpr())
6539 ConstexprConditionValue = Cond.getKnownValue();
6540
Douglas Gregorebe10102009-08-20 07:17:43 +00006541 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006542 StmtResult Then;
6543 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6544 Then = getDerived().TransformStmt(S->getThen());
6545 if (Then.isInvalid())
6546 return StmtError();
6547 } else {
6548 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6549 }
Mike Stump11289f42009-09-09 15:08:12 +00006550
Douglas Gregorebe10102009-08-20 07:17:43 +00006551 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006552 StmtResult Else;
6553 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6554 Else = getDerived().TransformStmt(S->getElse());
6555 if (Else.isInvalid())
6556 return StmtError();
6557 }
Mike Stump11289f42009-09-09 15:08:12 +00006558
Douglas Gregorebe10102009-08-20 07:17:43 +00006559 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006560 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006561 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006562 Then.get() == S->getThen() &&
6563 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006564 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006565
Richard Smithb130fe72016-06-23 19:16:49 +00006566 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006567 Init.get(), Then.get(), S->getElseLoc(),
6568 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006569}
6570
6571template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006572StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006573TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006574 // Transform the initialization statement
6575 StmtResult Init = getDerived().TransformStmt(S->getInit());
6576 if (Init.isInvalid())
6577 return StmtError();
6578
Douglas Gregorebe10102009-08-20 07:17:43 +00006579 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006580 Sema::ConditionResult Cond = getDerived().TransformCondition(
6581 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6582 Sema::ConditionKind::Switch);
6583 if (Cond.isInvalid())
6584 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006585
Douglas Gregorebe10102009-08-20 07:17:43 +00006586 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006587 StmtResult Switch
Richard Smitha547eb22016-07-14 00:11:03 +00006588 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(),
6589 S->getInit(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006590 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006591 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregorebe10102009-08-20 07:17:43 +00006593 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006594 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006595 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006596 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006597
Douglas Gregorebe10102009-08-20 07:17:43 +00006598 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006599 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6600 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006601}
Mike Stump11289f42009-09-09 15:08:12 +00006602
Douglas Gregorebe10102009-08-20 07:17:43 +00006603template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006604StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006605TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006606 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006607 Sema::ConditionResult Cond = getDerived().TransformCondition(
6608 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6609 Sema::ConditionKind::Boolean);
6610 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006611 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006612
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006614 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006615 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006616 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006617
Douglas Gregorebe10102009-08-20 07:17:43 +00006618 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006619 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006620 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006621 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006622
Richard Smith03a4aa32016-06-23 19:02:52 +00006623 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006624}
Mike Stump11289f42009-09-09 15:08:12 +00006625
Douglas Gregorebe10102009-08-20 07:17:43 +00006626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006627StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006628TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006629 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006630 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006631 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006633
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006634 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006635 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006636 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006638
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 if (!getDerived().AlwaysRebuild() &&
6640 Cond.get() == S->getCond() &&
6641 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006642 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006643
John McCallb268a282010-08-23 23:25:46 +00006644 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6645 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006646 S->getRParenLoc());
6647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregorebe10102009-08-20 07:17:43 +00006649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006651TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006652 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006653 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006654 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006655 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006656
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006657 // In OpenMP loop region loop control variable must be captured and be
6658 // private. Perform analysis of first part (if any).
6659 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6660 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6661
Douglas Gregorebe10102009-08-20 07:17:43 +00006662 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006663 Sema::ConditionResult Cond = getDerived().TransformCondition(
6664 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6665 Sema::ConditionKind::Boolean);
6666 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006667 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006668
Douglas Gregorebe10102009-08-20 07:17:43 +00006669 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006670 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006671 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006672 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006673
Richard Smith945f8d32013-01-14 22:39:08 +00006674 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006675 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006677
Douglas Gregorebe10102009-08-20 07:17:43 +00006678 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006679 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006680 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006681 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006682
Douglas Gregorebe10102009-08-20 07:17:43 +00006683 if (!getDerived().AlwaysRebuild() &&
6684 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006685 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006686 Inc.get() == S->getInc() &&
6687 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006688 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006689
Douglas Gregorebe10102009-08-20 07:17:43 +00006690 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006691 Init.get(), Cond, FullInc,
6692 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006693}
6694
6695template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006696StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006697TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006698 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6699 S->getLabel());
6700 if (!LD)
6701 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006702
Douglas Gregorebe10102009-08-20 07:17:43 +00006703 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006704 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006705 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006706}
6707
6708template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006709StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006710TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006711 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006712 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006713 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006714 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006715
Douglas Gregorebe10102009-08-20 07:17:43 +00006716 if (!getDerived().AlwaysRebuild() &&
6717 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006718 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006719
6720 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006721 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006722}
6723
6724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006725StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006726TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006727 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006728}
Mike Stump11289f42009-09-09 15:08:12 +00006729
Douglas Gregorebe10102009-08-20 07:17:43 +00006730template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006731StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006732TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006733 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006734}
Mike Stump11289f42009-09-09 15:08:12 +00006735
Douglas Gregorebe10102009-08-20 07:17:43 +00006736template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006737StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006738TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006739 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6740 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006741 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006742 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006743
Mike Stump11289f42009-09-09 15:08:12 +00006744 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006745 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006746 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006747}
Mike Stump11289f42009-09-09 15:08:12 +00006748
Douglas Gregorebe10102009-08-20 07:17:43 +00006749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006750StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006751TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006752 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006753 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006754 for (auto *D : S->decls()) {
6755 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006756 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006757 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006758
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006759 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006760 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006761
Douglas Gregorebe10102009-08-20 07:17:43 +00006762 Decls.push_back(Transformed);
6763 }
Mike Stump11289f42009-09-09 15:08:12 +00006764
Douglas Gregorebe10102009-08-20 07:17:43 +00006765 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006766 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006767
Rafael Espindolaab417692013-07-09 12:05:01 +00006768 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006769}
Mike Stump11289f42009-09-09 15:08:12 +00006770
Douglas Gregorebe10102009-08-20 07:17:43 +00006771template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006772StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006773TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006774
Benjamin Kramerf0623432012-08-23 22:51:59 +00006775 SmallVector<Expr*, 8> Constraints;
6776 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006777 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006778
John McCalldadc5752010-08-24 06:29:42 +00006779 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006780 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006781
6782 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Anders Carlssonaaeef072010-01-24 05:50:09 +00006784 // Go through the outputs.
6785 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006786 Names.push_back(S->getOutputIdentifier(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->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006790
Anders Carlssonaaeef072010-01-24 05:50:09 +00006791 // Transform the output expr.
6792 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006793 ExprResult Result = getDerived().TransformExpr(OutputExpr);
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() != OutputExpr;
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 // Go through the inputs.
6803 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006804 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006805
Anders Carlssonaaeef072010-01-24 05:50:09 +00006806 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006807 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006808
Anders Carlssonaaeef072010-01-24 05:50:09 +00006809 // Transform the input expr.
6810 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006811 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006812 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006813 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006814
Anders Carlssonaaeef072010-01-24 05:50:09 +00006815 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006816
John McCallb268a282010-08-23 23:25:46 +00006817 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006818 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006819
Anders Carlssonaaeef072010-01-24 05:50:09 +00006820 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006821 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006822
6823 // Go through the clobbers.
6824 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006825 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006826
6827 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006828 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006829 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6830 S->isVolatile(), S->getNumOutputs(),
6831 S->getNumInputs(), Names.data(),
6832 Constraints, Exprs, AsmString.get(),
6833 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006834}
6835
Chad Rosier32503022012-06-11 20:47:18 +00006836template<typename Derived>
6837StmtResult
6838TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006839 ArrayRef<Token> AsmToks =
6840 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006841
John McCallf413f5e2013-05-03 00:10:13 +00006842 bool HadError = false, HadChange = false;
6843
6844 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6845 SmallVector<Expr*, 8> TransformedExprs;
6846 TransformedExprs.reserve(SrcExprs.size());
6847 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6848 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6849 if (!Result.isUsable()) {
6850 HadError = true;
6851 } else {
6852 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006853 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006854 }
6855 }
6856
6857 if (HadError) return StmtError();
6858 if (!HadChange && !getDerived().AlwaysRebuild())
6859 return Owned(S);
6860
Chad Rosierb6f46c12012-08-15 16:53:30 +00006861 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006862 AsmToks, S->getAsmString(),
6863 S->getNumOutputs(), S->getNumInputs(),
6864 S->getAllConstraints(), S->getClobbers(),
6865 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006866}
Douglas Gregorebe10102009-08-20 07:17:43 +00006867
Richard Smith9f690bd2015-10-27 06:02:45 +00006868// C++ Coroutines TS
6869
6870template<typename Derived>
6871StmtResult
6872TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006873 auto *ScopeInfo = SemaRef.getCurFunction();
6874 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006875 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006876 ScopeInfo->NeedsCoroutineSuspends &&
6877 ScopeInfo->CoroutineSuspends.first == nullptr &&
6878 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006879 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006880
6881 // Set that we have (possibly-invalid) suspend points before we do anything
6882 // that may fail.
6883 ScopeInfo->setNeedsCoroutineSuspends(false);
6884
6885 // The new CoroutinePromise object needs to be built and put into the current
6886 // FunctionScopeInfo before any transformations or rebuilding occurs.
Eric Fiselierbee782b2017-04-03 19:21:00 +00006887 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6888 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006889 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006890 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6891 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006892
6893 // Transform the implicit coroutine statements we built during the initial
6894 // parse.
6895 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6896 if (InitSuspend.isInvalid())
6897 return StmtError();
6898 StmtResult FinalSuspend =
6899 getDerived().TransformStmt(S->getFinalSuspendStmt());
6900 if (FinalSuspend.isInvalid())
6901 return StmtError();
6902 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6903 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006904
6905 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6906 if (BodyRes.isInvalid())
6907 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006908
Eric Fiselierbee782b2017-04-03 19:21:00 +00006909 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6910 if (Builder.isInvalid())
6911 return StmtError();
6912
6913 Expr *ReturnObject = S->getReturnValueInit();
6914 assert(ReturnObject && "the return object is expected to be valid");
6915 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6916 /*NoCopyInit*/ false);
6917 if (Res.isInvalid())
6918 return StmtError();
6919 Builder.ReturnValue = Res.get();
6920
6921 if (S->hasDependentPromiseType()) {
6922 assert(!Promise->getType()->isDependentType() &&
6923 "the promise type must no longer be dependent");
6924 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6925 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6926 "these nodes should not have been built yet");
6927 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006928 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006929 } else {
6930 if (auto *OnFallthrough = S->getFallthroughHandler()) {
6931 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6932 if (Res.isInvalid())
6933 return StmtError();
6934 Builder.OnFallthrough = Res.get();
6935 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006936
Eric Fiselierbee782b2017-04-03 19:21:00 +00006937 if (auto *OnException = S->getExceptionHandler()) {
6938 StmtResult Res = getDerived().TransformStmt(OnException);
6939 if (Res.isInvalid())
6940 return StmtError();
6941 Builder.OnException = Res.get();
6942 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006943
Eric Fiselierbee782b2017-04-03 19:21:00 +00006944 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
6945 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
6946 if (Res.isInvalid())
6947 return StmtError();
6948 Builder.ReturnStmtOnAllocFailure = Res.get();
6949 }
6950
6951 // Transform any additional statements we may have already built
6952 assert(S->getAllocate() && S->getDeallocate() &&
6953 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006954 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
6955 if (AllocRes.isInvalid())
6956 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006957 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006958
6959 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
6960 if (DeallocRes.isInvalid())
6961 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006962 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00006963
6964 assert(S->getResultDecl() && "ResultDecl must already be built");
6965 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
6966 if (ResultDecl.isInvalid())
6967 return StmtError();
6968 Builder.ResultDecl = ResultDecl.get();
6969
6970 if (auto *ReturnStmt = S->getReturnStmt()) {
6971 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
6972 if (Res.isInvalid())
6973 return StmtError();
6974 Builder.ReturnStmt = Res.get();
6975 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006976 }
Eric Fiselierde7943b2017-06-03 00:22:18 +00006977 if (!Builder.buildParameterMoves())
6978 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006979
Eric Fiselierbee782b2017-04-03 19:21:00 +00006980 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00006981}
6982
6983template<typename Derived>
6984StmtResult
6985TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
6986 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
6987 /*NotCopyInit*/false);
6988 if (Result.isInvalid())
6989 return StmtError();
6990
6991 // Always rebuild; we don't know if this needs to be injected into a new
6992 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006993 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
6994 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00006995}
6996
6997template<typename Derived>
6998ExprResult
6999TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7000 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7001 /*NotCopyInit*/false);
7002 if (Result.isInvalid())
7003 return ExprError();
7004
7005 // Always rebuild; we don't know if this needs to be injected into a new
7006 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007007 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7008 E->isImplicit());
7009}
7010
7011template <typename Derived>
7012ExprResult
7013TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7014 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7015 /*NotCopyInit*/ false);
7016 if (OperandResult.isInvalid())
7017 return ExprError();
7018
7019 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7020 E->getOperatorCoawaitLookup());
7021
7022 if (LookupResult.isInvalid())
7023 return ExprError();
7024
7025 // Always rebuild; we don't know if this needs to be injected into a new
7026 // context or if the promise type has changed.
7027 return getDerived().RebuildDependentCoawaitExpr(
7028 E->getKeywordLoc(), OperandResult.get(),
7029 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007030}
7031
7032template<typename Derived>
7033ExprResult
7034TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7035 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7036 /*NotCopyInit*/false);
7037 if (Result.isInvalid())
7038 return ExprError();
7039
7040 // Always rebuild; we don't know if this needs to be injected into a new
7041 // context or if the promise type has changed.
7042 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7043}
7044
7045// Objective-C Statements.
7046
Douglas Gregorebe10102009-08-20 07:17:43 +00007047template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007048StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007049TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007050 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007051 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007052 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007053 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007054
Douglas Gregor96c79492010-04-23 22:50:49 +00007055 // Transform the @catch statements (if present).
7056 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007057 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007058 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007059 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007060 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007061 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007062 if (Catch.get() != S->getCatchStmt(I))
7063 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007064 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007065 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007066
Douglas Gregor306de2f2010-04-22 23:59:56 +00007067 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007068 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007069 if (S->getFinallyStmt()) {
7070 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7071 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007073 }
7074
7075 // If nothing changed, just retain this statement.
7076 if (!getDerived().AlwaysRebuild() &&
7077 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007078 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007079 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007080 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007081
Douglas Gregor306de2f2010-04-22 23:59:56 +00007082 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007083 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007084 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007085}
Mike Stump11289f42009-09-09 15:08:12 +00007086
Douglas Gregorebe10102009-08-20 07:17:43 +00007087template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007088StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007089TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007090 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007091 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007092 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007093 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007094 if (FromVar->getTypeSourceInfo()) {
7095 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7096 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007097 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007098 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007099
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007100 QualType T;
7101 if (TSInfo)
7102 T = TSInfo->getType();
7103 else {
7104 T = getDerived().TransformType(FromVar->getType());
7105 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007106 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007107 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007108
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007109 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7110 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007111 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007112 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007113
John McCalldadc5752010-08-24 06:29:42 +00007114 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007115 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007116 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007117
7118 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007119 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007120 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007121}
Mike Stump11289f42009-09-09 15:08:12 +00007122
Douglas Gregorebe10102009-08-20 07:17:43 +00007123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007124StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007125TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007126 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007127 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007128 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007129 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007130
Douglas Gregor306de2f2010-04-22 23:59:56 +00007131 // If nothing changed, just retain this statement.
7132 if (!getDerived().AlwaysRebuild() &&
7133 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007134 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007135
7136 // Build a new statement.
7137 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007138 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007139}
Mike Stump11289f42009-09-09 15:08:12 +00007140
Douglas Gregorebe10102009-08-20 07:17:43 +00007141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007142StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007143TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007144 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007145 if (S->getThrowExpr()) {
7146 Operand = getDerived().TransformExpr(S->getThrowExpr());
7147 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007148 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007150
Douglas Gregor2900c162010-04-22 21:44:01 +00007151 if (!getDerived().AlwaysRebuild() &&
7152 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007153 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007154
John McCallb268a282010-08-23 23:25:46 +00007155 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007156}
Mike Stump11289f42009-09-09 15:08:12 +00007157
Douglas Gregorebe10102009-08-20 07:17:43 +00007158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007159StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007160TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007161 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007162 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007163 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007164 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007165 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007166 Object =
7167 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7168 Object.get());
7169 if (Object.isInvalid())
7170 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007171
Douglas Gregor6148de72010-04-22 22:01:21 +00007172 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007173 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007174 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007175 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007176
Douglas Gregor6148de72010-04-22 22:01:21 +00007177 // If nothing change, just retain the current statement.
7178 if (!getDerived().AlwaysRebuild() &&
7179 Object.get() == S->getSynchExpr() &&
7180 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007181 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007182
7183 // Build a new statement.
7184 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007185 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007186}
7187
7188template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007189StmtResult
John McCall31168b02011-06-15 23:02:42 +00007190TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7191 ObjCAutoreleasePoolStmt *S) {
7192 // Transform the body.
7193 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7194 if (Body.isInvalid())
7195 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007196
John McCall31168b02011-06-15 23:02:42 +00007197 // If nothing changed, just retain this statement.
7198 if (!getDerived().AlwaysRebuild() &&
7199 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007200 return S;
John McCall31168b02011-06-15 23:02:42 +00007201
7202 // Build a new statement.
7203 return getDerived().RebuildObjCAutoreleasePoolStmt(
7204 S->getAtLoc(), Body.get());
7205}
7206
7207template<typename Derived>
7208StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007209TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007210 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007211 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007212 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007213 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007214 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007215
Douglas Gregorf68a5082010-04-22 23:10:45 +00007216 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007217 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007218 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007219 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007220
Douglas Gregorf68a5082010-04-22 23:10:45 +00007221 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007222 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007223 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007224 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007225
Douglas Gregorf68a5082010-04-22 23:10:45 +00007226 // If nothing changed, just retain this statement.
7227 if (!getDerived().AlwaysRebuild() &&
7228 Element.get() == S->getElement() &&
7229 Collection.get() == S->getCollection() &&
7230 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007231 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007232
Douglas Gregorf68a5082010-04-22 23:10:45 +00007233 // Build a new statement.
7234 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007235 Element.get(),
7236 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007237 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007238 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007239}
7240
David Majnemer5f7efef2013-10-15 09:50:08 +00007241template <typename Derived>
7242StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007243 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007244 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007245 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7246 TypeSourceInfo *T =
7247 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007248 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007249 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007250
David Majnemer5f7efef2013-10-15 09:50:08 +00007251 Var = getDerived().RebuildExceptionDecl(
7252 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7253 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007254 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007255 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007256 }
Mike Stump11289f42009-09-09 15:08:12 +00007257
Douglas Gregorebe10102009-08-20 07:17:43 +00007258 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007259 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007260 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007261 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007262
David Majnemer5f7efef2013-10-15 09:50:08 +00007263 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007264 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007265 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007266
David Majnemer5f7efef2013-10-15 09:50:08 +00007267 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007268}
Mike Stump11289f42009-09-09 15:08:12 +00007269
David Majnemer5f7efef2013-10-15 09:50:08 +00007270template <typename Derived>
7271StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007272 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007273 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007274 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007275 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007276
Douglas Gregorebe10102009-08-20 07:17:43 +00007277 // Transform the handlers.
7278 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007279 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007280 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007281 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007282 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007283 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007284
Douglas Gregorebe10102009-08-20 07:17:43 +00007285 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007286 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007287 }
Mike Stump11289f42009-09-09 15:08:12 +00007288
David Majnemer5f7efef2013-10-15 09:50:08 +00007289 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007290 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007291 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007292
John McCallb268a282010-08-23 23:25:46 +00007293 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007294 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007295}
Mike Stump11289f42009-09-09 15:08:12 +00007296
Richard Smith02e85f32011-04-14 22:09:26 +00007297template<typename Derived>
7298StmtResult
7299TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7300 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7301 if (Range.isInvalid())
7302 return StmtError();
7303
Richard Smith01694c32016-03-20 10:33:40 +00007304 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7305 if (Begin.isInvalid())
7306 return StmtError();
7307 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7308 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007309 return StmtError();
7310
7311 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7312 if (Cond.isInvalid())
7313 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007314 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007315 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007316 if (Cond.isInvalid())
7317 return StmtError();
7318 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007319 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007320
7321 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7322 if (Inc.isInvalid())
7323 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007324 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007325 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007326
7327 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7328 if (LoopVar.isInvalid())
7329 return StmtError();
7330
7331 StmtResult NewStmt = S;
7332 if (getDerived().AlwaysRebuild() ||
7333 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007334 Begin.get() != S->getBeginStmt() ||
7335 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007336 Cond.get() != S->getCond() ||
7337 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007338 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007339 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007340 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007341 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007342 Begin.get(), End.get(),
7343 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007344 Inc.get(), LoopVar.get(),
7345 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007346 if (NewStmt.isInvalid())
7347 return StmtError();
7348 }
Richard Smith02e85f32011-04-14 22:09:26 +00007349
7350 StmtResult Body = getDerived().TransformStmt(S->getBody());
7351 if (Body.isInvalid())
7352 return StmtError();
7353
7354 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7355 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007356 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007357 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007358 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007359 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007360 Begin.get(), End.get(),
7361 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007362 Inc.get(), LoopVar.get(),
7363 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007364 if (NewStmt.isInvalid())
7365 return StmtError();
7366 }
Richard Smith02e85f32011-04-14 22:09:26 +00007367
7368 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007369 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007370
7371 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7372}
7373
John Wiegley1c0675e2011-04-28 01:08:34 +00007374template<typename Derived>
7375StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007376TreeTransform<Derived>::TransformMSDependentExistsStmt(
7377 MSDependentExistsStmt *S) {
7378 // Transform the nested-name-specifier, if any.
7379 NestedNameSpecifierLoc QualifierLoc;
7380 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007381 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007382 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7383 if (!QualifierLoc)
7384 return StmtError();
7385 }
7386
7387 // Transform the declaration name.
7388 DeclarationNameInfo NameInfo = S->getNameInfo();
7389 if (NameInfo.getName()) {
7390 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7391 if (!NameInfo.getName())
7392 return StmtError();
7393 }
7394
7395 // Check whether anything changed.
7396 if (!getDerived().AlwaysRebuild() &&
7397 QualifierLoc == S->getQualifierLoc() &&
7398 NameInfo.getName() == S->getNameInfo().getName())
7399 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007400
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007401 // Determine whether this name exists, if we can.
7402 CXXScopeSpec SS;
7403 SS.Adopt(QualifierLoc);
7404 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007405 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007406 case Sema::IER_Exists:
7407 if (S->isIfExists())
7408 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007409
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007410 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7411
7412 case Sema::IER_DoesNotExist:
7413 if (S->isIfNotExists())
7414 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007415
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007416 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007417
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007418 case Sema::IER_Dependent:
7419 Dependent = true;
7420 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007421
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007422 case Sema::IER_Error:
7423 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007425
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007426 // We need to continue with the instantiation, so do so now.
7427 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7428 if (SubStmt.isInvalid())
7429 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007430
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007431 // If we have resolved the name, just transform to the substatement.
7432 if (!Dependent)
7433 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007434
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007435 // The name is still dependent, so build a dependent expression again.
7436 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7437 S->isIfExists(),
7438 QualifierLoc,
7439 NameInfo,
7440 SubStmt.get());
7441}
7442
7443template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007444ExprResult
7445TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7446 NestedNameSpecifierLoc QualifierLoc;
7447 if (E->getQualifierLoc()) {
7448 QualifierLoc
7449 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7450 if (!QualifierLoc)
7451 return ExprError();
7452 }
7453
7454 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7455 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7456 if (!PD)
7457 return ExprError();
7458
7459 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7460 if (Base.isInvalid())
7461 return ExprError();
7462
7463 return new (SemaRef.getASTContext())
7464 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7465 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7466 QualifierLoc, E->getMemberLoc());
7467}
7468
David Majnemerfad8f482013-10-15 09:33:02 +00007469template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007470ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7471 MSPropertySubscriptExpr *E) {
7472 auto BaseRes = getDerived().TransformExpr(E->getBase());
7473 if (BaseRes.isInvalid())
7474 return ExprError();
7475 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7476 if (IdxRes.isInvalid())
7477 return ExprError();
7478
7479 if (!getDerived().AlwaysRebuild() &&
7480 BaseRes.get() == E->getBase() &&
7481 IdxRes.get() == E->getIdx())
7482 return E;
7483
7484 return getDerived().RebuildArraySubscriptExpr(
7485 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7486}
7487
7488template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007489StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007490 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007491 if (TryBlock.isInvalid())
7492 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007493
7494 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007495 if (Handler.isInvalid())
7496 return StmtError();
7497
David Majnemerfad8f482013-10-15 09:33:02 +00007498 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7499 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007500 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007501
Warren Huntf6be4cb2014-07-25 20:52:51 +00007502 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7503 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007504}
7505
David Majnemerfad8f482013-10-15 09:33:02 +00007506template <typename Derived>
7507StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007508 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007509 if (Block.isInvalid())
7510 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007511
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007512 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007513}
7514
David Majnemerfad8f482013-10-15 09:33:02 +00007515template <typename Derived>
7516StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007517 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007518 if (FilterExpr.isInvalid())
7519 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007520
David Majnemer7e755502013-10-15 09:30:14 +00007521 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007522 if (Block.isInvalid())
7523 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007524
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007525 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7526 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007527}
7528
David Majnemerfad8f482013-10-15 09:33:02 +00007529template <typename Derived>
7530StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7531 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007532 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7533 else
7534 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7535}
7536
Nico Weber9b982072014-07-07 00:12:30 +00007537template<typename Derived>
7538StmtResult
7539TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7540 return S;
7541}
7542
Alexander Musman64d33f12014-06-04 07:53:32 +00007543//===----------------------------------------------------------------------===//
7544// OpenMP directive transformation
7545//===----------------------------------------------------------------------===//
7546template <typename Derived>
7547StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7548 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007549
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007550 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007551 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007552 ArrayRef<OMPClause *> Clauses = D->clauses();
7553 TClauses.reserve(Clauses.size());
7554 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7555 I != E; ++I) {
7556 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007557 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007558 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007559 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007560 if (Clause)
7561 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007562 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007563 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007564 }
7565 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007566 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007567 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007568 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7569 /*CurScope=*/nullptr);
7570 StmtResult Body;
7571 {
7572 Sema::CompoundScopeRAII CompoundScope(getSema());
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007573 int ThisCaptureLevel =
7574 Sema::getOpenMPCaptureLevels(D->getDirectiveKind());
7575 Stmt *CS = D->getAssociatedStmt();
7576 while (--ThisCaptureLevel >= 0)
7577 CS = cast<CapturedStmt>(CS)->getCapturedStmt();
7578 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007579 }
7580 AssociatedStmt =
7581 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007582 if (AssociatedStmt.isInvalid()) {
7583 return StmtError();
7584 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007585 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007586 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007587 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007588 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007589
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007590 // Transform directive name for 'omp critical' directive.
7591 DeclarationNameInfo DirName;
7592 if (D->getDirectiveKind() == OMPD_critical) {
7593 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7594 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7595 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007596 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7597 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7598 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007599 } else if (D->getDirectiveKind() == OMPD_cancel) {
7600 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007601 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007602
Alexander Musman64d33f12014-06-04 07:53:32 +00007603 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007604 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7605 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007606}
7607
Alexander Musman64d33f12014-06-04 07:53:32 +00007608template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007609StmtResult
7610TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7611 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007612 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7613 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007614 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7615 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7616 return Res;
7617}
7618
Alexander Musman64d33f12014-06-04 07:53:32 +00007619template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007620StmtResult
7621TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7622 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007623 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7624 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007625 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7626 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007627 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007628}
7629
Alexey Bataevf29276e2014-06-18 04:14:57 +00007630template <typename Derived>
7631StmtResult
7632TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7633 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007634 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7635 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007636 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7637 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7638 return Res;
7639}
7640
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007641template <typename Derived>
7642StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007643TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7644 DeclarationNameInfo DirName;
7645 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7646 D->getLocStart());
7647 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7648 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7649 return Res;
7650}
7651
7652template <typename Derived>
7653StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007654TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7655 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007656 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7657 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007658 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7659 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7660 return Res;
7661}
7662
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007663template <typename Derived>
7664StmtResult
7665TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7666 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007667 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7668 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007669 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7670 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7671 return Res;
7672}
7673
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007674template <typename Derived>
7675StmtResult
7676TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7677 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007678 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7679 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007680 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7681 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7682 return Res;
7683}
7684
Alexey Bataev4acb8592014-07-07 13:01:15 +00007685template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007686StmtResult
7687TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7688 DeclarationNameInfo DirName;
7689 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7690 D->getLocStart());
7691 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7692 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7693 return Res;
7694}
7695
7696template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007697StmtResult
7698TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7699 getDerived().getSema().StartOpenMPDSABlock(
7700 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7701 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7702 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7703 return Res;
7704}
7705
7706template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007707StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7708 OMPParallelForDirective *D) {
7709 DeclarationNameInfo DirName;
7710 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7711 nullptr, D->getLocStart());
7712 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7713 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7714 return Res;
7715}
7716
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007717template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007718StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7719 OMPParallelForSimdDirective *D) {
7720 DeclarationNameInfo DirName;
7721 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7722 nullptr, D->getLocStart());
7723 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7724 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7725 return Res;
7726}
7727
7728template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007729StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7730 OMPParallelSectionsDirective *D) {
7731 DeclarationNameInfo DirName;
7732 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7733 nullptr, D->getLocStart());
7734 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7735 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7736 return Res;
7737}
7738
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007739template <typename Derived>
7740StmtResult
7741TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7742 DeclarationNameInfo DirName;
7743 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7744 D->getLocStart());
7745 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7746 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7747 return Res;
7748}
7749
Alexey Bataev68446b72014-07-18 07:47:19 +00007750template <typename Derived>
7751StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7752 OMPTaskyieldDirective *D) {
7753 DeclarationNameInfo DirName;
7754 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7755 D->getLocStart());
7756 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7757 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7758 return Res;
7759}
7760
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007761template <typename Derived>
7762StmtResult
7763TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7764 DeclarationNameInfo DirName;
7765 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7766 D->getLocStart());
7767 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7768 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7769 return Res;
7770}
7771
Alexey Bataev2df347a2014-07-18 10:17:07 +00007772template <typename Derived>
7773StmtResult
7774TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7775 DeclarationNameInfo DirName;
7776 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7777 D->getLocStart());
7778 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7780 return Res;
7781}
7782
Alexey Bataev6125da92014-07-21 11:26:11 +00007783template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007784StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7785 OMPTaskgroupDirective *D) {
7786 DeclarationNameInfo DirName;
7787 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7788 D->getLocStart());
7789 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7790 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7791 return Res;
7792}
7793
7794template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007795StmtResult
7796TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7797 DeclarationNameInfo DirName;
7798 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7799 D->getLocStart());
7800 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7801 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7802 return Res;
7803}
7804
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007805template <typename Derived>
7806StmtResult
7807TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7808 DeclarationNameInfo DirName;
7809 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7810 D->getLocStart());
7811 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7812 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7813 return Res;
7814}
7815
Alexey Bataev0162e452014-07-22 10:10:35 +00007816template <typename Derived>
7817StmtResult
7818TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7819 DeclarationNameInfo DirName;
7820 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7821 D->getLocStart());
7822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7824 return Res;
7825}
7826
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007827template <typename Derived>
7828StmtResult
7829TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7830 DeclarationNameInfo DirName;
7831 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7832 D->getLocStart());
7833 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7834 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7835 return Res;
7836}
7837
Alexey Bataev13314bf2014-10-09 04:18:56 +00007838template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007839StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7840 OMPTargetDataDirective *D) {
7841 DeclarationNameInfo DirName;
7842 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7843 D->getLocStart());
7844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7845 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7846 return Res;
7847}
7848
7849template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007850StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7851 OMPTargetEnterDataDirective *D) {
7852 DeclarationNameInfo DirName;
7853 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, 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 Antao72590762016-01-19 20:04:50 +00007861StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7862 OMPTargetExitDataDirective *D) {
7863 DeclarationNameInfo DirName;
7864 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, 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>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007872StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7873 OMPTargetParallelDirective *D) {
7874 DeclarationNameInfo DirName;
7875 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7876 nullptr, D->getLocStart());
7877 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7878 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7879 return Res;
7880}
7881
7882template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007883StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7884 OMPTargetParallelForDirective *D) {
7885 DeclarationNameInfo DirName;
7886 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7887 nullptr, D->getLocStart());
7888 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7889 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7890 return Res;
7891}
7892
7893template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007894StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7895 OMPTargetUpdateDirective *D) {
7896 DeclarationNameInfo DirName;
7897 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7898 nullptr, D->getLocStart());
7899 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7900 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7901 return Res;
7902}
7903
7904template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007905StmtResult
7906TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7907 DeclarationNameInfo DirName;
7908 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7909 D->getLocStart());
7910 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7911 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7912 return Res;
7913}
7914
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007915template <typename Derived>
7916StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7917 OMPCancellationPointDirective *D) {
7918 DeclarationNameInfo DirName;
7919 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7920 nullptr, D->getLocStart());
7921 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7922 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7923 return Res;
7924}
7925
Alexey Bataev80909872015-07-02 11:25:17 +00007926template <typename Derived>
7927StmtResult
7928TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7929 DeclarationNameInfo DirName;
7930 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7931 D->getLocStart());
7932 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7933 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7934 return Res;
7935}
7936
Alexey Bataev49f6e782015-12-01 04:18:41 +00007937template <typename Derived>
7938StmtResult
7939TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7940 DeclarationNameInfo DirName;
7941 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7942 D->getLocStart());
7943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7945 return Res;
7946}
7947
Alexey Bataev0a6ed842015-12-03 09:40:15 +00007948template <typename Derived>
7949StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
7950 OMPTaskLoopSimdDirective *D) {
7951 DeclarationNameInfo DirName;
7952 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
7953 nullptr, D->getLocStart());
7954 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7955 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7956 return Res;
7957}
7958
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00007959template <typename Derived>
7960StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
7961 OMPDistributeDirective *D) {
7962 DeclarationNameInfo DirName;
7963 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
7964 D->getLocStart());
7965 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7966 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7967 return Res;
7968}
7969
Carlo Bertolli9925f152016-06-27 14:55:37 +00007970template <typename Derived>
7971StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
7972 OMPDistributeParallelForDirective *D) {
7973 DeclarationNameInfo DirName;
7974 getDerived().getSema().StartOpenMPDSABlock(
7975 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
7976 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7977 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7978 return Res;
7979}
7980
Kelvin Li4a39add2016-07-05 05:00:15 +00007981template <typename Derived>
7982StmtResult
7983TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
7984 OMPDistributeParallelForSimdDirective *D) {
7985 DeclarationNameInfo DirName;
7986 getDerived().getSema().StartOpenMPDSABlock(
7987 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
7988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990 return Res;
7991}
7992
Kelvin Li787f3fc2016-07-06 04:45:38 +00007993template <typename Derived>
7994StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
7995 OMPDistributeSimdDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
7998 nullptr, D->getLocStart());
7999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001 return Res;
8002}
8003
Kelvin Lia579b912016-07-14 02:54:56 +00008004template <typename Derived>
8005StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8006 OMPTargetParallelForSimdDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8009 DirName, nullptr,
8010 D->getLocStart());
8011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8012 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8013 return Res;
8014}
8015
Kelvin Li986330c2016-07-20 22:57:10 +00008016template <typename Derived>
8017StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8018 OMPTargetSimdDirective *D) {
8019 DeclarationNameInfo DirName;
8020 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8021 D->getLocStart());
8022 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8023 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8024 return Res;
8025}
8026
Kelvin Li02532872016-08-05 14:37:37 +00008027template <typename Derived>
8028StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8029 OMPTeamsDistributeDirective *D) {
8030 DeclarationNameInfo DirName;
8031 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8032 nullptr, D->getLocStart());
8033 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8034 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8035 return Res;
8036}
8037
Kelvin Li4e325f72016-10-25 12:50:55 +00008038template <typename Derived>
8039StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8040 OMPTeamsDistributeSimdDirective *D) {
8041 DeclarationNameInfo DirName;
8042 getDerived().getSema().StartOpenMPDSABlock(
8043 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8046 return Res;
8047}
8048
Kelvin Li579e41c2016-11-30 23:51:03 +00008049template <typename Derived>
8050StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8051 OMPTeamsDistributeParallelForSimdDirective *D) {
8052 DeclarationNameInfo DirName;
8053 getDerived().getSema().StartOpenMPDSABlock(
8054 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8057 return Res;
8058}
8059
Kelvin Li7ade93f2016-12-09 03:24:30 +00008060template <typename Derived>
8061StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8062 OMPTeamsDistributeParallelForDirective *D) {
8063 DeclarationNameInfo DirName;
8064 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8065 DirName, nullptr, D->getLocStart());
8066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8067 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8068 return Res;
8069}
8070
Kelvin Libf594a52016-12-17 05:48:59 +00008071template <typename Derived>
8072StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8073 OMPTargetTeamsDirective *D) {
8074 DeclarationNameInfo DirName;
8075 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8076 nullptr, D->getLocStart());
8077 auto Res = getDerived().TransformOMPExecutableDirective(D);
8078 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8079 return Res;
8080}
Kelvin Li579e41c2016-11-30 23:51:03 +00008081
Kelvin Li83c451e2016-12-25 04:52:54 +00008082template <typename Derived>
8083StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8084 OMPTargetTeamsDistributeDirective *D) {
8085 DeclarationNameInfo DirName;
8086 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8087 DirName, nullptr, D->getLocStart());
8088 auto Res = getDerived().TransformOMPExecutableDirective(D);
8089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8090 return Res;
8091}
8092
Kelvin Li80e8f562016-12-29 22:16:30 +00008093template <typename Derived>
8094StmtResult
8095TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8096 OMPTargetTeamsDistributeParallelForDirective *D) {
8097 DeclarationNameInfo DirName;
8098 getDerived().getSema().StartOpenMPDSABlock(
8099 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8100 D->getLocStart());
8101 auto Res = getDerived().TransformOMPExecutableDirective(D);
8102 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8103 return Res;
8104}
8105
Kelvin Li1851df52017-01-03 05:23:48 +00008106template <typename Derived>
8107StmtResult TreeTransform<Derived>::
8108 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8109 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8110 DeclarationNameInfo DirName;
8111 getDerived().getSema().StartOpenMPDSABlock(
8112 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8113 D->getLocStart());
8114 auto Res = getDerived().TransformOMPExecutableDirective(D);
8115 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8116 return Res;
8117}
8118
Kelvin Lida681182017-01-10 18:08:18 +00008119template <typename Derived>
8120StmtResult
8121TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8122 OMPTargetTeamsDistributeSimdDirective *D) {
8123 DeclarationNameInfo DirName;
8124 getDerived().getSema().StartOpenMPDSABlock(
8125 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8126 auto Res = getDerived().TransformOMPExecutableDirective(D);
8127 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8128 return Res;
8129}
8130
Kelvin Li1851df52017-01-03 05:23:48 +00008131
Alexander Musman64d33f12014-06-04 07:53:32 +00008132//===----------------------------------------------------------------------===//
8133// OpenMP clause transformation
8134//===----------------------------------------------------------------------===//
8135template <typename Derived>
8136OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008137 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8138 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008139 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008140 return getDerived().RebuildOMPIfClause(
8141 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8142 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008143}
8144
Alexander Musman64d33f12014-06-04 07:53:32 +00008145template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008146OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8147 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8148 if (Cond.isInvalid())
8149 return nullptr;
8150 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8151 C->getLParenLoc(), C->getLocEnd());
8152}
8153
8154template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008155OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008156TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8157 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8158 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008159 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008160 return getDerived().RebuildOMPNumThreadsClause(
8161 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00008162}
8163
Alexey Bataev62c87d22014-03-21 04:51:18 +00008164template <typename Derived>
8165OMPClause *
8166TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8167 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8168 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008169 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008170 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008171 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008172}
8173
Alexander Musman8bd31e62014-05-27 15:12:19 +00008174template <typename Derived>
8175OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008176TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8177 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8178 if (E.isInvalid())
8179 return nullptr;
8180 return getDerived().RebuildOMPSimdlenClause(
8181 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8182}
8183
8184template <typename Derived>
8185OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008186TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8187 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8188 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008189 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008190 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008191 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008192}
8193
Alexander Musman64d33f12014-06-04 07:53:32 +00008194template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008195OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008196TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008197 return getDerived().RebuildOMPDefaultClause(
8198 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8199 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008200}
8201
Alexander Musman64d33f12014-06-04 07:53:32 +00008202template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008203OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008204TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008205 return getDerived().RebuildOMPProcBindClause(
8206 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8207 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008208}
8209
Alexander Musman64d33f12014-06-04 07:53:32 +00008210template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008211OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008212TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8213 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8214 if (E.isInvalid())
8215 return nullptr;
8216 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008217 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008218 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008219 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008220 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8221}
8222
8223template <typename Derived>
8224OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008225TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008226 ExprResult E;
8227 if (auto *Num = C->getNumForLoops()) {
8228 E = getDerived().TransformExpr(Num);
8229 if (E.isInvalid())
8230 return nullptr;
8231 }
8232 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8233 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008234}
8235
8236template <typename Derived>
8237OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008238TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8239 // No need to rebuild this clause, no template-dependent parameters.
8240 return C;
8241}
8242
8243template <typename Derived>
8244OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008245TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8246 // No need to rebuild this clause, no template-dependent parameters.
8247 return C;
8248}
8249
8250template <typename Derived>
8251OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008252TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8253 // No need to rebuild this clause, no template-dependent parameters.
8254 return C;
8255}
8256
8257template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008258OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8259 // No need to rebuild this clause, no template-dependent parameters.
8260 return C;
8261}
8262
8263template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008264OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8265 // No need to rebuild this clause, no template-dependent parameters.
8266 return C;
8267}
8268
8269template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008270OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008271TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8272 // No need to rebuild this clause, no template-dependent parameters.
8273 return C;
8274}
8275
8276template <typename Derived>
8277OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008278TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8279 // No need to rebuild this clause, no template-dependent parameters.
8280 return C;
8281}
8282
8283template <typename Derived>
8284OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008285TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8286 // No need to rebuild this clause, no template-dependent parameters.
8287 return C;
8288}
8289
8290template <typename Derived>
8291OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008292TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8293 // No need to rebuild this clause, no template-dependent parameters.
8294 return C;
8295}
8296
8297template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008298OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8299 // No need to rebuild this clause, no template-dependent parameters.
8300 return C;
8301}
8302
8303template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008304OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008305TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8306 // No need to rebuild this clause, no template-dependent parameters.
8307 return C;
8308}
8309
8310template <typename Derived>
8311OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008312TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008313 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008314 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008315 for (auto *VE : C->varlists()) {
8316 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008317 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008318 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008319 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008320 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008321 return getDerived().RebuildOMPPrivateClause(
8322 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008323}
8324
Alexander Musman64d33f12014-06-04 07:53:32 +00008325template <typename Derived>
8326OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8327 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008328 llvm::SmallVector<Expr *, 16> Vars;
8329 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008330 for (auto *VE : C->varlists()) {
8331 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008332 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008333 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008334 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008335 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008336 return getDerived().RebuildOMPFirstprivateClause(
8337 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008338}
8339
Alexander Musman64d33f12014-06-04 07:53:32 +00008340template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008341OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008342TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8343 llvm::SmallVector<Expr *, 16> Vars;
8344 Vars.reserve(C->varlist_size());
8345 for (auto *VE : C->varlists()) {
8346 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8347 if (EVar.isInvalid())
8348 return nullptr;
8349 Vars.push_back(EVar.get());
8350 }
8351 return getDerived().RebuildOMPLastprivateClause(
8352 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8353}
8354
8355template <typename Derived>
8356OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008357TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8358 llvm::SmallVector<Expr *, 16> Vars;
8359 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008360 for (auto *VE : C->varlists()) {
8361 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008362 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008363 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008364 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008365 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008366 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8367 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008368}
8369
Alexander Musman64d33f12014-06-04 07:53:32 +00008370template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008371OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008372TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8373 llvm::SmallVector<Expr *, 16> Vars;
8374 Vars.reserve(C->varlist_size());
8375 for (auto *VE : C->varlists()) {
8376 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8377 if (EVar.isInvalid())
8378 return nullptr;
8379 Vars.push_back(EVar.get());
8380 }
8381 CXXScopeSpec ReductionIdScopeSpec;
8382 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8383
8384 DeclarationNameInfo NameInfo = C->getNameInfo();
8385 if (NameInfo.getName()) {
8386 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8387 if (!NameInfo.getName())
8388 return nullptr;
8389 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008390 // Build a list of all UDR decls with the same names ranged by the Scopes.
8391 // The Scope boundary is a duplication of the previous decl.
8392 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8393 for (auto *E : C->reduction_ops()) {
8394 // Transform all the decls.
8395 if (E) {
8396 auto *ULE = cast<UnresolvedLookupExpr>(E);
8397 UnresolvedSet<8> Decls;
8398 for (auto *D : ULE->decls()) {
8399 NamedDecl *InstD =
8400 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8401 Decls.addDecl(InstD, InstD->getAccess());
8402 }
8403 UnresolvedReductions.push_back(
8404 UnresolvedLookupExpr::Create(
8405 SemaRef.Context, /*NamingClass=*/nullptr,
8406 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8407 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8408 Decls.begin(), Decls.end()));
8409 } else
8410 UnresolvedReductions.push_back(nullptr);
8411 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008412 return getDerived().RebuildOMPReductionClause(
8413 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008414 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008415}
8416
8417template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008418OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8419 OMPTaskReductionClause *C) {
8420 llvm::SmallVector<Expr *, 16> Vars;
8421 Vars.reserve(C->varlist_size());
8422 for (auto *VE : C->varlists()) {
8423 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8424 if (EVar.isInvalid())
8425 return nullptr;
8426 Vars.push_back(EVar.get());
8427 }
8428 CXXScopeSpec ReductionIdScopeSpec;
8429 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8430
8431 DeclarationNameInfo NameInfo = C->getNameInfo();
8432 if (NameInfo.getName()) {
8433 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8434 if (!NameInfo.getName())
8435 return nullptr;
8436 }
8437 // Build a list of all UDR decls with the same names ranged by the Scopes.
8438 // The Scope boundary is a duplication of the previous decl.
8439 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8440 for (auto *E : C->reduction_ops()) {
8441 // Transform all the decls.
8442 if (E) {
8443 auto *ULE = cast<UnresolvedLookupExpr>(E);
8444 UnresolvedSet<8> Decls;
8445 for (auto *D : ULE->decls()) {
8446 NamedDecl *InstD =
8447 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8448 Decls.addDecl(InstD, InstD->getAccess());
8449 }
8450 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8451 SemaRef.Context, /*NamingClass=*/nullptr,
8452 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8453 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8454 } else
8455 UnresolvedReductions.push_back(nullptr);
8456 }
8457 return getDerived().RebuildOMPTaskReductionClause(
8458 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8459 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8460}
8461
8462template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008463OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008464TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8465 llvm::SmallVector<Expr *, 16> Vars;
8466 Vars.reserve(C->varlist_size());
8467 for (auto *VE : C->varlists()) {
8468 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8469 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008470 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008471 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008472 }
8473 ExprResult Step = getDerived().TransformExpr(C->getStep());
8474 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008475 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008476 return getDerived().RebuildOMPLinearClause(
8477 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8478 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008479}
8480
Alexander Musman64d33f12014-06-04 07:53:32 +00008481template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008482OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008483TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8484 llvm::SmallVector<Expr *, 16> Vars;
8485 Vars.reserve(C->varlist_size());
8486 for (auto *VE : C->varlists()) {
8487 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8488 if (EVar.isInvalid())
8489 return nullptr;
8490 Vars.push_back(EVar.get());
8491 }
8492 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8493 if (Alignment.isInvalid())
8494 return nullptr;
8495 return getDerived().RebuildOMPAlignedClause(
8496 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8497 C->getColonLoc(), C->getLocEnd());
8498}
8499
Alexander Musman64d33f12014-06-04 07:53:32 +00008500template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008501OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008502TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8503 llvm::SmallVector<Expr *, 16> Vars;
8504 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008505 for (auto *VE : C->varlists()) {
8506 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008507 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008508 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008509 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008510 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008511 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8512 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008513}
8514
Alexey Bataevbae9a792014-06-27 10:37:06 +00008515template <typename Derived>
8516OMPClause *
8517TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8518 llvm::SmallVector<Expr *, 16> Vars;
8519 Vars.reserve(C->varlist_size());
8520 for (auto *VE : C->varlists()) {
8521 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8522 if (EVar.isInvalid())
8523 return nullptr;
8524 Vars.push_back(EVar.get());
8525 }
8526 return getDerived().RebuildOMPCopyprivateClause(
8527 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8528}
8529
Alexey Bataev6125da92014-07-21 11:26:11 +00008530template <typename Derived>
8531OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8532 llvm::SmallVector<Expr *, 16> Vars;
8533 Vars.reserve(C->varlist_size());
8534 for (auto *VE : C->varlists()) {
8535 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8536 if (EVar.isInvalid())
8537 return nullptr;
8538 Vars.push_back(EVar.get());
8539 }
8540 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8541 C->getLParenLoc(), C->getLocEnd());
8542}
8543
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008544template <typename Derived>
8545OMPClause *
8546TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8547 llvm::SmallVector<Expr *, 16> Vars;
8548 Vars.reserve(C->varlist_size());
8549 for (auto *VE : C->varlists()) {
8550 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8551 if (EVar.isInvalid())
8552 return nullptr;
8553 Vars.push_back(EVar.get());
8554 }
8555 return getDerived().RebuildOMPDependClause(
8556 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8557 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8558}
8559
Michael Wonge710d542015-08-07 16:16:36 +00008560template <typename Derived>
8561OMPClause *
8562TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8563 ExprResult E = getDerived().TransformExpr(C->getDevice());
8564 if (E.isInvalid())
8565 return nullptr;
8566 return getDerived().RebuildOMPDeviceClause(
8567 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8568}
8569
Kelvin Li0bff7af2015-11-23 05:32:03 +00008570template <typename Derived>
8571OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8572 llvm::SmallVector<Expr *, 16> Vars;
8573 Vars.reserve(C->varlist_size());
8574 for (auto *VE : C->varlists()) {
8575 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8576 if (EVar.isInvalid())
8577 return nullptr;
8578 Vars.push_back(EVar.get());
8579 }
8580 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008581 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8582 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8583 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008584}
8585
Kelvin Li099bb8c2015-11-24 20:50:12 +00008586template <typename Derived>
8587OMPClause *
8588TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8589 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8590 if (E.isInvalid())
8591 return nullptr;
8592 return getDerived().RebuildOMPNumTeamsClause(
8593 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8594}
8595
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008596template <typename Derived>
8597OMPClause *
8598TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8599 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8600 if (E.isInvalid())
8601 return nullptr;
8602 return getDerived().RebuildOMPThreadLimitClause(
8603 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8604}
8605
Alexey Bataeva0569352015-12-01 10:17:31 +00008606template <typename Derived>
8607OMPClause *
8608TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8609 ExprResult E = getDerived().TransformExpr(C->getPriority());
8610 if (E.isInvalid())
8611 return nullptr;
8612 return getDerived().RebuildOMPPriorityClause(
8613 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8614}
8615
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008616template <typename Derived>
8617OMPClause *
8618TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8619 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8620 if (E.isInvalid())
8621 return nullptr;
8622 return getDerived().RebuildOMPGrainsizeClause(
8623 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8624}
8625
Alexey Bataev382967a2015-12-08 12:06:20 +00008626template <typename Derived>
8627OMPClause *
8628TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8629 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8630 if (E.isInvalid())
8631 return nullptr;
8632 return getDerived().RebuildOMPNumTasksClause(
8633 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8634}
8635
Alexey Bataev28c75412015-12-15 08:19:24 +00008636template <typename Derived>
8637OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8638 ExprResult E = getDerived().TransformExpr(C->getHint());
8639 if (E.isInvalid())
8640 return nullptr;
8641 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8642 C->getLParenLoc(), C->getLocEnd());
8643}
8644
Carlo Bertollib4adf552016-01-15 18:50:31 +00008645template <typename Derived>
8646OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8647 OMPDistScheduleClause *C) {
8648 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8649 if (E.isInvalid())
8650 return nullptr;
8651 return getDerived().RebuildOMPDistScheduleClause(
8652 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8653 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8654}
8655
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008656template <typename Derived>
8657OMPClause *
8658TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8659 return C;
8660}
8661
Samuel Antao661c0902016-05-26 17:39:58 +00008662template <typename Derived>
8663OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8664 llvm::SmallVector<Expr *, 16> Vars;
8665 Vars.reserve(C->varlist_size());
8666 for (auto *VE : C->varlists()) {
8667 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8668 if (EVar.isInvalid())
8669 return 0;
8670 Vars.push_back(EVar.get());
8671 }
8672 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8673 C->getLParenLoc(), C->getLocEnd());
8674}
8675
Samuel Antaoec172c62016-05-26 17:49:04 +00008676template <typename Derived>
8677OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8678 llvm::SmallVector<Expr *, 16> Vars;
8679 Vars.reserve(C->varlist_size());
8680 for (auto *VE : C->varlists()) {
8681 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8682 if (EVar.isInvalid())
8683 return 0;
8684 Vars.push_back(EVar.get());
8685 }
8686 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8687 C->getLParenLoc(), C->getLocEnd());
8688}
8689
Carlo Bertolli2404b172016-07-13 15:37:16 +00008690template <typename Derived>
8691OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8692 OMPUseDevicePtrClause *C) {
8693 llvm::SmallVector<Expr *, 16> Vars;
8694 Vars.reserve(C->varlist_size());
8695 for (auto *VE : C->varlists()) {
8696 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8697 if (EVar.isInvalid())
8698 return nullptr;
8699 Vars.push_back(EVar.get());
8700 }
8701 return getDerived().RebuildOMPUseDevicePtrClause(
8702 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8703}
8704
Carlo Bertolli70594e92016-07-13 17:16:49 +00008705template <typename Derived>
8706OMPClause *
8707TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8708 llvm::SmallVector<Expr *, 16> Vars;
8709 Vars.reserve(C->varlist_size());
8710 for (auto *VE : C->varlists()) {
8711 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8712 if (EVar.isInvalid())
8713 return nullptr;
8714 Vars.push_back(EVar.get());
8715 }
8716 return getDerived().RebuildOMPIsDevicePtrClause(
8717 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8718}
8719
Douglas Gregorebe10102009-08-20 07:17:43 +00008720//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008721// Expression transformation
8722//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008725TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008726 if (!E->isTypeDependent())
8727 return E;
8728
8729 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8730 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008731}
Mike Stump11289f42009-09-09 15:08:12 +00008732
8733template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008734ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008735TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008736 NestedNameSpecifierLoc QualifierLoc;
8737 if (E->getQualifierLoc()) {
8738 QualifierLoc
8739 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8740 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008741 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008742 }
John McCallce546572009-12-08 09:08:17 +00008743
8744 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008745 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8746 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008747 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008749
John McCall815039a2010-08-17 21:27:17 +00008750 DeclarationNameInfo NameInfo = E->getNameInfo();
8751 if (NameInfo.getName()) {
8752 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8753 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008754 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008755 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008756
8757 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008758 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008759 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008760 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008761 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008762
8763 // Mark it referenced in the new context regardless.
8764 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008765 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008766
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008767 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008768 }
John McCallce546572009-12-08 09:08:17 +00008769
Craig Topperc3ec1492014-05-26 06:22:03 +00008770 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008771 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008772 TemplateArgs = &TransArgs;
8773 TransArgs.setLAngleLoc(E->getLAngleLoc());
8774 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008775 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8776 E->getNumTemplateArgs(),
8777 TransArgs))
8778 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008779 }
8780
Chad Rosier1dcde962012-08-08 18:46:20 +00008781 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008782 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008783}
Mike Stump11289f42009-09-09 15:08:12 +00008784
Douglas Gregora16548e2009-08-11 05:31:07 +00008785template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008786ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008787TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008788 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008789}
Mike Stump11289f42009-09-09 15:08:12 +00008790
Douglas Gregora16548e2009-08-11 05:31:07 +00008791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008792ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008793TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008794 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008795}
Mike Stump11289f42009-09-09 15:08:12 +00008796
Douglas Gregora16548e2009-08-11 05:31:07 +00008797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008799TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008800 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008801}
Mike Stump11289f42009-09-09 15:08:12 +00008802
Douglas Gregora16548e2009-08-11 05:31:07 +00008803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008805TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008807}
Mike Stump11289f42009-09-09 15:08:12 +00008808
Douglas Gregora16548e2009-08-11 05:31:07 +00008809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008811TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008812 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008813}
8814
8815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008816ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008817TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008818 if (FunctionDecl *FD = E->getDirectCallee())
8819 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008820 return SemaRef.MaybeBindToTemporary(E);
8821}
8822
8823template<typename Derived>
8824ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008825TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8826 ExprResult ControllingExpr =
8827 getDerived().TransformExpr(E->getControllingExpr());
8828 if (ControllingExpr.isInvalid())
8829 return ExprError();
8830
Chris Lattner01cf8db2011-07-20 06:58:45 +00008831 SmallVector<Expr *, 4> AssocExprs;
8832 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008833 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8834 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8835 if (TS) {
8836 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8837 if (!AssocType)
8838 return ExprError();
8839 AssocTypes.push_back(AssocType);
8840 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008841 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008842 }
8843
8844 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8845 if (AssocExpr.isInvalid())
8846 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008847 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008848 }
8849
8850 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8851 E->getDefaultLoc(),
8852 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008853 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008854 AssocTypes,
8855 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008856}
8857
8858template<typename Derived>
8859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008860TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008861 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008862 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008863 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008864
Douglas Gregora16548e2009-08-11 05:31:07 +00008865 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008866 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008867
John McCallb268a282010-08-23 23:25:46 +00008868 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008869 E->getRParen());
8870}
8871
Richard Smithdb2630f2012-10-21 03:28:35 +00008872/// \brief The operand of a unary address-of operator has special rules: it's
8873/// allowed to refer to a non-static member of a class even if there's no 'this'
8874/// object available.
8875template<typename Derived>
8876ExprResult
8877TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8878 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008879 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008880 else
8881 return getDerived().TransformExpr(E);
8882}
8883
Mike Stump11289f42009-09-09 15:08:12 +00008884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008886TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008887 ExprResult SubExpr;
8888 if (E->getOpcode() == UO_AddrOf)
8889 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8890 else
8891 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008892 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008893 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008894
Douglas Gregora16548e2009-08-11 05:31:07 +00008895 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008896 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008897
Douglas Gregora16548e2009-08-11 05:31:07 +00008898 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
8899 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008900 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008901}
Mike Stump11289f42009-09-09 15:08:12 +00008902
Douglas Gregora16548e2009-08-11 05:31:07 +00008903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008904ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00008905TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
8906 // Transform the type.
8907 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
8908 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00008909 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008910
Douglas Gregor882211c2010-04-28 22:16:22 +00008911 // Transform all of the components into components similar to what the
8912 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00008913 // FIXME: It would be slightly more efficient in the non-dependent case to
8914 // just map FieldDecls, rather than requiring the rebuilder to look for
8915 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00008916 // template code that we don't care.
8917 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00008918 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00008919 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00008920 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00008921 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00008922 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00008923 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00008924 Comp.LocStart = ON.getSourceRange().getBegin();
8925 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00008926 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00008927 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00008928 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00008929 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00008930 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008931 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008932
Douglas Gregor882211c2010-04-28 22:16:22 +00008933 ExprChanged = ExprChanged || Index.get() != FromIndex;
8934 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00008935 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00008936 break;
8937 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008938
James Y Knight7281c352015-12-29 22:31:18 +00008939 case OffsetOfNode::Field:
8940 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00008941 Comp.isBrackets = false;
8942 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00008943 if (!Comp.U.IdentInfo)
8944 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00008945
Douglas Gregor882211c2010-04-28 22:16:22 +00008946 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00008947
James Y Knight7281c352015-12-29 22:31:18 +00008948 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00008949 // Will be recomputed during the rebuild.
8950 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00008951 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008952
Douglas Gregor882211c2010-04-28 22:16:22 +00008953 Components.push_back(Comp);
8954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008955
Douglas Gregor882211c2010-04-28 22:16:22 +00008956 // If nothing changed, retain the existing expression.
8957 if (!getDerived().AlwaysRebuild() &&
8958 Type == E->getTypeSourceInfo() &&
8959 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008960 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00008961
Douglas Gregor882211c2010-04-28 22:16:22 +00008962 // Build a new offsetof expression.
8963 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00008964 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00008965}
8966
8967template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008968ExprResult
John McCall8d69a212010-11-15 23:31:06 +00008969TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00008970 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00008971 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008972 return E;
John McCall8d69a212010-11-15 23:31:06 +00008973}
8974
8975template<typename Derived>
8976ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00008977TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
8978 return E;
8979}
8980
8981template<typename Derived>
8982ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00008983TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00008984 // Rebuild the syntactic form. The original syntactic form has
8985 // opaque-value expressions in it, so strip those away and rebuild
8986 // the result. This is a really awful way of doing this, but the
8987 // better solution (rebuilding the semantic expressions and
8988 // rebinding OVEs as necessary) doesn't work; we'd need
8989 // TreeTransform to not strip away implicit conversions.
8990 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
8991 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00008992 if (result.isInvalid()) return ExprError();
8993
8994 // If that gives us a pseudo-object result back, the pseudo-object
8995 // expression must have been an lvalue-to-rvalue conversion which we
8996 // should reapply.
8997 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008998 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00008999
9000 return result;
9001}
9002
9003template<typename Derived>
9004ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009005TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9006 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009007 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009008 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009009
John McCallbcd03502009-12-07 02:54:59 +00009010 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009011 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009012 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009013
John McCall4c98fd82009-11-04 07:28:41 +00009014 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009015 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009016
Peter Collingbournee190dee2011-03-11 19:24:49 +00009017 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9018 E->getKind(),
9019 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009020 }
Mike Stump11289f42009-09-09 15:08:12 +00009021
Eli Friedmane4f22df2012-02-29 04:03:55 +00009022 // C++0x [expr.sizeof]p1:
9023 // The operand is either an expression, which is an unevaluated operand
9024 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009025 EnterExpressionEvaluationContext Unevaluated(
9026 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9027 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009028
Reid Kleckner32506ed2014-06-12 23:03:48 +00009029 // Try to recover if we have something like sizeof(T::X) where X is a type.
9030 // Notably, there must be *exactly* one set of parens if X is a type.
9031 TypeSourceInfo *RecoveryTSI = nullptr;
9032 ExprResult SubExpr;
9033 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9034 if (auto *DRE =
9035 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9036 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9037 PE, DRE, false, &RecoveryTSI);
9038 else
9039 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9040
9041 if (RecoveryTSI) {
9042 return getDerived().RebuildUnaryExprOrTypeTrait(
9043 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9044 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009045 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009046
Eli Friedmane4f22df2012-02-29 04:03:55 +00009047 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009048 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009049
Peter Collingbournee190dee2011-03-11 19:24:49 +00009050 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9051 E->getOperatorLoc(),
9052 E->getKind(),
9053 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009054}
Mike Stump11289f42009-09-09 15:08:12 +00009055
Douglas Gregora16548e2009-08-11 05:31:07 +00009056template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009057ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009058TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009059 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009060 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009062
John McCalldadc5752010-08-24 06:29:42 +00009063 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009064 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009065 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009066
9067
Douglas Gregora16548e2009-08-11 05:31:07 +00009068 if (!getDerived().AlwaysRebuild() &&
9069 LHS.get() == E->getLHS() &&
9070 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009071 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009072
John McCallb268a282010-08-23 23:25:46 +00009073 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009074 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009075 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009076 E->getRBracketLoc());
9077}
Mike Stump11289f42009-09-09 15:08:12 +00009078
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009079template <typename Derived>
9080ExprResult
9081TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9082 ExprResult Base = getDerived().TransformExpr(E->getBase());
9083 if (Base.isInvalid())
9084 return ExprError();
9085
9086 ExprResult LowerBound;
9087 if (E->getLowerBound()) {
9088 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9089 if (LowerBound.isInvalid())
9090 return ExprError();
9091 }
9092
9093 ExprResult Length;
9094 if (E->getLength()) {
9095 Length = getDerived().TransformExpr(E->getLength());
9096 if (Length.isInvalid())
9097 return ExprError();
9098 }
9099
9100 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9101 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9102 return E;
9103
9104 return getDerived().RebuildOMPArraySectionExpr(
9105 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9106 Length.get(), E->getRBracketLoc());
9107}
9108
Mike Stump11289f42009-09-09 15:08:12 +00009109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009111TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009112 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009113 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009114 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009115 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009116
9117 // Transform arguments.
9118 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009119 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009120 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009121 &ArgChanged))
9122 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Douglas Gregora16548e2009-08-11 05:31:07 +00009124 if (!getDerived().AlwaysRebuild() &&
9125 Callee.get() == E->getCallee() &&
9126 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009127 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009128
Douglas Gregora16548e2009-08-11 05:31:07 +00009129 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009130 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009131 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009132 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009133 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009134 E->getRParenLoc());
9135}
Mike Stump11289f42009-09-09 15:08:12 +00009136
9137template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009138ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009139TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009140 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009141 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009143
Douglas Gregorea972d32011-02-28 21:54:11 +00009144 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009145 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009146 QualifierLoc
9147 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009148
Douglas Gregorea972d32011-02-28 21:54:11 +00009149 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009150 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009151 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009152 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009153
Eli Friedman2cfcef62009-12-04 06:40:45 +00009154 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009155 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9156 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009157 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009158 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009159
John McCall16df1e52010-03-30 21:47:33 +00009160 NamedDecl *FoundDecl = E->getFoundDecl();
9161 if (FoundDecl == E->getMemberDecl()) {
9162 FoundDecl = Member;
9163 } else {
9164 FoundDecl = cast_or_null<NamedDecl>(
9165 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9166 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009167 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009168 }
9169
Douglas Gregora16548e2009-08-11 05:31:07 +00009170 if (!getDerived().AlwaysRebuild() &&
9171 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009172 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009173 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009174 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009175 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009176
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009177 // Mark it referenced in the new context regardless.
9178 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009179 SemaRef.MarkMemberReferenced(E);
9180
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009181 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009182 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009183
John McCall6b51f282009-11-23 01:53:49 +00009184 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009185 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009186 TransArgs.setLAngleLoc(E->getLAngleLoc());
9187 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009188 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9189 E->getNumTemplateArgs(),
9190 TransArgs))
9191 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009192 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009193
Douglas Gregora16548e2009-08-11 05:31:07 +00009194 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009195 SourceLocation FakeOperatorLoc =
9196 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009197
John McCall38836f02010-01-15 08:34:02 +00009198 // FIXME: to do this check properly, we will need to preserve the
9199 // first-qualifier-in-scope here, just in case we had a dependent
9200 // base (and therefore couldn't do the check) and a
9201 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009202 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009203 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9204 if (MemberNameInfo.getName()) {
9205 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9206 if (!MemberNameInfo.getName())
9207 return ExprError();
9208 }
John McCall38836f02010-01-15 08:34:02 +00009209
John McCallb268a282010-08-23 23:25:46 +00009210 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009211 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009212 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009213 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009214 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009215 Member,
John McCall16df1e52010-03-30 21:47:33 +00009216 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009217 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009218 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009219 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009220}
Mike Stump11289f42009-09-09 15:08:12 +00009221
Douglas Gregora16548e2009-08-11 05:31:07 +00009222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009224TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009225 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009226 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009227 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009228
John McCalldadc5752010-08-24 06:29:42 +00009229 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009230 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009231 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009232
Douglas Gregora16548e2009-08-11 05:31:07 +00009233 if (!getDerived().AlwaysRebuild() &&
9234 LHS.get() == E->getLHS() &&
9235 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009236 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009237
Lang Hames5de91cc2012-10-02 04:45:10 +00009238 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009239 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009240
Douglas Gregora16548e2009-08-11 05:31:07 +00009241 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009242 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009243}
9244
Mike Stump11289f42009-09-09 15:08:12 +00009245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009246ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009247TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009248 CompoundAssignOperator *E) {
9249 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009250}
Mike Stump11289f42009-09-09 15:08:12 +00009251
Douglas Gregora16548e2009-08-11 05:31:07 +00009252template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009253ExprResult TreeTransform<Derived>::
9254TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9255 // Just rebuild the common and RHS expressions and see whether we
9256 // get any changes.
9257
9258 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9259 if (commonExpr.isInvalid())
9260 return ExprError();
9261
9262 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9263 if (rhs.isInvalid())
9264 return ExprError();
9265
9266 if (!getDerived().AlwaysRebuild() &&
9267 commonExpr.get() == e->getCommon() &&
9268 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009269 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009270
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009271 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009272 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009273 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009274 e->getColonLoc(),
9275 rhs.get());
9276}
9277
9278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009279ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009280TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009281 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009282 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009283 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009284
John McCalldadc5752010-08-24 06:29:42 +00009285 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009286 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009287 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009288
John McCalldadc5752010-08-24 06:29:42 +00009289 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009290 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009292
Douglas Gregora16548e2009-08-11 05:31:07 +00009293 if (!getDerived().AlwaysRebuild() &&
9294 Cond.get() == E->getCond() &&
9295 LHS.get() == E->getLHS() &&
9296 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009297 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009298
John McCallb268a282010-08-23 23:25:46 +00009299 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009300 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009301 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009302 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009303 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009304}
Mike Stump11289f42009-09-09 15:08:12 +00009305
9306template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009307ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009308TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009309 // Implicit casts are eliminated during transformation, since they
9310 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009311 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009312}
Mike Stump11289f42009-09-09 15:08:12 +00009313
Douglas Gregora16548e2009-08-11 05:31:07 +00009314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009316TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009317 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9318 if (!Type)
9319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009320
John McCalldadc5752010-08-24 06:29:42 +00009321 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009322 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009323 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009324 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009325
Douglas Gregora16548e2009-08-11 05:31:07 +00009326 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009327 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009328 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009329 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009330
John McCall97513962010-01-15 18:39:57 +00009331 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009332 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009333 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009334 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009335}
Mike Stump11289f42009-09-09 15:08:12 +00009336
Douglas Gregora16548e2009-08-11 05:31:07 +00009337template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009338ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009339TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009340 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9341 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9342 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009343 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009344
John McCalldadc5752010-08-24 06:29:42 +00009345 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009346 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009348
Douglas Gregora16548e2009-08-11 05:31:07 +00009349 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009350 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009351 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009352 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009353
John McCall5d7aa7f2010-01-19 22:33:45 +00009354 // Note: the expression type doesn't necessarily match the
9355 // type-as-written, but that's okay, because it should always be
9356 // derivable from the initializer.
9357
John McCalle15bbff2010-01-18 19:35:47 +00009358 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009359 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009360 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009361}
Mike Stump11289f42009-09-09 15:08:12 +00009362
Douglas Gregora16548e2009-08-11 05:31:07 +00009363template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009364ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009365TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009366 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009367 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009369
Douglas Gregora16548e2009-08-11 05:31:07 +00009370 if (!getDerived().AlwaysRebuild() &&
9371 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009372 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009373
Douglas Gregora16548e2009-08-11 05:31:07 +00009374 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009375 SourceLocation FakeOperatorLoc =
9376 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009377 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009378 E->getAccessorLoc(),
9379 E->getAccessor());
9380}
Mike Stump11289f42009-09-09 15:08:12 +00009381
Douglas Gregora16548e2009-08-11 05:31:07 +00009382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009383ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009384TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009385 if (InitListExpr *Syntactic = E->getSyntacticForm())
9386 E = Syntactic;
9387
Douglas Gregora16548e2009-08-11 05:31:07 +00009388 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009389
Benjamin Kramerf0623432012-08-23 22:51:59 +00009390 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009391 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009392 Inits, &InitChanged))
9393 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009394
Richard Smith520449d2015-02-05 06:15:50 +00009395 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9396 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9397 // in some cases. We can't reuse it in general, because the syntactic and
9398 // semantic forms are linked, and we can't know that semantic form will
9399 // match even if the syntactic form does.
9400 }
Mike Stump11289f42009-09-09 15:08:12 +00009401
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009402 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00009403 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00009404}
Mike Stump11289f42009-09-09 15:08:12 +00009405
Douglas Gregora16548e2009-08-11 05:31:07 +00009406template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009407ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009408TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009409 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009410
Douglas Gregorebe10102009-08-20 07:17:43 +00009411 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009412 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009413 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009414 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009415
Douglas Gregorebe10102009-08-20 07:17:43 +00009416 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009417 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009418 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009419 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9420 if (D.isFieldDesignator()) {
9421 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9422 D.getDotLoc(),
9423 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009424 if (D.getField()) {
9425 FieldDecl *Field = cast_or_null<FieldDecl>(
9426 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9427 if (Field != D.getField())
9428 // Rebuild the expression when the transformed FieldDecl is
9429 // different to the already assigned FieldDecl.
9430 ExprChanged = true;
9431 } else {
9432 // Ensure that the designator expression is rebuilt when there isn't
9433 // a resolved FieldDecl in the designator as we don't want to assign
9434 // a FieldDecl to a pattern designator that will be instantiated again.
9435 ExprChanged = true;
9436 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009437 continue;
9438 }
Mike Stump11289f42009-09-09 15:08:12 +00009439
David Majnemerf7e36092016-06-23 00:15:04 +00009440 if (D.isArrayDesignator()) {
9441 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009442 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009443 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009444
David Majnemerf7e36092016-06-23 00:15:04 +00009445 Desig.AddDesignator(
9446 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009447
David Majnemerf7e36092016-06-23 00:15:04 +00009448 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009449 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 continue;
9451 }
Mike Stump11289f42009-09-09 15:08:12 +00009452
David Majnemerf7e36092016-06-23 00:15:04 +00009453 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009454 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009455 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009456 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009457 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009458
David Majnemerf7e36092016-06-23 00:15:04 +00009459 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009460 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009461 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009462
9463 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009464 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009465 D.getLBracketLoc(),
9466 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009467
David Majnemerf7e36092016-06-23 00:15:04 +00009468 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9469 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009470
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009471 ArrayExprs.push_back(Start.get());
9472 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009473 }
Mike Stump11289f42009-09-09 15:08:12 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475 if (!getDerived().AlwaysRebuild() &&
9476 Init.get() == E->getInit() &&
9477 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009478 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009479
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009480 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009481 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009482 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009483}
Mike Stump11289f42009-09-09 15:08:12 +00009484
Yunzhong Gaocb779302015-06-10 00:27:52 +00009485// Seems that if TransformInitListExpr() only works on the syntactic form of an
9486// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9487template<typename Derived>
9488ExprResult
9489TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9490 DesignatedInitUpdateExpr *E) {
9491 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9492 "initializer");
9493 return ExprError();
9494}
9495
9496template<typename Derived>
9497ExprResult
9498TreeTransform<Derived>::TransformNoInitExpr(
9499 NoInitExpr *E) {
9500 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9501 return ExprError();
9502}
9503
Douglas Gregora16548e2009-08-11 05:31:07 +00009504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009505ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009506TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9507 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9508 return ExprError();
9509}
9510
9511template<typename Derived>
9512ExprResult
9513TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9514 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9515 return ExprError();
9516}
9517
9518template<typename Derived>
9519ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009520TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009521 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009522 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009523
Douglas Gregor3da3c062009-10-28 00:29:27 +00009524 // FIXME: Will we ever have proper type location here? Will we actually
9525 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009526 QualType T = getDerived().TransformType(E->getType());
9527 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009529
Douglas Gregora16548e2009-08-11 05:31:07 +00009530 if (!getDerived().AlwaysRebuild() &&
9531 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009532 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009533
Douglas Gregora16548e2009-08-11 05:31:07 +00009534 return getDerived().RebuildImplicitValueInitExpr(T);
9535}
Mike Stump11289f42009-09-09 15:08:12 +00009536
Douglas Gregora16548e2009-08-11 05:31:07 +00009537template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009538ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009539TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009540 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9541 if (!TInfo)
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 SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009545 if (SubExpr.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() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009549 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009550 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009551 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009552
John McCallb268a282010-08-23 23:25:46 +00009553 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009554 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009555}
9556
9557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009558ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009559TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009560 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009561 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009562 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9563 &ArgumentChanged))
9564 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009565
Douglas Gregora16548e2009-08-11 05:31:07 +00009566 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009567 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009568 E->getRParenLoc());
9569}
Mike Stump11289f42009-09-09 15:08:12 +00009570
Douglas Gregora16548e2009-08-11 05:31:07 +00009571/// \brief Transform an address-of-label expression.
9572///
9573/// By default, the transformation of an address-of-label expression always
9574/// rebuilds the expression, so that the label identifier can be resolved to
9575/// the corresponding label statement by semantic analysis.
9576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009578TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009579 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9580 E->getLabel());
9581 if (!LD)
9582 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009583
Douglas Gregora16548e2009-08-11 05:31:07 +00009584 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009585 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009586}
Mike Stump11289f42009-09-09 15:08:12 +00009587
9588template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009590TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009591 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009592 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009593 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009594 if (SubStmt.isInvalid()) {
9595 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009596 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009597 }
Mike Stump11289f42009-09-09 15:08:12 +00009598
Douglas Gregora16548e2009-08-11 05:31:07 +00009599 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009600 SubStmt.get() == E->getSubStmt()) {
9601 // Calling this an 'error' is unintuitive, but it does the right thing.
9602 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009603 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009604 }
Mike Stump11289f42009-09-09 15:08:12 +00009605
9606 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009607 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009608 E->getRParenLoc());
9609}
Mike Stump11289f42009-09-09 15:08:12 +00009610
Douglas Gregora16548e2009-08-11 05:31:07 +00009611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009613TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009614 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009615 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009616 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009617
John McCalldadc5752010-08-24 06:29:42 +00009618 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009619 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009620 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009621
John McCalldadc5752010-08-24 06:29:42 +00009622 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009623 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009624 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009625
Douglas Gregora16548e2009-08-11 05:31:07 +00009626 if (!getDerived().AlwaysRebuild() &&
9627 Cond.get() == E->getCond() &&
9628 LHS.get() == E->getLHS() &&
9629 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009630 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009631
Douglas Gregora16548e2009-08-11 05:31:07 +00009632 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009633 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009634 E->getRParenLoc());
9635}
Mike Stump11289f42009-09-09 15:08:12 +00009636
Douglas Gregora16548e2009-08-11 05:31:07 +00009637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009638ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009639TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009640 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009641}
9642
9643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009644ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009645TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009646 switch (E->getOperator()) {
9647 case OO_New:
9648 case OO_Delete:
9649 case OO_Array_New:
9650 case OO_Array_Delete:
9651 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009652
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009653 case OO_Call: {
9654 // This is a call to an object's operator().
9655 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9656
9657 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009658 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009659 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009660 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009661
9662 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009663 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9664 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009665
9666 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009667 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009668 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009669 Args))
9670 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009671
John McCallb268a282010-08-23 23:25:46 +00009672 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009673 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009674 E->getLocEnd());
9675 }
9676
9677#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9678 case OO_##Name:
9679#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9680#include "clang/Basic/OperatorKinds.def"
9681 case OO_Subscript:
9682 // Handled below.
9683 break;
9684
9685 case OO_Conditional:
9686 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009687
9688 case OO_None:
9689 case NUM_OVERLOADED_OPERATORS:
9690 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009691 }
9692
John McCalldadc5752010-08-24 06:29:42 +00009693 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009696
Richard Smithdb2630f2012-10-21 03:28:35 +00009697 ExprResult First;
9698 if (E->getOperator() == OO_Amp)
9699 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9700 else
9701 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009702 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009703 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009704
John McCalldadc5752010-08-24 06:29:42 +00009705 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009706 if (E->getNumArgs() == 2) {
9707 Second = getDerived().TransformExpr(E->getArg(1));
9708 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009709 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009710 }
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregora16548e2009-08-11 05:31:07 +00009712 if (!getDerived().AlwaysRebuild() &&
9713 Callee.get() == E->getCallee() &&
9714 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009715 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009716 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009717
Lang Hames5de91cc2012-10-02 04:45:10 +00009718 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009719 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009720
Douglas Gregora16548e2009-08-11 05:31:07 +00009721 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9722 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009723 Callee.get(),
9724 First.get(),
9725 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009726}
Mike Stump11289f42009-09-09 15:08:12 +00009727
Douglas Gregora16548e2009-08-11 05:31:07 +00009728template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009729ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009730TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9731 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009732}
Mike Stump11289f42009-09-09 15:08:12 +00009733
Douglas Gregora16548e2009-08-11 05:31:07 +00009734template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009735ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009736TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9737 // Transform the callee.
9738 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9739 if (Callee.isInvalid())
9740 return ExprError();
9741
9742 // Transform exec config.
9743 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9744 if (EC.isInvalid())
9745 return ExprError();
9746
9747 // Transform arguments.
9748 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009749 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009750 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009751 &ArgChanged))
9752 return ExprError();
9753
9754 if (!getDerived().AlwaysRebuild() &&
9755 Callee.get() == E->getCallee() &&
9756 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009757 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009758
9759 // FIXME: Wrong source location information for the '('.
9760 SourceLocation FakeLParenLoc
9761 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9762 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009763 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009764 E->getRParenLoc(), EC.get());
9765}
9766
9767template<typename Derived>
9768ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009769TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009770 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9771 if (!Type)
9772 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009773
John McCalldadc5752010-08-24 06:29:42 +00009774 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009775 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009776 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009780 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009782 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009783 return getDerived().RebuildCXXNamedCastExpr(
9784 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9785 Type, E->getAngleBrackets().getEnd(),
9786 // FIXME. this should be '(' location
9787 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009788}
Mike Stump11289f42009-09-09 15:08:12 +00009789
Douglas Gregora16548e2009-08-11 05:31:07 +00009790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009791ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009792TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9793 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009794}
Mike Stump11289f42009-09-09 15:08:12 +00009795
9796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009797ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009798TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9799 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009800}
9801
Douglas Gregora16548e2009-08-11 05:31:07 +00009802template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009803ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009804TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009805 CXXReinterpretCastExpr *E) {
9806 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009807}
Mike Stump11289f42009-09-09 15:08:12 +00009808
Douglas Gregora16548e2009-08-11 05:31:07 +00009809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009811TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9812 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009813}
Mike Stump11289f42009-09-09 15:08:12 +00009814
Douglas Gregora16548e2009-08-11 05:31:07 +00009815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009816ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009817TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009818 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009819 TypeSourceInfo *Type =
9820 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009821 if (!Type)
9822 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009823
John McCalldadc5752010-08-24 06:29:42 +00009824 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009825 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009826 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009828
Douglas Gregora16548e2009-08-11 05:31:07 +00009829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009830 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009831 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009832 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009833
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009834 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009835 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009836 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009837 E->getRParenLoc());
9838}
Mike Stump11289f42009-09-09 15:08:12 +00009839
Douglas Gregora16548e2009-08-11 05:31:07 +00009840template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009841ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009842TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009843 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009844 TypeSourceInfo *TInfo
9845 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9846 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009847 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009848
Douglas Gregora16548e2009-08-11 05:31:07 +00009849 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009850 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009851 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009852
Douglas Gregor9da64192010-04-26 22:37:10 +00009853 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9854 E->getLocStart(),
9855 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009856 E->getLocEnd());
9857 }
Mike Stump11289f42009-09-09 15:08:12 +00009858
Eli Friedman456f0182012-01-20 01:26:23 +00009859 // We don't know whether the subexpression is potentially evaluated until
9860 // after we perform semantic analysis. We speculatively assume it is
9861 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009862 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +00009863 EnterExpressionEvaluationContext Unevaluated(
9864 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9865 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009866
John McCalldadc5752010-08-24 06:29:42 +00009867 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009868 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009869 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009870
Douglas Gregora16548e2009-08-11 05:31:07 +00009871 if (!getDerived().AlwaysRebuild() &&
9872 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009873 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009874
Douglas Gregor9da64192010-04-26 22:37:10 +00009875 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9876 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009877 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009878 E->getLocEnd());
9879}
9880
9881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009882ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009883TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9884 if (E->isTypeOperand()) {
9885 TypeSourceInfo *TInfo
9886 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9887 if (!TInfo)
9888 return ExprError();
9889
9890 if (!getDerived().AlwaysRebuild() &&
9891 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009892 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009893
Douglas Gregor69735112011-03-06 17:40:41 +00009894 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009895 E->getLocStart(),
9896 TInfo,
9897 E->getLocEnd());
9898 }
9899
Faisal Valid143a0c2017-04-01 21:30:49 +00009900 EnterExpressionEvaluationContext Unevaluated(
9901 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +00009902
9903 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
9904 if (SubExpr.isInvalid())
9905 return ExprError();
9906
9907 if (!getDerived().AlwaysRebuild() &&
9908 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009909 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009910
9911 return getDerived().RebuildCXXUuidofExpr(E->getType(),
9912 E->getLocStart(),
9913 SubExpr.get(),
9914 E->getLocEnd());
9915}
9916
9917template<typename Derived>
9918ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009919TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009920 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009921}
Mike Stump11289f42009-09-09 15:08:12 +00009922
Douglas Gregora16548e2009-08-11 05:31:07 +00009923template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009924ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009925TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009926 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009927 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009928}
Mike Stump11289f42009-09-09 15:08:12 +00009929
Douglas Gregora16548e2009-08-11 05:31:07 +00009930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009931ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009932TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00009933 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00009934
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009935 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
9936 // Make sure that we capture 'this'.
9937 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009938 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00009939 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009940
Douglas Gregorb15af892010-01-07 23:12:05 +00009941 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009942}
Mike Stump11289f42009-09-09 15:08:12 +00009943
Douglas Gregora16548e2009-08-11 05:31:07 +00009944template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009945ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009946TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009947 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009948 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009949 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009950
Douglas Gregora16548e2009-08-11 05:31:07 +00009951 if (!getDerived().AlwaysRebuild() &&
9952 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009953 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009954
Douglas Gregor53e191ed2011-07-06 22:04:06 +00009955 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
9956 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00009957}
Mike Stump11289f42009-09-09 15:08:12 +00009958
Douglas Gregora16548e2009-08-11 05:31:07 +00009959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009961TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00009962 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009963 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
9964 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009965 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00009966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009967
Chandler Carruth794da4c2010-02-08 06:42:49 +00009968 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009969 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009970 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009971
Douglas Gregor033f6752009-12-23 23:03:06 +00009972 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00009973}
Mike Stump11289f42009-09-09 15:08:12 +00009974
Douglas Gregora16548e2009-08-11 05:31:07 +00009975template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009976ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00009977TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
9978 FieldDecl *Field
9979 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
9980 E->getField()));
9981 if (!Field)
9982 return ExprError();
9983
9984 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009985 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00009986
9987 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
9988}
9989
9990template<typename Derived>
9991ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00009992TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
9993 CXXScalarValueInitExpr *E) {
9994 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9995 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009996 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009997
Douglas Gregora16548e2009-08-11 05:31:07 +00009998 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009999 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010000 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010001
Chad Rosier1dcde962012-08-08 18:46:20 +000010002 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010003 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010004 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010005}
Mike Stump11289f42009-09-09 15:08:12 +000010006
Douglas Gregora16548e2009-08-11 05:31:07 +000010007template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010008ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010009TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010010 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010011 TypeSourceInfo *AllocTypeInfo =
10012 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010013 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010014 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010015
Douglas Gregora16548e2009-08-11 05:31:07 +000010016 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010017 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010018 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010019 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010020
Douglas Gregora16548e2009-08-11 05:31:07 +000010021 // Transform the placement arguments (if any).
10022 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010023 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010024 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010025 E->getNumPlacementArgs(), true,
10026 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010027 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010028
Sebastian Redl6047f072012-02-16 12:22:20 +000010029 // Transform the initializer (if any).
10030 Expr *OldInit = E->getInitializer();
10031 ExprResult NewInit;
10032 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010033 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010034 if (NewInit.isInvalid())
10035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010036
Sebastian Redl6047f072012-02-16 12:22:20 +000010037 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010038 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010039 if (E->getOperatorNew()) {
10040 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010041 getDerived().TransformDecl(E->getLocStart(),
10042 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010043 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010044 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010045 }
10046
Craig Topperc3ec1492014-05-26 06:22:03 +000010047 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010048 if (E->getOperatorDelete()) {
10049 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010050 getDerived().TransformDecl(E->getLocStart(),
10051 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010052 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010053 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010054 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010055
Douglas Gregora16548e2009-08-11 05:31:07 +000010056 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010057 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010058 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010059 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010060 OperatorNew == E->getOperatorNew() &&
10061 OperatorDelete == E->getOperatorDelete() &&
10062 !ArgumentChanged) {
10063 // Mark any declarations we need as referenced.
10064 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010065 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010066 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010067 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010068 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010069
Sebastian Redl6047f072012-02-16 12:22:20 +000010070 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010071 QualType ElementType
10072 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10073 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10074 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10075 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +000010076 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010077 }
10078 }
10079 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010080
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010081 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010082 }
Mike Stump11289f42009-09-09 15:08:12 +000010083
Douglas Gregor0744ef62010-09-07 21:49:58 +000010084 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010085 if (!ArraySize.get()) {
10086 // If no array size was specified, but the new expression was
10087 // instantiated with an array type (e.g., "new T" where T is
10088 // instantiated with "int[4]"), extract the outer bound from the
10089 // array type as our array size. We do this with constant and
10090 // dependently-sized array types.
10091 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10092 if (!ArrayT) {
10093 // Do nothing
10094 } else if (const ConstantArrayType *ConsArrayT
10095 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010096 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10097 SemaRef.Context.getSizeType(),
10098 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010099 AllocType = ConsArrayT->getElementType();
10100 } else if (const DependentSizedArrayType *DepArrayT
10101 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10102 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010103 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010104 AllocType = DepArrayT->getElementType();
10105 }
10106 }
10107 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010108
Douglas Gregora16548e2009-08-11 05:31:07 +000010109 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10110 E->isGlobalNew(),
10111 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010112 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010113 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010114 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010115 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010116 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010117 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010118 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010119 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010120}
Mike Stump11289f42009-09-09 15:08:12 +000010121
Douglas Gregora16548e2009-08-11 05:31:07 +000010122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010123ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010124TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010125 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010126 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010127 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010128
Douglas Gregord2d9da02010-02-26 00:38:10 +000010129 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010130 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010131 if (E->getOperatorDelete()) {
10132 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010133 getDerived().TransformDecl(E->getLocStart(),
10134 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010135 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010136 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010137 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010138
Douglas Gregora16548e2009-08-11 05:31:07 +000010139 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010140 Operand.get() == E->getArgument() &&
10141 OperatorDelete == E->getOperatorDelete()) {
10142 // Mark any declarations we need as referenced.
10143 // FIXME: instantiation-specific.
10144 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010145 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010146
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010147 if (!E->getArgument()->isTypeDependent()) {
10148 QualType Destroyed = SemaRef.Context.getBaseElementType(
10149 E->getDestroyedType());
10150 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10151 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010152 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010153 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010154 }
10155 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010156
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010157 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010158 }
Mike Stump11289f42009-09-09 15:08:12 +000010159
Douglas Gregora16548e2009-08-11 05:31:07 +000010160 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10161 E->isGlobalDelete(),
10162 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010163 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010164}
Mike Stump11289f42009-09-09 15:08:12 +000010165
Douglas Gregora16548e2009-08-11 05:31:07 +000010166template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010167ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010168TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010169 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010170 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010171 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010172 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010173
John McCallba7bf592010-08-24 05:47:05 +000010174 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010175 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010176 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010177 E->getOperatorLoc(),
10178 E->isArrow()? tok::arrow : tok::period,
10179 ObjectTypePtr,
10180 MayBePseudoDestructor);
10181 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010182 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010183
John McCallba7bf592010-08-24 05:47:05 +000010184 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010185 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10186 if (QualifierLoc) {
10187 QualifierLoc
10188 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10189 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010190 return ExprError();
10191 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010192 CXXScopeSpec SS;
10193 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010194
Douglas Gregor678f90d2010-02-25 01:56:36 +000010195 PseudoDestructorTypeStorage Destroyed;
10196 if (E->getDestroyedTypeInfo()) {
10197 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010198 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010199 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010200 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010201 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010202 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010203 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010204 // We aren't likely to be able to resolve the identifier down to a type
10205 // now anyway, so just retain the identifier.
10206 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10207 E->getDestroyedTypeLoc());
10208 } else {
10209 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010210 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010211 *E->getDestroyedTypeIdentifier(),
10212 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010213 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010214 SS, ObjectTypePtr,
10215 false);
10216 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010217 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010218
Douglas Gregor678f90d2010-02-25 01:56:36 +000010219 Destroyed
10220 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10221 E->getDestroyedTypeLoc());
10222 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010223
Craig Topperc3ec1492014-05-26 06:22:03 +000010224 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010225 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010226 CXXScopeSpec EmptySS;
10227 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010228 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010229 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010230 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010231 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010232
John McCallb268a282010-08-23 23:25:46 +000010233 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010234 E->getOperatorLoc(),
10235 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010236 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010237 ScopeTypeInfo,
10238 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010239 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010240 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010241}
Mike Stump11289f42009-09-09 15:08:12 +000010242
Richard Smith151c4562016-12-20 21:35:28 +000010243template <typename Derived>
10244bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10245 bool RequiresADL,
10246 LookupResult &R) {
10247 // Transform all the decls.
10248 bool AllEmptyPacks = true;
10249 for (auto *OldD : Old->decls()) {
10250 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10251 if (!InstD) {
10252 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10253 // This can happen because of dependent hiding.
10254 if (isa<UsingShadowDecl>(OldD))
10255 continue;
10256 else {
10257 R.clear();
10258 return true;
10259 }
10260 }
10261
10262 // Expand using pack declarations.
10263 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10264 ArrayRef<NamedDecl*> Decls = SingleDecl;
10265 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10266 Decls = UPD->expansions();
10267
10268 // Expand using declarations.
10269 for (auto *D : Decls) {
10270 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10271 for (auto *SD : UD->shadows())
10272 R.addDecl(SD);
10273 } else {
10274 R.addDecl(D);
10275 }
10276 }
10277
10278 AllEmptyPacks &= Decls.empty();
10279 };
10280
10281 // C++ [temp.res]/8.4.2:
10282 // The program is ill-formed, no diagnostic required, if [...] lookup for
10283 // a name in the template definition found a using-declaration, but the
10284 // lookup in the corresponding scope in the instantiation odoes not find
10285 // any declarations because the using-declaration was a pack expansion and
10286 // the corresponding pack is empty
10287 if (AllEmptyPacks && !RequiresADL) {
10288 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10289 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10290 return true;
10291 }
10292
10293 // Resolve a kind, but don't do any further analysis. If it's
10294 // ambiguous, the callee needs to deal with it.
10295 R.resolveKind();
10296 return false;
10297}
10298
Douglas Gregorad8a3362009-09-04 17:36:40 +000010299template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010300ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010301TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010302 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010303 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10304 Sema::LookupOrdinaryName);
10305
Richard Smith151c4562016-12-20 21:35:28 +000010306 // Transform the declaration set.
10307 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10308 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010309
10310 // Rebuild the nested-name qualifier, if present.
10311 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010312 if (Old->getQualifierLoc()) {
10313 NestedNameSpecifierLoc QualifierLoc
10314 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10315 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010316 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010317
Douglas Gregor0da1d432011-02-28 20:01:57 +000010318 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010319 }
10320
Douglas Gregor9262f472010-04-27 18:19:34 +000010321 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010322 CXXRecordDecl *NamingClass
10323 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10324 Old->getNameLoc(),
10325 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010326 if (!NamingClass) {
10327 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010328 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010329 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010330
Douglas Gregorda7be082010-04-27 16:10:10 +000010331 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010332 }
10333
Abramo Bagnara7945c982012-01-27 09:46:47 +000010334 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10335
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010336 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010337 // it's a normal declaration name or member reference.
10338 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10339 NamedDecl *D = R.getAsSingle<NamedDecl>();
10340 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10341 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10342 // give a good diagnostic.
10343 if (D && D->isCXXInstanceMember()) {
10344 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10345 /*TemplateArgs=*/nullptr,
10346 /*Scope=*/nullptr);
10347 }
10348
John McCalle66edc12009-11-24 19:00:30 +000010349 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010350 }
John McCalle66edc12009-11-24 19:00:30 +000010351
10352 // If we have template arguments, rebuild them, then rebuild the
10353 // templateid expression.
10354 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010355 if (Old->hasExplicitTemplateArgs() &&
10356 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010357 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010358 TransArgs)) {
10359 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010360 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010361 }
John McCalle66edc12009-11-24 19:00:30 +000010362
Abramo Bagnara7945c982012-01-27 09:46:47 +000010363 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010364 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010365}
Mike Stump11289f42009-09-09 15:08:12 +000010366
Douglas Gregora16548e2009-08-11 05:31:07 +000010367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010368ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010369TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10370 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010371 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010372 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10373 TypeSourceInfo *From = E->getArg(I);
10374 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010375 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010376 TypeLocBuilder TLB;
10377 TLB.reserve(FromTL.getFullDataSize());
10378 QualType To = getDerived().TransformType(TLB, FromTL);
10379 if (To.isNull())
10380 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010381
Douglas Gregor29c42f22012-02-24 07:38:34 +000010382 if (To == From->getType())
10383 Args.push_back(From);
10384 else {
10385 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10386 ArgChanged = true;
10387 }
10388 continue;
10389 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010390
Douglas Gregor29c42f22012-02-24 07:38:34 +000010391 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010392
Douglas Gregor29c42f22012-02-24 07:38:34 +000010393 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010394 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010395 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10396 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10397 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010398
Douglas Gregor29c42f22012-02-24 07:38:34 +000010399 // Determine whether the set of unexpanded parameter packs can and should
10400 // be expanded.
10401 bool Expand = true;
10402 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010403 Optional<unsigned> OrigNumExpansions =
10404 ExpansionTL.getTypePtr()->getNumExpansions();
10405 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010406 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10407 PatternTL.getSourceRange(),
10408 Unexpanded,
10409 Expand, RetainExpansion,
10410 NumExpansions))
10411 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010412
Douglas Gregor29c42f22012-02-24 07:38:34 +000010413 if (!Expand) {
10414 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010415 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010416 // expansion.
10417 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010418
Douglas Gregor29c42f22012-02-24 07:38:34 +000010419 TypeLocBuilder TLB;
10420 TLB.reserve(From->getTypeLoc().getFullDataSize());
10421
10422 QualType To = getDerived().TransformType(TLB, PatternTL);
10423 if (To.isNull())
10424 return ExprError();
10425
Chad Rosier1dcde962012-08-08 18:46:20 +000010426 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010427 PatternTL.getSourceRange(),
10428 ExpansionTL.getEllipsisLoc(),
10429 NumExpansions);
10430 if (To.isNull())
10431 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010432
Douglas Gregor29c42f22012-02-24 07:38:34 +000010433 PackExpansionTypeLoc ToExpansionTL
10434 = TLB.push<PackExpansionTypeLoc>(To);
10435 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10436 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10437 continue;
10438 }
10439
10440 // Expand the pack expansion by substituting for each argument in the
10441 // pack(s).
10442 for (unsigned I = 0; I != *NumExpansions; ++I) {
10443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10444 TypeLocBuilder TLB;
10445 TLB.reserve(PatternTL.getFullDataSize());
10446 QualType To = getDerived().TransformType(TLB, PatternTL);
10447 if (To.isNull())
10448 return ExprError();
10449
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010450 if (To->containsUnexpandedParameterPack()) {
10451 To = getDerived().RebuildPackExpansionType(To,
10452 PatternTL.getSourceRange(),
10453 ExpansionTL.getEllipsisLoc(),
10454 NumExpansions);
10455 if (To.isNull())
10456 return ExprError();
10457
10458 PackExpansionTypeLoc ToExpansionTL
10459 = TLB.push<PackExpansionTypeLoc>(To);
10460 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10461 }
10462
Douglas Gregor29c42f22012-02-24 07:38:34 +000010463 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10464 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010465
Douglas Gregor29c42f22012-02-24 07:38:34 +000010466 if (!RetainExpansion)
10467 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010468
Douglas Gregor29c42f22012-02-24 07:38:34 +000010469 // If we're supposed to retain a pack expansion, do so by temporarily
10470 // forgetting the partially-substituted parameter pack.
10471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10472
10473 TypeLocBuilder TLB;
10474 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010475
Douglas Gregor29c42f22012-02-24 07:38:34 +000010476 QualType To = getDerived().TransformType(TLB, PatternTL);
10477 if (To.isNull())
10478 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010479
10480 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010481 PatternTL.getSourceRange(),
10482 ExpansionTL.getEllipsisLoc(),
10483 NumExpansions);
10484 if (To.isNull())
10485 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010486
Douglas Gregor29c42f22012-02-24 07:38:34 +000010487 PackExpansionTypeLoc ToExpansionTL
10488 = TLB.push<PackExpansionTypeLoc>(To);
10489 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10490 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10491 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
Douglas Gregor29c42f22012-02-24 07:38:34 +000010493 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010494 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010495
10496 return getDerived().RebuildTypeTrait(E->getTrait(),
10497 E->getLocStart(),
10498 Args,
10499 E->getLocEnd());
10500}
10501
10502template<typename Derived>
10503ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010504TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10505 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10506 if (!T)
10507 return ExprError();
10508
10509 if (!getDerived().AlwaysRebuild() &&
10510 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010511 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010512
10513 ExprResult SubExpr;
10514 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010515 EnterExpressionEvaluationContext Unevaluated(
10516 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010517 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10518 if (SubExpr.isInvalid())
10519 return ExprError();
10520
10521 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010522 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010523 }
10524
10525 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10526 E->getLocStart(),
10527 T,
10528 SubExpr.get(),
10529 E->getLocEnd());
10530}
10531
10532template<typename Derived>
10533ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010534TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10535 ExprResult SubExpr;
10536 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010537 EnterExpressionEvaluationContext Unevaluated(
10538 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010539 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10540 if (SubExpr.isInvalid())
10541 return ExprError();
10542
10543 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010544 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010545 }
10546
10547 return getDerived().RebuildExpressionTrait(
10548 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10549}
10550
Reid Kleckner32506ed2014-06-12 23:03:48 +000010551template <typename Derived>
10552ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10553 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10554 TypeSourceInfo **RecoveryTSI) {
10555 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10556 DRE, AddrTaken, RecoveryTSI);
10557
10558 // Propagate both errors and recovered types, which return ExprEmpty.
10559 if (!NewDRE.isUsable())
10560 return NewDRE;
10561
10562 // We got an expr, wrap it up in parens.
10563 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10564 return PE;
10565 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10566 PE->getRParen());
10567}
10568
10569template <typename Derived>
10570ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10571 DependentScopeDeclRefExpr *E) {
10572 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10573 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010574}
10575
10576template<typename Derived>
10577ExprResult
10578TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10579 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010580 bool IsAddressOfOperand,
10581 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010582 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010583 NestedNameSpecifierLoc QualifierLoc
10584 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10585 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010586 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010587 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010588
John McCall31f82722010-11-12 08:19:04 +000010589 // TODO: If this is a conversion-function-id, verify that the
10590 // destination type name (if present) resolves the same way after
10591 // instantiation as it did in the local scope.
10592
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010593 DeclarationNameInfo NameInfo
10594 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10595 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010597
John McCalle66edc12009-11-24 19:00:30 +000010598 if (!E->hasExplicitTemplateArgs()) {
10599 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010600 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010601 // Note: it is sufficient to compare the Name component of NameInfo:
10602 // if name has not changed, DNLoc has not changed either.
10603 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010604 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010605
Reid Kleckner32506ed2014-06-12 23:03:48 +000010606 return getDerived().RebuildDependentScopeDeclRefExpr(
10607 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10608 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010609 }
John McCall6b51f282009-11-23 01:53:49 +000010610
10611 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010612 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10613 E->getNumTemplateArgs(),
10614 TransArgs))
10615 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010616
Reid Kleckner32506ed2014-06-12 23:03:48 +000010617 return getDerived().RebuildDependentScopeDeclRefExpr(
10618 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10619 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010620}
10621
10622template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010623ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010624TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010625 // CXXConstructExprs other than for list-initialization and
10626 // CXXTemporaryObjectExpr are always implicit, so when we have
10627 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010628 if ((E->getNumArgs() == 1 ||
10629 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010630 (!getDerived().DropCallArgument(E->getArg(0))) &&
10631 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010632 return getDerived().TransformExpr(E->getArg(0));
10633
Douglas Gregora16548e2009-08-11 05:31:07 +000010634 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10635
10636 QualType T = getDerived().TransformType(E->getType());
10637 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010638 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010639
10640 CXXConstructorDecl *Constructor
10641 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010642 getDerived().TransformDecl(E->getLocStart(),
10643 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010644 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010646
Douglas Gregora16548e2009-08-11 05:31:07 +000010647 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010648 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010649 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010650 &ArgumentChanged))
10651 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010652
Douglas Gregora16548e2009-08-11 05:31:07 +000010653 if (!getDerived().AlwaysRebuild() &&
10654 T == E->getType() &&
10655 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010656 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010657 // Mark the constructor as referenced.
10658 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010659 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010660 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010661 }
Mike Stump11289f42009-09-09 15:08:12 +000010662
Douglas Gregordb121ba2009-12-14 16:27:04 +000010663 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010664 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010665 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010666 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010667 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010668 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010669 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010670 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010671 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010672}
Mike Stump11289f42009-09-09 15:08:12 +000010673
Richard Smith5179eb72016-06-28 19:03:57 +000010674template<typename Derived>
10675ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10676 CXXInheritedCtorInitExpr *E) {
10677 QualType T = getDerived().TransformType(E->getType());
10678 if (T.isNull())
10679 return ExprError();
10680
10681 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10682 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10683 if (!Constructor)
10684 return ExprError();
10685
10686 if (!getDerived().AlwaysRebuild() &&
10687 T == E->getType() &&
10688 Constructor == E->getConstructor()) {
10689 // Mark the constructor as referenced.
10690 // FIXME: Instantiation-specific
10691 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10692 return E;
10693 }
10694
10695 return getDerived().RebuildCXXInheritedCtorInitExpr(
10696 T, E->getLocation(), Constructor,
10697 E->constructsVBase(), E->inheritedFromVBase());
10698}
10699
Douglas Gregora16548e2009-08-11 05:31:07 +000010700/// \brief Transform a C++ temporary-binding expression.
10701///
Douglas Gregor363b1512009-12-24 18:51:59 +000010702/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10703/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010704template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010705ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010706TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010707 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010708}
Mike Stump11289f42009-09-09 15:08:12 +000010709
John McCall5d413782010-12-06 08:20:24 +000010710/// \brief Transform a C++ expression that contains cleanups that should
10711/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010712///
John McCall5d413782010-12-06 08:20:24 +000010713/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010714/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010716ExprResult
John McCall5d413782010-12-06 08:20:24 +000010717TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010718 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010719}
Mike Stump11289f42009-09-09 15:08:12 +000010720
Douglas Gregora16548e2009-08-11 05:31:07 +000010721template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010722ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010723TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010724 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010725 TypeSourceInfo *T =
10726 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010727 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010729
Douglas Gregora16548e2009-08-11 05:31:07 +000010730 CXXConstructorDecl *Constructor
10731 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010732 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010733 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010734 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010735 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010736
Douglas Gregora16548e2009-08-11 05:31:07 +000010737 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010738 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010739 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010740 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010741 &ArgumentChanged))
10742 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010743
Douglas Gregora16548e2009-08-11 05:31:07 +000010744 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010745 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010746 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010747 !ArgumentChanged) {
10748 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010749 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010750 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010751 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010752
Richard Smithd59b8322012-12-19 01:39:02 +000010753 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +000010754 return getDerived().RebuildCXXTemporaryObjectExpr(T,
10755 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010756 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000010757 E->getLocEnd());
10758}
Mike Stump11289f42009-09-09 15:08:12 +000010759
Douglas Gregora16548e2009-08-11 05:31:07 +000010760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010761ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010762TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010763 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010764 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010765 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010766 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10767 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010768 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010769 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010770 CEnd = E->capture_end();
10771 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010772 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010773 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010774 EnterExpressionEvaluationContext EEEC(
10775 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010776 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10777 C->getCapturedVar()->getInit(),
10778 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010779
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010780 if (NewExprInitResult.isInvalid())
10781 return ExprError();
10782 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010783
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010784 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010785 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010786 getSema().buildLambdaInitCaptureInitialization(
10787 C->getLocation(), OldVD->getType()->isReferenceType(),
10788 OldVD->getIdentifier(),
10789 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010790 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010791 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10792 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010793 }
10794
Faisal Vali2cba1332013-10-23 06:44:28 +000010795 // Transform the template parameters, and add them to the current
10796 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010797 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010798 E->getTemplateParameterList());
10799
Richard Smith01014ce2014-11-20 23:53:14 +000010800 // Transform the type of the original lambda's call operator.
10801 // The transformation MUST be done in the CurrentInstantiationScope since
10802 // it introduces a mapping of the original to the newly created
10803 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010804 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010805 {
10806 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10807 FunctionProtoTypeLoc OldCallOpFPTL =
10808 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010809
10810 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010811 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010812 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010813 QualType NewCallOpType = TransformFunctionProtoType(
10814 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010815 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10816 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10817 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010818 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010819 if (NewCallOpType.isNull())
10820 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010821 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10822 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010823 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010824
Richard Smithc38498f2015-04-27 21:27:54 +000010825 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10826 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10827 LSI->GLTemplateParameterList = TPL;
10828
Eli Friedmand564afb2012-09-19 01:18:11 +000010829 // Create the local class that will describe the lambda.
10830 CXXRecordDecl *Class
10831 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010832 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010833 /*KnownDependent=*/false,
10834 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010835 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10836
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010837 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010838 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10839 Class, E->getIntroducerRange(), NewCallOpTSI,
10840 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010841 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10842 E->getCallOperator()->isConstexpr());
10843
Faisal Vali2cba1332013-10-23 06:44:28 +000010844 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010845
Akira Hatanaka402818462016-12-16 21:16:57 +000010846 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10847 I != NumParams; ++I) {
10848 auto *P = NewCallOperator->getParamDecl(I);
10849 if (P->hasUninstantiatedDefaultArg()) {
10850 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010851 getSema(),
10852 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010853 ExprResult R = getDerived().TransformExpr(
10854 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10855 P->setDefaultArg(R.get());
10856 }
10857 }
10858
Faisal Vali2cba1332013-10-23 06:44:28 +000010859 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010860 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010861
Douglas Gregorb4328232012-02-14 00:00:48 +000010862 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010863 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010864 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010865
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010866 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010867 getSema().buildLambdaScope(LSI, NewCallOperator,
10868 E->getIntroducerRange(),
10869 E->getCaptureDefault(),
10870 E->getCaptureDefaultLoc(),
10871 E->hasExplicitParameters(),
10872 E->hasExplicitResultType(),
10873 E->isMutable());
10874
10875 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010876
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010877 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010878 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010879 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010880 CEnd = E->capture_end();
10881 C != CEnd; ++C) {
10882 // When we hit the first implicit capture, tell Sema that we've finished
10883 // the list of explicit captures.
10884 if (!FinishedExplicitCaptures && C->isImplicit()) {
10885 getSema().finishLambdaExplicitCaptures(LSI);
10886 FinishedExplicitCaptures = true;
10887 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010888
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010889 // Capturing 'this' is trivial.
10890 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010891 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10892 /*BuildAndDiagnose*/ true, nullptr,
10893 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010894 continue;
10895 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010896 // Captured expression will be recaptured during captured variables
10897 // rebuilding.
10898 if (C->capturesVLAType())
10899 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010900
Richard Smithba71c082013-05-16 06:20:58 +000010901 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000010902 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010903 InitCaptureInfoTy InitExprTypePair =
10904 InitCaptureExprsAndTypes[C - E->capture_begin()];
10905 ExprResult Init = InitExprTypePair.first;
10906 QualType InitQualType = InitExprTypePair.second;
10907 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000010908 Invalid = true;
10909 continue;
10910 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010911 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010912 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000010913 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
10914 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000010915 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000010916 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010917 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000010918 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010919 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000010920 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000010921 continue;
10922 }
10923
10924 assert(C->capturesVariable() && "unexpected kind of lambda capture");
10925
Douglas Gregor3e308b12012-02-14 19:27:52 +000010926 // Determine the capture kind for Sema.
10927 Sema::TryCaptureKind Kind
10928 = C->isImplicit()? Sema::TryCapture_Implicit
10929 : C->getCaptureKind() == LCK_ByCopy
10930 ? Sema::TryCapture_ExplicitByVal
10931 : Sema::TryCapture_ExplicitByRef;
10932 SourceLocation EllipsisLoc;
10933 if (C->isPackExpansion()) {
10934 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
10935 bool ShouldExpand = false;
10936 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010937 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010938 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
10939 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010940 Unexpanded,
10941 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000010942 NumExpansions)) {
10943 Invalid = true;
10944 continue;
10945 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010946
Douglas Gregor3e308b12012-02-14 19:27:52 +000010947 if (ShouldExpand) {
10948 // The transform has determined that we should perform an expansion;
10949 // transform and capture each of the arguments.
10950 // expansion of the pattern. Do so.
10951 VarDecl *Pack = C->getCapturedVar();
10952 for (unsigned I = 0; I != *NumExpansions; ++I) {
10953 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10954 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010955 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000010956 Pack));
10957 if (!CapturedVar) {
10958 Invalid = true;
10959 continue;
10960 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010961
Douglas Gregor3e308b12012-02-14 19:27:52 +000010962 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000010963 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
10964 }
Richard Smith9467be42014-06-06 17:33:35 +000010965
10966 // FIXME: Retain a pack expansion if RetainExpansion is true.
10967
Douglas Gregor3e308b12012-02-14 19:27:52 +000010968 continue;
10969 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010970
Douglas Gregor3e308b12012-02-14 19:27:52 +000010971 EllipsisLoc = C->getEllipsisLoc();
10972 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010973
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010974 // Transform the captured variable.
10975 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000010976 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010977 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000010978 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010979 Invalid = true;
10980 continue;
10981 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010982
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010983 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000010984 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
10985 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010986 }
10987 if (!FinishedExplicitCaptures)
10988 getSema().finishLambdaExplicitCaptures(LSI);
10989
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010990 // Enter a new evaluation context to insulate the lambda from any
10991 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000010992 getSema().PushExpressionEvaluationContext(
10993 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010994
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010995 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000010996 StmtResult Body =
10997 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
10998
10999 // ActOnLambda* will pop the function scope for us.
11000 FuncScopeCleanup.disable();
11001
Douglas Gregorb4328232012-02-14 00:00:48 +000011002 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011003 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000011004 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011005 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011006 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011007 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011008
Richard Smithc38498f2015-04-27 21:27:54 +000011009 // Copy the LSI before ActOnFinishFunctionBody removes it.
11010 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11011 // the call operator.
11012 auto LSICopy = *LSI;
11013 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11014 /*IsInstantiation*/ true);
11015 SavedContext.pop();
11016
11017 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11018 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011019}
11020
11021template<typename Derived>
11022ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011023TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011024 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011025 TypeSourceInfo *T =
11026 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011027 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011028 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011029
Douglas Gregora16548e2009-08-11 05:31:07 +000011030 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011031 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011032 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011033 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011034 &ArgumentChanged))
11035 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011036
Douglas Gregora16548e2009-08-11 05:31:07 +000011037 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011038 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011039 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011040 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011041
Douglas Gregora16548e2009-08-11 05:31:07 +000011042 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +000011043 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +000011044 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011045 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +000011046 E->getRParenLoc());
11047}
Mike Stump11289f42009-09-09 15:08:12 +000011048
Douglas Gregora16548e2009-08-11 05:31:07 +000011049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011050ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011051TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011052 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011053 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011054 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011055 Expr *OldBase;
11056 QualType BaseType;
11057 QualType ObjectType;
11058 if (!E->isImplicitAccess()) {
11059 OldBase = E->getBase();
11060 Base = getDerived().TransformExpr(OldBase);
11061 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011062 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011063
John McCall2d74de92009-12-01 22:10:20 +000011064 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011065 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011066 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011067 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011068 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011069 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011070 ObjectTy,
11071 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011072 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011073 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011074
John McCallba7bf592010-08-24 05:47:05 +000011075 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011076 BaseType = ((Expr*) Base.get())->getType();
11077 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011078 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011079 BaseType = getDerived().TransformType(E->getBaseType());
11080 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11081 }
Mike Stump11289f42009-09-09 15:08:12 +000011082
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011083 // Transform the first part of the nested-name-specifier that qualifies
11084 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011085 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011086 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011087 E->getFirstQualifierFoundInScope(),
11088 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011089
Douglas Gregore16af532011-02-28 18:50:33 +000011090 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011091 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011092 QualifierLoc
11093 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11094 ObjectType,
11095 FirstQualifierInScope);
11096 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011097 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011098 }
Mike Stump11289f42009-09-09 15:08:12 +000011099
Abramo Bagnara7945c982012-01-27 09:46:47 +000011100 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11101
John McCall31f82722010-11-12 08:19:04 +000011102 // TODO: If this is a conversion-function-id, verify that the
11103 // destination type name (if present) resolves the same way after
11104 // instantiation as it did in the local scope.
11105
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011106 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011107 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011108 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011109 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011110
John McCall2d74de92009-12-01 22:10:20 +000011111 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011112 // This is a reference to a member without an explicitly-specified
11113 // template argument list. Optimize for this common case.
11114 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011115 Base.get() == OldBase &&
11116 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011117 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011118 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011119 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011120 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011121
John McCallb268a282010-08-23 23:25:46 +000011122 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011123 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011124 E->isArrow(),
11125 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011126 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011127 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011128 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011129 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011130 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011131 }
11132
John McCall6b51f282009-11-23 01:53:49 +000011133 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011134 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11135 E->getNumTemplateArgs(),
11136 TransArgs))
11137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011138
John McCallb268a282010-08-23 23:25:46 +000011139 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011140 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011141 E->isArrow(),
11142 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011143 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011144 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011145 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011146 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011147 &TransArgs);
11148}
11149
11150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011152TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011153 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011154 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011155 QualType BaseType;
11156 if (!Old->isImplicitAccess()) {
11157 Base = getDerived().TransformExpr(Old->getBase());
11158 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011159 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011160 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011161 Old->isArrow());
11162 if (Base.isInvalid())
11163 return ExprError();
11164 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011165 } else {
11166 BaseType = getDerived().TransformType(Old->getBaseType());
11167 }
John McCall10eae182009-11-30 22:42:35 +000011168
Douglas Gregor0da1d432011-02-28 20:01:57 +000011169 NestedNameSpecifierLoc QualifierLoc;
11170 if (Old->getQualifierLoc()) {
11171 QualifierLoc
11172 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11173 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011174 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011175 }
11176
Abramo Bagnara7945c982012-01-27 09:46:47 +000011177 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11178
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011179 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011180 Sema::LookupOrdinaryName);
11181
Richard Smith151c4562016-12-20 21:35:28 +000011182 // Transform the declaration set.
11183 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11184 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011185
Douglas Gregor9262f472010-04-27 18:19:34 +000011186 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011187 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011188 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011189 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011190 Old->getMemberLoc(),
11191 Old->getNamingClass()));
11192 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011194
Douglas Gregorda7be082010-04-27 16:10:10 +000011195 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011196 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011197
John McCall10eae182009-11-30 22:42:35 +000011198 TemplateArgumentListInfo TransArgs;
11199 if (Old->hasExplicitTemplateArgs()) {
11200 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11201 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011202 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11203 Old->getNumTemplateArgs(),
11204 TransArgs))
11205 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011206 }
John McCall38836f02010-01-15 08:34:02 +000011207
11208 // FIXME: to do this check properly, we will need to preserve the
11209 // first-qualifier-in-scope here, just in case we had a dependent
11210 // base (and therefore couldn't do the check) and a
11211 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011212 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011213
John McCallb268a282010-08-23 23:25:46 +000011214 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011215 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011216 Old->getOperatorLoc(),
11217 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011218 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011219 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011220 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011221 R,
11222 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011223 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011224}
11225
11226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011227ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011228TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011229 EnterExpressionEvaluationContext Unevaluated(
11230 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011231 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11232 if (SubExpr.isInvalid())
11233 return ExprError();
11234
11235 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011236 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011237
11238 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11239}
11240
11241template<typename Derived>
11242ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011243TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011244 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11245 if (Pattern.isInvalid())
11246 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011247
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011248 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011249 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011250
Douglas Gregorb8840002011-01-14 21:20:45 +000011251 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11252 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011253}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011254
11255template<typename Derived>
11256ExprResult
11257TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11258 // If E is not value-dependent, then nothing will change when we transform it.
11259 // Note: This is an instantiation-centric view.
11260 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011261 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011262
Faisal Valid143a0c2017-04-01 21:30:49 +000011263 EnterExpressionEvaluationContext Unevaluated(
11264 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011265
Richard Smithd784e682015-09-23 21:41:42 +000011266 ArrayRef<TemplateArgument> PackArgs;
11267 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011268
Richard Smithd784e682015-09-23 21:41:42 +000011269 // Find the argument list to transform.
11270 if (E->isPartiallySubstituted()) {
11271 PackArgs = E->getPartialArguments();
11272 } else if (E->isValueDependent()) {
11273 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11274 bool ShouldExpand = false;
11275 bool RetainExpansion = false;
11276 Optional<unsigned> NumExpansions;
11277 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11278 Unexpanded,
11279 ShouldExpand, RetainExpansion,
11280 NumExpansions))
11281 return ExprError();
11282
11283 // If we need to expand the pack, build a template argument from it and
11284 // expand that.
11285 if (ShouldExpand) {
11286 auto *Pack = E->getPack();
11287 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11288 ArgStorage = getSema().Context.getPackExpansionType(
11289 getSema().Context.getTypeDeclType(TTPD), None);
11290 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11291 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11292 } else {
11293 auto *VD = cast<ValueDecl>(Pack);
11294 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11295 VK_RValue, E->getPackLoc());
11296 if (DRE.isInvalid())
11297 return ExprError();
11298 ArgStorage = new (getSema().Context) PackExpansionExpr(
11299 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11300 }
11301 PackArgs = ArgStorage;
11302 }
11303 }
11304
11305 // If we're not expanding the pack, just transform the decl.
11306 if (!PackArgs.size()) {
11307 auto *Pack = cast_or_null<NamedDecl>(
11308 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011309 if (!Pack)
11310 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011311 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11312 E->getPackLoc(),
11313 E->getRParenLoc(), None, None);
11314 }
11315
Richard Smithc5452ed2016-10-19 22:18:42 +000011316 // Try to compute the result without performing a partial substitution.
11317 Optional<unsigned> Result = 0;
11318 for (const TemplateArgument &Arg : PackArgs) {
11319 if (!Arg.isPackExpansion()) {
11320 Result = *Result + 1;
11321 continue;
11322 }
11323
11324 TemplateArgumentLoc ArgLoc;
11325 InventTemplateArgumentLoc(Arg, ArgLoc);
11326
11327 // Find the pattern of the pack expansion.
11328 SourceLocation Ellipsis;
11329 Optional<unsigned> OrigNumExpansions;
11330 TemplateArgumentLoc Pattern =
11331 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11332 OrigNumExpansions);
11333
11334 // Substitute under the pack expansion. Do not expand the pack (yet).
11335 TemplateArgumentLoc OutPattern;
11336 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11337 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11338 /*Uneval*/ true))
11339 return true;
11340
11341 // See if we can determine the number of arguments from the result.
11342 Optional<unsigned> NumExpansions =
11343 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11344 if (!NumExpansions) {
11345 // No: we must be in an alias template expansion, and we're going to need
11346 // to actually expand the packs.
11347 Result = None;
11348 break;
11349 }
11350
11351 Result = *Result + *NumExpansions;
11352 }
11353
11354 // Common case: we could determine the number of expansions without
11355 // substituting.
11356 if (Result)
11357 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11358 E->getPackLoc(),
11359 E->getRParenLoc(), *Result, None);
11360
Richard Smithd784e682015-09-23 21:41:42 +000011361 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11362 E->getPackLoc());
11363 {
11364 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11365 typedef TemplateArgumentLocInventIterator<
11366 Derived, const TemplateArgument*> PackLocIterator;
11367 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11368 PackLocIterator(*this, PackArgs.end()),
11369 TransformedPackArgs, /*Uneval*/true))
11370 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011371 }
11372
Richard Smithc5452ed2016-10-19 22:18:42 +000011373 // Check whether we managed to fully-expand the pack.
11374 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011375 SmallVector<TemplateArgument, 8> Args;
11376 bool PartialSubstitution = false;
11377 for (auto &Loc : TransformedPackArgs.arguments()) {
11378 Args.push_back(Loc.getArgument());
11379 if (Loc.getArgument().isPackExpansion())
11380 PartialSubstitution = true;
11381 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011382
Richard Smithd784e682015-09-23 21:41:42 +000011383 if (PartialSubstitution)
11384 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11385 E->getPackLoc(),
11386 E->getRParenLoc(), None, Args);
11387
11388 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011389 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011390 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011391}
11392
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011393template<typename Derived>
11394ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011395TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11396 SubstNonTypeTemplateParmPackExpr *E) {
11397 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011398 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011399}
11400
11401template<typename Derived>
11402ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011403TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11404 SubstNonTypeTemplateParmExpr *E) {
11405 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011406 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011407}
11408
11409template<typename Derived>
11410ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011411TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11412 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011413 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011414}
11415
11416template<typename Derived>
11417ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011418TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11419 MaterializeTemporaryExpr *E) {
11420 return getDerived().TransformExpr(E->GetTemporaryExpr());
11421}
Chad Rosier1dcde962012-08-08 18:46:20 +000011422
Douglas Gregorfe314812011-06-21 17:03:29 +000011423template<typename Derived>
11424ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011425TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11426 Expr *Pattern = E->getPattern();
11427
11428 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11429 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11430 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11431
11432 // Determine whether the set of unexpanded parameter packs can and should
11433 // be expanded.
11434 bool Expand = true;
11435 bool RetainExpansion = false;
11436 Optional<unsigned> NumExpansions;
11437 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11438 Pattern->getSourceRange(),
11439 Unexpanded,
11440 Expand, RetainExpansion,
11441 NumExpansions))
11442 return true;
11443
11444 if (!Expand) {
11445 // Do not expand any packs here, just transform and rebuild a fold
11446 // expression.
11447 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11448
11449 ExprResult LHS =
11450 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11451 if (LHS.isInvalid())
11452 return true;
11453
11454 ExprResult RHS =
11455 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11456 if (RHS.isInvalid())
11457 return true;
11458
11459 if (!getDerived().AlwaysRebuild() &&
11460 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11461 return E;
11462
11463 return getDerived().RebuildCXXFoldExpr(
11464 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11465 RHS.get(), E->getLocEnd());
11466 }
11467
11468 // The transform has determined that we should perform an elementwise
11469 // expansion of the pattern. Do so.
11470 ExprResult Result = getDerived().TransformExpr(E->getInit());
11471 if (Result.isInvalid())
11472 return true;
11473 bool LeftFold = E->isLeftFold();
11474
11475 // If we're retaining an expansion for a right fold, it is the innermost
11476 // component and takes the init (if any).
11477 if (!LeftFold && RetainExpansion) {
11478 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11479
11480 ExprResult Out = getDerived().TransformExpr(Pattern);
11481 if (Out.isInvalid())
11482 return true;
11483
11484 Result = getDerived().RebuildCXXFoldExpr(
11485 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11486 Result.get(), E->getLocEnd());
11487 if (Result.isInvalid())
11488 return true;
11489 }
11490
11491 for (unsigned I = 0; I != *NumExpansions; ++I) {
11492 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11493 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11494 ExprResult Out = getDerived().TransformExpr(Pattern);
11495 if (Out.isInvalid())
11496 return true;
11497
11498 if (Out.get()->containsUnexpandedParameterPack()) {
11499 // We still have a pack; retain a pack expansion for this slice.
11500 Result = getDerived().RebuildCXXFoldExpr(
11501 E->getLocStart(),
11502 LeftFold ? Result.get() : Out.get(),
11503 E->getOperator(), E->getEllipsisLoc(),
11504 LeftFold ? Out.get() : Result.get(),
11505 E->getLocEnd());
11506 } else if (Result.isUsable()) {
11507 // We've got down to a single element; build a binary operator.
11508 Result = getDerived().RebuildBinaryOperator(
11509 E->getEllipsisLoc(), E->getOperator(),
11510 LeftFold ? Result.get() : Out.get(),
11511 LeftFold ? Out.get() : Result.get());
11512 } else
11513 Result = Out;
11514
11515 if (Result.isInvalid())
11516 return true;
11517 }
11518
11519 // If we're retaining an expansion for a left fold, it is the outermost
11520 // component and takes the complete expansion so far as its init (if any).
11521 if (LeftFold && RetainExpansion) {
11522 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11523
11524 ExprResult Out = getDerived().TransformExpr(Pattern);
11525 if (Out.isInvalid())
11526 return true;
11527
11528 Result = getDerived().RebuildCXXFoldExpr(
11529 E->getLocStart(), Result.get(),
11530 E->getOperator(), E->getEllipsisLoc(),
11531 Out.get(), E->getLocEnd());
11532 if (Result.isInvalid())
11533 return true;
11534 }
11535
11536 // If we had no init and an empty pack, and we're not retaining an expansion,
11537 // then produce a fallback value or error.
11538 if (Result.isUnset())
11539 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11540 E->getOperator());
11541
11542 return Result;
11543}
11544
11545template<typename Derived>
11546ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011547TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11548 CXXStdInitializerListExpr *E) {
11549 return getDerived().TransformExpr(E->getSubExpr());
11550}
11551
11552template<typename Derived>
11553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011554TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011555 return SemaRef.MaybeBindToTemporary(E);
11556}
11557
11558template<typename Derived>
11559ExprResult
11560TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011561 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011562}
11563
11564template<typename Derived>
11565ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011566TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11567 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11568 if (SubExpr.isInvalid())
11569 return ExprError();
11570
11571 if (!getDerived().AlwaysRebuild() &&
11572 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011573 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011574
11575 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011576}
11577
11578template<typename Derived>
11579ExprResult
11580TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11581 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011582 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011583 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011584 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011585 /*IsCall=*/false, Elements, &ArgChanged))
11586 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011587
Ted Kremeneke65b0862012-03-06 20:05:56 +000011588 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11589 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011590
Ted Kremeneke65b0862012-03-06 20:05:56 +000011591 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11592 Elements.data(),
11593 Elements.size());
11594}
11595
11596template<typename Derived>
11597ExprResult
11598TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011599 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011600 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011601 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011602 bool ArgChanged = false;
11603 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11604 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011605
Ted Kremeneke65b0862012-03-06 20:05:56 +000011606 if (OrigElement.isPackExpansion()) {
11607 // This key/value element is a pack expansion.
11608 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11609 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11610 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11611 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11612
11613 // Determine whether the set of unexpanded parameter packs can
11614 // and should be expanded.
11615 bool Expand = true;
11616 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011617 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11618 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011619 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11620 OrigElement.Value->getLocEnd());
11621 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11622 PatternRange,
11623 Unexpanded,
11624 Expand, RetainExpansion,
11625 NumExpansions))
11626 return ExprError();
11627
11628 if (!Expand) {
11629 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011630 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011631 // expansion.
11632 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11633 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11634 if (Key.isInvalid())
11635 return ExprError();
11636
11637 if (Key.get() != OrigElement.Key)
11638 ArgChanged = true;
11639
11640 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11641 if (Value.isInvalid())
11642 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011643
Ted Kremeneke65b0862012-03-06 20:05:56 +000011644 if (Value.get() != OrigElement.Value)
11645 ArgChanged = true;
11646
Chad Rosier1dcde962012-08-08 18:46:20 +000011647 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011648 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11649 };
11650 Elements.push_back(Expansion);
11651 continue;
11652 }
11653
11654 // Record right away that the argument was changed. This needs
11655 // to happen even if the array expands to nothing.
11656 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011657
Ted Kremeneke65b0862012-03-06 20:05:56 +000011658 // The transform has determined that we should perform an elementwise
11659 // expansion of the pattern. Do so.
11660 for (unsigned I = 0; I != *NumExpansions; ++I) {
11661 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11662 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11663 if (Key.isInvalid())
11664 return ExprError();
11665
11666 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11667 if (Value.isInvalid())
11668 return ExprError();
11669
Chad Rosier1dcde962012-08-08 18:46:20 +000011670 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011671 Key.get(), Value.get(), SourceLocation(), NumExpansions
11672 };
11673
11674 // If any unexpanded parameter packs remain, we still have a
11675 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011676 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011677 if (Key.get()->containsUnexpandedParameterPack() ||
11678 Value.get()->containsUnexpandedParameterPack())
11679 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011680
Ted Kremeneke65b0862012-03-06 20:05:56 +000011681 Elements.push_back(Element);
11682 }
11683
Richard Smith9467be42014-06-06 17:33:35 +000011684 // FIXME: Retain a pack expansion if RetainExpansion is true.
11685
Ted Kremeneke65b0862012-03-06 20:05:56 +000011686 // We've finished with this pack expansion.
11687 continue;
11688 }
11689
11690 // Transform and check key.
11691 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11692 if (Key.isInvalid())
11693 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011694
Ted Kremeneke65b0862012-03-06 20:05:56 +000011695 if (Key.get() != OrigElement.Key)
11696 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011697
Ted Kremeneke65b0862012-03-06 20:05:56 +000011698 // Transform and check value.
11699 ExprResult Value
11700 = getDerived().TransformExpr(OrigElement.Value);
11701 if (Value.isInvalid())
11702 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011703
Ted Kremeneke65b0862012-03-06 20:05:56 +000011704 if (Value.get() != OrigElement.Value)
11705 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011706
11707 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011708 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011709 };
11710 Elements.push_back(Element);
11711 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011712
Ted Kremeneke65b0862012-03-06 20:05:56 +000011713 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11714 return SemaRef.MaybeBindToTemporary(E);
11715
11716 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011717 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011718}
11719
Mike Stump11289f42009-09-09 15:08:12 +000011720template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011721ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011722TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011723 TypeSourceInfo *EncodedTypeInfo
11724 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11725 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011726 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011727
Douglas Gregora16548e2009-08-11 05:31:07 +000011728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011729 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011730 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011731
11732 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011733 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011734 E->getRParenLoc());
11735}
Mike Stump11289f42009-09-09 15:08:12 +000011736
Douglas Gregora16548e2009-08-11 05:31:07 +000011737template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011738ExprResult TreeTransform<Derived>::
11739TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011740 // This is a kind of implicit conversion, and it needs to get dropped
11741 // and recomputed for the same general reasons that ImplicitCastExprs
11742 // do, as well a more specific one: this expression is only valid when
11743 // it appears *immediately* as an argument expression.
11744 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011745}
11746
11747template<typename Derived>
11748ExprResult TreeTransform<Derived>::
11749TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011750 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011751 = getDerived().TransformType(E->getTypeInfoAsWritten());
11752 if (!TSInfo)
11753 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011754
John McCall31168b02011-06-15 23:02:42 +000011755 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011756 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011757 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011758
John McCall31168b02011-06-15 23:02:42 +000011759 if (!getDerived().AlwaysRebuild() &&
11760 TSInfo == E->getTypeInfoAsWritten() &&
11761 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011762 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011763
John McCall31168b02011-06-15 23:02:42 +000011764 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011765 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011766 Result.get());
11767}
11768
Erik Pilkington29099de2016-07-16 00:35:23 +000011769template <typename Derived>
11770ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11771 ObjCAvailabilityCheckExpr *E) {
11772 return E;
11773}
11774
John McCall31168b02011-06-15 23:02:42 +000011775template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011777TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011778 // Transform arguments.
11779 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011780 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011781 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011782 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011783 &ArgChanged))
11784 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011785
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011786 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11787 // Class message: transform the receiver type.
11788 TypeSourceInfo *ReceiverTypeInfo
11789 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11790 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011791 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011792
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011793 // If nothing changed, just retain the existing message send.
11794 if (!getDerived().AlwaysRebuild() &&
11795 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011796 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011797
11798 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011799 SmallVector<SourceLocation, 16> SelLocs;
11800 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011801 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11802 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011803 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011804 E->getMethodDecl(),
11805 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011806 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011807 E->getRightLoc());
11808 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011809 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11810 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011811 if (!E->getMethodDecl())
11812 return ExprError();
11813
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011814 // Build a new class message send to 'super'.
11815 SmallVector<SourceLocation, 16> SelLocs;
11816 E->getSelectorLocs(SelLocs);
11817 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11818 E->getSelector(),
11819 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011820 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011821 E->getMethodDecl(),
11822 E->getLeftLoc(),
11823 Args,
11824 E->getRightLoc());
11825 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011826
11827 // Instance message: transform the receiver
11828 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11829 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011830 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011831 = getDerived().TransformExpr(E->getInstanceReceiver());
11832 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011833 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011834
11835 // If nothing changed, just retain the existing message send.
11836 if (!getDerived().AlwaysRebuild() &&
11837 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011838 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011839
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011840 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011841 SmallVector<SourceLocation, 16> SelLocs;
11842 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011843 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011844 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011845 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011846 E->getMethodDecl(),
11847 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011848 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011849 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011850}
11851
Mike Stump11289f42009-09-09 15:08:12 +000011852template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011853ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011854TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011855 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011856}
11857
Mike Stump11289f42009-09-09 15:08:12 +000011858template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011859ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011860TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011861 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011862}
11863
Mike Stump11289f42009-09-09 15:08:12 +000011864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011866TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011867 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011868 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011869 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011870 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011871
11872 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011873
Douglas Gregord51d90d2010-04-26 20:11:03 +000011874 // If nothing changed, just retain the existing expression.
11875 if (!getDerived().AlwaysRebuild() &&
11876 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011877 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011878
John McCallb268a282010-08-23 23:25:46 +000011879 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011880 E->getLocation(),
11881 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011882}
11883
Mike Stump11289f42009-09-09 15:08:12 +000011884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011885ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011886TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011887 // 'super' and types never change. Property never changes. Just
11888 // retain the existing expression.
11889 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011890 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011891
Douglas Gregor9faee212010-04-26 20:47:02 +000011892 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011893 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011894 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011895 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011896
Douglas Gregor9faee212010-04-26 20:47:02 +000011897 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011898
Douglas Gregor9faee212010-04-26 20:47:02 +000011899 // If nothing changed, just retain the existing expression.
11900 if (!getDerived().AlwaysRebuild() &&
11901 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011902 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011903
John McCallb7bd14f2010-12-02 01:19:52 +000011904 if (E->isExplicitProperty())
11905 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
11906 E->getExplicitProperty(),
11907 E->getLocation());
11908
11909 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000011910 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000011911 E->getImplicitPropertyGetter(),
11912 E->getImplicitPropertySetter(),
11913 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000011914}
11915
Mike Stump11289f42009-09-09 15:08:12 +000011916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011917ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000011918TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
11919 // Transform the base expression.
11920 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
11921 if (Base.isInvalid())
11922 return ExprError();
11923
11924 // Transform the key expression.
11925 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
11926 if (Key.isInvalid())
11927 return ExprError();
11928
11929 // If nothing changed, just retain the existing expression.
11930 if (!getDerived().AlwaysRebuild() &&
11931 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011932 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011933
Chad Rosier1dcde962012-08-08 18:46:20 +000011934 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011935 Base.get(), Key.get(),
11936 E->getAtIndexMethodDecl(),
11937 E->setAtIndexMethodDecl());
11938}
11939
11940template<typename Derived>
11941ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011942TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011943 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011944 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011945 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011946 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011947
Douglas Gregord51d90d2010-04-26 20:11:03 +000011948 // If nothing changed, just retain the existing expression.
11949 if (!getDerived().AlwaysRebuild() &&
11950 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011951 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011952
John McCallb268a282010-08-23 23:25:46 +000011953 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000011954 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011955 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000011956}
11957
Mike Stump11289f42009-09-09 15:08:12 +000011958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011959ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011960TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011961 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011962 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000011963 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011964 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000011965 SubExprs, &ArgumentChanged))
11966 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011967
Douglas Gregora16548e2009-08-11 05:31:07 +000011968 if (!getDerived().AlwaysRebuild() &&
11969 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011970 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011971
Douglas Gregora16548e2009-08-11 05:31:07 +000011972 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011973 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000011974 E->getRParenLoc());
11975}
11976
Mike Stump11289f42009-09-09 15:08:12 +000011977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011978ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000011979TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
11980 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
11981 if (SrcExpr.isInvalid())
11982 return ExprError();
11983
11984 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11985 if (!Type)
11986 return ExprError();
11987
11988 if (!getDerived().AlwaysRebuild() &&
11989 Type == E->getTypeSourceInfo() &&
11990 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011991 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000011992
11993 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
11994 SrcExpr.get(), Type,
11995 E->getRParenLoc());
11996}
11997
11998template<typename Derived>
11999ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012000TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012001 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012002
Craig Topperc3ec1492014-05-26 06:22:03 +000012003 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012004 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12005
12006 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012007 blockScope->TheDecl->setBlockMissingReturnType(
12008 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012009
Chris Lattner01cf8db2011-07-20 06:58:45 +000012010 SmallVector<ParmVarDecl*, 4> params;
12011 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012012
John McCallc8e321d2016-03-01 02:09:25 +000012013 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12014
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012015 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012016 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012017 if (getDerived().TransformFunctionTypeParams(
12018 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12019 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12020 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012021 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012022 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012023 }
John McCall490112f2011-02-04 18:33:18 +000012024
Eli Friedman34b49062012-01-26 03:00:14 +000012025 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012026 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012027
John McCallc8e321d2016-03-01 02:09:25 +000012028 auto epi = exprFunctionType->getExtProtoInfo();
12029 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12030
Jordan Rose5c382722013-03-08 21:51:21 +000012031 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012032 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012033 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012034
12035 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012036 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012037 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012038
12039 if (!oldBlock->blockMissingReturnType()) {
12040 blockScope->HasImplicitReturnType = false;
12041 blockScope->ReturnType = exprResultType;
12042 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012043
John McCall3882ace2011-01-05 12:14:39 +000012044 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012045 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012046 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012047 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012048 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012049 }
John McCall3882ace2011-01-05 12:14:39 +000012050
John McCall490112f2011-02-04 18:33:18 +000012051#ifndef NDEBUG
12052 // In builds with assertions, make sure that we captured everything we
12053 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012054 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012055 for (const auto &I : oldBlock->captures()) {
12056 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012057
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012058 // Ignore parameter packs.
12059 if (isa<ParmVarDecl>(oldCapture) &&
12060 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12061 continue;
John McCall490112f2011-02-04 18:33:18 +000012062
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012063 VarDecl *newCapture =
12064 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12065 oldCapture));
12066 assert(blockScope->CaptureMap.count(newCapture));
12067 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012068 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012069 }
12070#endif
12071
12072 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012073 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012074}
12075
Mike Stump11289f42009-09-09 15:08:12 +000012076template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012077ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012078TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012079 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012080}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012081
12082template<typename Derived>
12083ExprResult
12084TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012085 QualType RetTy = getDerived().TransformType(E->getType());
12086 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012087 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012088 SubExprs.reserve(E->getNumSubExprs());
12089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12090 SubExprs, &ArgumentChanged))
12091 return ExprError();
12092
12093 if (!getDerived().AlwaysRebuild() &&
12094 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012095 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012096
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012097 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012098 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012099}
Chad Rosier1dcde962012-08-08 18:46:20 +000012100
Douglas Gregora16548e2009-08-11 05:31:07 +000012101//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012102// Type reconstruction
12103//===----------------------------------------------------------------------===//
12104
Mike Stump11289f42009-09-09 15:08:12 +000012105template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012106QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12107 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012108 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012109 getDerived().getBaseEntity());
12110}
12111
Mike Stump11289f42009-09-09 15:08:12 +000012112template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012113QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12114 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012115 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012116 getDerived().getBaseEntity());
12117}
12118
Mike Stump11289f42009-09-09 15:08:12 +000012119template<typename Derived>
12120QualType
John McCall70dd5f62009-10-30 00:06:24 +000012121TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12122 bool WrittenAsLValue,
12123 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012124 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012125 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012126}
12127
12128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012129QualType
John McCall70dd5f62009-10-30 00:06:24 +000012130TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12131 QualType ClassType,
12132 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012133 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12134 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012135}
12136
12137template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012138QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12139 const ObjCTypeParamDecl *Decl,
12140 SourceLocation ProtocolLAngleLoc,
12141 ArrayRef<ObjCProtocolDecl *> Protocols,
12142 ArrayRef<SourceLocation> ProtocolLocs,
12143 SourceLocation ProtocolRAngleLoc) {
12144 return SemaRef.BuildObjCTypeParamType(Decl,
12145 ProtocolLAngleLoc, Protocols,
12146 ProtocolLocs, ProtocolRAngleLoc,
12147 /*FailOnError=*/true);
12148}
12149
12150template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012151QualType TreeTransform<Derived>::RebuildObjCObjectType(
12152 QualType BaseType,
12153 SourceLocation Loc,
12154 SourceLocation TypeArgsLAngleLoc,
12155 ArrayRef<TypeSourceInfo *> TypeArgs,
12156 SourceLocation TypeArgsRAngleLoc,
12157 SourceLocation ProtocolLAngleLoc,
12158 ArrayRef<ObjCProtocolDecl *> Protocols,
12159 ArrayRef<SourceLocation> ProtocolLocs,
12160 SourceLocation ProtocolRAngleLoc) {
12161 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12162 TypeArgs, TypeArgsRAngleLoc,
12163 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12164 ProtocolRAngleLoc,
12165 /*FailOnError=*/true);
12166}
12167
12168template<typename Derived>
12169QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12170 QualType PointeeType,
12171 SourceLocation Star) {
12172 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12173}
12174
12175template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012176QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012177TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12178 ArrayType::ArraySizeModifier SizeMod,
12179 const llvm::APInt *Size,
12180 Expr *SizeExpr,
12181 unsigned IndexTypeQuals,
12182 SourceRange BracketsRange) {
12183 if (SizeExpr || !Size)
12184 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12185 IndexTypeQuals, BracketsRange,
12186 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012187
12188 QualType Types[] = {
12189 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12190 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12191 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012192 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012193 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012194 QualType SizeType;
12195 for (unsigned I = 0; I != NumTypes; ++I)
12196 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12197 SizeType = Types[I];
12198 break;
12199 }
Mike Stump11289f42009-09-09 15:08:12 +000012200
Eli Friedman9562f392012-01-25 23:20:27 +000012201 // Note that we can return a VariableArrayType here in the case where
12202 // the element type was a dependent VariableArrayType.
12203 IntegerLiteral *ArraySize
12204 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12205 /*FIXME*/BracketsRange.getBegin());
12206 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012207 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012208 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012209}
Mike Stump11289f42009-09-09 15:08:12 +000012210
Douglas Gregord6ff3322009-08-04 16:50:30 +000012211template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012212QualType
12213TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012214 ArrayType::ArraySizeModifier SizeMod,
12215 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012216 unsigned IndexTypeQuals,
12217 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012218 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012219 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012220}
12221
12222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012223QualType
Mike Stump11289f42009-09-09 15:08:12 +000012224TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012225 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012226 unsigned IndexTypeQuals,
12227 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012228 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012229 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012230}
Mike Stump11289f42009-09-09 15:08:12 +000012231
Douglas Gregord6ff3322009-08-04 16:50:30 +000012232template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012233QualType
12234TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012235 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012236 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012237 unsigned IndexTypeQuals,
12238 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012239 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012240 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012241 IndexTypeQuals, BracketsRange);
12242}
12243
12244template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012245QualType
12246TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012247 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012248 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012249 unsigned IndexTypeQuals,
12250 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012251 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012252 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012253 IndexTypeQuals, BracketsRange);
12254}
12255
12256template<typename Derived>
12257QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000012258 unsigned NumElements,
12259 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012260 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012261 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012262}
Mike Stump11289f42009-09-09 15:08:12 +000012263
Douglas Gregord6ff3322009-08-04 16:50:30 +000012264template<typename Derived>
12265QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12266 unsigned NumElements,
12267 SourceLocation AttributeLoc) {
12268 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12269 NumElements, true);
12270 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012271 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12272 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012273 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012274}
Mike Stump11289f42009-09-09 15:08:12 +000012275
Douglas Gregord6ff3322009-08-04 16:50:30 +000012276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012277QualType
12278TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012279 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012280 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012281 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012282}
Mike Stump11289f42009-09-09 15:08:12 +000012283
Douglas Gregord6ff3322009-08-04 16:50:30 +000012284template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012285QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12286 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012287 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012288 const FunctionProtoType::ExtProtoInfo &EPI) {
12289 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012290 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012291 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012292 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012293}
Mike Stump11289f42009-09-09 15:08:12 +000012294
Douglas Gregord6ff3322009-08-04 16:50:30 +000012295template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012296QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12297 return SemaRef.Context.getFunctionNoProtoType(T);
12298}
12299
12300template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012301QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12302 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012303 assert(D && "no decl found");
12304 if (D->isInvalidDecl()) return QualType();
12305
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012306 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012307 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012308 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12309 // A valid resolved using typename pack expansion decl can have multiple
12310 // UsingDecls, but they must each have exactly one type, and it must be
12311 // the same type in every case. But we must have at least one expansion!
12312 if (UPD->expansions().empty()) {
12313 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12314 << UPD->isCXXClassMember() << UPD;
12315 return QualType();
12316 }
12317
12318 // We might still have some unresolved types. Try to pick a resolved type
12319 // if we can. The final instantiation will check that the remaining
12320 // unresolved types instantiate to the type we pick.
12321 QualType FallbackT;
12322 QualType T;
12323 for (auto *E : UPD->expansions()) {
12324 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12325 if (ThisT.isNull())
12326 continue;
12327 else if (ThisT->getAs<UnresolvedUsingType>())
12328 FallbackT = ThisT;
12329 else if (T.isNull())
12330 T = ThisT;
12331 else
12332 assert(getSema().Context.hasSameType(ThisT, T) &&
12333 "mismatched resolved types in using pack expansion");
12334 }
12335 return T.isNull() ? FallbackT : T;
12336 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012337 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012338 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12339
12340 // A valid resolved using typename decl points to exactly one type decl.
12341 assert(++Using->shadow_begin() == Using->shadow_end());
12342 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012343 } else {
12344 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12345 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12346 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12347 }
12348
12349 return SemaRef.Context.getTypeDeclType(Ty);
12350}
12351
12352template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012353QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12354 SourceLocation Loc) {
12355 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012356}
12357
12358template<typename Derived>
12359QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12360 return SemaRef.Context.getTypeOfType(Underlying);
12361}
12362
12363template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012364QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12365 SourceLocation Loc) {
12366 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012367}
12368
12369template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012370QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12371 UnaryTransformType::UTTKind UKind,
12372 SourceLocation Loc) {
12373 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12374}
12375
12376template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012377QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012378 TemplateName Template,
12379 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012380 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012381 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012382}
Mike Stump11289f42009-09-09 15:08:12 +000012383
Douglas Gregor1135c352009-08-06 05:28:30 +000012384template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012385QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12386 SourceLocation KWLoc) {
12387 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12388}
12389
12390template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012391QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012392 SourceLocation KWLoc,
12393 bool isReadPipe) {
12394 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12395 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012396}
12397
12398template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012399TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012400TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012401 bool TemplateKW,
12402 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012403 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012404 Template);
12405}
12406
12407template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012408TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012409TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12410 const IdentifierInfo &Name,
12411 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012412 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012413 NamedDecl *FirstQualifierInScope,
12414 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012415 UnqualifiedId TemplateName;
12416 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012417 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012418 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012419 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012420 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012421 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012422 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012423 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012424 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012425}
Mike Stump11289f42009-09-09 15:08:12 +000012426
Douglas Gregora16548e2009-08-11 05:31:07 +000012427template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012428TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012429TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012430 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012431 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012432 QualType ObjectType,
12433 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012434 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012435 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012436 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012437 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012438 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012439 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012440 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012441 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012442 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012443 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012444 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012445 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012446}
Chad Rosier1dcde962012-08-08 18:46:20 +000012447
Douglas Gregor71395fa2009-11-04 00:56:37 +000012448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012449ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012450TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12451 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012452 Expr *OrigCallee,
12453 Expr *First,
12454 Expr *Second) {
12455 Expr *Callee = OrigCallee->IgnoreParenCasts();
12456 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012457
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012458 if (First->getObjectKind() == OK_ObjCProperty) {
12459 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12460 if (BinaryOperator::isAssignmentOp(Opc))
12461 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12462 First, Second);
12463 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12464 if (Result.isInvalid())
12465 return ExprError();
12466 First = Result.get();
12467 }
12468
12469 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12470 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12471 if (Result.isInvalid())
12472 return ExprError();
12473 Second = Result.get();
12474 }
12475
Douglas Gregora16548e2009-08-11 05:31:07 +000012476 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012477 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012478 if (!First->getType()->isOverloadableType() &&
12479 !Second->getType()->isOverloadableType())
12480 return getSema().CreateBuiltinArraySubscriptExpr(First,
12481 Callee->getLocStart(),
12482 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012483 } else if (Op == OO_Arrow) {
12484 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012485 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12486 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012487 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012488 // The argument is not of overloadable type, so try to create a
12489 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012490 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012491 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012492
John McCallb268a282010-08-23 23:25:46 +000012493 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012494 }
12495 } else {
John McCallb268a282010-08-23 23:25:46 +000012496 if (!First->getType()->isOverloadableType() &&
12497 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012498 // Neither of the arguments is an overloadable type, so try to
12499 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012500 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012501 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012502 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012503 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012505
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012506 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012507 }
12508 }
Mike Stump11289f42009-09-09 15:08:12 +000012509
12510 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012511 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012512 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000012513
John McCallb268a282010-08-23 23:25:46 +000012514 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000012515 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000012516 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000012517 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012518 // If we've resolved this to a particular non-member function, just call
12519 // that function. If we resolved it to a member function,
12520 // CreateOverloaded* will find that function for us.
12521 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12522 if (!isa<CXXMethodDecl>(ND))
12523 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000012524 }
Mike Stump11289f42009-09-09 15:08:12 +000012525
Douglas Gregora16548e2009-08-11 05:31:07 +000012526 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012527 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012528 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012529
Douglas Gregora16548e2009-08-11 05:31:07 +000012530 // Create the overloaded operator invocation for unary operators.
12531 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012532 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012533 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000012534 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012535 }
Mike Stump11289f42009-09-09 15:08:12 +000012536
Douglas Gregore9d62932011-07-15 16:25:15 +000012537 if (Op == OO_Subscript) {
12538 SourceLocation LBrace;
12539 SourceLocation RBrace;
12540
12541 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012542 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012543 LBrace = SourceLocation::getFromRawEncoding(
12544 NameLoc.CXXOperatorName.BeginOpNameLoc);
12545 RBrace = SourceLocation::getFromRawEncoding(
12546 NameLoc.CXXOperatorName.EndOpNameLoc);
12547 } else {
12548 LBrace = Callee->getLocStart();
12549 RBrace = OpLoc;
12550 }
12551
12552 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12553 First, Second);
12554 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012555
Douglas Gregora16548e2009-08-11 05:31:07 +000012556 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012557 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012558 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000012559 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
12560 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012562
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012563 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012564}
Mike Stump11289f42009-09-09 15:08:12 +000012565
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012566template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012567ExprResult
John McCallb268a282010-08-23 23:25:46 +000012568TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012569 SourceLocation OperatorLoc,
12570 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012571 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012572 TypeSourceInfo *ScopeType,
12573 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012574 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012575 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012576 QualType BaseType = Base->getType();
12577 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012578 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012579 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012580 !BaseType->getAs<PointerType>()->getPointeeType()
12581 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012582 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012583 return SemaRef.BuildPseudoDestructorExpr(
12584 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12585 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012586 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012587
Douglas Gregor678f90d2010-02-25 01:56:36 +000012588 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012589 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12590 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12591 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12592 NameInfo.setNamedTypeInfo(DestroyedType);
12593
Richard Smith8e4a3862012-05-15 06:15:11 +000012594 // The scope type is now known to be a valid nested name specifier
12595 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012596 if (ScopeType) {
12597 if (!ScopeType->getType()->getAs<TagType>()) {
12598 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12599 diag::err_expected_class_or_namespace)
12600 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12601 return ExprError();
12602 }
12603 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12604 CCLoc);
12605 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012606
Abramo Bagnara7945c982012-01-27 09:46:47 +000012607 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012608 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012609 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012610 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012611 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012612 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012613 /*TemplateArgs*/ nullptr,
12614 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012615}
12616
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012617template<typename Derived>
12618StmtResult
12619TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012620 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012621 CapturedDecl *CD = S->getCapturedDecl();
12622 unsigned NumParams = CD->getNumParams();
12623 unsigned ContextParamPos = CD->getContextParamPosition();
12624 SmallVector<Sema::CapturedParamNameType, 4> Params;
12625 for (unsigned I = 0; I < NumParams; ++I) {
12626 if (I != ContextParamPos) {
12627 Params.push_back(
12628 std::make_pair(
12629 CD->getParam(I)->getName(),
12630 getDerived().TransformType(CD->getParam(I)->getType())));
12631 } else {
12632 Params.push_back(std::make_pair(StringRef(), QualType()));
12633 }
12634 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012635 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012636 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012637 StmtResult Body;
12638 {
12639 Sema::CompoundScopeRAII CompoundScope(getSema());
12640 Body = getDerived().TransformStmt(S->getCapturedStmt());
12641 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012642
12643 if (Body.isInvalid()) {
12644 getSema().ActOnCapturedRegionError();
12645 return StmtError();
12646 }
12647
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012648 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012649}
12650
Douglas Gregord6ff3322009-08-04 16:50:30 +000012651} // end namespace clang
12652
Hans Wennborg59dbe862015-09-29 20:56:43 +000012653#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H