blob: 4eb45bc0c9a845453f78c48c0f3d898b66ed88fc [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
Andrew Gozillon572bbb02017-10-02 06:25:51 +0000838 /// \brief Build a new DependentAddressSpaceType or return the pointee
839 /// type variable with the correct address space (retrieved from
840 /// AddrSpaceExpr) applied to it. The former will be returned in cases
841 /// where the address space remains dependent.
842 ///
843 /// By default, performs semantic analysis when building the type with address
844 /// space applied. Subclasses may override this routine to provide different
845 /// behavior.
846 QualType RebuildDependentAddressSpaceType(QualType PointeeType,
847 Expr *AddrSpaceExpr,
848 SourceLocation AttributeLoc);
849
Douglas Gregord6ff3322009-08-04 16:50:30 +0000850 /// \brief Build a new function type.
851 ///
852 /// By default, performs semantic analysis when building the function type.
853 /// Subclasses may override this routine to provide different behavior.
854 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000855 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000856 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000857
John McCall550e0c22009-10-21 00:40:46 +0000858 /// \brief Build a new unprototyped function type.
859 QualType RebuildFunctionNoProtoType(QualType ResultType);
860
John McCallb96ec562009-12-04 22:46:56 +0000861 /// \brief Rebuild an unresolved typename type, given the decl that
862 /// the UnresolvedUsingTypenameDecl was transformed to.
Richard Smith151c4562016-12-20 21:35:28 +0000863 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
John McCallb96ec562009-12-04 22:46:56 +0000864
Douglas Gregord6ff3322009-08-04 16:50:30 +0000865 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000866 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000867 return SemaRef.Context.getTypeDeclType(Typedef);
868 }
869
870 /// \brief Build a new class/struct/union type.
871 QualType RebuildRecordType(RecordDecl *Record) {
872 return SemaRef.Context.getTypeDeclType(Record);
873 }
874
875 /// \brief Build a new Enum type.
876 QualType RebuildEnumType(EnumDecl *Enum) {
877 return SemaRef.Context.getTypeDeclType(Enum);
878 }
John McCallfcc33b02009-09-05 00:15:47 +0000879
Mike Stump11289f42009-09-09 15:08:12 +0000880 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000881 ///
882 /// By default, performs semantic analysis when building the typeof type.
883 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000884 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885
Mike Stump11289f42009-09-09 15:08:12 +0000886 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000887 ///
888 /// By default, builds a new TypeOfType with the given underlying type.
889 QualType RebuildTypeOfType(QualType Underlying);
890
Alexis Hunte852b102011-05-24 22:41:36 +0000891 /// \brief Build a new unary transform type.
892 QualType RebuildUnaryTransformType(QualType BaseType,
893 UnaryTransformType::UTTKind UKind,
894 SourceLocation Loc);
895
Richard Smith74aeef52013-04-26 16:15:35 +0000896 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000897 ///
898 /// By default, performs semantic analysis when building the decltype type.
899 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000900 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000901
Richard Smith74aeef52013-04-26 16:15:35 +0000902 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000903 ///
904 /// By default, builds a new AutoType with the given deduced type.
Richard Smithe301ba22015-11-11 02:02:15 +0000905 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword) {
Richard Smith27d807c2013-04-30 13:56:41 +0000906 // Note, IsDependent is always false here: we implicitly convert an 'auto'
907 // which has been deduced to a dependent type into an undeduced 'auto', so
908 // that we'll retry deduction after the transformation.
Richard Smithe301ba22015-11-11 02:02:15 +0000909 return SemaRef.Context.getAutoType(Deduced, Keyword,
Faisal Vali2b391ab2013-09-26 19:54:12 +0000910 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000911 }
912
Richard Smith600b5262017-01-26 20:40:47 +0000913 /// By default, builds a new DeducedTemplateSpecializationType with the given
914 /// deduced type.
915 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
916 QualType Deduced) {
917 return SemaRef.Context.getDeducedTemplateSpecializationType(
918 Template, Deduced, /*IsDependent*/ false);
919 }
920
Douglas Gregord6ff3322009-08-04 16:50:30 +0000921 /// \brief Build a new template specialization type.
922 ///
923 /// By default, performs semantic analysis when building the template
924 /// specialization type. Subclasses may override this routine to provide
925 /// different behavior.
926 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000927 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000928 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000929
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000930 /// \brief Build a new parenthesized type.
931 ///
932 /// By default, builds a new ParenType type from the inner type.
933 /// Subclasses may override this routine to provide different behavior.
934 QualType RebuildParenType(QualType InnerType) {
Richard Smithee579842017-01-30 20:39:26 +0000935 return SemaRef.BuildParenType(InnerType);
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000936 }
937
Douglas Gregord6ff3322009-08-04 16:50:30 +0000938 /// \brief Build a new qualified name type.
939 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000940 /// By default, builds a new ElaboratedType type from the keyword,
941 /// the nested-name-specifier and the named type.
942 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000943 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
944 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000945 NestedNameSpecifierLoc QualifierLoc,
946 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000947 return SemaRef.Context.getElaboratedType(Keyword,
948 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000949 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000950 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000951
952 /// \brief Build a new typename type that refers to a template-id.
953 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000954 /// By default, builds a new DependentNameType type from the
955 /// nested-name-specifier and the given type. Subclasses may override
956 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000957 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000958 ElaboratedTypeKeyword Keyword,
959 NestedNameSpecifierLoc QualifierLoc,
960 const IdentifierInfo *Name,
961 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +0000962 TemplateArgumentListInfo &Args,
963 bool AllowInjectedClassName) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000964 // Rebuild the template name.
965 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000966 CXXScopeSpec SS;
967 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000968 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000969 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
Richard Smithfd3dae02017-01-20 00:20:39 +0000970 nullptr, AllowInjectedClassName);
Chad Rosier1dcde962012-08-08 18:46:20 +0000971
Douglas Gregora7a795b2011-03-01 20:11:18 +0000972 if (InstName.isNull())
973 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000974
Douglas Gregora7a795b2011-03-01 20:11:18 +0000975 // If it's still dependent, make a dependent specialization.
976 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000977 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
978 QualifierLoc.getNestedNameSpecifier(),
979 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000980 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregora7a795b2011-03-01 20:11:18 +0000982 // Otherwise, make an elaborated type wrapping a non-dependent
983 // specialization.
984 QualType T =
985 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
986 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000987
Craig Topperc3ec1492014-05-26 06:22:03 +0000988 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000989 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000990
991 return SemaRef.Context.getElaboratedType(Keyword,
992 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000993 T);
994 }
995
Douglas Gregord6ff3322009-08-04 16:50:30 +0000996 /// \brief Build a new typename type that refers to an identifier.
997 ///
998 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000999 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +00001000 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001001 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +00001002 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001003 NestedNameSpecifierLoc QualifierLoc,
1004 const IdentifierInfo *Id,
Richard Smithee579842017-01-30 20:39:26 +00001005 SourceLocation IdLoc,
1006 bool DeducedTSTContext) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001007 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001008 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00001009
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001010 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +00001011 // If the name is still dependent, just build a new dependent name type.
1012 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +00001013 return SemaRef.Context.getDependentNameType(Keyword,
1014 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001015 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +00001016 }
1017
Richard Smithee579842017-01-30 20:39:26 +00001018 if (Keyword == ETK_None || Keyword == ETK_Typename) {
1019 QualType T = SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1020 *Id, IdLoc);
1021 // If a dependent name resolves to a deduced template specialization type,
1022 // check that we're in one of the syntactic contexts permitting it.
1023 if (!DeducedTSTContext) {
1024 if (auto *Deduced = dyn_cast_or_null<DeducedTemplateSpecializationType>(
1025 T.isNull() ? nullptr : T->getContainedDeducedType())) {
1026 SemaRef.Diag(IdLoc, diag::err_dependent_deduced_tst)
1027 << (int)SemaRef.getTemplateNameKindForDiagnostics(
1028 Deduced->getTemplateName())
1029 << QualType(QualifierLoc.getNestedNameSpecifier()->getAsType(), 0);
1030 if (auto *TD = Deduced->getTemplateName().getAsTemplateDecl())
1031 SemaRef.Diag(TD->getLocation(), diag::note_template_decl_here);
1032 return QualType();
1033 }
1034 }
1035 return T;
1036 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001037
1038 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
1039
Abramo Bagnarad7548482010-05-19 21:37:53 +00001040 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +00001041 // into a non-dependent elaborated-type-specifier. Find the tag we're
1042 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +00001043 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +00001044 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1045 if (!DC)
1046 return QualType();
1047
John McCallbf8c5192010-05-27 06:40:31 +00001048 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1049 return QualType();
1050
Craig Topperc3ec1492014-05-26 06:22:03 +00001051 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +00001052 SemaRef.LookupQualifiedName(Result, DC);
1053 switch (Result.getResultKind()) {
1054 case LookupResult::NotFound:
1055 case LookupResult::NotFoundInCurrentInstantiation:
1056 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001057
Douglas Gregore677daf2010-03-31 22:19:08 +00001058 case LookupResult::Found:
1059 Tag = Result.getAsSingle<TagDecl>();
1060 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00001061
Douglas Gregore677daf2010-03-31 22:19:08 +00001062 case LookupResult::FoundOverloaded:
1063 case LookupResult::FoundUnresolvedValue:
1064 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +00001065
Douglas Gregore677daf2010-03-31 22:19:08 +00001066 case LookupResult::Ambiguous:
1067 // Let the LookupResult structure handle ambiguities.
1068 return QualType();
1069 }
1070
1071 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +00001072 // Check where the name exists but isn't a tag type and use that to emit
1073 // better diagnostics.
1074 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
1075 SemaRef.LookupQualifiedName(Result, DC);
1076 switch (Result.getResultKind()) {
1077 case LookupResult::Found:
1078 case LookupResult::FoundOverloaded:
1079 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001080 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00001081 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1082 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
1083 << NTK << Kind;
Nick Lewycky0c438082011-01-24 19:01:04 +00001084 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1085 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001086 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001087 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001088 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001089 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001090 break;
1091 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001092 return QualType();
1093 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001094
Richard Trieucaa33d32011-06-10 03:11:26 +00001095 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001096 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001097 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001098 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1099 return QualType();
1100 }
1101
1102 // Build the elaborated-type-specifier type.
1103 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001104 return SemaRef.Context.getElaboratedType(Keyword,
1105 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001106 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001107 }
Mike Stump11289f42009-09-09 15:08:12 +00001108
Douglas Gregor822d0302011-01-12 17:07:58 +00001109 /// \brief Build a new pack expansion type.
1110 ///
1111 /// By default, builds a new PackExpansionType type from the given pattern.
1112 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001113 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001114 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001115 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001116 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001117 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1118 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001119 }
1120
Eli Friedman0dfb8892011-10-06 23:00:33 +00001121 /// \brief Build a new atomic type given its value type.
1122 ///
1123 /// By default, performs semantic analysis when building the atomic type.
1124 /// Subclasses may override this routine to provide different behavior.
1125 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1126
Xiuli Pan9c14e282016-01-09 12:53:17 +00001127 /// \brief Build a new pipe type given its value type.
Joey Gouly5788b782016-11-18 14:10:54 +00001128 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
1129 bool isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00001130
Douglas Gregor71dc5092009-08-06 06:41:21 +00001131 /// \brief Build a new template name given a nested name specifier, a flag
1132 /// indicating whether the "template" keyword was provided, and the template
1133 /// that the template name refers to.
1134 ///
1135 /// By default, builds the new template name directly. Subclasses may override
1136 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001137 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001138 bool TemplateKW,
1139 TemplateDecl *Template);
1140
Douglas Gregor71dc5092009-08-06 06:41:21 +00001141 /// \brief Build a new template name given a nested name specifier and the
1142 /// name that is referred to as a template.
1143 ///
1144 /// By default, performs semantic analysis to determine whether the name can
1145 /// be resolved to a specific template, then builds the appropriate kind of
1146 /// template name. Subclasses may override this routine to provide different
1147 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001148 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1149 const IdentifierInfo &Name,
1150 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001151 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00001152 NamedDecl *FirstQualifierInScope,
1153 bool AllowInjectedClassName);
Mike Stump11289f42009-09-09 15:08:12 +00001154
Douglas Gregor71395fa2009-11-04 00:56:37 +00001155 /// \brief Build a new template name given a nested name specifier and the
1156 /// overloaded operator name that is referred to as a template.
1157 ///
1158 /// By default, performs semantic analysis to determine whether the name can
1159 /// be resolved to a specific template, then builds the appropriate kind of
1160 /// template name. Subclasses may override this routine to provide different
1161 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001162 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001163 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001164 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00001165 QualType ObjectType,
1166 bool AllowInjectedClassName);
Douglas Gregor5590be02011-01-15 06:45:20 +00001167
1168 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001169 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001170 ///
1171 /// By default, performs semantic analysis to determine whether the name can
1172 /// be resolved to a specific template, then builds the appropriate kind of
1173 /// template name. Subclasses may override this routine to provide different
1174 /// behavior.
1175 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1176 const TemplateArgument &ArgPack) {
1177 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1178 }
1179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Build a new compound 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 RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001185 MultiStmtArg Statements,
1186 SourceLocation RBraceLoc,
1187 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 IsStmtExpr);
1190 }
1191
1192 /// \brief Build a new case statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001196 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001197 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001199 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001200 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001201 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001202 ColonLoc);
1203 }
Mike Stump11289f42009-09-09 15:08:12 +00001204
Douglas Gregorebe10102009-08-20 07:17:43 +00001205 /// \brief Attach the body to a new case statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001209 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001210 getSema().ActOnCaseStmtBody(S, Body);
1211 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001212 }
Mike Stump11289f42009-09-09 15:08:12 +00001213
Douglas Gregorebe10102009-08-20 07:17:43 +00001214 /// \brief Build a new default statement.
1215 ///
1216 /// By default, performs semantic analysis to build the new statement.
1217 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001218 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001220 Stmt *SubStmt) {
1221 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001222 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregorebe10102009-08-20 07:17:43 +00001225 /// \brief Build a new label statement.
1226 ///
1227 /// By default, performs semantic analysis to build the new statement.
1228 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001229 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1230 SourceLocation ColonLoc, Stmt *SubStmt) {
1231 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001232 }
Mike Stump11289f42009-09-09 15:08:12 +00001233
Richard Smithc202b282012-04-14 00:33:13 +00001234 /// \brief Build a new label statement.
1235 ///
1236 /// By default, performs semantic analysis to build the new statement.
1237 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001238 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1239 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001240 Stmt *SubStmt) {
1241 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1242 }
1243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new "if" statement.
1245 ///
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
Richard Smithb130fe72016-06-23 19:16:49 +00001248 StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr,
Richard Smitha547eb22016-07-14 00:11:03 +00001249 Sema::ConditionResult Cond, Stmt *Init, Stmt *Then,
Richard Smithb130fe72016-06-23 19:16:49 +00001250 SourceLocation ElseLoc, Stmt *Else) {
Richard Smitha547eb22016-07-14 00:11:03 +00001251 return getSema().ActOnIfStmt(IfLoc, IsConstexpr, Init, Cond, Then,
Richard Smithc7a05a92016-06-29 21:17:59 +00001252 ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregorebe10102009-08-20 07:17:43 +00001255 /// \brief Start building a new switch statement.
1256 ///
1257 /// By default, performs semantic analysis to build the new statement.
1258 /// Subclasses may override this routine to provide different behavior.
Richard Smitha547eb22016-07-14 00:11:03 +00001259 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, Stmt *Init,
Richard Smith03a4aa32016-06-23 19:02:52 +00001260 Sema::ConditionResult Cond) {
Richard Smitha547eb22016-07-14 00:11:03 +00001261 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Init, Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00001262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregorebe10102009-08-20 07:17:43 +00001264 /// \brief Attach the body to the switch statement.
1265 ///
1266 /// By default, performs semantic analysis to build the new statement.
1267 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001268 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001269 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001270 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001271 }
1272
1273 /// \brief Build a new while statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Richard Smith03a4aa32016-06-23 19:02:52 +00001277 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
1278 Sema::ConditionResult Cond, Stmt *Body) {
1279 return getSema().ActOnWhileStmt(WhileLoc, Cond, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001280 }
Mike Stump11289f42009-09-09 15:08:12 +00001281
Douglas Gregorebe10102009-08-20 07:17:43 +00001282 /// \brief Build a new do-while statement.
1283 ///
1284 /// By default, performs semantic analysis to build the new statement.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001287 SourceLocation WhileLoc, SourceLocation LParenLoc,
1288 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001289 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1290 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001291 }
1292
1293 /// \brief Build a new for 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 RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Richard Smith03a4aa32016-06-23 19:02:52 +00001298 Stmt *Init, Sema::ConditionResult Cond,
1299 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1300 Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001301 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Richard Smith03a4aa32016-06-23 19:02:52 +00001302 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregorebe10102009-08-20 07:17:43 +00001305 /// \brief Build a new goto statement.
1306 ///
1307 /// By default, performs semantic analysis to build the new statement.
1308 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001309 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1310 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001311 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001312 }
1313
1314 /// \brief Build a new indirect goto statement.
1315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001319 SourceLocation StarLoc,
1320 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001321 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Douglas Gregorebe10102009-08-20 07:17:43 +00001324 /// \brief Build a new return statement.
1325 ///
1326 /// By default, performs semantic analysis to build the new statement.
1327 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001328 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001329 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregorebe10102009-08-20 07:17:43 +00001332 /// \brief Build a new declaration statement.
1333 ///
1334 /// By default, performs semantic analysis to build the new statement.
1335 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001336 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001337 SourceLocation StartLoc, SourceLocation EndLoc) {
1338 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001339 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Anders Carlssonaaeef072010-01-24 05:50:09 +00001342 /// \brief Build a new inline asm statement.
1343 ///
1344 /// By default, performs semantic analysis to build the new statement.
1345 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001346 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1347 bool IsVolatile, unsigned NumOutputs,
1348 unsigned NumInputs, IdentifierInfo **Names,
1349 MultiExprArg Constraints, MultiExprArg Exprs,
1350 Expr *AsmString, MultiExprArg Clobbers,
1351 SourceLocation RParenLoc) {
1352 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1353 NumInputs, Names, Constraints, Exprs,
1354 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001355 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001356
Chad Rosier32503022012-06-11 20:47:18 +00001357 /// \brief Build a new MS style inline asm statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001361 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001362 ArrayRef<Token> AsmToks,
1363 StringRef AsmString,
1364 unsigned NumOutputs, unsigned NumInputs,
1365 ArrayRef<StringRef> Constraints,
1366 ArrayRef<StringRef> Clobbers,
1367 ArrayRef<Expr*> Exprs,
1368 SourceLocation EndLoc) {
1369 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1370 NumOutputs, NumInputs,
1371 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001372 }
1373
Richard Smith9f690bd2015-10-27 06:02:45 +00001374 /// \brief Build a new co_return statement.
1375 ///
1376 /// By default, performs semantic analysis to build the new statement.
1377 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001378 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
1379 bool IsImplicit) {
1380 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
Richard Smith9f690bd2015-10-27 06:02:45 +00001381 }
1382
1383 /// \brief Build a new co_await expression.
1384 ///
1385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001387 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
1388 bool IsImplicit) {
1389 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
1390 }
1391
1392 /// \brief Build a new co_await expression.
1393 ///
1394 /// By default, performs semantic analysis to build the new expression.
1395 /// Subclasses may override this routine to provide different behavior.
1396 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
1397 Expr *Result,
1398 UnresolvedLookupExpr *Lookup) {
1399 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
Richard Smith9f690bd2015-10-27 06:02:45 +00001400 }
1401
1402 /// \brief Build a new co_yield expression.
1403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
1407 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1408 }
1409
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001410 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1411 return getSema().BuildCoroutineBodyStmt(Args);
1412 }
1413
James Dennett2a4d13c2012-06-15 07:13:21 +00001414 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001415 ///
1416 /// By default, performs semantic analysis to build the new statement.
1417 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001418 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001419 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001420 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001421 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001422 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001423 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001424 }
1425
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001426 /// \brief Rebuild an Objective-C exception declaration.
1427 ///
1428 /// By default, performs semantic analysis to build the new declaration.
1429 /// Subclasses may override this routine to provide different behavior.
1430 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1431 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001432 return getSema().BuildObjCExceptionDecl(TInfo, T,
1433 ExceptionDecl->getInnerLocStart(),
1434 ExceptionDecl->getLocation(),
1435 ExceptionDecl->getIdentifier());
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 \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +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 RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001443 SourceLocation RParenLoc,
1444 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001445 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001446 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001447 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001449
James Dennett2a4d13c2012-06-15 07:13:21 +00001450 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001451 ///
1452 /// By default, performs semantic analysis to build the new statement.
1453 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001454 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001455 Stmt *Body) {
1456 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001458
James Dennett2a4d13c2012-06-15 07:13:21 +00001459 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001460 ///
1461 /// By default, performs semantic analysis to build the new statement.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001463 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001464 Expr *Operand) {
1465 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001466 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001467
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001468 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001469 ///
1470 /// By default, performs semantic analysis to build the new statement.
1471 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001472 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001473 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001474 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001475 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001476 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001477 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001478 return getSema().ActOnOpenMPExecutableDirective(
1479 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001480 }
1481
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001482 /// \brief Build a new OpenMP 'if' clause.
1483 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001484 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001485 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001486 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1487 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001488 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001489 SourceLocation NameModifierLoc,
1490 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001491 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001492 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1493 LParenLoc, NameModifierLoc, ColonLoc,
1494 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001495 }
1496
Alexey Bataev3778b602014-07-17 07:32:53 +00001497 /// \brief Build a new OpenMP 'final' clause.
1498 ///
1499 /// By default, performs semantic analysis to build the new OpenMP clause.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1502 SourceLocation LParenLoc,
1503 SourceLocation EndLoc) {
1504 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1505 EndLoc);
1506 }
1507
Alexey Bataev568a8332014-03-06 06:15:19 +00001508 /// \brief Build a new OpenMP 'num_threads' clause.
1509 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001510 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001511 /// Subclasses may override this routine to provide different behavior.
1512 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1513 SourceLocation StartLoc,
1514 SourceLocation LParenLoc,
1515 SourceLocation EndLoc) {
1516 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1517 LParenLoc, EndLoc);
1518 }
1519
Alexey Bataev62c87d22014-03-21 04:51:18 +00001520 /// \brief Build a new OpenMP 'safelen' clause.
1521 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001522 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001523 /// Subclasses may override this routine to provide different behavior.
1524 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation EndLoc) {
1527 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1528 }
1529
Alexey Bataev66b15b52015-08-21 11:14:16 +00001530 /// \brief Build a new OpenMP 'simdlen' clause.
1531 ///
1532 /// By default, performs semantic analysis to build the new OpenMP clause.
1533 /// Subclasses may override this routine to provide different behavior.
1534 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1535 SourceLocation LParenLoc,
1536 SourceLocation EndLoc) {
1537 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1538 }
1539
Alexander Musman8bd31e62014-05-27 15:12:19 +00001540 /// \brief Build a new OpenMP 'collapse' clause.
1541 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001542 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001543 /// Subclasses may override this routine to provide different behavior.
1544 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1545 SourceLocation LParenLoc,
1546 SourceLocation EndLoc) {
1547 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1548 EndLoc);
1549 }
1550
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001551 /// \brief Build a new OpenMP 'default' clause.
1552 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001553 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001554 /// Subclasses may override this routine to provide different behavior.
1555 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1556 SourceLocation KindKwLoc,
1557 SourceLocation StartLoc,
1558 SourceLocation LParenLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1561 StartLoc, LParenLoc, EndLoc);
1562 }
1563
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001564 /// \brief Build a new OpenMP 'proc_bind' clause.
1565 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001566 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1569 SourceLocation KindKwLoc,
1570 SourceLocation StartLoc,
1571 SourceLocation LParenLoc,
1572 SourceLocation EndLoc) {
1573 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1574 StartLoc, LParenLoc, EndLoc);
1575 }
1576
Alexey Bataev56dafe82014-06-20 07:16:17 +00001577 /// \brief Build a new OpenMP 'schedule' clause.
1578 ///
1579 /// By default, performs semantic analysis to build the new OpenMP clause.
1580 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6402bca2015-12-28 07:25:51 +00001581 OMPClause *RebuildOMPScheduleClause(
1582 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
1583 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1584 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1585 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
Alexey Bataev56dafe82014-06-20 07:16:17 +00001586 return getSema().ActOnOpenMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00001587 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1588 CommaLoc, EndLoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001589 }
1590
Alexey Bataev10e775f2015-07-30 11:36:16 +00001591 /// \brief Build a new OpenMP 'ordered' clause.
1592 ///
1593 /// By default, performs semantic analysis to build the new OpenMP clause.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1596 SourceLocation EndLoc,
1597 SourceLocation LParenLoc, Expr *Num) {
1598 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1599 }
1600
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001601 /// \brief Build a new OpenMP 'private' clause.
1602 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001603 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001604 /// Subclasses may override this routine to provide different behavior.
1605 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1606 SourceLocation StartLoc,
1607 SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1610 EndLoc);
1611 }
1612
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001613 /// \brief Build a new OpenMP 'firstprivate' clause.
1614 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001615 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1618 SourceLocation StartLoc,
1619 SourceLocation LParenLoc,
1620 SourceLocation EndLoc) {
1621 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1622 EndLoc);
1623 }
1624
Alexander Musman1bb328c2014-06-04 13:06:39 +00001625 /// \brief Build a new OpenMP 'lastprivate' clause.
1626 ///
1627 /// By default, performs semantic analysis to build the new OpenMP clause.
1628 /// Subclasses may override this routine to provide different behavior.
1629 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1630 SourceLocation StartLoc,
1631 SourceLocation LParenLoc,
1632 SourceLocation EndLoc) {
1633 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1634 EndLoc);
1635 }
1636
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001637 /// \brief Build a new OpenMP 'shared' clause.
1638 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001639 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001640 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001641 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1642 SourceLocation StartLoc,
1643 SourceLocation LParenLoc,
1644 SourceLocation EndLoc) {
1645 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1646 EndLoc);
1647 }
1648
Alexey Bataevc5e02582014-06-16 07:08:35 +00001649 /// \brief Build a new OpenMP 'reduction' clause.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1654 SourceLocation StartLoc,
1655 SourceLocation LParenLoc,
1656 SourceLocation ColonLoc,
1657 SourceLocation EndLoc,
1658 CXXScopeSpec &ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001659 const DeclarationNameInfo &ReductionId,
1660 ArrayRef<Expr *> UnresolvedReductions) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001661 return getSema().ActOnOpenMPReductionClause(
1662 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001663 ReductionId, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001664 }
1665
Alexey Bataev169d96a2017-07-18 20:17:46 +00001666 /// Build a new OpenMP 'task_reduction' clause.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1670 OMPClause *RebuildOMPTaskReductionClause(
1671 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1672 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1673 CXXScopeSpec &ReductionIdScopeSpec,
1674 const DeclarationNameInfo &ReductionId,
1675 ArrayRef<Expr *> UnresolvedReductions) {
1676 return getSema().ActOnOpenMPTaskReductionClause(
1677 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1678 ReductionId, UnresolvedReductions);
1679 }
1680
Alexey Bataevfa312f32017-07-21 18:48:21 +00001681 /// Build a new OpenMP 'in_reduction' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new statement.
1684 /// Subclasses may override this routine to provide different behavior.
1685 OMPClause *
1686 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1687 SourceLocation LParenLoc, SourceLocation ColonLoc,
1688 SourceLocation EndLoc,
1689 CXXScopeSpec &ReductionIdScopeSpec,
1690 const DeclarationNameInfo &ReductionId,
1691 ArrayRef<Expr *> UnresolvedReductions) {
1692 return getSema().ActOnOpenMPInReductionClause(
1693 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1694 ReductionId, UnresolvedReductions);
1695 }
1696
Alexander Musman8dba6642014-04-22 13:09:42 +00001697 /// \brief Build a new OpenMP 'linear' clause.
1698 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001699 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001700 /// Subclasses may override this routine to provide different behavior.
1701 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1702 SourceLocation StartLoc,
1703 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001704 OpenMPLinearClauseKind Modifier,
1705 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001706 SourceLocation ColonLoc,
1707 SourceLocation EndLoc) {
1708 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001709 Modifier, ModifierLoc, ColonLoc,
1710 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001711 }
1712
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001713 /// \brief Build a new OpenMP 'aligned' clause.
1714 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001715 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001716 /// Subclasses may override this routine to provide different behavior.
1717 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1718 SourceLocation StartLoc,
1719 SourceLocation LParenLoc,
1720 SourceLocation ColonLoc,
1721 SourceLocation EndLoc) {
1722 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1723 LParenLoc, ColonLoc, EndLoc);
1724 }
1725
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001726 /// \brief Build a new OpenMP 'copyin' clause.
1727 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001728 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001729 /// Subclasses may override this routine to provide different behavior.
1730 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1731 SourceLocation StartLoc,
1732 SourceLocation LParenLoc,
1733 SourceLocation EndLoc) {
1734 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1735 EndLoc);
1736 }
1737
Alexey Bataevbae9a792014-06-27 10:37:06 +00001738 /// \brief Build a new OpenMP 'copyprivate' clause.
1739 ///
1740 /// By default, performs semantic analysis to build the new OpenMP clause.
1741 /// Subclasses may override this routine to provide different behavior.
1742 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1743 SourceLocation StartLoc,
1744 SourceLocation LParenLoc,
1745 SourceLocation EndLoc) {
1746 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1747 EndLoc);
1748 }
1749
Alexey Bataev6125da92014-07-21 11:26:11 +00001750 /// \brief Build a new OpenMP 'flush' pseudo clause.
1751 ///
1752 /// By default, performs semantic analysis to build the new OpenMP clause.
1753 /// Subclasses may override this routine to provide different behavior.
1754 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1755 SourceLocation StartLoc,
1756 SourceLocation LParenLoc,
1757 SourceLocation EndLoc) {
1758 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1759 EndLoc);
1760 }
1761
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001762 /// \brief Build a new OpenMP 'depend' pseudo clause.
1763 ///
1764 /// By default, performs semantic analysis to build the new OpenMP clause.
1765 /// Subclasses may override this routine to provide different behavior.
1766 OMPClause *
1767 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1768 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1769 SourceLocation StartLoc, SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1772 StartLoc, LParenLoc, EndLoc);
1773 }
1774
Michael Wonge710d542015-08-07 16:16:36 +00001775 /// \brief Build a new OpenMP 'device' clause.
1776 ///
1777 /// By default, performs semantic analysis to build the new statement.
1778 /// Subclasses may override this routine to provide different behavior.
1779 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
Kelvin Li099bb8c2015-11-24 20:50:12 +00001782 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
Michael Wonge710d542015-08-07 16:16:36 +00001783 EndLoc);
1784 }
1785
Kelvin Li0bff7af2015-11-23 05:32:03 +00001786 /// \brief Build a new OpenMP 'map' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
Samuel Antao23abd722016-01-19 20:40:49 +00001790 OMPClause *
1791 RebuildOMPMapClause(OpenMPMapClauseKind MapTypeModifier,
1792 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
1793 SourceLocation MapLoc, SourceLocation ColonLoc,
1794 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1795 SourceLocation LParenLoc, SourceLocation EndLoc) {
1796 return getSema().ActOnOpenMPMapClause(MapTypeModifier, MapType,
1797 IsMapTypeImplicit, MapLoc, ColonLoc,
1798 VarList, StartLoc, LParenLoc, EndLoc);
Kelvin Li0bff7af2015-11-23 05:32:03 +00001799 }
1800
Kelvin Li099bb8c2015-11-24 20:50:12 +00001801 /// \brief Build a new OpenMP 'num_teams' clause.
1802 ///
1803 /// By default, performs semantic analysis to build the new statement.
1804 /// Subclasses may override this routine to provide different behavior.
1805 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc) {
1808 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
1809 EndLoc);
1810 }
1811
Kelvin Lia15fb1a2015-11-27 18:47:36 +00001812 /// \brief Build a new OpenMP 'thread_limit' clause.
1813 ///
1814 /// By default, performs semantic analysis to build the new statement.
1815 /// Subclasses may override this routine to provide different behavior.
1816 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
1817 SourceLocation StartLoc,
1818 SourceLocation LParenLoc,
1819 SourceLocation EndLoc) {
1820 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
1821 LParenLoc, EndLoc);
1822 }
1823
Alexey Bataeva0569352015-12-01 10:17:31 +00001824 /// \brief Build a new OpenMP 'priority' clause.
1825 ///
1826 /// By default, performs semantic analysis to build the new statement.
1827 /// Subclasses may override this routine to provide different behavior.
1828 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
1829 SourceLocation LParenLoc,
1830 SourceLocation EndLoc) {
1831 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
1832 EndLoc);
1833 }
1834
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00001835 /// \brief Build a new OpenMP 'grainsize' clause.
1836 ///
1837 /// By default, performs semantic analysis to build the new statement.
1838 /// Subclasses may override this routine to provide different behavior.
1839 OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc,
1841 SourceLocation EndLoc) {
1842 return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
1843 EndLoc);
1844 }
1845
Alexey Bataev382967a2015-12-08 12:06:20 +00001846 /// \brief Build a new OpenMP 'num_tasks' clause.
1847 ///
1848 /// By default, performs semantic analysis to build the new statement.
1849 /// Subclasses may override this routine to provide different behavior.
1850 OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
1851 SourceLocation LParenLoc,
1852 SourceLocation EndLoc) {
1853 return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
1854 EndLoc);
1855 }
1856
Alexey Bataev28c75412015-12-15 08:19:24 +00001857 /// \brief Build a new OpenMP 'hint' clause.
1858 ///
1859 /// By default, performs semantic analysis to build the new statement.
1860 /// Subclasses may override this routine to provide different behavior.
1861 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
1862 SourceLocation LParenLoc,
1863 SourceLocation EndLoc) {
1864 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
1865 }
1866
Carlo Bertollib4adf552016-01-15 18:50:31 +00001867 /// \brief Build a new OpenMP 'dist_schedule' clause.
1868 ///
1869 /// By default, performs semantic analysis to build the new OpenMP clause.
1870 /// Subclasses may override this routine to provide different behavior.
1871 OMPClause *
1872 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
1873 Expr *ChunkSize, SourceLocation StartLoc,
1874 SourceLocation LParenLoc, SourceLocation KindLoc,
1875 SourceLocation CommaLoc, SourceLocation EndLoc) {
1876 return getSema().ActOnOpenMPDistScheduleClause(
1877 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1878 }
1879
Samuel Antao661c0902016-05-26 17:39:58 +00001880 /// \brief Build a new OpenMP 'to' clause.
1881 ///
1882 /// By default, performs semantic analysis to build the new statement.
1883 /// Subclasses may override this routine to provide different behavior.
1884 OMPClause *RebuildOMPToClause(ArrayRef<Expr *> VarList,
1885 SourceLocation StartLoc,
1886 SourceLocation LParenLoc,
1887 SourceLocation EndLoc) {
1888 return getSema().ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc);
1889 }
1890
Samuel Antaoec172c62016-05-26 17:49:04 +00001891 /// \brief Build a new OpenMP 'from' clause.
1892 ///
1893 /// By default, performs semantic analysis to build the new statement.
1894 /// Subclasses may override this routine to provide different behavior.
1895 OMPClause *RebuildOMPFromClause(ArrayRef<Expr *> VarList,
1896 SourceLocation StartLoc,
1897 SourceLocation LParenLoc,
1898 SourceLocation EndLoc) {
1899 return getSema().ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc,
1900 EndLoc);
1901 }
1902
Carlo Bertolli2404b172016-07-13 15:37:16 +00001903 /// Build a new OpenMP 'use_device_ptr' clause.
1904 ///
1905 /// By default, performs semantic analysis to build the new OpenMP clause.
1906 /// Subclasses may override this routine to provide different behavior.
1907 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
1908 SourceLocation StartLoc,
1909 SourceLocation LParenLoc,
1910 SourceLocation EndLoc) {
1911 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc,
1912 EndLoc);
1913 }
1914
Carlo Bertolli70594e92016-07-13 17:16:49 +00001915 /// Build a new OpenMP 'is_device_ptr' clause.
1916 ///
1917 /// By default, performs semantic analysis to build the new OpenMP clause.
1918 /// Subclasses may override this routine to provide different behavior.
1919 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
1920 SourceLocation StartLoc,
1921 SourceLocation LParenLoc,
1922 SourceLocation EndLoc) {
1923 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc,
1924 EndLoc);
1925 }
1926
James Dennett2a4d13c2012-06-15 07:13:21 +00001927 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001928 ///
1929 /// By default, performs semantic analysis to build the new statement.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1932 Expr *object) {
1933 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1934 }
1935
James Dennett2a4d13c2012-06-15 07:13:21 +00001936 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001937 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001938 /// By default, performs semantic analysis to build the new statement.
1939 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001940 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001941 Expr *Object, Stmt *Body) {
1942 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001943 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001944
James Dennett2a4d13c2012-06-15 07:13:21 +00001945 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001946 ///
1947 /// By default, performs semantic analysis to build the new statement.
1948 /// Subclasses may override this routine to provide different behavior.
1949 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1950 Stmt *Body) {
1951 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1952 }
John McCall53848232011-07-27 01:07:15 +00001953
Douglas Gregorf68a5082010-04-22 23:10:45 +00001954 /// \brief Build a new Objective-C fast enumeration statement.
1955 ///
1956 /// By default, performs semantic analysis to build the new statement.
1957 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001958 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001959 Stmt *Element,
1960 Expr *Collection,
1961 SourceLocation RParenLoc,
1962 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001963 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001964 Element,
John McCallb268a282010-08-23 23:25:46 +00001965 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001966 RParenLoc);
1967 if (ForEachStmt.isInvalid())
1968 return StmtError();
1969
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001970 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001971 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 /// \brief Build a new C++ exception declaration.
1974 ///
1975 /// By default, performs semantic analysis to build the new decaration.
1976 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001977 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001978 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001979 SourceLocation StartLoc,
1980 SourceLocation IdLoc,
1981 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001982 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001983 StartLoc, IdLoc, Id);
1984 if (Var)
1985 getSema().CurContext->addDecl(Var);
1986 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001987 }
1988
1989 /// \brief Build a new C++ catch statement.
1990 ///
1991 /// By default, performs semantic analysis to build the new statement.
1992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001993 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001994 VarDecl *ExceptionDecl,
1995 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001996 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1997 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001998 }
Mike Stump11289f42009-09-09 15:08:12 +00001999
Douglas Gregorebe10102009-08-20 07:17:43 +00002000 /// \brief Build a new C++ try statement.
2001 ///
2002 /// By default, performs semantic analysis to build the new statement.
2003 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00002004 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
2005 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002006 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Richard Smith02e85f32011-04-14 22:09:26 +00002009 /// \brief Build a new C++0x range-based for statement.
2010 ///
2011 /// By default, performs semantic analysis to build the new statement.
2012 /// Subclasses may override this routine to provide different behavior.
2013 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
Richard Smith9f690bd2015-10-27 06:02:45 +00002014 SourceLocation CoawaitLoc,
Richard Smith02e85f32011-04-14 22:09:26 +00002015 SourceLocation ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002016 Stmt *Range, Stmt *Begin, Stmt *End,
Richard Smith02e85f32011-04-14 22:09:26 +00002017 Expr *Cond, Expr *Inc,
2018 Stmt *LoopVar,
2019 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00002020 // If we've just learned that the range is actually an Objective-C
2021 // collection, treat this as an Objective-C fast enumeration loop.
2022 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2023 if (RangeStmt->isSingleDecl()) {
2024 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00002025 if (RangeVar->isInvalidDecl())
2026 return StmtError();
2027
Douglas Gregorf7106af2013-04-08 18:40:13 +00002028 Expr *RangeExpr = RangeVar->getInit();
2029 if (!RangeExpr->isTypeDependent() &&
2030 RangeExpr->getType()->isObjCObjectPointerType())
2031 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
2032 RParenLoc);
2033 }
2034 }
2035 }
2036
Richard Smithcfd53b42015-10-22 06:13:50 +00002037 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, ColonLoc,
Richard Smith01694c32016-03-20 10:33:40 +00002038 Range, Begin, End,
Richard Smitha05b3b52012-09-20 21:52:32 +00002039 Cond, Inc, LoopVar, RParenLoc,
2040 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00002041 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002042
2043 /// \brief Build a new C++0x range-based for statement.
2044 ///
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002047 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00002048 bool IsIfExists,
2049 NestedNameSpecifierLoc QualifierLoc,
2050 DeclarationNameInfo NameInfo,
2051 Stmt *Nested) {
2052 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2053 QualifierLoc, NameInfo, Nested);
2054 }
2055
Richard Smith02e85f32011-04-14 22:09:26 +00002056 /// \brief Attach body to a C++0x range-based for statement.
2057 ///
2058 /// By default, performs semantic analysis to finish the new statement.
2059 /// Subclasses may override this routine to provide different behavior.
2060 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
2061 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2062 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002063
David Majnemerfad8f482013-10-15 09:33:02 +00002064 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00002065 Stmt *TryBlock, Stmt *Handler) {
2066 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00002067 }
2068
David Majnemerfad8f482013-10-15 09:33:02 +00002069 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00002070 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00002071 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002072 }
2073
David Majnemerfad8f482013-10-15 09:33:02 +00002074 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00002075 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00002076 }
2077
Alexey Bataevec474782014-10-09 08:45:04 +00002078 /// \brief Build a new predefined expression.
2079 ///
2080 /// By default, performs semantic analysis to build the new expression.
2081 /// Subclasses may override this routine to provide different behavior.
2082 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
2083 PredefinedExpr::IdentType IT) {
2084 return getSema().BuildPredefinedExpr(Loc, IT);
2085 }
2086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new expression that references a declaration.
2088 ///
2089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00002092 LookupResult &R,
2093 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00002094 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2095 }
2096
2097
2098 /// \brief Build a new expression that references a declaration.
2099 ///
2100 /// By default, performs semantic analysis to build the new expression.
2101 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00002102 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002103 ValueDecl *VD,
2104 const DeclarationNameInfo &NameInfo,
2105 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00002106 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002107 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00002108
2109 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002110
2111 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 }
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregora16548e2009-08-11 05:31:07 +00002114 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 /// By default, performs semantic analysis to build the new expression.
2117 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002118 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00002120 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 }
2122
Douglas Gregorad8a3362009-09-04 17:36:40 +00002123 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00002124 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00002125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002127 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00002128 SourceLocation OperatorLoc,
2129 bool isArrow,
2130 CXXScopeSpec &SS,
2131 TypeSourceInfo *ScopeType,
2132 SourceLocation CCLoc,
2133 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00002134 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002140 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002141 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002143 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 }
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregor882211c2010-04-28 22:16:22 +00002146 /// \brief Build a new builtin offsetof expression.
2147 ///
2148 /// By default, performs semantic analysis to build the new expression.
2149 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002150 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00002151 TypeSourceInfo *Type,
2152 ArrayRef<Sema::OffsetOfComponent> Components,
2153 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00002154 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00002155 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00002156 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002157
2158 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00002159 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00002160 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002163 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
2164 SourceLocation OpLoc,
2165 UnaryExprOrTypeTrait ExprKind,
2166 SourceRange R) {
2167 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00002168 }
2169
Peter Collingbournee190dee2011-03-11 19:24:49 +00002170 /// \brief Build a new sizeof, alignof or vec step expression with an
2171 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00002172 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 /// By default, performs semantic analysis to build the new expression.
2174 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00002175 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
2176 UnaryExprOrTypeTrait ExprKind,
2177 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00002178 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00002179 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00002180 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002181 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002182
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002183 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 }
Mike Stump11289f42009-09-09 15:08:12 +00002185
Douglas Gregora16548e2009-08-11 05:31:07 +00002186 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00002187 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 /// By default, performs semantic analysis to build the new expression.
2189 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002190 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00002192 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002193 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002194 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00002195 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002196 RBracketLoc);
2197 }
2198
Alexey Bataev1a3320e2015-08-25 14:24:04 +00002199 /// \brief Build a new array section expression.
2200 ///
2201 /// By default, performs semantic analysis to build the new expression.
2202 /// Subclasses may override this routine to provide different behavior.
2203 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
2204 Expr *LowerBound,
2205 SourceLocation ColonLoc, Expr *Length,
2206 SourceLocation RBracketLoc) {
2207 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2208 ColonLoc, Length, RBracketLoc);
2209 }
2210
Douglas Gregora16548e2009-08-11 05:31:07 +00002211 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00002212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00002217 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00002218 Expr *ExecConfig = nullptr) {
2219 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002220 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00002221 }
2222
2223 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 /// By default, performs semantic analysis to build the new expression.
2226 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002227 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002228 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00002229 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002230 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002231 const DeclarationNameInfo &MemberNameInfo,
2232 ValueDecl *Member,
2233 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00002234 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00002235 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00002236 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
2237 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00002238 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00002239 // We have a reference to an unnamed field. This is always the
2240 // base of an anonymous struct/union member access, i.e. the
2241 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00002242 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00002243 assert(Member->getType()->isRecordType() &&
2244 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00002245
Richard Smithcab9a7d2011-10-26 19:06:56 +00002246 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002247 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00002248 QualifierLoc.getNestedNameSpecifier(),
2249 FoundDecl, Member);
2250 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002251 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002252 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00002253 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00002254 MemberExpr *ME = new (getSema().Context)
2255 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
2256 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002257 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00002258 }
Mike Stump11289f42009-09-09 15:08:12 +00002259
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002260 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00002261 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00002262
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002263 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00002264 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00002265
Saleem Abdulrasool1f5f5c22017-04-20 22:23:10 +00002266 if (isArrow && !BaseType->isPointerType())
2267 return ExprError();
2268
John McCall16df1e52010-03-30 21:47:33 +00002269 // FIXME: this involves duplicating earlier analysis in a lot of
2270 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002271 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00002272 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00002273 R.resolveKind();
2274
John McCallb268a282010-08-23 23:25:46 +00002275 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002276 SS, TemplateKWLoc,
2277 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002278 R, ExplicitTemplateArgs,
2279 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 }
Mike Stump11289f42009-09-09 15:08:12 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002283 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00002287 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00002288 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00002289 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002290 }
2291
2292 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00002293 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002294 /// By default, performs semantic analysis to build the new expression.
2295 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002296 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00002297 SourceLocation QuestionLoc,
2298 Expr *LHS,
2299 SourceLocation ColonLoc,
2300 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002301 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2302 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002303 }
2304
Douglas Gregora16548e2009-08-11 05:31:07 +00002305 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002306 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 /// By default, performs semantic analysis to build the new expression.
2308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002309 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002310 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002312 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002313 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002314 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 }
Mike Stump11289f42009-09-09 15:08:12 +00002316
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002318 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 /// By default, performs semantic analysis to build the new expression.
2320 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002321 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002322 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002323 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002324 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002325 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002326 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002327 }
Mike Stump11289f42009-09-09 15:08:12 +00002328
Douglas Gregora16548e2009-08-11 05:31:07 +00002329 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002330 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002331 /// By default, performs semantic analysis to build the new expression.
2332 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002333 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002334 SourceLocation OpLoc,
2335 SourceLocation AccessorLoc,
2336 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002337
John McCall10eae182009-11-30 22:42:35 +00002338 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002339 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002340 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002341 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002342 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002343 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002344 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002345 /* TemplateArgs */ nullptr,
2346 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002347 }
Mike Stump11289f42009-09-09 15:08:12 +00002348
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002350 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002351 /// By default, performs semantic analysis to build the new expression.
2352 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002353 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002354 MultiExprArg Inits,
Richard Smithd1036122018-01-12 22:21:33 +00002355 SourceLocation RBraceLoc) {
2356 return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
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 designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002360 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002361 /// By default, performs semantic analysis to build the new expression.
2362 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002363 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002364 MultiExprArg ArrayExprs,
2365 SourceLocation EqualOrColonLoc,
2366 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002367 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002368 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002370 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002371 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002372 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002373
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002374 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002375 }
Mike Stump11289f42009-09-09 15:08:12 +00002376
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002378 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002379 /// By default, builds the implicit value initialization without performing
2380 /// any semantic analysis. Subclasses may override this routine to provide
2381 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002382 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002383 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002384 }
Mike Stump11289f42009-09-09 15:08:12 +00002385
Douglas Gregora16548e2009-08-11 05:31:07 +00002386 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002387 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002388 /// By default, performs semantic analysis to build the new expression.
2389 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002390 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002391 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002392 SourceLocation RParenLoc) {
2393 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002394 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002395 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002396 }
2397
2398 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002399 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 /// By default, performs semantic analysis to build the new expression.
2401 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002402 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002403 MultiExprArg SubExprs,
2404 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002405 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002406 }
Mike Stump11289f42009-09-09 15:08:12 +00002407
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002409 ///
2410 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002411 /// rather than attempting to map the label statement itself.
2412 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002413 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002414 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002415 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 }
Mike Stump11289f42009-09-09 15:08:12 +00002417
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002419 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002420 /// By default, performs semantic analysis to build the new expression.
2421 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002422 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002423 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002425 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 }
Mike Stump11289f42009-09-09 15:08:12 +00002427
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 /// \brief Build a new __builtin_choose_expr expression.
2429 ///
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002433 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002434 SourceLocation RParenLoc) {
2435 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002436 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 RParenLoc);
2438 }
Mike Stump11289f42009-09-09 15:08:12 +00002439
Peter Collingbourne91147592011-04-15 00:35:48 +00002440 /// \brief Build a new generic selection expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
2444 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2445 SourceLocation DefaultLoc,
2446 SourceLocation RParenLoc,
2447 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002448 ArrayRef<TypeSourceInfo *> Types,
2449 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002450 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002451 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002452 }
2453
Douglas Gregora16548e2009-08-11 05:31:07 +00002454 /// \brief Build a new overloaded operator call expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// The semantic analysis provides the behavior of template instantiation,
2458 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002459 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002460 /// argument-dependent lookup, etc. Subclasses may override this routine to
2461 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002462 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002463 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002464 Expr *Callee,
2465 Expr *First,
2466 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002467
2468 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002469 /// reinterpret_cast.
2470 ///
2471 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002472 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002473 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002474 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 Stmt::StmtClass Class,
2476 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002477 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002478 SourceLocation RAngleLoc,
2479 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002480 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002481 SourceLocation RParenLoc) {
2482 switch (Class) {
2483 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002484 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002485 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002486 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002487
2488 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002489 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002490 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002491 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002492
Douglas Gregora16548e2009-08-11 05:31:07 +00002493 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002494 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002495 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002496 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002497 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002498
Douglas Gregora16548e2009-08-11 05:31:07 +00002499 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002500 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002501 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002502 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002503
Douglas Gregora16548e2009-08-11 05:31:07 +00002504 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002505 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002506 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 }
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregora16548e2009-08-11 05:31:07 +00002509 /// \brief Build a new C++ static_cast expression.
2510 ///
2511 /// By default, performs semantic analysis to build the new expression.
2512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002513 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002514 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002515 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002516 SourceLocation RAngleLoc,
2517 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002518 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002519 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002520 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002521 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002522 SourceRange(LAngleLoc, RAngleLoc),
2523 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002524 }
2525
2526 /// \brief Build a new C++ dynamic_cast expression.
2527 ///
2528 /// By default, performs semantic analysis to build the new expression.
2529 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002530 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002531 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002532 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002533 SourceLocation RAngleLoc,
2534 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002535 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002537 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002538 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002539 SourceRange(LAngleLoc, RAngleLoc),
2540 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 }
2542
2543 /// \brief Build a new C++ reinterpret_cast expression.
2544 ///
2545 /// By default, performs semantic analysis to build the new expression.
2546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002547 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002549 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 SourceLocation RAngleLoc,
2551 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002552 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002554 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002555 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002556 SourceRange(LAngleLoc, RAngleLoc),
2557 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 }
2559
2560 /// \brief Build a new C++ const_cast expression.
2561 ///
2562 /// By default, performs semantic analysis to build the new expression.
2563 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002564 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002565 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002566 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 SourceLocation RAngleLoc,
2568 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002569 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002570 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002571 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002572 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002573 SourceRange(LAngleLoc, RAngleLoc),
2574 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002575 }
Mike Stump11289f42009-09-09 15:08:12 +00002576
Douglas Gregora16548e2009-08-11 05:31:07 +00002577 /// \brief Build a new C++ functional-style cast expression.
2578 ///
2579 /// By default, performs semantic analysis to build the new expression.
2580 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002581 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2582 SourceLocation LParenLoc,
2583 Expr *Sub,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002584 SourceLocation RParenLoc,
2585 bool ListInitialization) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00002586 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002587 MultiExprArg(&Sub, 1), RParenLoc,
2588 ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 }
Mike Stump11289f42009-09-09 15:08:12 +00002590
Douglas Gregora16548e2009-08-11 05:31:07 +00002591 /// \brief Build a new C++ typeid(type) expression.
2592 ///
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002595 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002596 SourceLocation TypeidLoc,
2597 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002598 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002599 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002600 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002601 }
Mike Stump11289f42009-09-09 15:08:12 +00002602
Francois Pichet9f4f2072010-09-08 12:20:18 +00002603
Douglas Gregora16548e2009-08-11 05:31:07 +00002604 /// \brief Build a new C++ typeid(expr) expression.
2605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002608 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002609 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002610 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002611 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002612 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002613 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002614 }
2615
Francois Pichet9f4f2072010-09-08 12:20:18 +00002616 /// \brief Build a new C++ __uuidof(type) expression.
2617 ///
2618 /// By default, performs semantic analysis to build the new expression.
2619 /// Subclasses may override this routine to provide different behavior.
2620 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2621 SourceLocation TypeidLoc,
2622 TypeSourceInfo *Operand,
2623 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002624 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002625 RParenLoc);
2626 }
2627
2628 /// \brief Build a new C++ __uuidof(expr) expression.
2629 ///
2630 /// By default, performs semantic analysis to build the new expression.
2631 /// Subclasses may override this routine to provide different behavior.
2632 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2633 SourceLocation TypeidLoc,
2634 Expr *Operand,
2635 SourceLocation RParenLoc) {
2636 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2637 RParenLoc);
2638 }
2639
Douglas Gregora16548e2009-08-11 05:31:07 +00002640 /// \brief Build a new C++ "this" expression.
2641 ///
2642 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002643 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002644 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002645 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002646 QualType ThisType,
2647 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002648 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002649 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002650 }
2651
2652 /// \brief Build a new C++ throw expression.
2653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002656 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2657 bool IsThrownVariableInScope) {
2658 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002659 }
2660
2661 /// \brief Build a new C++ default-argument expression.
2662 ///
2663 /// By default, builds a new default-argument expression, which does not
2664 /// require any semantic analysis. Subclasses may override this routine to
2665 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002666 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002667 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002668 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 }
2670
Richard Smith852c9db2013-04-20 22:23:05 +00002671 /// \brief Build a new C++11 default-initialization expression.
2672 ///
2673 /// By default, builds a new default field initialization expression, which
2674 /// does not require any semantic analysis. Subclasses may override this
2675 /// routine to provide different behavior.
2676 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2677 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002678 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002679 }
2680
Douglas Gregora16548e2009-08-11 05:31:07 +00002681 /// \brief Build a new C++ zero-initialization expression.
2682 ///
2683 /// By default, performs semantic analysis to build the new expression.
2684 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002685 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2686 SourceLocation LParenLoc,
2687 SourceLocation RParenLoc) {
Vedant Kumara14a1f92018-01-17 18:53:51 +00002688 return getSema().BuildCXXTypeConstructExpr(
2689 TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
Douglas Gregora16548e2009-08-11 05:31:07 +00002690 }
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregora16548e2009-08-11 05:31:07 +00002692 /// \brief Build a new C++ "new" expression.
2693 ///
2694 /// By default, performs semantic analysis to build the new expression.
2695 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002696 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002697 bool UseGlobal,
2698 SourceLocation PlacementLParen,
2699 MultiExprArg PlacementArgs,
2700 SourceLocation PlacementRParen,
2701 SourceRange TypeIdParens,
2702 QualType AllocatedType,
2703 TypeSourceInfo *AllocatedTypeInfo,
2704 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002705 SourceRange DirectInitRange,
2706 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002707 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002708 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002709 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002710 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002711 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002712 AllocatedType,
2713 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002714 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002715 DirectInitRange,
2716 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002717 }
Mike Stump11289f42009-09-09 15:08:12 +00002718
Douglas Gregora16548e2009-08-11 05:31:07 +00002719 /// \brief Build a new C++ "delete" expression.
2720 ///
2721 /// By default, performs semantic analysis to build the new expression.
2722 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002723 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002724 bool IsGlobalDelete,
2725 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002726 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002727 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002728 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002729 }
Mike Stump11289f42009-09-09 15:08:12 +00002730
Douglas Gregor29c42f22012-02-24 07:38:34 +00002731 /// \brief Build a new type trait expression.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
2735 ExprResult RebuildTypeTrait(TypeTrait Trait,
2736 SourceLocation StartLoc,
2737 ArrayRef<TypeSourceInfo *> Args,
2738 SourceLocation RParenLoc) {
2739 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2740 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002741
John Wiegley6242b6a2011-04-28 00:16:57 +00002742 /// \brief Build a new array type trait expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
2746 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2747 SourceLocation StartLoc,
2748 TypeSourceInfo *TSInfo,
2749 Expr *DimExpr,
2750 SourceLocation RParenLoc) {
2751 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2752 }
2753
John Wiegleyf9f65842011-04-25 06:54:41 +00002754 /// \brief Build a new expression trait expression.
2755 ///
2756 /// By default, performs semantic analysis to build the new expression.
2757 /// Subclasses may override this routine to provide different behavior.
2758 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2759 SourceLocation StartLoc,
2760 Expr *Queried,
2761 SourceLocation RParenLoc) {
2762 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2763 }
2764
Mike Stump11289f42009-09-09 15:08:12 +00002765 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002766 /// expression.
2767 ///
2768 /// By default, performs semantic analysis to build the new expression.
2769 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002770 ExprResult RebuildDependentScopeDeclRefExpr(
2771 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002772 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002773 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002774 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002775 bool IsAddressOfOperand,
2776 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002777 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002778 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002779
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002780 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002781 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2782 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002783
Reid Kleckner32506ed2014-06-12 23:03:48 +00002784 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002785 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002786 }
2787
2788 /// \brief Build a new template-id expression.
2789 ///
2790 /// By default, performs semantic analysis to build the new expression.
2791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002792 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002793 SourceLocation TemplateKWLoc,
2794 LookupResult &R,
2795 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002796 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002797 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2798 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002799 }
2800
2801 /// \brief Build a new object-construction expression.
2802 ///
2803 /// By default, performs semantic analysis to build the new expression.
2804 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002805 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002806 SourceLocation Loc,
2807 CXXConstructorDecl *Constructor,
2808 bool IsElidable,
2809 MultiExprArg Args,
2810 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002811 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002812 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002813 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002814 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002815 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002816 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002817 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002818 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002819 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002820
Richard Smithc83bf822016-06-10 00:58:19 +00002821 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +00002822 IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002823 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002824 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002825 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002826 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002827 RequiresZeroInit, ConstructKind,
2828 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002829 }
2830
Richard Smith5179eb72016-06-28 19:03:57 +00002831 /// \brief Build a new implicit construction via inherited constructor
2832 /// expression.
2833 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
2834 CXXConstructorDecl *Constructor,
2835 bool ConstructsVBase,
2836 bool InheritedFromVBase) {
2837 return new (getSema().Context) CXXInheritedCtorInitExpr(
2838 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
2839 }
2840
Douglas Gregora16548e2009-08-11 05:31:07 +00002841 /// \brief Build a new object-construction expression.
2842 ///
2843 /// By default, performs semantic analysis to build the new expression.
2844 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002845 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002846 SourceLocation LParenOrBraceLoc,
Douglas Gregor2b88c112010-09-08 00:15:04 +00002847 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002848 SourceLocation RParenOrBraceLoc,
2849 bool ListInitialization) {
2850 return getSema().BuildCXXTypeConstructExpr(
2851 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002852 }
2853
2854 /// \brief Build a new object-construction expression.
2855 ///
2856 /// By default, performs semantic analysis to build the new expression.
2857 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002858 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2859 SourceLocation LParenLoc,
2860 MultiExprArg Args,
Vedant Kumara14a1f92018-01-17 18:53:51 +00002861 SourceLocation RParenLoc,
2862 bool ListInitialization) {
2863 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
2864 RParenLoc, ListInitialization);
Douglas Gregora16548e2009-08-11 05:31:07 +00002865 }
Mike Stump11289f42009-09-09 15:08:12 +00002866
Douglas Gregora16548e2009-08-11 05:31:07 +00002867 /// \brief Build a new member reference expression.
2868 ///
2869 /// By default, performs semantic analysis to build the new expression.
2870 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002871 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002872 QualType BaseType,
2873 bool IsArrow,
2874 SourceLocation OperatorLoc,
2875 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002876 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002877 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002878 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002879 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002880 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002881 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002882
John McCallb268a282010-08-23 23:25:46 +00002883 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002884 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002885 SS, TemplateKWLoc,
2886 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002887 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002888 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002889 }
2890
John McCall10eae182009-11-30 22:42:35 +00002891 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002892 ///
2893 /// By default, performs semantic analysis to build the new expression.
2894 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002895 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2896 SourceLocation OperatorLoc,
2897 bool IsArrow,
2898 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002899 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002900 NamedDecl *FirstQualifierInScope,
2901 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002902 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002903 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002904 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002905
John McCallb268a282010-08-23 23:25:46 +00002906 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002907 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002908 SS, TemplateKWLoc,
2909 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002910 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002911 }
Mike Stump11289f42009-09-09 15:08:12 +00002912
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002913 /// \brief Build a new noexcept expression.
2914 ///
2915 /// By default, performs semantic analysis to build the new expression.
2916 /// Subclasses may override this routine to provide different behavior.
2917 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2918 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2919 }
2920
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002921 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002922 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2923 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002924 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002925 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002926 Optional<unsigned> Length,
2927 ArrayRef<TemplateArgument> PartialArgs) {
2928 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2929 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002930 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002931
Patrick Beard0caa3942012-04-19 00:25:12 +00002932 /// \brief Build a new Objective-C boxed expression.
2933 ///
2934 /// By default, performs semantic analysis to build the new expression.
2935 /// Subclasses may override this routine to provide different behavior.
2936 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2937 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2938 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002939
Ted Kremeneke65b0862012-03-06 20:05:56 +00002940 /// \brief Build a new Objective-C array literal.
2941 ///
2942 /// By default, performs semantic analysis to build the new expression.
2943 /// Subclasses may override this routine to provide different behavior.
2944 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2945 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002946 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002947 MultiExprArg(Elements, NumElements));
2948 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002949
2950 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002951 Expr *Base, Expr *Key,
2952 ObjCMethodDecl *getterMethod,
2953 ObjCMethodDecl *setterMethod) {
2954 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2955 getterMethod, setterMethod);
2956 }
2957
2958 /// \brief Build a new Objective-C dictionary literal.
2959 ///
2960 /// By default, performs semantic analysis to build the new expression.
2961 /// Subclasses may override this routine to provide different behavior.
2962 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
Craig Topperd4336e02015-12-24 23:58:15 +00002963 MutableArrayRef<ObjCDictionaryElement> Elements) {
2964 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
Ted Kremeneke65b0862012-03-06 20:05:56 +00002965 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002966
James Dennett2a4d13c2012-06-15 07:13:21 +00002967 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002968 ///
2969 /// By default, performs semantic analysis to build the new expression.
2970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002971 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002972 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002973 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002974 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002975 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002976
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002977 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002978 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002979 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002980 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002981 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002982 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002983 MultiExprArg Args,
2984 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002985 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2986 ReceiverTypeInfo->getType(),
2987 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002988 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002989 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002990 }
2991
2992 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002993 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002994 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002995 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002996 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002997 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002998 MultiExprArg Args,
2999 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00003000 return SemaRef.BuildInstanceMessage(Receiver,
3001 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003002 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00003003 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00003004 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003005 }
3006
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003007 /// \brief Build a new Objective-C instance/class message to 'super'.
3008 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
3009 Selector Sel,
3010 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003011 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003012 ObjCMethodDecl *Method,
3013 SourceLocation LBracLoc,
3014 MultiExprArg Args,
3015 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003016 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003017 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003018 SuperLoc,
3019 Sel, Method, LBracLoc, SelectorLocs,
3020 RBracLoc, Args)
3021 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00003022 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00003023 SuperLoc,
3024 Sel, Method, LBracLoc, SelectorLocs,
3025 RBracLoc, Args);
3026
3027
3028 }
3029
Douglas Gregord51d90d2010-04-26 20:11:03 +00003030 /// \brief Build a new Objective-C ivar reference expression.
3031 ///
3032 /// By default, performs semantic analysis to build the new expression.
3033 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003034 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00003035 SourceLocation IvarLoc,
3036 bool IsArrow, bool IsFreeIvar) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003037 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003038 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
Alex Lorenz776b4172017-02-03 14:22:33 +00003039 ExprResult Result = getSema().BuildMemberReferenceExpr(
3040 BaseArg, BaseArg->getType(),
3041 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3042 /*FirstQualifierInScope=*/nullptr, NameInfo,
3043 /*TemplateArgs=*/nullptr,
3044 /*S=*/nullptr);
3045 if (IsFreeIvar && Result.isUsable())
3046 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3047 return Result;
Douglas Gregord51d90d2010-04-26 20:11:03 +00003048 }
Douglas Gregor9faee212010-04-26 20:47:02 +00003049
3050 /// \brief Build a new Objective-C property reference expression.
3051 ///
3052 /// By default, performs semantic analysis to build the new expression.
3053 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00003054 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00003055 ObjCPropertyDecl *Property,
3056 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00003057 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003058 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3059 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3060 /*FIXME:*/PropertyLoc,
3061 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003062 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003063 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003064 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003065 /*TemplateArgs=*/nullptr,
3066 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00003067 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003068
John McCallb7bd14f2010-12-02 01:19:52 +00003069 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003070 ///
3071 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00003072 /// Subclasses may override this routine to provide different behavior.
3073 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
3074 ObjCMethodDecl *Getter,
3075 ObjCMethodDecl *Setter,
3076 SourceLocation PropertyLoc) {
3077 // Since these expressions can only be value-dependent, we do not
3078 // need to perform semantic analysis again.
3079 return Owned(
3080 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3081 VK_LValue, OK_ObjCProperty,
3082 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00003083 }
3084
Douglas Gregord51d90d2010-04-26 20:11:03 +00003085 /// \brief Build a new Objective-C "isa" 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 RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00003090 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00003091 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00003092 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3093 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00003094 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00003095 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00003096 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00003097 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00003098 /*TemplateArgs=*/nullptr,
3099 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00003100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregora16548e2009-08-11 05:31:07 +00003102 /// \brief Build a new shuffle vector expression.
3103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00003106 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00003107 MultiExprArg SubExprs,
3108 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003109 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00003110 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00003111 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3112 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
3113 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00003114 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00003115
Douglas Gregora16548e2009-08-11 05:31:07 +00003116 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00003117 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00003118 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
3119 SemaRef.Context.BuiltinFnTy,
3120 VK_RValue, BuiltinLoc);
3121 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3122 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003123 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00003124
3125 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003126 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00003127 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003128 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00003129
Douglas Gregora16548e2009-08-11 05:31:07 +00003130 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003131 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003132 }
John McCall31f82722010-11-12 08:19:04 +00003133
Hal Finkelc4d7c822013-09-18 03:29:45 +00003134 /// \brief Build a new convert vector expression.
3135 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
3136 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3137 SourceLocation RParenLoc) {
3138 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3139 BuiltinLoc, RParenLoc);
3140 }
3141
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003142 /// \brief Build a new template argument pack expansion.
3143 ///
3144 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003145 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003146 /// different behavior.
3147 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003148 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003149 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003150 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00003151 case TemplateArgument::Expression: {
3152 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00003153 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
3154 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00003155 if (Result.isInvalid())
3156 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor98318c22011-01-03 21:37:45 +00003158 return TemplateArgumentLoc(Result.get(), Result.get());
3159 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003160
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003161 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003162 return TemplateArgumentLoc(TemplateArgument(
3163 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00003164 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00003165 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003166 Pattern.getTemplateNameLoc(),
3167 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003168
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003169 case TemplateArgument::Null:
3170 case TemplateArgument::Integral:
3171 case TemplateArgument::Declaration:
3172 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003173 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00003174 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003175 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003177 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00003178 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003179 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003180 EllipsisLoc,
3181 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003182 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3183 Expansion);
3184 break;
3185 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003186
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003187 return TemplateArgumentLoc();
3188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003189
Douglas Gregor968f23a2011-01-03 19:31:53 +00003190 /// \brief Build a new expression pack expansion.
3191 ///
3192 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00003193 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00003194 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00003195 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00003196 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00003197 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003198 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003199
Richard Smith0f0af192014-11-08 05:07:16 +00003200 /// \brief Build a new C++1z fold-expression.
3201 ///
3202 /// By default, performs semantic analysis in order to build a new fold
3203 /// expression.
3204 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
3205 BinaryOperatorKind Operator,
3206 SourceLocation EllipsisLoc, Expr *RHS,
3207 SourceLocation RParenLoc) {
3208 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
3209 RHS, RParenLoc);
3210 }
3211
3212 /// \brief Build an empty C++1z fold-expression with the given operator.
3213 ///
3214 /// By default, produces the fallback value for the fold-expression, or
3215 /// produce an error if there is no fallback value.
3216 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
3217 BinaryOperatorKind Operator) {
3218 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3219 }
3220
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003221 /// \brief Build a new atomic operation expression.
3222 ///
3223 /// By default, performs semantic analysis to build the new expression.
3224 /// Subclasses may override this routine to provide different behavior.
3225 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
3226 MultiExprArg SubExprs,
3227 QualType RetTy,
3228 AtomicExpr::AtomicOp Op,
3229 SourceLocation RParenLoc) {
3230 // Just create the expression; there is not any interesting semantic
3231 // analysis here because we can't actually build an AtomicExpr until
3232 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00003233 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00003234 RParenLoc);
3235 }
3236
John McCall31f82722010-11-12 08:19:04 +00003237private:
Douglas Gregor14454802011-02-25 02:25:35 +00003238 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
3239 QualType ObjectType,
3240 NamedDecl *FirstQualifierInScope,
3241 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003242
3243 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3244 QualType ObjectType,
3245 NamedDecl *FirstQualifierInScope,
3246 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003247
3248 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
3249 NamedDecl *FirstQualifierInScope,
3250 CXXScopeSpec &SS);
Richard Smithee579842017-01-30 20:39:26 +00003251
3252 QualType TransformDependentNameType(TypeLocBuilder &TLB,
3253 DependentNameTypeLoc TL,
3254 bool DeducibleTSTContext);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003255};
Douglas Gregora16548e2009-08-11 05:31:07 +00003256
Douglas Gregorebe10102009-08-20 07:17:43 +00003257template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003258StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003260 return S;
Mike Stump11289f42009-09-09 15:08:12 +00003261
Douglas Gregorebe10102009-08-20 07:17:43 +00003262 switch (S->getStmtClass()) {
3263 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00003264
Douglas Gregorebe10102009-08-20 07:17:43 +00003265 // Transform individual statement nodes
3266#define STMT(Node, Parent) \
3267 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00003268#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00003269#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00003270#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregorebe10102009-08-20 07:17:43 +00003272 // Transform expressions by calling TransformExpr.
3273#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00003274#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00003275#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00003276#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00003277 {
John McCalldadc5752010-08-24 06:29:42 +00003278 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00003279 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00003280 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003281
Richard Smith945f8d32013-01-14 22:39:08 +00003282 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00003283 }
Mike Stump11289f42009-09-09 15:08:12 +00003284 }
3285
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003286 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00003287}
Mike Stump11289f42009-09-09 15:08:12 +00003288
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00003289template<typename Derived>
3290OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
3291 if (!S)
3292 return S;
3293
3294 switch (S->getClauseKind()) {
3295 default: break;
3296 // Transform individual clause nodes
3297#define OPENMP_CLAUSE(Name, Class) \
3298 case OMPC_ ## Name : \
3299 return getDerived().Transform ## Class(cast<Class>(S));
3300#include "clang/Basic/OpenMPKinds.def"
3301 }
3302
3303 return S;
3304}
3305
Mike Stump11289f42009-09-09 15:08:12 +00003306
Douglas Gregore922c772009-08-04 22:27:00 +00003307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003308ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003309 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003310 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003311
3312 switch (E->getStmtClass()) {
3313 case Stmt::NoStmtClass: break;
3314#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003315#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003316#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003317 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003318#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003319 }
3320
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003321 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003322}
3323
3324template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003325ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003326 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003327 // Initializers are instantiated like expressions, except that various outer
3328 // layers are stripped.
3329 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003330 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003331
3332 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3333 Init = ExprTemp->getSubExpr();
3334
Richard Smith410306b2016-12-12 02:53:20 +00003335 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init))
3336 Init = AIL->getCommonExpr();
3337
Richard Smithe6ca4752013-05-30 22:40:16 +00003338 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3339 Init = MTE->GetTemporaryExpr();
3340
Richard Smithd59b8322012-12-19 01:39:02 +00003341 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3342 Init = Binder->getSubExpr();
3343
3344 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3345 Init = ICE->getSubExprAsWritten();
3346
Richard Smithcc1b96d2013-06-12 22:31:48 +00003347 if (CXXStdInitializerListExpr *ILE =
3348 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003349 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003350
Richard Smithc6abd962014-07-25 01:12:44 +00003351 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003352 // InitListExprs. Other forms of copy-initialization will be a no-op if
3353 // the initializer is already the right type.
3354 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003355 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003356 return getDerived().TransformExpr(Init);
3357
3358 // Revert value-initialization back to empty parens.
3359 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3360 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003361 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003362 Parens.getEnd());
3363 }
3364
3365 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3366 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003367 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003368 SourceLocation());
3369
3370 // Revert initialization by constructor back to a parenthesized or braced list
3371 // of expressions. Any other form of initializer can just be reused directly.
3372 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003373 return getDerived().TransformExpr(Init);
3374
Richard Smithf8adcdc2014-07-17 05:12:35 +00003375 // If the initialization implicitly converted an initializer list to a
3376 // std::initializer_list object, unwrap the std::initializer_list too.
3377 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003378 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003379
Richard Smithd59b8322012-12-19 01:39:02 +00003380 SmallVector<Expr*, 8> NewArgs;
3381 bool ArgChanged = false;
3382 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003383 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003384 return ExprError();
3385
Richard Smithd1036122018-01-12 22:21:33 +00003386 // If this was list initialization, revert to syntactic list form.
Richard Smithd59b8322012-12-19 01:39:02 +00003387 if (Construct->isListInitialization())
3388 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
Richard Smithd1036122018-01-12 22:21:33 +00003389 Construct->getLocEnd());
Richard Smithd59b8322012-12-19 01:39:02 +00003390
Richard Smithd59b8322012-12-19 01:39:02 +00003391 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003392 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003393 if (Parens.isInvalid()) {
3394 // This was a variable declaration's initialization for which no initializer
3395 // was specified.
3396 assert(NewArgs.empty() &&
3397 "no parens or braces but have direct init with arguments?");
3398 return ExprEmpty();
3399 }
Richard Smithd59b8322012-12-19 01:39:02 +00003400 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3401 Parens.getEnd());
3402}
3403
3404template<typename Derived>
Craig Topper99d23532015-12-24 23:58:29 +00003405bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
Chad Rosier1dcde962012-08-08 18:46:20 +00003406 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003407 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003408 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003409 bool *ArgChanged) {
3410 for (unsigned I = 0; I != NumInputs; ++I) {
3411 // If requested, drop call arguments that need to be dropped.
3412 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3413 if (ArgChanged)
3414 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003415
Douglas Gregora3efea12011-01-03 19:04:46 +00003416 break;
3417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor968f23a2011-01-03 19:31:53 +00003419 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3420 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Chris Lattner01cf8db2011-07-20 06:58:45 +00003422 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003423 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3424 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregor968f23a2011-01-03 19:31:53 +00003426 // Determine whether the set of unexpanded parameter packs can and should
3427 // be expanded.
3428 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003429 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003430 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3431 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003432 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3433 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003434 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003435 Expand, RetainExpansion,
3436 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003437 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003438
Douglas Gregor968f23a2011-01-03 19:31:53 +00003439 if (!Expand) {
3440 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003441 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003442 // expansion.
3443 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3444 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3445 if (OutPattern.isInvalid())
3446 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
3448 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003449 Expansion->getEllipsisLoc(),
3450 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003451 if (Out.isInvalid())
3452 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003453
Douglas Gregor968f23a2011-01-03 19:31:53 +00003454 if (ArgChanged)
3455 *ArgChanged = true;
3456 Outputs.push_back(Out.get());
3457 continue;
3458 }
John McCall542e7c62011-07-06 07:30:07 +00003459
3460 // Record right away that the argument was changed. This needs
3461 // to happen even if the array expands to nothing.
3462 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003463
Douglas Gregor968f23a2011-01-03 19:31:53 +00003464 // The transform has determined that we should perform an elementwise
3465 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003466 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003467 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3468 ExprResult Out = getDerived().TransformExpr(Pattern);
3469 if (Out.isInvalid())
3470 return true;
3471
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003472 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003473 Out = getDerived().RebuildPackExpansion(
3474 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003475 if (Out.isInvalid())
3476 return true;
3477 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003478
Douglas Gregor968f23a2011-01-03 19:31:53 +00003479 Outputs.push_back(Out.get());
3480 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003481
Richard Smith9467be42014-06-06 17:33:35 +00003482 // If we're supposed to retain a pack expansion, do so by temporarily
3483 // forgetting the partially-substituted parameter pack.
3484 if (RetainExpansion) {
3485 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3486
3487 ExprResult Out = getDerived().TransformExpr(Pattern);
3488 if (Out.isInvalid())
3489 return true;
3490
3491 Out = getDerived().RebuildPackExpansion(
3492 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3493 if (Out.isInvalid())
3494 return true;
3495
3496 Outputs.push_back(Out.get());
3497 }
3498
Douglas Gregor968f23a2011-01-03 19:31:53 +00003499 continue;
3500 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003501
Richard Smithd59b8322012-12-19 01:39:02 +00003502 ExprResult Result =
3503 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3504 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003505 if (Result.isInvalid())
3506 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003507
Douglas Gregora3efea12011-01-03 19:04:46 +00003508 if (Result.get() != Inputs[I] && ArgChanged)
3509 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003510
3511 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003512 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003513
Douglas Gregora3efea12011-01-03 19:04:46 +00003514 return false;
3515}
3516
Richard Smith03a4aa32016-06-23 19:02:52 +00003517template <typename Derived>
3518Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
3519 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
3520 if (Var) {
3521 VarDecl *ConditionVar = cast_or_null<VarDecl>(
3522 getDerived().TransformDefinition(Var->getLocation(), Var));
3523
3524 if (!ConditionVar)
3525 return Sema::ConditionError();
3526
3527 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
3528 }
3529
3530 if (Expr) {
3531 ExprResult CondExpr = getDerived().TransformExpr(Expr);
3532
3533 if (CondExpr.isInvalid())
3534 return Sema::ConditionError();
3535
3536 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind);
3537 }
3538
3539 return Sema::ConditionResult();
3540}
3541
Douglas Gregora3efea12011-01-03 19:04:46 +00003542template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003543NestedNameSpecifierLoc
3544TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3545 NestedNameSpecifierLoc NNS,
3546 QualType ObjectType,
3547 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003548 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003549 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003550 Qualifier = Qualifier.getPrefix())
3551 Qualifiers.push_back(Qualifier);
3552
3553 CXXScopeSpec SS;
3554 while (!Qualifiers.empty()) {
3555 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3556 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003557
Douglas Gregor14454802011-02-25 02:25:35 +00003558 switch (QNNS->getKind()) {
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003559 case NestedNameSpecifier::Identifier: {
3560 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
3561 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType);
3562 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
3563 SS, FirstQualifierInScope, false))
Douglas Gregor14454802011-02-25 02:25:35 +00003564 return NestedNameSpecifierLoc();
Serge Pavlovd931b9f2016-08-08 04:02:15 +00003565 }
Douglas Gregor14454802011-02-25 02:25:35 +00003566 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003567
Douglas Gregor14454802011-02-25 02:25:35 +00003568 case NestedNameSpecifier::Namespace: {
3569 NamespaceDecl *NS
3570 = cast_or_null<NamespaceDecl>(
3571 getDerived().TransformDecl(
3572 Q.getLocalBeginLoc(),
3573 QNNS->getAsNamespace()));
3574 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3575 break;
3576 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003577
Douglas Gregor14454802011-02-25 02:25:35 +00003578 case NestedNameSpecifier::NamespaceAlias: {
3579 NamespaceAliasDecl *Alias
3580 = cast_or_null<NamespaceAliasDecl>(
3581 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3582 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003583 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003584 Q.getLocalEndLoc());
3585 break;
3586 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003587
Douglas Gregor14454802011-02-25 02:25:35 +00003588 case NestedNameSpecifier::Global:
3589 // There is no meaningful transformation that one could perform on the
3590 // global scope.
3591 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3592 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Nikola Smiljanic67860242014-09-26 00:28:20 +00003594 case NestedNameSpecifier::Super: {
3595 CXXRecordDecl *RD =
3596 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3597 SourceLocation(), QNNS->getAsRecordDecl()));
3598 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3599 break;
3600 }
3601
Douglas Gregor14454802011-02-25 02:25:35 +00003602 case NestedNameSpecifier::TypeSpecWithTemplate:
3603 case NestedNameSpecifier::TypeSpec: {
3604 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3605 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003606
Douglas Gregor14454802011-02-25 02:25:35 +00003607 if (!TL)
3608 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003609
Douglas Gregor14454802011-02-25 02:25:35 +00003610 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003611 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003612 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003613 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003614 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003615 if (TL.getType()->isEnumeralType())
3616 SemaRef.Diag(TL.getBeginLoc(),
3617 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003618 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3619 Q.getLocalEndLoc());
3620 break;
3621 }
Richard Trieude756fb2011-05-07 01:36:37 +00003622 // If the nested-name-specifier is an invalid type def, don't emit an
3623 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003624 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3625 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003626 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003627 << TL.getType() << SS.getRange();
3628 }
Douglas Gregor14454802011-02-25 02:25:35 +00003629 return NestedNameSpecifierLoc();
3630 }
Douglas Gregore16af532011-02-28 18:50:33 +00003631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003632
Douglas Gregore16af532011-02-28 18:50:33 +00003633 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003634 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003635 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003636 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor14454802011-02-25 02:25:35 +00003638 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003639 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003640 !getDerived().AlwaysRebuild())
3641 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003642
3643 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003644 // nested-name-specifier, do so.
3645 if (SS.location_size() == NNS.getDataLength() &&
3646 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3647 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3648
3649 // Allocate new nested-name-specifier location information.
3650 return SS.getWithLocInContext(SemaRef.Context);
3651}
3652
3653template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003654DeclarationNameInfo
3655TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003656::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003657 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003658 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003659 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003660
3661 switch (Name.getNameKind()) {
3662 case DeclarationName::Identifier:
3663 case DeclarationName::ObjCZeroArgSelector:
3664 case DeclarationName::ObjCOneArgSelector:
3665 case DeclarationName::ObjCMultiArgSelector:
3666 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003667 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003668 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003669 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003670
Richard Smith35845152017-02-07 01:37:30 +00003671 case DeclarationName::CXXDeductionGuideName: {
3672 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
3673 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
3674 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
3675 if (!NewTemplate)
3676 return DeclarationNameInfo();
3677
3678 DeclarationNameInfo NewNameInfo(NameInfo);
3679 NewNameInfo.setName(
3680 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
3681 return NewNameInfo;
3682 }
3683
Douglas Gregorf816bd72009-09-03 22:13:48 +00003684 case DeclarationName::CXXConstructorName:
3685 case DeclarationName::CXXDestructorName:
3686 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003687 TypeSourceInfo *NewTInfo;
3688 CanQualType NewCanTy;
3689 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003690 NewTInfo = getDerived().TransformType(OldTInfo);
3691 if (!NewTInfo)
3692 return DeclarationNameInfo();
3693 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003694 }
3695 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003696 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003697 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003698 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003699 if (NewT.isNull())
3700 return DeclarationNameInfo();
3701 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3702 }
Mike Stump11289f42009-09-09 15:08:12 +00003703
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003704 DeclarationName NewName
3705 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3706 NewCanTy);
3707 DeclarationNameInfo NewNameInfo(NameInfo);
3708 NewNameInfo.setName(NewName);
3709 NewNameInfo.setNamedTypeInfo(NewTInfo);
3710 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003711 }
Mike Stump11289f42009-09-09 15:08:12 +00003712 }
3713
David Blaikie83d382b2011-09-23 05:06:16 +00003714 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003715}
3716
3717template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003718TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003719TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3720 TemplateName Name,
3721 SourceLocation NameLoc,
3722 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003723 NamedDecl *FirstQualifierInScope,
3724 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +00003725 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3726 TemplateDecl *Template = QTN->getTemplateDecl();
3727 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregor9db53502011-03-02 18:07:45 +00003729 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003730 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003731 Template));
3732 if (!TransTemplate)
3733 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003734
Douglas Gregor9db53502011-03-02 18:07:45 +00003735 if (!getDerived().AlwaysRebuild() &&
3736 SS.getScopeRep() == QTN->getQualifier() &&
3737 TransTemplate == Template)
3738 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
Douglas Gregor9db53502011-03-02 18:07:45 +00003740 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3741 TransTemplate);
3742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor9db53502011-03-02 18:07:45 +00003744 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3745 if (SS.getScopeRep()) {
3746 // These apply to the scope specifier, not the template.
3747 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003748 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003749 }
3750
Douglas Gregor9db53502011-03-02 18:07:45 +00003751 if (!getDerived().AlwaysRebuild() &&
3752 SS.getScopeRep() == DTN->getQualifier() &&
3753 ObjectType.isNull())
3754 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003755
Douglas Gregor9db53502011-03-02 18:07:45 +00003756 if (DTN->isIdentifier()) {
3757 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003758 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003759 NameLoc,
3760 ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +00003761 FirstQualifierInScope,
3762 AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003763 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
Douglas Gregor9db53502011-03-02 18:07:45 +00003765 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +00003766 ObjectType, AllowInjectedClassName);
Douglas Gregor9db53502011-03-02 18:07:45 +00003767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003768
Douglas Gregor9db53502011-03-02 18:07:45 +00003769 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3770 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003771 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003772 Template));
3773 if (!TransTemplate)
3774 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003775
Douglas Gregor9db53502011-03-02 18:07:45 +00003776 if (!getDerived().AlwaysRebuild() &&
3777 TransTemplate == Template)
3778 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003779
Douglas Gregor9db53502011-03-02 18:07:45 +00003780 return TemplateName(TransTemplate);
3781 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003782
Douglas Gregor9db53502011-03-02 18:07:45 +00003783 if (SubstTemplateTemplateParmPackStorage *SubstPack
3784 = Name.getAsSubstTemplateTemplateParmPack()) {
3785 TemplateTemplateParmDecl *TransParam
3786 = cast_or_null<TemplateTemplateParmDecl>(
3787 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3788 if (!TransParam)
3789 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003790
Douglas Gregor9db53502011-03-02 18:07:45 +00003791 if (!getDerived().AlwaysRebuild() &&
3792 TransParam == SubstPack->getParameterPack())
3793 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003794
3795 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003796 SubstPack->getArgumentPack());
3797 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003798
Douglas Gregor9db53502011-03-02 18:07:45 +00003799 // These should be getting filtered out before they reach the AST.
3800 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003801}
3802
3803template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003804void TreeTransform<Derived>::InventTemplateArgumentLoc(
3805 const TemplateArgument &Arg,
3806 TemplateArgumentLoc &Output) {
3807 SourceLocation Loc = getDerived().getBaseLocation();
3808 switch (Arg.getKind()) {
3809 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003810 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003811 break;
3812
3813 case TemplateArgument::Type:
3814 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003815 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003816
John McCall0ad16662009-10-29 08:12:44 +00003817 break;
3818
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003819 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003820 case TemplateArgument::TemplateExpansion: {
3821 NestedNameSpecifierLocBuilder Builder;
Manuel Klimek4c67fa72016-01-11 11:39:00 +00003822 TemplateName Template = Arg.getAsTemplateOrTemplatePattern();
Douglas Gregor9d802122011-03-02 17:09:35 +00003823 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3824 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3825 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3826 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003827
Douglas Gregor9d802122011-03-02 17:09:35 +00003828 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003829 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003830 Builder.getWithLocInContext(SemaRef.Context),
3831 Loc);
3832 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003833 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003834 Builder.getWithLocInContext(SemaRef.Context),
3835 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003836
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003837 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003838 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003839
John McCall0ad16662009-10-29 08:12:44 +00003840 case TemplateArgument::Expression:
3841 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3842 break;
3843
3844 case TemplateArgument::Declaration:
3845 case TemplateArgument::Integral:
3846 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003847 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003848 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003849 break;
3850 }
3851}
3852
3853template<typename Derived>
3854bool TreeTransform<Derived>::TransformTemplateArgument(
3855 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003856 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003857 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003858 switch (Arg.getKind()) {
3859 case TemplateArgument::Null:
3860 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003861 case TemplateArgument::Pack:
3862 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003863 case TemplateArgument::NullPtr:
3864 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregore922c772009-08-04 22:27:00 +00003866 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003867 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003868 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003869 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003870
3871 DI = getDerived().TransformType(DI);
3872 if (!DI) return true;
3873
3874 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3875 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003876 }
Mike Stump11289f42009-09-09 15:08:12 +00003877
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003878 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003879 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3880 if (QualifierLoc) {
3881 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3882 if (!QualifierLoc)
3883 return true;
3884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003885
Douglas Gregordf846d12011-03-02 18:46:51 +00003886 CXXScopeSpec SS;
3887 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003888 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003889 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3890 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003891 if (Template.isNull())
3892 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003893
Douglas Gregor9d802122011-03-02 17:09:35 +00003894 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003895 Input.getTemplateNameLoc());
3896 return false;
3897 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003898
3899 case TemplateArgument::TemplateExpansion:
3900 llvm_unreachable("Caller should expand pack expansions");
3901
Douglas Gregore922c772009-08-04 22:27:00 +00003902 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003903 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003904 EnterExpressionEvaluationContext Unevaluated(
Faisal Valid143a0c2017-04-01 21:30:49 +00003905 getSema(), Uneval
3906 ? Sema::ExpressionEvaluationContext::Unevaluated
3907 : Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003908
John McCall0ad16662009-10-29 08:12:44 +00003909 Expr *InputExpr = Input.getSourceExpression();
3910 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3911
Chris Lattnercdb591a2011-04-25 20:37:58 +00003912 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003913 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003914 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003915 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003916 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003917 }
Douglas Gregore922c772009-08-04 22:27:00 +00003918 }
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregore922c772009-08-04 22:27:00 +00003920 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003921 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003922}
3923
Douglas Gregorfe921a72010-12-20 23:36:19 +00003924/// \brief Iterator adaptor that invents template argument location information
3925/// for each of the template arguments in its underlying iterator.
3926template<typename Derived, typename InputIterator>
3927class TemplateArgumentLocInventIterator {
3928 TreeTransform<Derived> &Self;
3929 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003930
Douglas Gregorfe921a72010-12-20 23:36:19 +00003931public:
3932 typedef TemplateArgumentLoc value_type;
3933 typedef TemplateArgumentLoc reference;
3934 typedef typename std::iterator_traits<InputIterator>::difference_type
3935 difference_type;
3936 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003937
Douglas Gregorfe921a72010-12-20 23:36:19 +00003938 class pointer {
3939 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003940
Douglas Gregorfe921a72010-12-20 23:36:19 +00003941 public:
3942 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003943
Douglas Gregorfe921a72010-12-20 23:36:19 +00003944 const TemplateArgumentLoc *operator->() const { return &Arg; }
3945 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003946
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003947 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003948
Douglas Gregorfe921a72010-12-20 23:36:19 +00003949 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3950 InputIterator Iter)
3951 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003952
Douglas Gregorfe921a72010-12-20 23:36:19 +00003953 TemplateArgumentLocInventIterator &operator++() {
3954 ++Iter;
3955 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003957
Douglas Gregorfe921a72010-12-20 23:36:19 +00003958 TemplateArgumentLocInventIterator operator++(int) {
3959 TemplateArgumentLocInventIterator Old(*this);
3960 ++(*this);
3961 return Old;
3962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003963
Douglas Gregorfe921a72010-12-20 23:36:19 +00003964 reference operator*() const {
3965 TemplateArgumentLoc Result;
3966 Self.InventTemplateArgumentLoc(*Iter, Result);
3967 return Result;
3968 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003969
Douglas Gregorfe921a72010-12-20 23:36:19 +00003970 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003971
Douglas Gregorfe921a72010-12-20 23:36:19 +00003972 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3973 const TemplateArgumentLocInventIterator &Y) {
3974 return X.Iter == Y.Iter;
3975 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003976
Douglas Gregorfe921a72010-12-20 23:36:19 +00003977 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3978 const TemplateArgumentLocInventIterator &Y) {
3979 return X.Iter != Y.Iter;
3980 }
3981};
Chad Rosier1dcde962012-08-08 18:46:20 +00003982
Douglas Gregor42cafa82010-12-20 17:42:22 +00003983template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003984template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003985bool TreeTransform<Derived>::TransformTemplateArguments(
3986 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3987 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003988 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003989 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003990 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003991
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003992 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3993 // Unpack argument packs, which we translate them into separate
3994 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003995 // FIXME: We could do much better if we could guarantee that the
3996 // TemplateArgumentLocInfo for the pack expansion would be usable for
3997 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003998 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003999 TemplateArgument::pack_iterator>
4000 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00004001 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00004002 In.getArgument().pack_begin()),
4003 PackLocIterator(*this,
4004 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00004005 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00004006 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004007
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004008 continue;
4009 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004010
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004011 if (In.getArgument().isPackExpansion()) {
4012 // We have a pack expansion, for which we will be substituting into
4013 // the pattern.
4014 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00004015 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004016 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00004017 = getSema().getTemplateArgumentPackExpansionPattern(
4018 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004019
Chris Lattner01cf8db2011-07-20 06:58:45 +00004020 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004021 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4022 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00004023
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004024 // Determine whether the set of unexpanded parameter packs can and should
4025 // be expanded.
4026 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004027 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004028 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004029 if (getDerived().TryExpandParameterPacks(Ellipsis,
4030 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00004031 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00004032 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004033 RetainExpansion,
4034 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004035 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004036
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004037 if (!Expand) {
4038 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00004039 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004040 // expansion.
4041 TemplateArgumentLoc OutPattern;
4042 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00004043 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004044 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004045
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004046 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4047 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004048 if (Out.getArgument().isNull())
4049 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004050
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004051 Outputs.addArgument(Out);
4052 continue;
4053 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004054
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004055 // The transform has determined that we should perform an elementwise
4056 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004057 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4059
Richard Smithd784e682015-09-23 21:41:42 +00004060 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004061 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004062
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004063 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004064 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4065 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00004066 if (Out.getArgument().isNull())
4067 return true;
4068 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004069
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004070 Outputs.addArgument(Out);
4071 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004072
Douglas Gregor48d24112011-01-10 20:53:55 +00004073 // If we're supposed to retain a pack expansion, do so by temporarily
4074 // forgetting the partially-substituted parameter pack.
4075 if (RetainExpansion) {
4076 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004077
Richard Smithd784e682015-09-23 21:41:42 +00004078 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00004079 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004080
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004081 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4082 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00004083 if (Out.getArgument().isNull())
4084 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004085
Douglas Gregor48d24112011-01-10 20:53:55 +00004086 Outputs.addArgument(Out);
4087 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004088
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004089 continue;
4090 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004091
4092 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00004093 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004094 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004095
Douglas Gregor42cafa82010-12-20 17:42:22 +00004096 Outputs.addArgument(Out);
4097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004098
Douglas Gregor42cafa82010-12-20 17:42:22 +00004099 return false;
4100
4101}
4102
Douglas Gregord6ff3322009-08-04 16:50:30 +00004103//===----------------------------------------------------------------------===//
4104// Type transformation
4105//===----------------------------------------------------------------------===//
4106
4107template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004108QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00004109 if (getDerived().AlreadyTransformed(T))
4110 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004111
John McCall550e0c22009-10-21 00:40:46 +00004112 // Temporary workaround. All of these transformations should
4113 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00004114 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4115 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00004116
John McCall31f82722010-11-12 08:19:04 +00004117 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00004118
John McCall550e0c22009-10-21 00:40:46 +00004119 if (!NewDI)
4120 return QualType();
4121
4122 return NewDI->getType();
4123}
4124
4125template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00004126TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004127 // Refine the base location to the type's location.
4128 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4129 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00004130 if (getDerived().AlreadyTransformed(DI->getType()))
4131 return DI;
4132
4133 TypeLocBuilder TLB;
4134
4135 TypeLoc TL = DI->getTypeLoc();
4136 TLB.reserve(TL.getFullDataSize());
4137
John McCall31f82722010-11-12 08:19:04 +00004138 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00004139 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004140 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00004141
John McCallbcd03502009-12-07 02:54:59 +00004142 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00004143}
4144
4145template<typename Derived>
4146QualType
John McCall31f82722010-11-12 08:19:04 +00004147TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004148 switch (T.getTypeLocClass()) {
4149#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00004150#define TYPELOC(CLASS, PARENT) \
4151 case TypeLoc::CLASS: \
4152 return getDerived().Transform##CLASS##Type(TLB, \
4153 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00004154#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00004155 }
Mike Stump11289f42009-09-09 15:08:12 +00004156
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00004157 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00004158}
4159
Richard Smithee579842017-01-30 20:39:26 +00004160template<typename Derived>
4161QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
4162 if (!isa<DependentNameType>(T))
4163 return TransformType(T);
4164
4165 if (getDerived().AlreadyTransformed(T))
4166 return T;
4167 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4168 getDerived().getBaseLocation());
4169 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4170 return NewDI ? NewDI->getType() : QualType();
4171}
4172
4173template<typename Derived>
4174TypeSourceInfo *
4175TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
4176 if (!isa<DependentNameType>(DI->getType()))
4177 return TransformType(DI);
4178
4179 // Refine the base location to the type's location.
4180 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4181 getDerived().getBaseEntity());
4182 if (getDerived().AlreadyTransformed(DI->getType()))
4183 return DI;
4184
4185 TypeLocBuilder TLB;
4186
4187 TypeLoc TL = DI->getTypeLoc();
4188 TLB.reserve(TL.getFullDataSize());
4189
Richard Smithee579842017-01-30 20:39:26 +00004190 auto QTL = TL.getAs<QualifiedTypeLoc>();
4191 if (QTL)
4192 TL = QTL.getUnqualifiedLoc();
4193
4194 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4195
4196 QualType Result = getDerived().TransformDependentNameType(
4197 TLB, DNTL, /*DeducedTSTContext*/true);
4198 if (Result.isNull())
4199 return nullptr;
4200
4201 if (QTL) {
4202 Result = getDerived().RebuildQualifiedType(
4203 Result, QTL.getBeginLoc(), QTL.getType().getLocalQualifiers());
4204 TLB.TypeWasModifiedSafely(Result);
4205 }
4206
4207 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4208}
4209
John McCall550e0c22009-10-21 00:40:46 +00004210template<typename Derived>
4211QualType
4212TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004213 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00004214 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00004215
John McCall31f82722010-11-12 08:19:04 +00004216 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00004217 if (Result.isNull())
4218 return QualType();
4219
Richard Smithee579842017-01-30 20:39:26 +00004220 Result = getDerived().RebuildQualifiedType(Result, T.getBeginLoc(), Quals);
4221
4222 // RebuildQualifiedType might have updated the type, but not in a way
4223 // that invalidates the TypeLoc. (There's no location information for
4224 // qualifiers.)
4225 TLB.TypeWasModifiedSafely(Result);
4226
4227 return Result;
4228}
4229
4230template<typename Derived>
4231QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
4232 SourceLocation Loc,
4233 Qualifiers Quals) {
4234 // C++ [dcl.fct]p7:
4235 // [When] adding cv-qualifications on top of the function type [...] the
4236 // cv-qualifiers are ignored.
4237 // C++ [dcl.ref]p1:
4238 // when the cv-qualifiers are introduced through the use of a typedef-name
4239 // or decltype-specifier [...] the cv-qualifiers are ignored.
4240 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
4241 // applied to a reference type.
4242 // FIXME: This removes all qualifiers, not just cv-qualifiers!
4243 if (T->isFunctionType() || T->isReferenceType())
4244 return T;
Mike Stump11289f42009-09-09 15:08:12 +00004245
John McCall31168b02011-06-15 23:02:42 +00004246 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00004247 // resulting type.
4248 if (Quals.hasObjCLifetime()) {
Richard Smithee579842017-01-30 20:39:26 +00004249 if (!T->isObjCLifetimeType() && !T->isDependentType())
Douglas Gregore46db902011-06-17 22:11:49 +00004250 Quals.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004251 else if (T.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004252 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00004253 // A lifetime qualifier applied to a substituted template parameter
4254 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00004255 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00004256 if (const SubstTemplateTypeParmType *SubstTypeParam
Richard Smithee579842017-01-30 20:39:26 +00004257 = dyn_cast<SubstTemplateTypeParmType>(T)) {
Douglas Gregore46db902011-06-17 22:11:49 +00004258 QualType Replacement = SubstTypeParam->getReplacementType();
4259 Qualifiers Qs = Replacement.getQualifiers();
4260 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004261 Replacement = SemaRef.Context.getQualifiedType(
4262 Replacement.getUnqualifiedType(), Qs);
4263 T = SemaRef.Context.getSubstTemplateTypeParmType(
4264 SubstTypeParam->getReplacedParameter(), Replacement);
4265 } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
Douglas Gregorf4e43312013-01-17 23:59:28 +00004266 // 'auto' types behave the same way as template parameters.
4267 QualType Deduced = AutoTy->getDeducedType();
4268 Qualifiers Qs = Deduced.getQualifiers();
4269 Qs.removeObjCLifetime();
Richard Smithee579842017-01-30 20:39:26 +00004270 Deduced =
4271 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
4272 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
4273 AutoTy->isDependentType());
Douglas Gregore46db902011-06-17 22:11:49 +00004274 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00004275 // Otherwise, complain about the addition of a qualifier to an
4276 // already-qualified type.
Richard Smithee579842017-01-30 20:39:26 +00004277 // FIXME: Why is this check not in Sema::BuildQualifiedType?
4278 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
Douglas Gregore46db902011-06-17 22:11:49 +00004279 Quals.removeObjCLifetime();
4280 }
4281 }
4282 }
John McCall550e0c22009-10-21 00:40:46 +00004283
Richard Smithee579842017-01-30 20:39:26 +00004284 return SemaRef.BuildQualifiedType(T, Loc, Quals);
John McCall550e0c22009-10-21 00:40:46 +00004285}
4286
Douglas Gregor14454802011-02-25 02:25:35 +00004287template<typename Derived>
4288TypeLoc
4289TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
4290 QualType ObjectType,
4291 NamedDecl *UnqualLookup,
4292 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004293 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00004294 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00004295
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004296 TypeSourceInfo *TSI =
4297 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
4298 if (TSI)
4299 return TSI->getTypeLoc();
4300 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00004301}
4302
Douglas Gregor579c15f2011-03-02 18:32:08 +00004303template<typename Derived>
4304TypeSourceInfo *
4305TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4306 QualType ObjectType,
4307 NamedDecl *UnqualLookup,
4308 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004309 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00004310 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00004311
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00004312 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
4313 UnqualLookup, SS);
4314}
4315
4316template <typename Derived>
4317TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
4318 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
4319 CXXScopeSpec &SS) {
4320 QualType T = TL.getType();
4321 assert(!getDerived().AlreadyTransformed(T));
4322
Douglas Gregor579c15f2011-03-02 18:32:08 +00004323 TypeLocBuilder TLB;
4324 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00004325
Douglas Gregor579c15f2011-03-02 18:32:08 +00004326 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004327 TemplateSpecializationTypeLoc SpecTL =
4328 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004329
Richard Smithfd3dae02017-01-20 00:20:39 +00004330 TemplateName Template = getDerived().TransformTemplateName(
4331 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
4332 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +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().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004337 Template);
4338 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00004339 DependentTemplateSpecializationTypeLoc SpecTL =
4340 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004341
Douglas Gregor579c15f2011-03-02 18:32:08 +00004342 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00004343 = getDerived().RebuildTemplateName(SS,
4344 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00004345 SpecTL.getTemplateNameLoc(),
Richard Smithfd3dae02017-01-20 00:20:39 +00004346 ObjectType, UnqualLookup,
4347 /*AllowInjectedClassName*/true);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004348 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004349 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004350
4351 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00004352 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004353 Template,
4354 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00004355 } else {
4356 // Nothing special needs to be done for these.
4357 Result = getDerived().TransformType(TLB, TL);
4358 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004359
4360 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004361 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004362
Douglas Gregor579c15f2011-03-02 18:32:08 +00004363 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4364}
4365
John McCall550e0c22009-10-21 00:40:46 +00004366template <class TyLoc> static inline
4367QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
4368 TyLoc NewT = TLB.push<TyLoc>(T.getType());
4369 NewT.setNameLoc(T.getNameLoc());
4370 return T.getType();
4371}
4372
John McCall550e0c22009-10-21 00:40:46 +00004373template<typename Derived>
4374QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004375 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00004376 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
4377 NewT.setBuiltinLoc(T.getBuiltinLoc());
4378 if (T.needsExtraLocalData())
4379 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
4380 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004381}
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregord6ff3322009-08-04 16:50:30 +00004383template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004384QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004385 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00004386 // FIXME: recurse?
4387 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004388}
Mike Stump11289f42009-09-09 15:08:12 +00004389
Reid Kleckner0503a872013-12-05 01:23:43 +00004390template <typename Derived>
4391QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
4392 AdjustedTypeLoc TL) {
4393 // Adjustments applied during transformation are handled elsewhere.
4394 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4395}
4396
Douglas Gregord6ff3322009-08-04 16:50:30 +00004397template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004398QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4399 DecayedTypeLoc TL) {
4400 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4401 if (OriginalType.isNull())
4402 return QualType();
4403
4404 QualType Result = TL.getType();
4405 if (getDerived().AlwaysRebuild() ||
4406 OriginalType != TL.getOriginalLoc().getType())
4407 Result = SemaRef.Context.getDecayedType(OriginalType);
4408 TLB.push<DecayedTypeLoc>(Result);
4409 // Nothing to set for DecayedTypeLoc.
4410 return Result;
4411}
4412
4413template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004414QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004415 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004416 QualType PointeeType
4417 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004418 if (PointeeType.isNull())
4419 return QualType();
4420
4421 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004422 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004423 // A dependent pointer type 'T *' has is being transformed such
4424 // that an Objective-C class type is being replaced for 'T'. The
4425 // resulting pointer type is an ObjCObjectPointerType, not a
4426 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004427 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004428
John McCall8b07ec22010-05-15 11:32:37 +00004429 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4430 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004431 return Result;
4432 }
John McCall31f82722010-11-12 08:19:04 +00004433
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004434 if (getDerived().AlwaysRebuild() ||
4435 PointeeType != TL.getPointeeLoc().getType()) {
4436 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4437 if (Result.isNull())
4438 return QualType();
4439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004440
John McCall31168b02011-06-15 23:02:42 +00004441 // Objective-C ARC can add lifetime qualifiers to the type that we're
4442 // pointing to.
4443 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004444
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004445 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4446 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004447 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004448}
Mike Stump11289f42009-09-09 15:08:12 +00004449
4450template<typename Derived>
4451QualType
John McCall550e0c22009-10-21 00:40:46 +00004452TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004453 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004454 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004455 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4456 if (PointeeType.isNull())
4457 return QualType();
4458
4459 QualType Result = TL.getType();
4460 if (getDerived().AlwaysRebuild() ||
4461 PointeeType != TL.getPointeeLoc().getType()) {
4462 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004463 TL.getSigilLoc());
4464 if (Result.isNull())
4465 return QualType();
4466 }
4467
Douglas Gregor049211a2010-04-22 16:50:51 +00004468 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004469 NewT.setSigilLoc(TL.getSigilLoc());
4470 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004471}
4472
John McCall70dd5f62009-10-30 00:06:24 +00004473/// Transforms a reference type. Note that somewhat paradoxically we
4474/// don't care whether the type itself is an l-value type or an r-value
4475/// type; we only care if the type was *written* as an l-value type
4476/// or an r-value type.
4477template<typename Derived>
4478QualType
4479TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004480 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004481 const ReferenceType *T = TL.getTypePtr();
4482
4483 // Note that this works with the pointee-as-written.
4484 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4485 if (PointeeType.isNull())
4486 return QualType();
4487
4488 QualType Result = TL.getType();
4489 if (getDerived().AlwaysRebuild() ||
4490 PointeeType != T->getPointeeTypeAsWritten()) {
4491 Result = getDerived().RebuildReferenceType(PointeeType,
4492 T->isSpelledAsLValue(),
4493 TL.getSigilLoc());
4494 if (Result.isNull())
4495 return QualType();
4496 }
4497
John McCall31168b02011-06-15 23:02:42 +00004498 // Objective-C ARC can add lifetime qualifiers to the type that we're
4499 // referring to.
4500 TLB.TypeWasModifiedSafely(
4501 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4502
John McCall70dd5f62009-10-30 00:06:24 +00004503 // r-value references can be rebuilt as l-value references.
4504 ReferenceTypeLoc NewTL;
4505 if (isa<LValueReferenceType>(Result))
4506 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4507 else
4508 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4509 NewTL.setSigilLoc(TL.getSigilLoc());
4510
4511 return Result;
4512}
4513
Mike Stump11289f42009-09-09 15:08:12 +00004514template<typename Derived>
4515QualType
John McCall550e0c22009-10-21 00:40:46 +00004516TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004517 LValueReferenceTypeLoc TL) {
4518 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004519}
4520
Mike Stump11289f42009-09-09 15:08:12 +00004521template<typename Derived>
4522QualType
John McCall550e0c22009-10-21 00:40:46 +00004523TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004524 RValueReferenceTypeLoc TL) {
4525 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004526}
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregord6ff3322009-08-04 16:50:30 +00004528template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004529QualType
John McCall550e0c22009-10-21 00:40:46 +00004530TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004531 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004532 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004533 if (PointeeType.isNull())
4534 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004535
Abramo Bagnara509357842011-03-05 14:42:21 +00004536 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004537 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004538 if (OldClsTInfo) {
4539 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4540 if (!NewClsTInfo)
4541 return QualType();
4542 }
4543
4544 const MemberPointerType *T = TL.getTypePtr();
4545 QualType OldClsType = QualType(T->getClass(), 0);
4546 QualType NewClsType;
4547 if (NewClsTInfo)
4548 NewClsType = NewClsTInfo->getType();
4549 else {
4550 NewClsType = getDerived().TransformType(OldClsType);
4551 if (NewClsType.isNull())
4552 return QualType();
4553 }
Mike Stump11289f42009-09-09 15:08:12 +00004554
John McCall550e0c22009-10-21 00:40:46 +00004555 QualType Result = TL.getType();
4556 if (getDerived().AlwaysRebuild() ||
4557 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004558 NewClsType != OldClsType) {
4559 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004560 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004561 if (Result.isNull())
4562 return QualType();
4563 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004564
Reid Kleckner0503a872013-12-05 01:23:43 +00004565 // If we had to adjust the pointee type when building a member pointer, make
4566 // sure to push TypeLoc info for it.
4567 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4568 if (MPT && PointeeType != MPT->getPointeeType()) {
4569 assert(isa<AdjustedType>(MPT->getPointeeType()));
4570 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4571 }
4572
John McCall550e0c22009-10-21 00:40:46 +00004573 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4574 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004575 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004576
4577 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004578}
4579
Mike Stump11289f42009-09-09 15:08:12 +00004580template<typename Derived>
4581QualType
John McCall550e0c22009-10-21 00:40:46 +00004582TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004583 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004584 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004585 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004586 if (ElementType.isNull())
4587 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCall550e0c22009-10-21 00:40:46 +00004589 QualType Result = TL.getType();
4590 if (getDerived().AlwaysRebuild() ||
4591 ElementType != T->getElementType()) {
4592 Result = getDerived().RebuildConstantArrayType(ElementType,
4593 T->getSizeModifier(),
4594 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004595 T->getIndexTypeCVRQualifiers(),
4596 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004597 if (Result.isNull())
4598 return QualType();
4599 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004600
4601 // We might have either a ConstantArrayType or a VariableArrayType now:
4602 // a ConstantArrayType is allowed to have an element type which is a
4603 // VariableArrayType if the type is dependent. Fortunately, all array
4604 // types have the same location layout.
4605 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004606 NewTL.setLBracketLoc(TL.getLBracketLoc());
4607 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004608
John McCall550e0c22009-10-21 00:40:46 +00004609 Expr *Size = TL.getSizeExpr();
4610 if (Size) {
Faisal Valid143a0c2017-04-01 21:30:49 +00004611 EnterExpressionEvaluationContext Unevaluated(
4612 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004613 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4614 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004615 }
4616 NewTL.setSizeExpr(Size);
4617
4618 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004619}
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregord6ff3322009-08-04 16:50:30 +00004621template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004622QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004623 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004624 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004625 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004626 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004627 if (ElementType.isNull())
4628 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004629
John McCall550e0c22009-10-21 00:40:46 +00004630 QualType Result = TL.getType();
4631 if (getDerived().AlwaysRebuild() ||
4632 ElementType != T->getElementType()) {
4633 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004634 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004635 T->getIndexTypeCVRQualifiers(),
4636 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004637 if (Result.isNull())
4638 return QualType();
4639 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004640
John McCall550e0c22009-10-21 00:40:46 +00004641 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4642 NewTL.setLBracketLoc(TL.getLBracketLoc());
4643 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004644 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004645
4646 return Result;
4647}
4648
4649template<typename Derived>
4650QualType
4651TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004652 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004653 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004654 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4655 if (ElementType.isNull())
4656 return QualType();
4657
Tim Shenb34d0ef2017-02-14 23:46:37 +00004658 ExprResult SizeResult;
4659 {
Faisal Valid143a0c2017-04-01 21:30:49 +00004660 EnterExpressionEvaluationContext Context(
4661 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Tim Shenb34d0ef2017-02-14 23:46:37 +00004662 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
4663 }
4664 if (SizeResult.isInvalid())
4665 return QualType();
4666 SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
John McCall550e0c22009-10-21 00:40:46 +00004667 if (SizeResult.isInvalid())
4668 return QualType();
4669
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004670 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004671
4672 QualType Result = TL.getType();
4673 if (getDerived().AlwaysRebuild() ||
4674 ElementType != T->getElementType() ||
4675 Size != T->getSizeExpr()) {
4676 Result = getDerived().RebuildVariableArrayType(ElementType,
4677 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004678 Size,
John McCall550e0c22009-10-21 00:40:46 +00004679 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004680 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004681 if (Result.isNull())
4682 return QualType();
4683 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004684
Serge Pavlov774c6d02014-02-06 03:49:11 +00004685 // We might have constant size array now, but fortunately it has the same
4686 // location layout.
4687 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004688 NewTL.setLBracketLoc(TL.getLBracketLoc());
4689 NewTL.setRBracketLoc(TL.getRBracketLoc());
4690 NewTL.setSizeExpr(Size);
4691
4692 return Result;
4693}
4694
4695template<typename Derived>
4696QualType
4697TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004698 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004699 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4701 if (ElementType.isNull())
4702 return QualType();
4703
Richard Smith764d2fe2011-12-20 02:08:33 +00004704 // Array bounds are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004705 EnterExpressionEvaluationContext Unevaluated(
4706 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004707
John McCall33ddac02011-01-19 10:06:00 +00004708 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4709 Expr *origSize = TL.getSizeExpr();
4710 if (!origSize) origSize = T->getSizeExpr();
4711
4712 ExprResult sizeResult
4713 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004714 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004715 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004716 return QualType();
4717
John McCall33ddac02011-01-19 10:06:00 +00004718 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004719
4720 QualType Result = TL.getType();
4721 if (getDerived().AlwaysRebuild() ||
4722 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004723 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004724 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4725 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004726 size,
John McCall550e0c22009-10-21 00:40:46 +00004727 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004728 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004729 if (Result.isNull())
4730 return QualType();
4731 }
John McCall550e0c22009-10-21 00:40:46 +00004732
4733 // We might have any sort of array type now, but fortunately they
4734 // all have the same location layout.
4735 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4736 NewTL.setLBracketLoc(TL.getLBracketLoc());
4737 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004738 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004739
4740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004741}
Mike Stump11289f42009-09-09 15:08:12 +00004742
4743template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004744QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004745 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004746 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004747 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004748
4749 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004750 QualType ElementType = getDerived().TransformType(T->getElementType());
4751 if (ElementType.isNull())
4752 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004753
Richard Smith764d2fe2011-12-20 02:08:33 +00004754 // Vector sizes are constant expressions.
Faisal Valid143a0c2017-04-01 21:30:49 +00004755 EnterExpressionEvaluationContext Unevaluated(
4756 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004757
John McCalldadc5752010-08-24 06:29:42 +00004758 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004759 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004760 if (Size.isInvalid())
4761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004762
John McCall550e0c22009-10-21 00:40:46 +00004763 QualType Result = TL.getType();
4764 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004765 ElementType != T->getElementType() ||
4766 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004767 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004768 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004769 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004770 if (Result.isNull())
4771 return QualType();
4772 }
John McCall550e0c22009-10-21 00:40:46 +00004773
4774 // Result might be dependent or not.
4775 if (isa<DependentSizedExtVectorType>(Result)) {
4776 DependentSizedExtVectorTypeLoc NewTL
4777 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4778 NewTL.setNameLoc(TL.getNameLoc());
4779 } else {
4780 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4781 NewTL.setNameLoc(TL.getNameLoc());
4782 }
4783
4784 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
Andrew Gozillon572bbb02017-10-02 06:25:51 +00004787template <typename Derived>
4788QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
4789 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
4790 const DependentAddressSpaceType *T = TL.getTypePtr();
4791
4792 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
4793
4794 if (pointeeType.isNull())
4795 return QualType();
4796
4797 // Address spaces are constant expressions.
4798 EnterExpressionEvaluationContext Unevaluated(
4799 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
4800
4801 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
4802 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
4803 if (AddrSpace.isInvalid())
4804 return QualType();
4805
4806 QualType Result = TL.getType();
4807 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
4808 AddrSpace.get() != T->getAddrSpaceExpr()) {
4809 Result = getDerived().RebuildDependentAddressSpaceType(
4810 pointeeType, AddrSpace.get(), T->getAttributeLoc());
4811 if (Result.isNull())
4812 return QualType();
4813 }
4814
4815 // Result might be dependent or not.
4816 if (isa<DependentAddressSpaceType>(Result)) {
4817 DependentAddressSpaceTypeLoc NewTL =
4818 TLB.push<DependentAddressSpaceTypeLoc>(Result);
4819
4820 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4821 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
4822 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
4823
4824 } else {
4825 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
4826 Result, getDerived().getBaseLocation());
4827 TransformType(TLB, DI->getTypeLoc());
4828 }
4829
4830 return Result;
4831}
4832
4833template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004834QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004835 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004836 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004837 QualType ElementType = getDerived().TransformType(T->getElementType());
4838 if (ElementType.isNull())
4839 return QualType();
4840
John McCall550e0c22009-10-21 00:40:46 +00004841 QualType Result = TL.getType();
4842 if (getDerived().AlwaysRebuild() ||
4843 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004844 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004845 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004846 if (Result.isNull())
4847 return QualType();
4848 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004849
John McCall550e0c22009-10-21 00:40:46 +00004850 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4851 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004852
John McCall550e0c22009-10-21 00:40:46 +00004853 return Result;
4854}
4855
4856template<typename Derived>
4857QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004858 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004859 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004860 QualType ElementType = getDerived().TransformType(T->getElementType());
4861 if (ElementType.isNull())
4862 return QualType();
4863
4864 QualType Result = TL.getType();
4865 if (getDerived().AlwaysRebuild() ||
4866 ElementType != T->getElementType()) {
4867 Result = getDerived().RebuildExtVectorType(ElementType,
4868 T->getNumElements(),
4869 /*FIXME*/ SourceLocation());
4870 if (Result.isNull())
4871 return QualType();
4872 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004873
John McCall550e0c22009-10-21 00:40:46 +00004874 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4875 NewTL.setNameLoc(TL.getNameLoc());
4876
4877 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004878}
Mike Stump11289f42009-09-09 15:08:12 +00004879
David Blaikie05785d12013-02-20 22:23:23 +00004880template <typename Derived>
4881ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4882 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4883 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004884 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004885 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004886
Douglas Gregor715e4612011-01-14 22:40:04 +00004887 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004888 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004889 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004890 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004891 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004892
Douglas Gregor715e4612011-01-14 22:40:04 +00004893 TypeLocBuilder TLB;
4894 TypeLoc NewTL = OldDI->getTypeLoc();
4895 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004896
4897 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004898 OldExpansionTL.getPatternLoc());
4899 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004900 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004901
4902 Result = RebuildPackExpansionType(Result,
4903 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004904 OldExpansionTL.getEllipsisLoc(),
4905 NumExpansions);
4906 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004907 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004908
Douglas Gregor715e4612011-01-14 22:40:04 +00004909 PackExpansionTypeLoc NewExpansionTL
4910 = TLB.push<PackExpansionTypeLoc>(Result);
4911 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4912 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4913 } else
4914 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004915 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004916 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004917
John McCall8fb0d9d2011-05-01 22:35:37 +00004918 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004919 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004920
4921 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4922 OldParm->getDeclContext(),
4923 OldParm->getInnerLocStart(),
4924 OldParm->getLocation(),
4925 OldParm->getIdentifier(),
4926 NewDI->getType(),
4927 NewDI,
4928 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004929 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004930 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4931 OldParm->getFunctionScopeIndex() + indexAdjustment);
4932 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004933}
4934
David Majnemer59f77922016-06-24 04:05:48 +00004935template <typename Derived>
4936bool TreeTransform<Derived>::TransformFunctionTypeParams(
4937 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
4938 const QualType *ParamTypes,
4939 const FunctionProtoType::ExtParameterInfo *ParamInfos,
4940 SmallVectorImpl<QualType> &OutParamTypes,
4941 SmallVectorImpl<ParmVarDecl *> *PVars,
4942 Sema::ExtParameterInfoBuilder &PInfos) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004943 int indexAdjustment = 0;
4944
David Majnemer59f77922016-06-24 04:05:48 +00004945 unsigned NumParams = Params.size();
Douglas Gregordd472162011-01-07 00:20:55 +00004946 for (unsigned i = 0; i != NumParams; ++i) {
4947 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004948 assert(OldParm->getFunctionScopeIndex() == i);
4949
David Blaikie05785d12013-02-20 22:23:23 +00004950 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004951 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004952 if (OldParm->isParameterPack()) {
4953 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004954 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004955
Douglas Gregor5499af42011-01-05 23:12:31 +00004956 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004957 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004958 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004959 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4960 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004961 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4962
Douglas Gregor5499af42011-01-05 23:12:31 +00004963 // Determine whether we should expand the parameter packs.
4964 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004965 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004966 Optional<unsigned> OrigNumExpansions =
4967 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004968 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004969 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4970 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004971 Unexpanded,
4972 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004973 RetainExpansion,
4974 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004975 return true;
4976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004977
Douglas Gregor5499af42011-01-05 23:12:31 +00004978 if (ShouldExpand) {
4979 // Expand the function parameter pack into multiple, separate
4980 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004981 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004982 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004983 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004984 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004985 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004986 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004987 OrigNumExpansions,
4988 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004989 if (!NewParm)
4990 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004991
John McCallc8e321d2016-03-01 02:09:25 +00004992 if (ParamInfos)
4993 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00004994 OutParamTypes.push_back(NewParm->getType());
4995 if (PVars)
4996 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004997 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004998
4999 // If we're supposed to retain a pack expansion, do so by temporarily
5000 // forgetting the partially-substituted parameter pack.
5001 if (RetainExpansion) {
5002 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00005003 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00005004 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005005 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005006 OrigNumExpansions,
5007 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005008 if (!NewParm)
5009 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005010
John McCallc8e321d2016-03-01 02:09:25 +00005011 if (ParamInfos)
5012 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005013 OutParamTypes.push_back(NewParm->getType());
5014 if (PVars)
5015 PVars->push_back(NewParm);
5016 }
5017
John McCall8fb0d9d2011-05-01 22:35:37 +00005018 // The next parameter should have the same adjustment as the
5019 // last thing we pushed, but we post-incremented indexAdjustment
5020 // on every push. Also, if we push nothing, the adjustment should
5021 // go down by one.
5022 indexAdjustment--;
5023
Douglas Gregor5499af42011-01-05 23:12:31 +00005024 // We're done with the pack expansion.
5025 continue;
5026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005027
5028 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005029 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00005030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5031 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00005032 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00005033 NumExpansions,
5034 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00005035 } else {
David Blaikie05785d12013-02-20 22:23:23 +00005036 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00005037 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00005038 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00005039
John McCall58f10c32010-03-11 09:03:00 +00005040 if (!NewParm)
5041 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005042
John McCallc8e321d2016-03-01 02:09:25 +00005043 if (ParamInfos)
5044 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005045 OutParamTypes.push_back(NewParm->getType());
5046 if (PVars)
5047 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00005048 continue;
5049 }
John McCall58f10c32010-03-11 09:03:00 +00005050
5051 // Deal with the possibility that we don't have a parameter
5052 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00005053 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00005054 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00005055 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005056 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00005057 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00005058 = dyn_cast<PackExpansionType>(OldType)) {
5059 // We have a function parameter pack that may need to be expanded.
5060 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00005061 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00005062 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00005063
Douglas Gregor5499af42011-01-05 23:12:31 +00005064 // Determine whether we should expand the parameter packs.
5065 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005066 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00005067 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005068 Unexpanded,
5069 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005070 RetainExpansion,
5071 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00005072 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00005073 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005074
Douglas Gregor5499af42011-01-05 23:12:31 +00005075 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005076 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00005077 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005078 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00005079 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5080 QualType NewType = getDerived().TransformType(Pattern);
5081 if (NewType.isNull())
5082 return true;
John McCall58f10c32010-03-11 09:03:00 +00005083
Erik Pilkingtonf1bd0002016-07-05 17:57:24 +00005084 if (NewType->containsUnexpandedParameterPack()) {
5085 NewType =
5086 getSema().getASTContext().getPackExpansionType(NewType, None);
5087
5088 if (NewType.isNull())
5089 return true;
5090 }
5091
John McCallc8e321d2016-03-01 02:09:25 +00005092 if (ParamInfos)
5093 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005094 OutParamTypes.push_back(NewType);
5095 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005096 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00005097 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005098
Douglas Gregor5499af42011-01-05 23:12:31 +00005099 // We're done with the pack expansion.
5100 continue;
5101 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005102
Douglas Gregor48d24112011-01-10 20:53:55 +00005103 // If we're supposed to retain a pack expansion, do so by temporarily
5104 // forgetting the partially-substituted parameter pack.
5105 if (RetainExpansion) {
5106 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5107 QualType NewType = getDerived().TransformType(Pattern);
5108 if (NewType.isNull())
5109 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00005110
John McCallc8e321d2016-03-01 02:09:25 +00005111 if (ParamInfos)
5112 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregor48d24112011-01-10 20:53:55 +00005113 OutParamTypes.push_back(NewType);
5114 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005115 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00005116 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00005117
Chad Rosier1dcde962012-08-08 18:46:20 +00005118 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00005119 // expansion.
5120 OldType = Expansion->getPattern();
5121 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00005122 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5123 NewType = getDerived().TransformType(OldType);
5124 } else {
5125 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00005126 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005127
Douglas Gregor5499af42011-01-05 23:12:31 +00005128 if (NewType.isNull())
5129 return true;
5130
5131 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005132 NewType = getSema().Context.getPackExpansionType(NewType,
5133 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00005134
John McCallc8e321d2016-03-01 02:09:25 +00005135 if (ParamInfos)
5136 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
Douglas Gregordd472162011-01-07 00:20:55 +00005137 OutParamTypes.push_back(NewType);
5138 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00005139 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00005140 }
5141
John McCall8fb0d9d2011-05-01 22:35:37 +00005142#ifndef NDEBUG
5143 if (PVars) {
5144 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
5145 if (ParmVarDecl *parm = (*PVars)[i])
5146 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00005147 }
John McCall8fb0d9d2011-05-01 22:35:37 +00005148#endif
5149
5150 return false;
5151}
John McCall58f10c32010-03-11 09:03:00 +00005152
5153template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005154QualType
John McCall550e0c22009-10-21 00:40:46 +00005155TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005156 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00005157 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00005158 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00005159 return getDerived().TransformFunctionProtoType(
5160 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00005161 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
5162 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
5163 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00005164 });
Douglas Gregor3024f072012-04-16 07:05:22 +00005165}
5166
Richard Smith2e321552014-11-12 02:00:47 +00005167template<typename Derived> template<typename Fn>
5168QualType TreeTransform<Derived>::TransformFunctionProtoType(
5169 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
5170 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
John McCallc8e321d2016-03-01 02:09:25 +00005171
Douglas Gregor4afc2362010-08-31 00:26:14 +00005172 // Transform the parameters and return type.
5173 //
Richard Smithf623c962012-04-17 00:58:00 +00005174 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00005175 // When the function has a trailing return type, we instantiate the
5176 // parameters before the return type, since the return type can then refer
5177 // to the parameters themselves (via decltype, sizeof, etc.).
5178 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00005179 SmallVector<QualType, 4> ParamTypes;
5180 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallc8e321d2016-03-01 02:09:25 +00005181 Sema::ExtParameterInfoBuilder ExtParamInfos;
John McCall424cec92011-01-19 06:33:43 +00005182 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00005183
Douglas Gregor7fb25412010-10-01 18:44:50 +00005184 QualType ResultType;
5185
Richard Smith1226c602012-08-14 22:51:13 +00005186 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00005187 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005188 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005189 TL.getTypePtr()->param_type_begin(),
5190 T->getExtParameterInfosOrNull(),
5191 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005192 return QualType();
5193
Douglas Gregor3024f072012-04-16 07:05:22 +00005194 {
5195 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00005196 // If a declaration declares a member function or member function
5197 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00005198 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00005199 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00005200 // declarator.
5201 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00005202
Alp Toker42a16a62014-01-25 23:51:36 +00005203 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00005204 if (ResultType.isNull())
5205 return QualType();
5206 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00005207 }
5208 else {
Alp Toker42a16a62014-01-25 23:51:36 +00005209 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00005210 if (ResultType.isNull())
5211 return QualType();
5212
Alp Toker9cacbab2014-01-20 20:26:09 +00005213 if (getDerived().TransformFunctionTypeParams(
David Majnemer59f77922016-06-24 04:05:48 +00005214 TL.getBeginLoc(), TL.getParams(),
John McCallc8e321d2016-03-01 02:09:25 +00005215 TL.getTypePtr()->param_type_begin(),
5216 T->getExtParameterInfosOrNull(),
5217 ParamTypes, &ParamDecls, ExtParamInfos))
Douglas Gregor7fb25412010-10-01 18:44:50 +00005218 return QualType();
5219 }
5220
Richard Smith2e321552014-11-12 02:00:47 +00005221 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
5222
5223 bool EPIChanged = false;
5224 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
5225 return QualType();
5226
John McCallc8e321d2016-03-01 02:09:25 +00005227 // Handle extended parameter information.
5228 if (auto NewExtParamInfos =
5229 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
5230 if (!EPI.ExtParameterInfos ||
5231 llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
5232 != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
5233 EPIChanged = true;
5234 }
5235 EPI.ExtParameterInfos = NewExtParamInfos;
5236 } else if (EPI.ExtParameterInfos) {
5237 EPIChanged = true;
5238 EPI.ExtParameterInfos = nullptr;
5239 }
Richard Smithf623c962012-04-17 00:58:00 +00005240
John McCall550e0c22009-10-21 00:40:46 +00005241 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005242 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00005243 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00005244 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00005245 if (Result.isNull())
5246 return QualType();
5247 }
Mike Stump11289f42009-09-09 15:08:12 +00005248
John McCall550e0c22009-10-21 00:40:46 +00005249 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005250 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005251 NewTL.setLParenLoc(TL.getLParenLoc());
5252 NewTL.setRParenLoc(TL.getRParenLoc());
Malcolm Parsonsa3220ce2017-01-12 16:11:28 +00005253 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005254 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00005255 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
5256 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00005257
5258 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259}
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregord6ff3322009-08-04 16:50:30 +00005261template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00005262bool TreeTransform<Derived>::TransformExceptionSpec(
5263 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
5264 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
5265 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
5266
5267 // Instantiate a dynamic noexcept expression, if any.
5268 if (ESI.Type == EST_ComputedNoexcept) {
Faisal Valid143a0c2017-04-01 21:30:49 +00005269 EnterExpressionEvaluationContext Unevaluated(
5270 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
Richard Smith2e321552014-11-12 02:00:47 +00005271 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
5272 if (NoexceptExpr.isInvalid())
5273 return true;
5274
Richard Smith03a4aa32016-06-23 19:02:52 +00005275 // FIXME: This is bogus, a noexcept expression is not a condition.
5276 NoexceptExpr = getSema().CheckBooleanCondition(Loc, NoexceptExpr.get());
Richard Smith2e321552014-11-12 02:00:47 +00005277 if (NoexceptExpr.isInvalid())
5278 return true;
5279
5280 if (!NoexceptExpr.get()->isValueDependent()) {
5281 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
5282 NoexceptExpr.get(), nullptr,
5283 diag::err_noexcept_needs_constant_expression,
5284 /*AllowFold*/false);
5285 if (NoexceptExpr.isInvalid())
5286 return true;
5287 }
5288
5289 if (ESI.NoexceptExpr != NoexceptExpr.get())
5290 Changed = true;
5291 ESI.NoexceptExpr = NoexceptExpr.get();
5292 }
5293
5294 if (ESI.Type != EST_Dynamic)
5295 return false;
5296
5297 // Instantiate a dynamic exception specification's type.
5298 for (QualType T : ESI.Exceptions) {
5299 if (const PackExpansionType *PackExpansion =
5300 T->getAs<PackExpansionType>()) {
5301 Changed = true;
5302
5303 // We have a pack expansion. Instantiate it.
5304 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5305 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5306 Unexpanded);
5307 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5308
5309 // Determine whether the set of unexpanded parameter packs can and
5310 // should
5311 // be expanded.
5312 bool Expand = false;
5313 bool RetainExpansion = false;
5314 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5315 // FIXME: Track the location of the ellipsis (and track source location
5316 // information for the types in the exception specification in general).
5317 if (getDerived().TryExpandParameterPacks(
5318 Loc, SourceRange(), Unexpanded, Expand,
5319 RetainExpansion, NumExpansions))
5320 return true;
5321
5322 if (!Expand) {
5323 // We can't expand this pack expansion into separate arguments yet;
5324 // just substitute into the pattern and create a new pack expansion
5325 // type.
5326 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5327 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5328 if (U.isNull())
5329 return true;
5330
5331 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
5332 Exceptions.push_back(U);
5333 continue;
5334 }
5335
5336 // Substitute into the pack expansion pattern for each slice of the
5337 // pack.
5338 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5339 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5340
5341 QualType U = getDerived().TransformType(PackExpansion->getPattern());
5342 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5343 return true;
5344
5345 Exceptions.push_back(U);
5346 }
5347 } else {
5348 QualType U = getDerived().TransformType(T);
5349 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
5350 return true;
5351 if (T != U)
5352 Changed = true;
5353
5354 Exceptions.push_back(U);
5355 }
5356 }
5357
5358 ESI.Exceptions = Exceptions;
Richard Smithfda59e52016-10-26 01:05:54 +00005359 if (ESI.Exceptions.empty())
5360 ESI.Type = EST_DynamicNone;
Richard Smith2e321552014-11-12 02:00:47 +00005361 return false;
5362}
5363
5364template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00005365QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00005366 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005367 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005368 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00005369 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00005370 if (ResultType.isNull())
5371 return QualType();
5372
5373 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00005374 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00005375 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
5376
5377 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005378 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00005379 NewTL.setLParenLoc(TL.getLParenLoc());
5380 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00005381 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00005382
5383 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005384}
Mike Stump11289f42009-09-09 15:08:12 +00005385
John McCallb96ec562009-12-04 22:46:56 +00005386template<typename Derived> QualType
5387TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005388 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005389 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005390 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00005391 if (!D)
5392 return QualType();
5393
5394 QualType Result = TL.getType();
5395 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
Richard Smith151c4562016-12-20 21:35:28 +00005396 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
John McCallb96ec562009-12-04 22:46:56 +00005397 if (Result.isNull())
5398 return QualType();
5399 }
5400
5401 // We might get an arbitrary type spec type back. We should at
5402 // least always get a type spec type, though.
5403 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
5404 NewTL.setNameLoc(TL.getNameLoc());
5405
5406 return Result;
5407}
5408
Douglas Gregord6ff3322009-08-04 16:50:30 +00005409template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005410QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005411 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005412 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00005413 TypedefNameDecl *Typedef
5414 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5415 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005416 if (!Typedef)
5417 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005418
John McCall550e0c22009-10-21 00:40:46 +00005419 QualType Result = TL.getType();
5420 if (getDerived().AlwaysRebuild() ||
5421 Typedef != T->getDecl()) {
5422 Result = getDerived().RebuildTypedefType(Typedef);
5423 if (Result.isNull())
5424 return QualType();
5425 }
Mike Stump11289f42009-09-09 15:08:12 +00005426
John McCall550e0c22009-10-21 00:40:46 +00005427 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
5428 NewTL.setNameLoc(TL.getNameLoc());
5429
5430 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005431}
Mike Stump11289f42009-09-09 15:08:12 +00005432
Douglas Gregord6ff3322009-08-04 16:50:30 +00005433template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005434QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005435 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00005436 // typeof expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005437 EnterExpressionEvaluationContext Unevaluated(
5438 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
5439 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00005440
John McCalldadc5752010-08-24 06:29:42 +00005441 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005442 if (E.isInvalid())
5443 return QualType();
5444
Eli Friedmane4f22df2012-02-29 04:03:55 +00005445 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
5446 if (E.isInvalid())
5447 return QualType();
5448
John McCall550e0c22009-10-21 00:40:46 +00005449 QualType Result = TL.getType();
5450 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00005451 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005452 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00005453 if (Result.isNull())
5454 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005455 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005456 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005457
John McCall550e0c22009-10-21 00:40:46 +00005458 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005459 NewTL.setTypeofLoc(TL.getTypeofLoc());
5460 NewTL.setLParenLoc(TL.getLParenLoc());
5461 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00005462
5463 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005464}
Mike Stump11289f42009-09-09 15:08:12 +00005465
5466template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005467QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005468 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00005469 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
5470 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
5471 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005472 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005473
John McCall550e0c22009-10-21 00:40:46 +00005474 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00005475 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
5476 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00005477 if (Result.isNull())
5478 return QualType();
5479 }
Mike Stump11289f42009-09-09 15:08:12 +00005480
John McCall550e0c22009-10-21 00:40:46 +00005481 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00005482 NewTL.setTypeofLoc(TL.getTypeofLoc());
5483 NewTL.setLParenLoc(TL.getLParenLoc());
5484 NewTL.setRParenLoc(TL.getRParenLoc());
5485 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00005486
5487 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005488}
Mike Stump11289f42009-09-09 15:08:12 +00005489
5490template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005491QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005492 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005493 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005494
Douglas Gregore922c772009-08-04 22:27:00 +00005495 // decltype expressions are not potentially evaluated contexts
Faisal Valid143a0c2017-04-01 21:30:49 +00005496 EnterExpressionEvaluationContext Unevaluated(
5497 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
5498 /*IsDecltype=*/true);
Mike Stump11289f42009-09-09 15:08:12 +00005499
John McCalldadc5752010-08-24 06:29:42 +00005500 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005501 if (E.isInvalid())
5502 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005503
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005504 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005505 if (E.isInvalid())
5506 return QualType();
5507
John McCall550e0c22009-10-21 00:40:46 +00005508 QualType Result = TL.getType();
5509 if (getDerived().AlwaysRebuild() ||
5510 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005511 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005512 if (Result.isNull())
5513 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005514 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005515 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005516
John McCall550e0c22009-10-21 00:40:46 +00005517 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5518 NewTL.setNameLoc(TL.getNameLoc());
5519
5520 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005521}
5522
5523template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005524QualType TreeTransform<Derived>::TransformUnaryTransformType(
5525 TypeLocBuilder &TLB,
5526 UnaryTransformTypeLoc TL) {
5527 QualType Result = TL.getType();
5528 if (Result->isDependentType()) {
5529 const UnaryTransformType *T = TL.getTypePtr();
5530 QualType NewBase =
5531 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5532 Result = getDerived().RebuildUnaryTransformType(NewBase,
5533 T->getUTTKind(),
5534 TL.getKWLoc());
5535 if (Result.isNull())
5536 return QualType();
5537 }
5538
5539 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5540 NewTL.setKWLoc(TL.getKWLoc());
5541 NewTL.setParensRange(TL.getParensRange());
5542 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5543 return Result;
5544}
5545
5546template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005547QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5548 AutoTypeLoc TL) {
5549 const AutoType *T = TL.getTypePtr();
5550 QualType OldDeduced = T->getDeducedType();
5551 QualType NewDeduced;
5552 if (!OldDeduced.isNull()) {
5553 NewDeduced = getDerived().TransformType(OldDeduced);
5554 if (NewDeduced.isNull())
5555 return QualType();
5556 }
5557
5558 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005559 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5560 T->isDependentType()) {
Richard Smithe301ba22015-11-11 02:02:15 +00005561 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword());
Richard Smith30482bc2011-02-20 03:19:35 +00005562 if (Result.isNull())
5563 return QualType();
5564 }
5565
5566 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5567 NewTL.setNameLoc(TL.getNameLoc());
5568
5569 return Result;
5570}
5571
5572template<typename Derived>
Richard Smith600b5262017-01-26 20:40:47 +00005573QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
5574 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
5575 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
5576
5577 CXXScopeSpec SS;
5578 TemplateName TemplateName = getDerived().TransformTemplateName(
5579 SS, T->getTemplateName(), TL.getTemplateNameLoc());
5580 if (TemplateName.isNull())
5581 return QualType();
5582
5583 QualType OldDeduced = T->getDeducedType();
5584 QualType NewDeduced;
5585 if (!OldDeduced.isNull()) {
5586 NewDeduced = getDerived().TransformType(OldDeduced);
5587 if (NewDeduced.isNull())
5588 return QualType();
5589 }
5590
5591 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
5592 TemplateName, NewDeduced);
5593 if (Result.isNull())
5594 return QualType();
5595
5596 DeducedTemplateSpecializationTypeLoc NewTL =
5597 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
5598 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5599
5600 return Result;
5601}
5602
5603template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005604QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005605 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005606 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005607 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005608 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5609 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005610 if (!Record)
5611 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005612
John McCall550e0c22009-10-21 00:40:46 +00005613 QualType Result = TL.getType();
5614 if (getDerived().AlwaysRebuild() ||
5615 Record != T->getDecl()) {
5616 Result = getDerived().RebuildRecordType(Record);
5617 if (Result.isNull())
5618 return QualType();
5619 }
Mike Stump11289f42009-09-09 15:08:12 +00005620
John McCall550e0c22009-10-21 00:40:46 +00005621 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5622 NewTL.setNameLoc(TL.getNameLoc());
5623
5624 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005625}
Mike Stump11289f42009-09-09 15:08:12 +00005626
5627template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005628QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005629 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005630 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005631 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005632 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5633 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005634 if (!Enum)
5635 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005636
John McCall550e0c22009-10-21 00:40:46 +00005637 QualType Result = TL.getType();
5638 if (getDerived().AlwaysRebuild() ||
5639 Enum != T->getDecl()) {
5640 Result = getDerived().RebuildEnumType(Enum);
5641 if (Result.isNull())
5642 return QualType();
5643 }
Mike Stump11289f42009-09-09 15:08:12 +00005644
John McCall550e0c22009-10-21 00:40:46 +00005645 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5646 NewTL.setNameLoc(TL.getNameLoc());
5647
5648 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005649}
John McCallfcc33b02009-09-05 00:15:47 +00005650
John McCalle78aac42010-03-10 03:28:59 +00005651template<typename Derived>
5652QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5653 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005654 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005655 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5656 TL.getTypePtr()->getDecl());
5657 if (!D) return QualType();
5658
5659 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5660 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5661 return T;
5662}
5663
Douglas Gregord6ff3322009-08-04 16:50:30 +00005664template<typename Derived>
5665QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005666 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005667 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005668 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005669}
5670
Mike Stump11289f42009-09-09 15:08:12 +00005671template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005672QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005673 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005674 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005675 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005676
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005677 // Substitute into the replacement type, which itself might involve something
5678 // that needs to be transformed. This only tends to occur with default
5679 // template arguments of template template parameters.
5680 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5681 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5682 if (Replacement.isNull())
5683 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005684
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005685 // Always canonicalize the replacement type.
5686 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5687 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005688 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005689 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005690
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005691 // Propagate type-source information.
5692 SubstTemplateTypeParmTypeLoc NewTL
5693 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5694 NewTL.setNameLoc(TL.getNameLoc());
5695 return Result;
5696
John McCallcebee162009-10-18 09:09:24 +00005697}
5698
5699template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005700QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5701 TypeLocBuilder &TLB,
5702 SubstTemplateTypeParmPackTypeLoc TL) {
5703 return TransformTypeSpecType(TLB, TL);
5704}
5705
5706template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005707QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005708 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005709 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005710 const TemplateSpecializationType *T = TL.getTypePtr();
5711
Douglas Gregordf846d12011-03-02 18:46:51 +00005712 // The nested-name-specifier never matters in a TemplateSpecializationType,
5713 // because we can't have a dependent nested-name-specifier anyway.
5714 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005715 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005716 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5717 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005718 if (Template.isNull())
5719 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005720
John McCall31f82722010-11-12 08:19:04 +00005721 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5722}
5723
Eli Friedman0dfb8892011-10-06 23:00:33 +00005724template<typename Derived>
5725QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5726 AtomicTypeLoc TL) {
5727 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5728 if (ValueType.isNull())
5729 return QualType();
5730
5731 QualType Result = TL.getType();
5732 if (getDerived().AlwaysRebuild() ||
5733 ValueType != TL.getValueLoc().getType()) {
5734 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5735 if (Result.isNull())
5736 return QualType();
5737 }
5738
5739 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5740 NewTL.setKWLoc(TL.getKWLoc());
5741 NewTL.setLParenLoc(TL.getLParenLoc());
5742 NewTL.setRParenLoc(TL.getRParenLoc());
5743
5744 return Result;
5745}
5746
Xiuli Pan9c14e282016-01-09 12:53:17 +00005747template <typename Derived>
5748QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
5749 PipeTypeLoc TL) {
5750 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5751 if (ValueType.isNull())
5752 return QualType();
5753
5754 QualType Result = TL.getType();
5755 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
Joey Gouly5788b782016-11-18 14:10:54 +00005756 const PipeType *PT = Result->getAs<PipeType>();
5757 bool isReadPipe = PT->isReadOnly();
5758 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
Xiuli Pan9c14e282016-01-09 12:53:17 +00005759 if (Result.isNull())
5760 return QualType();
5761 }
5762
5763 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
5764 NewTL.setKWLoc(TL.getKWLoc());
5765
5766 return Result;
5767}
5768
Chad Rosier1dcde962012-08-08 18:46:20 +00005769 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005770 /// container that provides a \c getArgLoc() member function.
5771 ///
5772 /// This iterator is intended to be used with the iterator form of
5773 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5774 template<typename ArgLocContainer>
5775 class TemplateArgumentLocContainerIterator {
5776 ArgLocContainer *Container;
5777 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005778
Douglas Gregorfe921a72010-12-20 23:36:19 +00005779 public:
5780 typedef TemplateArgumentLoc value_type;
5781 typedef TemplateArgumentLoc reference;
5782 typedef int difference_type;
5783 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005784
Douglas Gregorfe921a72010-12-20 23:36:19 +00005785 class pointer {
5786 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005787
Douglas Gregorfe921a72010-12-20 23:36:19 +00005788 public:
5789 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005790
Douglas Gregorfe921a72010-12-20 23:36:19 +00005791 const TemplateArgumentLoc *operator->() const {
5792 return &Arg;
5793 }
5794 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005795
5796
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005797 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005798
Douglas Gregorfe921a72010-12-20 23:36:19 +00005799 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5800 unsigned Index)
5801 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005802
Douglas Gregorfe921a72010-12-20 23:36:19 +00005803 TemplateArgumentLocContainerIterator &operator++() {
5804 ++Index;
5805 return *this;
5806 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005807
Douglas Gregorfe921a72010-12-20 23:36:19 +00005808 TemplateArgumentLocContainerIterator operator++(int) {
5809 TemplateArgumentLocContainerIterator Old(*this);
5810 ++(*this);
5811 return Old;
5812 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005813
Douglas Gregorfe921a72010-12-20 23:36:19 +00005814 TemplateArgumentLoc operator*() const {
5815 return Container->getArgLoc(Index);
5816 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005817
Douglas Gregorfe921a72010-12-20 23:36:19 +00005818 pointer operator->() const {
5819 return pointer(Container->getArgLoc(Index));
5820 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005821
Douglas Gregorfe921a72010-12-20 23:36:19 +00005822 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005823 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005824 return X.Container == Y.Container && X.Index == Y.Index;
5825 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005826
Douglas Gregorfe921a72010-12-20 23:36:19 +00005827 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005828 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005829 return !(X == Y);
5830 }
5831 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005832
5833
John McCall31f82722010-11-12 08:19:04 +00005834template <typename Derived>
5835QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5836 TypeLocBuilder &TLB,
5837 TemplateSpecializationTypeLoc TL,
5838 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005839 TemplateArgumentListInfo NewTemplateArgs;
5840 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5841 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005842 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5843 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005844 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005845 ArgIterator(TL, TL.getNumArgs()),
5846 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005847 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005848
John McCall0ad16662009-10-29 08:12:44 +00005849 // FIXME: maybe don't rebuild if all the template arguments are the same.
5850
5851 QualType Result =
5852 getDerived().RebuildTemplateSpecializationType(Template,
5853 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005854 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005855
5856 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005857 // Specializations of template template parameters are represented as
5858 // TemplateSpecializationTypes, and substitution of type alias templates
5859 // within a dependent context can transform them into
5860 // DependentTemplateSpecializationTypes.
5861 if (isa<DependentTemplateSpecializationType>(Result)) {
5862 DependentTemplateSpecializationTypeLoc NewTL
5863 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005864 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005865 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005866 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005867 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005868 NewTL.setLAngleLoc(TL.getLAngleLoc());
5869 NewTL.setRAngleLoc(TL.getRAngleLoc());
5870 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5871 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5872 return Result;
5873 }
5874
John McCall0ad16662009-10-29 08:12:44 +00005875 TemplateSpecializationTypeLoc NewTL
5876 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005877 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005878 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5879 NewTL.setLAngleLoc(TL.getLAngleLoc());
5880 NewTL.setRAngleLoc(TL.getRAngleLoc());
5881 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5882 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005883 }
Mike Stump11289f42009-09-09 15:08:12 +00005884
John McCall0ad16662009-10-29 08:12:44 +00005885 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005886}
Mike Stump11289f42009-09-09 15:08:12 +00005887
Douglas Gregor5a064722011-02-28 17:23:35 +00005888template <typename Derived>
5889QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5890 TypeLocBuilder &TLB,
5891 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005892 TemplateName Template,
5893 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005894 TemplateArgumentListInfo NewTemplateArgs;
5895 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5896 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5897 typedef TemplateArgumentLocContainerIterator<
5898 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005899 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005900 ArgIterator(TL, TL.getNumArgs()),
5901 NewTemplateArgs))
5902 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005903
Douglas Gregor5a064722011-02-28 17:23:35 +00005904 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005905
Douglas Gregor5a064722011-02-28 17:23:35 +00005906 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5907 QualType Result
5908 = getSema().Context.getDependentTemplateSpecializationType(
5909 TL.getTypePtr()->getKeyword(),
5910 DTN->getQualifier(),
5911 DTN->getIdentifier(),
5912 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005913
Douglas Gregor5a064722011-02-28 17:23:35 +00005914 DependentTemplateSpecializationTypeLoc NewTL
5915 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005916 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005917 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005918 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005919 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005920 NewTL.setLAngleLoc(TL.getLAngleLoc());
5921 NewTL.setRAngleLoc(TL.getRAngleLoc());
5922 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5923 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5924 return Result;
5925 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005926
5927 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005928 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005929 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005930 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005931
Douglas Gregor5a064722011-02-28 17:23:35 +00005932 if (!Result.isNull()) {
5933 /// FIXME: Wrap this in an elaborated-type-specifier?
5934 TemplateSpecializationTypeLoc NewTL
5935 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005936 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005937 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005938 NewTL.setLAngleLoc(TL.getLAngleLoc());
5939 NewTL.setRAngleLoc(TL.getRAngleLoc());
5940 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5941 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5942 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005943
Douglas Gregor5a064722011-02-28 17:23:35 +00005944 return Result;
5945}
5946
Mike Stump11289f42009-09-09 15:08:12 +00005947template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005948QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005949TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005950 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005951 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005952
Douglas Gregor844cb502011-03-01 18:12:44 +00005953 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005954 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005955 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005956 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005957 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5958 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005959 return QualType();
5960 }
Mike Stump11289f42009-09-09 15:08:12 +00005961
John McCall31f82722010-11-12 08:19:04 +00005962 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5963 if (NamedT.isNull())
5964 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005965
Richard Smith3f1b5d02011-05-05 21:57:07 +00005966 // C++0x [dcl.type.elab]p2:
5967 // If the identifier resolves to a typedef-name or the simple-template-id
5968 // resolves to an alias template specialization, the
5969 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005970 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5971 if (const TemplateSpecializationType *TST =
5972 NamedT->getAs<TemplateSpecializationType>()) {
5973 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005974 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5975 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005976 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
Reid Klecknerf33bfcb02016-10-03 18:34:23 +00005977 diag::err_tag_reference_non_tag)
Reid Kleckner1a4ab7e2016-12-09 19:47:58 +00005978 << TAT << Sema::NTK_TypeAliasTemplate
5979 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
Richard Smith0c4a34b2011-05-14 15:04:18 +00005980 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5981 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005982 }
5983 }
5984
John McCall550e0c22009-10-21 00:40:46 +00005985 QualType Result = TL.getType();
5986 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005987 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005988 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005989 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005990 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005991 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005992 if (Result.isNull())
5993 return QualType();
5994 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005995
Abramo Bagnara6150c882010-05-11 21:36:43 +00005996 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005997 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005998 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005999 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006000}
Mike Stump11289f42009-09-09 15:08:12 +00006001
6002template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00006003QualType TreeTransform<Derived>::TransformAttributedType(
6004 TypeLocBuilder &TLB,
6005 AttributedTypeLoc TL) {
6006 const AttributedType *oldType = TL.getTypePtr();
6007 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
6008 if (modifiedType.isNull())
6009 return QualType();
6010
6011 QualType result = TL.getType();
6012
6013 // FIXME: dependent operand expressions?
6014 if (getDerived().AlwaysRebuild() ||
6015 modifiedType != oldType->getModifiedType()) {
6016 // TODO: this is really lame; we should really be rebuilding the
6017 // equivalent type from first principles.
6018 QualType equivalentType
6019 = getDerived().TransformType(oldType->getEquivalentType());
6020 if (equivalentType.isNull())
6021 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00006022
6023 // Check whether we can add nullability; it is only represented as
6024 // type sugar, and therefore cannot be diagnosed in any other way.
6025 if (auto nullability = oldType->getImmediateNullability()) {
6026 if (!modifiedType->canHaveNullability()) {
6027 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00006028 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00006029 return QualType();
6030 }
6031 }
6032
John McCall81904512011-01-06 01:58:22 +00006033 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
6034 modifiedType,
6035 equivalentType);
6036 }
6037
6038 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
6039 newTL.setAttrNameLoc(TL.getAttrNameLoc());
6040 if (TL.hasAttrOperand())
6041 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6042 if (TL.hasAttrExprOperand())
6043 newTL.setAttrExprOperand(TL.getAttrExprOperand());
6044 else if (TL.hasAttrEnumOperand())
6045 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
6046
6047 return result;
6048}
6049
6050template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00006051QualType
6052TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
6053 ParenTypeLoc TL) {
6054 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
6055 if (Inner.isNull())
6056 return QualType();
6057
6058 QualType Result = TL.getType();
6059 if (getDerived().AlwaysRebuild() ||
6060 Inner != TL.getInnerLoc().getType()) {
6061 Result = getDerived().RebuildParenType(Inner);
6062 if (Result.isNull())
6063 return QualType();
6064 }
6065
6066 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
6067 NewTL.setLParenLoc(TL.getLParenLoc());
6068 NewTL.setRParenLoc(TL.getRParenLoc());
6069 return Result;
6070}
6071
6072template<typename Derived>
Richard Smithee579842017-01-30 20:39:26 +00006073QualType TreeTransform<Derived>::TransformDependentNameType(
6074 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
6075 return TransformDependentNameType(TLB, TL, false);
6076}
6077
6078template<typename Derived>
6079QualType TreeTransform<Derived>::TransformDependentNameType(
6080 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
John McCall424cec92011-01-19 06:33:43 +00006081 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00006082
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006083 NestedNameSpecifierLoc QualifierLoc
6084 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6085 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00006086 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00006087
John McCallc392f372010-06-11 00:33:02 +00006088 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006089 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006090 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006091 QualifierLoc,
6092 T->getIdentifier(),
Richard Smithee579842017-01-30 20:39:26 +00006093 TL.getNameLoc(),
6094 DeducedTSTContext);
John McCall550e0c22009-10-21 00:40:46 +00006095 if (Result.isNull())
6096 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00006097
Abramo Bagnarad7548482010-05-19 21:37:53 +00006098 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
6099 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00006100 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
6101
Abramo Bagnarad7548482010-05-19 21:37:53 +00006102 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006103 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00006104 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00006105 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00006106 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006107 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00006108 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00006109 NewTL.setNameLoc(TL.getNameLoc());
6110 }
John McCall550e0c22009-10-21 00:40:46 +00006111 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006112}
Mike Stump11289f42009-09-09 15:08:12 +00006113
Douglas Gregord6ff3322009-08-04 16:50:30 +00006114template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00006115QualType TreeTransform<Derived>::
6116 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006117 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00006118 NestedNameSpecifierLoc QualifierLoc;
6119 if (TL.getQualifierLoc()) {
6120 QualifierLoc
6121 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
6122 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00006123 return QualType();
6124 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006125
John McCall31f82722010-11-12 08:19:04 +00006126 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00006127 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00006128}
6129
6130template<typename Derived>
6131QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00006132TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
6133 DependentTemplateSpecializationTypeLoc TL,
6134 NestedNameSpecifierLoc QualifierLoc) {
6135 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00006136
Douglas Gregora7a795b2011-03-01 20:11:18 +00006137 TemplateArgumentListInfo NewTemplateArgs;
6138 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6139 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006140
Douglas Gregora7a795b2011-03-01 20:11:18 +00006141 typedef TemplateArgumentLocContainerIterator<
6142 DependentTemplateSpecializationTypeLoc> ArgIterator;
6143 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
6144 ArgIterator(TL, TL.getNumArgs()),
6145 NewTemplateArgs))
6146 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006147
Richard Smithfd3dae02017-01-20 00:20:39 +00006148 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
6149 T->getKeyword(), QualifierLoc, T->getIdentifier(),
6150 TL.getTemplateNameLoc(), NewTemplateArgs,
6151 /*AllowInjectedClassName*/ false);
Douglas Gregora7a795b2011-03-01 20:11:18 +00006152 if (Result.isNull())
6153 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregora7a795b2011-03-01 20:11:18 +00006155 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
6156 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006157
Douglas Gregora7a795b2011-03-01 20:11:18 +00006158 // Copy information relevant to the template specialization.
6159 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00006160 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006161 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006162 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006163 NamedTL.setLAngleLoc(TL.getLAngleLoc());
6164 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006165 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006166 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00006167
Douglas Gregora7a795b2011-03-01 20:11:18 +00006168 // Copy information relevant to the elaborated type.
6169 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00006170 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006171 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00006172 } else if (isa<DependentTemplateSpecializationType>(Result)) {
6173 DependentTemplateSpecializationTypeLoc SpecTL
6174 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006175 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006176 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006177 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006178 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006179 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6180 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006181 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006182 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006183 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00006184 TemplateSpecializationTypeLoc SpecTL
6185 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00006186 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00006187 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00006188 SpecTL.setLAngleLoc(TL.getLAngleLoc());
6189 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00006190 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00006191 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00006192 }
6193 return Result;
6194}
6195
6196template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00006197QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
6198 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006199 QualType Pattern
6200 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00006201 if (Pattern.isNull())
6202 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00006203
6204 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00006205 if (getDerived().AlwaysRebuild() ||
6206 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006207 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00006208 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00006209 TL.getEllipsisLoc(),
6210 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00006211 if (Result.isNull())
6212 return QualType();
6213 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006214
Douglas Gregor822d0302011-01-12 17:07:58 +00006215 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
6216 NewT.setEllipsisLoc(TL.getEllipsisLoc());
6217 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00006218}
6219
6220template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006221QualType
6222TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006223 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006224 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00006225 TLB.pushFullCopy(TL);
6226 return TL.getType();
6227}
6228
6229template<typename Derived>
6230QualType
Manman Rene6be26c2016-09-13 17:25:08 +00006231TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
6232 ObjCTypeParamTypeLoc TL) {
6233 const ObjCTypeParamType *T = TL.getTypePtr();
6234 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
6235 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
6236 if (!OTP)
6237 return QualType();
6238
6239 QualType Result = TL.getType();
6240 if (getDerived().AlwaysRebuild() ||
6241 OTP != T->getDecl()) {
6242 Result = getDerived().RebuildObjCTypeParamType(OTP,
6243 TL.getProtocolLAngleLoc(),
6244 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6245 TL.getNumProtocols()),
6246 TL.getProtocolLocs(),
6247 TL.getProtocolRAngleLoc());
6248 if (Result.isNull())
6249 return QualType();
6250 }
6251
6252 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
6253 if (TL.getNumProtocols()) {
6254 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6255 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6256 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
6257 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6258 }
6259 return Result;
6260}
6261
6262template<typename Derived>
6263QualType
John McCall8b07ec22010-05-15 11:32:37 +00006264TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006265 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006266 // Transform base type.
6267 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
6268 if (BaseType.isNull())
6269 return QualType();
6270
6271 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
6272
6273 // Transform type arguments.
6274 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
6275 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
6276 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
6277 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
6278 QualType TypeArg = TypeArgInfo->getType();
6279 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
6280 AnyChanged = true;
6281
6282 // We have a pack expansion. Instantiate it.
6283 const auto *PackExpansion = PackExpansionLoc.getType()
6284 ->castAs<PackExpansionType>();
6285 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
6286 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6287 Unexpanded);
6288 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6289
6290 // Determine whether the set of unexpanded parameter packs can
6291 // and should be expanded.
6292 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
6293 bool Expand = false;
6294 bool RetainExpansion = false;
6295 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6296 if (getDerived().TryExpandParameterPacks(
6297 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
6298 Unexpanded, Expand, RetainExpansion, NumExpansions))
6299 return QualType();
6300
6301 if (!Expand) {
6302 // We can't expand this pack expansion into separate arguments yet;
6303 // just substitute into the pattern and create a new pack expansion
6304 // type.
6305 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6306
6307 TypeLocBuilder TypeArgBuilder;
6308 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6309 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
6310 PatternLoc);
6311 if (NewPatternType.isNull())
6312 return QualType();
6313
6314 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
6315 NewPatternType, NumExpansions);
6316 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
6317 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
6318 NewTypeArgInfos.push_back(
6319 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
6320 continue;
6321 }
6322
6323 // Substitute into the pack expansion pattern for each slice of the
6324 // pack.
6325 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6326 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6327
6328 TypeLocBuilder TypeArgBuilder;
6329 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
6330
6331 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
6332 PatternLoc);
6333 if (NewTypeArg.isNull())
6334 return QualType();
6335
6336 NewTypeArgInfos.push_back(
6337 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6338 }
6339
6340 continue;
6341 }
6342
6343 TypeLocBuilder TypeArgBuilder;
6344 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
6345 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
6346 if (NewTypeArg.isNull())
6347 return QualType();
6348
6349 // If nothing changed, just keep the old TypeSourceInfo.
6350 if (NewTypeArg == TypeArg) {
6351 NewTypeArgInfos.push_back(TypeArgInfo);
6352 continue;
6353 }
6354
6355 NewTypeArgInfos.push_back(
6356 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
6357 AnyChanged = true;
6358 }
6359
6360 QualType Result = TL.getType();
6361 if (getDerived().AlwaysRebuild() || AnyChanged) {
6362 // Rebuild the type.
6363 Result = getDerived().RebuildObjCObjectType(
6364 BaseType,
6365 TL.getLocStart(),
6366 TL.getTypeArgsLAngleLoc(),
6367 NewTypeArgInfos,
6368 TL.getTypeArgsRAngleLoc(),
6369 TL.getProtocolLAngleLoc(),
6370 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
6371 TL.getNumProtocols()),
6372 TL.getProtocolLocs(),
6373 TL.getProtocolRAngleLoc());
6374
6375 if (Result.isNull())
6376 return QualType();
6377 }
6378
6379 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006380 NewT.setHasBaseTypeAsWritten(true);
6381 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
6382 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
6383 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
6384 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
6385 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
6386 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
6387 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
6388 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
6389 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00006390}
Mike Stump11289f42009-09-09 15:08:12 +00006391
6392template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006393QualType
6394TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00006395 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00006396 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
6397 if (PointeeType.isNull())
6398 return QualType();
6399
6400 QualType Result = TL.getType();
6401 if (getDerived().AlwaysRebuild() ||
6402 PointeeType != TL.getPointeeLoc().getType()) {
6403 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
6404 TL.getStarLoc());
6405 if (Result.isNull())
6406 return QualType();
6407 }
6408
6409 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
6410 NewT.setStarLoc(TL.getStarLoc());
6411 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00006412}
6413
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00006415// Statement transformation
6416//===----------------------------------------------------------------------===//
6417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006418StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006419TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006420 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006421}
6422
6423template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006424StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006425TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
6426 return getDerived().TransformCompoundStmt(S, false);
6427}
6428
6429template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006430StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006431TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00006432 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00006433 Sema::CompoundScopeRAII CompoundScope(getSema());
6434
John McCall1ababa62010-08-27 19:56:05 +00006435 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00006436 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006437 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006438 for (auto *B : S->body()) {
6439 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00006440 if (Result.isInvalid()) {
6441 // Immediately fail if this was a DeclStmt, since it's very
6442 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006443 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00006444 return StmtError();
6445
6446 // Otherwise, just keep processing substatements and fail later.
6447 SubStmtInvalid = true;
6448 continue;
6449 }
Mike Stump11289f42009-09-09 15:08:12 +00006450
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00006451 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006452 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006453 }
Mike Stump11289f42009-09-09 15:08:12 +00006454
John McCall1ababa62010-08-27 19:56:05 +00006455 if (SubStmtInvalid)
6456 return StmtError();
6457
Douglas Gregorebe10102009-08-20 07:17:43 +00006458 if (!getDerived().AlwaysRebuild() &&
6459 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006460 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006461
6462 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006463 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00006464 S->getRBracLoc(),
6465 IsStmtExpr);
6466}
Mike Stump11289f42009-09-09 15:08:12 +00006467
Douglas Gregorebe10102009-08-20 07:17:43 +00006468template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006469StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006470TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006471 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00006472 {
Faisal Valid143a0c2017-04-01 21:30:49 +00006473 EnterExpressionEvaluationContext Unevaluated(
6474 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006475
Eli Friedman06577382009-11-19 03:14:00 +00006476 // Transform the left-hand case value.
6477 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006478 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00006479 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006480 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006481
Eli Friedman06577382009-11-19 03:14:00 +00006482 // Transform the right-hand case value (for the GNU case-range extension).
6483 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00006484 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00006485 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006486 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00006487 }
Mike Stump11289f42009-09-09 15:08:12 +00006488
Douglas Gregorebe10102009-08-20 07:17:43 +00006489 // Build the case statement.
6490 // Case statements are always rebuilt so that they will attached to their
6491 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006492 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00006493 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006494 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00006495 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006496 S->getColonLoc());
6497 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregorebe10102009-08-20 07:17:43 +00006500 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00006501 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006502 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006504
Douglas Gregorebe10102009-08-20 07:17:43 +00006505 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00006506 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006507}
6508
6509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006510StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006511TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006512 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00006513 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006514 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006516
Douglas Gregorebe10102009-08-20 07:17:43 +00006517 // Default statements are always rebuilt
6518 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006519 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006520}
Mike Stump11289f42009-09-09 15:08:12 +00006521
Douglas Gregorebe10102009-08-20 07:17:43 +00006522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006523StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006524TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006525 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00006526 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006527 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006528
Chris Lattnercab02a62011-02-17 20:34:02 +00006529 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
6530 S->getDecl());
6531 if (!LD)
6532 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00006533
6534
Douglas Gregorebe10102009-08-20 07:17:43 +00006535 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00006536 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006537 cast<LabelDecl>(LD), SourceLocation(),
6538 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006539}
Mike Stump11289f42009-09-09 15:08:12 +00006540
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006541template <typename Derived>
6542const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
6543 if (!R)
6544 return R;
6545
6546 switch (R->getKind()) {
6547// Transform attributes with a pragma spelling by calling TransformXXXAttr.
6548#define ATTR(X)
6549#define PRAGMA_SPELLING_ATTR(X) \
6550 case attr::X: \
6551 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
6552#include "clang/Basic/AttrList.inc"
6553 default:
6554 return R;
6555 }
6556}
6557
6558template <typename Derived>
6559StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
6560 bool AttrsChanged = false;
6561 SmallVector<const Attr *, 1> Attrs;
6562
6563 // Visit attributes and keep track if any are transformed.
6564 for (const auto *I : S->getAttrs()) {
6565 const Attr *R = getDerived().TransformAttr(I);
6566 AttrsChanged |= (I != R);
6567 Attrs.push_back(R);
6568 }
6569
Richard Smithc202b282012-04-14 00:33:13 +00006570 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
6571 if (SubStmt.isInvalid())
6572 return StmtError();
6573
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006574 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00006575 return S;
6576
Tyler Nowickic724a83e2014-10-12 20:46:07 +00006577 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00006578 SubStmt.get());
6579}
6580
6581template<typename Derived>
6582StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006583TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006584 // Transform the initialization statement
6585 StmtResult Init = getDerived().TransformStmt(S->getInit());
6586 if (Init.isInvalid())
6587 return StmtError();
6588
Douglas Gregorebe10102009-08-20 07:17:43 +00006589 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006590 Sema::ConditionResult Cond = getDerived().TransformCondition(
6591 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
Richard Smithb130fe72016-06-23 19:16:49 +00006592 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
6593 : Sema::ConditionKind::Boolean);
Richard Smith03a4aa32016-06-23 19:02:52 +00006594 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006595 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006596
Richard Smithb130fe72016-06-23 19:16:49 +00006597 // If this is a constexpr if, determine which arm we should instantiate.
6598 llvm::Optional<bool> ConstexprConditionValue;
6599 if (S->isConstexpr())
6600 ConstexprConditionValue = Cond.getKnownValue();
6601
Douglas Gregorebe10102009-08-20 07:17:43 +00006602 // Transform the "then" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006603 StmtResult Then;
6604 if (!ConstexprConditionValue || *ConstexprConditionValue) {
6605 Then = getDerived().TransformStmt(S->getThen());
6606 if (Then.isInvalid())
6607 return StmtError();
6608 } else {
6609 Then = new (getSema().Context) NullStmt(S->getThen()->getLocStart());
6610 }
Mike Stump11289f42009-09-09 15:08:12 +00006611
Douglas Gregorebe10102009-08-20 07:17:43 +00006612 // Transform the "else" branch.
Richard Smithb130fe72016-06-23 19:16:49 +00006613 StmtResult Else;
6614 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
6615 Else = getDerived().TransformStmt(S->getElse());
6616 if (Else.isInvalid())
6617 return StmtError();
6618 }
Mike Stump11289f42009-09-09 15:08:12 +00006619
Douglas Gregorebe10102009-08-20 07:17:43 +00006620 if (!getDerived().AlwaysRebuild() &&
Richard Smitha547eb22016-07-14 00:11:03 +00006621 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006622 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006623 Then.get() == S->getThen() &&
6624 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006625 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006626
Richard Smithb130fe72016-06-23 19:16:49 +00006627 return getDerived().RebuildIfStmt(S->getIfLoc(), S->isConstexpr(), Cond,
Richard Smitha547eb22016-07-14 00:11:03 +00006628 Init.get(), Then.get(), S->getElseLoc(),
6629 Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006630}
6631
6632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006633StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006634TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Richard Smitha547eb22016-07-14 00:11:03 +00006635 // Transform the initialization statement
6636 StmtResult Init = getDerived().TransformStmt(S->getInit());
6637 if (Init.isInvalid())
6638 return StmtError();
6639
Douglas Gregorebe10102009-08-20 07:17:43 +00006640 // Transform the condition.
Richard Smith03a4aa32016-06-23 19:02:52 +00006641 Sema::ConditionResult Cond = getDerived().TransformCondition(
6642 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
6643 Sema::ConditionKind::Switch);
6644 if (Cond.isInvalid())
6645 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006646
Douglas Gregorebe10102009-08-20 07:17:43 +00006647 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006648 StmtResult Switch
Volodymyr Sapsaiddf524c2017-09-21 17:58:27 +00006649 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Init.get(), Cond);
Douglas Gregorebe10102009-08-20 07:17:43 +00006650 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006651 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006652
Douglas Gregorebe10102009-08-20 07:17:43 +00006653 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006654 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006655 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006656 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006657
Douglas Gregorebe10102009-08-20 07:17:43 +00006658 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006659 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6660 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006661}
Mike Stump11289f42009-09-09 15:08:12 +00006662
Douglas Gregorebe10102009-08-20 07:17:43 +00006663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006664StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006665TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006666 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006667 Sema::ConditionResult Cond = getDerived().TransformCondition(
6668 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
6669 Sema::ConditionKind::Boolean);
6670 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006671 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006672
Douglas Gregorebe10102009-08-20 07:17:43 +00006673 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006674 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006675 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006676 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006677
Douglas Gregorebe10102009-08-20 07:17:43 +00006678 if (!getDerived().AlwaysRebuild() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006679 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006680 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006681 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006682
Richard Smith03a4aa32016-06-23 19:02:52 +00006683 return getDerived().RebuildWhileStmt(S->getWhileLoc(), Cond, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006684}
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregorebe10102009-08-20 07:17:43 +00006686template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006687StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006688TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006689 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006690 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006691 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006692 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006693
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006694 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006695 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006696 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006697 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006698
Douglas Gregorebe10102009-08-20 07:17:43 +00006699 if (!getDerived().AlwaysRebuild() &&
6700 Cond.get() == S->getCond() &&
6701 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006702 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006703
John McCallb268a282010-08-23 23:25:46 +00006704 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6705 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006706 S->getRParenLoc());
6707}
Mike Stump11289f42009-09-09 15:08:12 +00006708
Douglas Gregorebe10102009-08-20 07:17:43 +00006709template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006710StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006711TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006712 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006713 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006714 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006715 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006716
Alexey Bataeva636c7f2015-12-23 10:27:45 +00006717 // In OpenMP loop region loop control variable must be captured and be
6718 // private. Perform analysis of first part (if any).
6719 if (getSema().getLangOpts().OpenMP && Init.isUsable())
6720 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
6721
Douglas Gregorebe10102009-08-20 07:17:43 +00006722 // Transform the condition
Richard Smith03a4aa32016-06-23 19:02:52 +00006723 Sema::ConditionResult Cond = getDerived().TransformCondition(
6724 S->getForLoc(), S->getConditionVariable(), S->getCond(),
6725 Sema::ConditionKind::Boolean);
6726 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006728
Douglas Gregorebe10102009-08-20 07:17:43 +00006729 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006730 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006731 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006732 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006733
Richard Smith945f8d32013-01-14 22:39:08 +00006734 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006735 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006736 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006737
Douglas Gregorebe10102009-08-20 07:17:43 +00006738 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006739 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006740 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006742
Douglas Gregorebe10102009-08-20 07:17:43 +00006743 if (!getDerived().AlwaysRebuild() &&
6744 Init.get() == S->getInit() &&
Richard Smith03a4aa32016-06-23 19:02:52 +00006745 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006746 Inc.get() == S->getInc() &&
6747 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006748 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006749
Douglas Gregorebe10102009-08-20 07:17:43 +00006750 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Richard Smith03a4aa32016-06-23 19:02:52 +00006751 Init.get(), Cond, FullInc,
6752 S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006753}
6754
6755template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006756StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006757TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006758 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6759 S->getLabel());
6760 if (!LD)
6761 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006762
Douglas Gregorebe10102009-08-20 07:17:43 +00006763 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006764 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006765 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006766}
6767
6768template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006769StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006770TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006771 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006772 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006773 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006774 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006775
Douglas Gregorebe10102009-08-20 07:17:43 +00006776 if (!getDerived().AlwaysRebuild() &&
6777 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006778 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006779
6780 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006781 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006782}
6783
6784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006785StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006786TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006787 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006788}
Mike Stump11289f42009-09-09 15:08:12 +00006789
Douglas Gregorebe10102009-08-20 07:17:43 +00006790template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006791StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006792TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006793 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006794}
Mike Stump11289f42009-09-09 15:08:12 +00006795
Douglas Gregorebe10102009-08-20 07:17:43 +00006796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006798TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006799 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6800 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006801 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006802 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006803
Mike Stump11289f42009-09-09 15:08:12 +00006804 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006805 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006806 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006807}
Mike Stump11289f42009-09-09 15:08:12 +00006808
Douglas Gregorebe10102009-08-20 07:17:43 +00006809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006810StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006811TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006812 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006813 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006814 for (auto *D : S->decls()) {
6815 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006816 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006817 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006818
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006819 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006820 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006821
Douglas Gregorebe10102009-08-20 07:17:43 +00006822 Decls.push_back(Transformed);
6823 }
Mike Stump11289f42009-09-09 15:08:12 +00006824
Douglas Gregorebe10102009-08-20 07:17:43 +00006825 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006826 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006827
Rafael Espindolaab417692013-07-09 12:05:01 +00006828 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006829}
Mike Stump11289f42009-09-09 15:08:12 +00006830
Douglas Gregorebe10102009-08-20 07:17:43 +00006831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006832StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006833TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006834
Benjamin Kramerf0623432012-08-23 22:51:59 +00006835 SmallVector<Expr*, 8> Constraints;
6836 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006837 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006838
John McCalldadc5752010-08-24 06:29:42 +00006839 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006840 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006841
6842 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006843
Anders Carlssonaaeef072010-01-24 05:50:09 +00006844 // Go through the outputs.
6845 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006846 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006847
Anders Carlssonaaeef072010-01-24 05:50:09 +00006848 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006849 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006850
Anders Carlssonaaeef072010-01-24 05:50:09 +00006851 // Transform the output expr.
6852 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006853 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006854 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006855 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006856
Anders Carlssonaaeef072010-01-24 05:50:09 +00006857 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006858
John McCallb268a282010-08-23 23:25:46 +00006859 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006860 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006861
Anders Carlssonaaeef072010-01-24 05:50:09 +00006862 // Go through the inputs.
6863 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006864 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006865
Anders Carlssonaaeef072010-01-24 05:50:09 +00006866 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006867 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006868
Anders Carlssonaaeef072010-01-24 05:50:09 +00006869 // Transform the input expr.
6870 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006871 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006872 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006873 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006874
Anders Carlssonaaeef072010-01-24 05:50:09 +00006875 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006876
John McCallb268a282010-08-23 23:25:46 +00006877 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006878 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006879
Anders Carlssonaaeef072010-01-24 05:50:09 +00006880 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006881 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006882
6883 // Go through the clobbers.
6884 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006885 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006886
6887 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006888 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006889 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6890 S->isVolatile(), S->getNumOutputs(),
6891 S->getNumInputs(), Names.data(),
6892 Constraints, Exprs, AsmString.get(),
6893 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006894}
6895
Chad Rosier32503022012-06-11 20:47:18 +00006896template<typename Derived>
6897StmtResult
6898TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006899 ArrayRef<Token> AsmToks =
6900 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006901
John McCallf413f5e2013-05-03 00:10:13 +00006902 bool HadError = false, HadChange = false;
6903
6904 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6905 SmallVector<Expr*, 8> TransformedExprs;
6906 TransformedExprs.reserve(SrcExprs.size());
6907 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6908 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6909 if (!Result.isUsable()) {
6910 HadError = true;
6911 } else {
6912 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006913 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006914 }
6915 }
6916
6917 if (HadError) return StmtError();
6918 if (!HadChange && !getDerived().AlwaysRebuild())
6919 return Owned(S);
6920
Chad Rosierb6f46c12012-08-15 16:53:30 +00006921 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006922 AsmToks, S->getAsmString(),
6923 S->getNumOutputs(), S->getNumInputs(),
6924 S->getAllConstraints(), S->getClobbers(),
6925 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006926}
Douglas Gregorebe10102009-08-20 07:17:43 +00006927
Richard Smith9f690bd2015-10-27 06:02:45 +00006928// C++ Coroutines TS
6929
6930template<typename Derived>
6931StmtResult
6932TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006933 auto *ScopeInfo = SemaRef.getCurFunction();
6934 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
Eric Fiselierbee782b2017-04-03 19:21:00 +00006935 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006936 ScopeInfo->NeedsCoroutineSuspends &&
6937 ScopeInfo->CoroutineSuspends.first == nullptr &&
6938 ScopeInfo->CoroutineSuspends.second == nullptr &&
Eric Fiseliercac0a592017-03-11 02:35:37 +00006939 "expected clean scope info");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006940
6941 // Set that we have (possibly-invalid) suspend points before we do anything
6942 // that may fail.
6943 ScopeInfo->setNeedsCoroutineSuspends(false);
6944
6945 // The new CoroutinePromise object needs to be built and put into the current
6946 // FunctionScopeInfo before any transformations or rebuilding occurs.
Eric Fiselierbee782b2017-04-03 19:21:00 +00006947 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
6948 if (!Promise)
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006949 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006950 getDerived().transformedLocalDecl(S->getPromiseDecl(), Promise);
6951 ScopeInfo->CoroutinePromise = Promise;
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006952
6953 // Transform the implicit coroutine statements we built during the initial
6954 // parse.
6955 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
6956 if (InitSuspend.isInvalid())
6957 return StmtError();
6958 StmtResult FinalSuspend =
6959 getDerived().TransformStmt(S->getFinalSuspendStmt());
6960 if (FinalSuspend.isInvalid())
6961 return StmtError();
6962 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
6963 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006964
6965 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
6966 if (BodyRes.isInvalid())
6967 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006968
Eric Fiselierbee782b2017-04-03 19:21:00 +00006969 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
6970 if (Builder.isInvalid())
6971 return StmtError();
6972
6973 Expr *ReturnObject = S->getReturnValueInit();
6974 assert(ReturnObject && "the return object is expected to be valid");
6975 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
6976 /*NoCopyInit*/ false);
6977 if (Res.isInvalid())
6978 return StmtError();
6979 Builder.ReturnValue = Res.get();
6980
6981 if (S->hasDependentPromiseType()) {
6982 assert(!Promise->getType()->isDependentType() &&
6983 "the promise type must no longer be dependent");
6984 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
6985 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
6986 "these nodes should not have been built yet");
6987 if (!Builder.buildDependentStatements())
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006988 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00006989 } else {
6990 if (auto *OnFallthrough = S->getFallthroughHandler()) {
6991 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
6992 if (Res.isInvalid())
6993 return StmtError();
6994 Builder.OnFallthrough = Res.get();
6995 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00006996
Eric Fiselierbee782b2017-04-03 19:21:00 +00006997 if (auto *OnException = S->getExceptionHandler()) {
6998 StmtResult Res = getDerived().TransformStmt(OnException);
6999 if (Res.isInvalid())
7000 return StmtError();
7001 Builder.OnException = Res.get();
7002 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007003
Eric Fiselierbee782b2017-04-03 19:21:00 +00007004 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
7005 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
7006 if (Res.isInvalid())
7007 return StmtError();
7008 Builder.ReturnStmtOnAllocFailure = Res.get();
7009 }
7010
7011 // Transform any additional statements we may have already built
7012 assert(S->getAllocate() && S->getDeallocate() &&
7013 "allocation and deallocation calls must already be built");
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007014 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
7015 if (AllocRes.isInvalid())
7016 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007017 Builder.Allocate = AllocRes.get();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007018
7019 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
7020 if (DeallocRes.isInvalid())
7021 return StmtError();
Eric Fiselierbee782b2017-04-03 19:21:00 +00007022 Builder.Deallocate = DeallocRes.get();
Gor Nishanovafff89e2017-05-24 15:44:57 +00007023
7024 assert(S->getResultDecl() && "ResultDecl must already be built");
7025 StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
7026 if (ResultDecl.isInvalid())
7027 return StmtError();
7028 Builder.ResultDecl = ResultDecl.get();
7029
7030 if (auto *ReturnStmt = S->getReturnStmt()) {
7031 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
7032 if (Res.isInvalid())
7033 return StmtError();
7034 Builder.ReturnStmt = Res.get();
7035 }
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007036 }
Eric Fiselierde7943b2017-06-03 00:22:18 +00007037 if (!Builder.buildParameterMoves())
7038 return StmtError();
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007039
Eric Fiselierbee782b2017-04-03 19:21:00 +00007040 return getDerived().RebuildCoroutineBodyStmt(Builder);
Richard Smith9f690bd2015-10-27 06:02:45 +00007041}
7042
7043template<typename Derived>
7044StmtResult
7045TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
7046 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
7047 /*NotCopyInit*/false);
7048 if (Result.isInvalid())
7049 return StmtError();
7050
7051 // Always rebuild; we don't know if this needs to be injected into a new
7052 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007053 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
7054 S->isImplicit());
Richard Smith9f690bd2015-10-27 06:02:45 +00007055}
7056
7057template<typename Derived>
7058ExprResult
7059TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
7060 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7061 /*NotCopyInit*/false);
7062 if (Result.isInvalid())
7063 return ExprError();
7064
7065 // Always rebuild; we don't know if this needs to be injected into a new
7066 // context or if the promise type has changed.
Eric Fiselier20f25cb2017-03-06 23:38:15 +00007067 return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
7068 E->isImplicit());
7069}
7070
7071template <typename Derived>
7072ExprResult
7073TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
7074 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
7075 /*NotCopyInit*/ false);
7076 if (OperandResult.isInvalid())
7077 return ExprError();
7078
7079 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
7080 E->getOperatorCoawaitLookup());
7081
7082 if (LookupResult.isInvalid())
7083 return ExprError();
7084
7085 // Always rebuild; we don't know if this needs to be injected into a new
7086 // context or if the promise type has changed.
7087 return getDerived().RebuildDependentCoawaitExpr(
7088 E->getKeywordLoc(), OperandResult.get(),
7089 cast<UnresolvedLookupExpr>(LookupResult.get()));
Richard Smith9f690bd2015-10-27 06:02:45 +00007090}
7091
7092template<typename Derived>
7093ExprResult
7094TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
7095 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
7096 /*NotCopyInit*/false);
7097 if (Result.isInvalid())
7098 return ExprError();
7099
7100 // Always rebuild; we don't know if this needs to be injected into a new
7101 // context or if the promise type has changed.
7102 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
7103}
7104
7105// Objective-C Statements.
7106
Douglas Gregorebe10102009-08-20 07:17:43 +00007107template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007108StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007109TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007110 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00007111 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007112 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007113 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007114
Douglas Gregor96c79492010-04-23 22:50:49 +00007115 // Transform the @catch statements (if present).
7116 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007117 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00007118 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00007119 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00007120 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007121 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00007122 if (Catch.get() != S->getCatchStmt(I))
7123 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007124 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007125 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007126
Douglas Gregor306de2f2010-04-22 23:59:56 +00007127 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00007128 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007129 if (S->getFinallyStmt()) {
7130 Finally = getDerived().TransformStmt(S->getFinallyStmt());
7131 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007132 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00007133 }
7134
7135 // If nothing changed, just retain this statement.
7136 if (!getDerived().AlwaysRebuild() &&
7137 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00007138 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00007139 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007140 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007141
Douglas Gregor306de2f2010-04-22 23:59:56 +00007142 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00007143 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007144 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007145}
Mike Stump11289f42009-09-09 15:08:12 +00007146
Douglas Gregorebe10102009-08-20 07:17:43 +00007147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007148StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007149TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007150 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00007151 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007152 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00007153 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007154 if (FromVar->getTypeSourceInfo()) {
7155 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
7156 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007157 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007158 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007159
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007160 QualType T;
7161 if (TSInfo)
7162 T = TSInfo->getType();
7163 else {
7164 T = getDerived().TransformType(FromVar->getType());
7165 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00007166 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007167 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007168
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007169 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
7170 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00007171 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007173
John McCalldadc5752010-08-24 06:29:42 +00007174 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007175 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007176 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007177
7178 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00007179 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007180 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007181}
Mike Stump11289f42009-09-09 15:08:12 +00007182
Douglas Gregorebe10102009-08-20 07:17:43 +00007183template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007184StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007185TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00007186 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007187 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00007188 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007189 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007190
Douglas Gregor306de2f2010-04-22 23:59:56 +00007191 // If nothing changed, just retain this statement.
7192 if (!getDerived().AlwaysRebuild() &&
7193 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007194 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00007195
7196 // Build a new statement.
7197 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00007198 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007199}
Mike Stump11289f42009-09-09 15:08:12 +00007200
Douglas Gregorebe10102009-08-20 07:17:43 +00007201template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007202StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00007203TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00007204 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00007205 if (S->getThrowExpr()) {
7206 Operand = getDerived().TransformExpr(S->getThrowExpr());
7207 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007208 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00007209 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007210
Douglas Gregor2900c162010-04-22 21:44:01 +00007211 if (!getDerived().AlwaysRebuild() &&
7212 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007213 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007214
John McCallb268a282010-08-23 23:25:46 +00007215 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007216}
Mike Stump11289f42009-09-09 15:08:12 +00007217
Douglas Gregorebe10102009-08-20 07:17:43 +00007218template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007219StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007220TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007221 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00007222 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00007223 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00007224 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007225 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00007226 Object =
7227 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
7228 Object.get());
7229 if (Object.isInvalid())
7230 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007231
Douglas Gregor6148de72010-04-22 22:01:21 +00007232 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007233 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00007234 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007236
Douglas Gregor6148de72010-04-22 22:01:21 +00007237 // If nothing change, just retain the current statement.
7238 if (!getDerived().AlwaysRebuild() &&
7239 Object.get() == S->getSynchExpr() &&
7240 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007241 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00007242
7243 // Build a new statement.
7244 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00007245 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007246}
7247
7248template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007249StmtResult
John McCall31168b02011-06-15 23:02:42 +00007250TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
7251 ObjCAutoreleasePoolStmt *S) {
7252 // Transform the body.
7253 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
7254 if (Body.isInvalid())
7255 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007256
John McCall31168b02011-06-15 23:02:42 +00007257 // If nothing changed, just retain this statement.
7258 if (!getDerived().AlwaysRebuild() &&
7259 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007260 return S;
John McCall31168b02011-06-15 23:02:42 +00007261
7262 // Build a new statement.
7263 return getDerived().RebuildObjCAutoreleasePoolStmt(
7264 S->getAtLoc(), Body.get());
7265}
7266
7267template<typename Derived>
7268StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00007269TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00007270 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00007271 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00007272 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007273 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007274 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007275
Douglas Gregorf68a5082010-04-22 23:10:45 +00007276 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00007277 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007278 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007279 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007280
Douglas Gregorf68a5082010-04-22 23:10:45 +00007281 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00007282 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00007283 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007284 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007285
Douglas Gregorf68a5082010-04-22 23:10:45 +00007286 // If nothing changed, just retain this statement.
7287 if (!getDerived().AlwaysRebuild() &&
7288 Element.get() == S->getElement() &&
7289 Collection.get() == S->getCollection() &&
7290 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007291 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007292
Douglas Gregorf68a5082010-04-22 23:10:45 +00007293 // Build a new statement.
7294 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00007295 Element.get(),
7296 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00007297 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00007298 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007299}
7300
David Majnemer5f7efef2013-10-15 09:50:08 +00007301template <typename Derived>
7302StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007303 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00007304 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00007305 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
7306 TypeSourceInfo *T =
7307 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00007308 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007309 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007310
David Majnemer5f7efef2013-10-15 09:50:08 +00007311 Var = getDerived().RebuildExceptionDecl(
7312 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
7313 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00007314 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00007315 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00007316 }
Mike Stump11289f42009-09-09 15:08:12 +00007317
Douglas Gregorebe10102009-08-20 07:17:43 +00007318 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00007319 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00007320 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007321 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007322
David Majnemer5f7efef2013-10-15 09:50:08 +00007323 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007324 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007325 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007326
David Majnemer5f7efef2013-10-15 09:50:08 +00007327 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00007328}
Mike Stump11289f42009-09-09 15:08:12 +00007329
David Majnemer5f7efef2013-10-15 09:50:08 +00007330template <typename Derived>
7331StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00007332 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00007333 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00007334 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007335 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007336
Douglas Gregorebe10102009-08-20 07:17:43 +00007337 // Transform the handlers.
7338 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00007339 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00007340 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00007341 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00007342 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007343 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00007344
Douglas Gregorebe10102009-08-20 07:17:43 +00007345 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007346 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00007347 }
Mike Stump11289f42009-09-09 15:08:12 +00007348
David Majnemer5f7efef2013-10-15 09:50:08 +00007349 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00007350 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007351 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00007352
John McCallb268a282010-08-23 23:25:46 +00007353 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007354 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00007355}
Mike Stump11289f42009-09-09 15:08:12 +00007356
Richard Smith02e85f32011-04-14 22:09:26 +00007357template<typename Derived>
7358StmtResult
7359TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
7360 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
7361 if (Range.isInvalid())
7362 return StmtError();
7363
Richard Smith01694c32016-03-20 10:33:40 +00007364 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
7365 if (Begin.isInvalid())
7366 return StmtError();
7367 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
7368 if (End.isInvalid())
Richard Smith02e85f32011-04-14 22:09:26 +00007369 return StmtError();
7370
7371 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7372 if (Cond.isInvalid())
7373 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007374 if (Cond.get())
Richard Smith03a4aa32016-06-23 19:02:52 +00007375 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
Eli Friedman87d32802012-01-31 22:45:40 +00007376 if (Cond.isInvalid())
7377 return StmtError();
7378 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007379 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007380
7381 ExprResult Inc = getDerived().TransformExpr(S->getInc());
7382 if (Inc.isInvalid())
7383 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00007384 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007385 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00007386
7387 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
7388 if (LoopVar.isInvalid())
7389 return StmtError();
7390
7391 StmtResult NewStmt = S;
7392 if (getDerived().AlwaysRebuild() ||
7393 Range.get() != S->getRangeStmt() ||
Richard Smith01694c32016-03-20 10:33:40 +00007394 Begin.get() != S->getBeginStmt() ||
7395 End.get() != S->getEndStmt() ||
Richard Smith02e85f32011-04-14 22:09:26 +00007396 Cond.get() != S->getCond() ||
7397 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007398 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00007399 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007400 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007401 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007402 Begin.get(), End.get(),
7403 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007404 Inc.get(), LoopVar.get(),
7405 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007406 if (NewStmt.isInvalid())
7407 return StmtError();
7408 }
Richard Smith02e85f32011-04-14 22:09:26 +00007409
7410 StmtResult Body = getDerived().TransformStmt(S->getBody());
7411 if (Body.isInvalid())
7412 return StmtError();
7413
7414 // Body has changed but we didn't rebuild the for-range statement. Rebuild
7415 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007416 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00007417 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
Richard Smith9f690bd2015-10-27 06:02:45 +00007418 S->getCoawaitLoc(),
Richard Smith02e85f32011-04-14 22:09:26 +00007419 S->getColonLoc(), Range.get(),
Richard Smith01694c32016-03-20 10:33:40 +00007420 Begin.get(), End.get(),
7421 Cond.get(),
Richard Smith02e85f32011-04-14 22:09:26 +00007422 Inc.get(), LoopVar.get(),
7423 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00007424 if (NewStmt.isInvalid())
7425 return StmtError();
7426 }
Richard Smith02e85f32011-04-14 22:09:26 +00007427
7428 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007429 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00007430
7431 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
7432}
7433
John Wiegley1c0675e2011-04-28 01:08:34 +00007434template<typename Derived>
7435StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007436TreeTransform<Derived>::TransformMSDependentExistsStmt(
7437 MSDependentExistsStmt *S) {
7438 // Transform the nested-name-specifier, if any.
7439 NestedNameSpecifierLoc QualifierLoc;
7440 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00007441 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007442 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
7443 if (!QualifierLoc)
7444 return StmtError();
7445 }
7446
7447 // Transform the declaration name.
7448 DeclarationNameInfo NameInfo = S->getNameInfo();
7449 if (NameInfo.getName()) {
7450 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7451 if (!NameInfo.getName())
7452 return StmtError();
7453 }
7454
7455 // Check whether anything changed.
7456 if (!getDerived().AlwaysRebuild() &&
7457 QualifierLoc == S->getQualifierLoc() &&
7458 NameInfo.getName() == S->getNameInfo().getName())
7459 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00007460
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007461 // Determine whether this name exists, if we can.
7462 CXXScopeSpec SS;
7463 SS.Adopt(QualifierLoc);
7464 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00007465 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007466 case Sema::IER_Exists:
7467 if (S->isIfExists())
7468 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007469
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007470 return new (getSema().Context) NullStmt(S->getKeywordLoc());
7471
7472 case Sema::IER_DoesNotExist:
7473 if (S->isIfNotExists())
7474 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007475
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007476 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007477
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007478 case Sema::IER_Dependent:
7479 Dependent = true;
7480 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007481
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00007482 case Sema::IER_Error:
7483 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007484 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007485
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007486 // We need to continue with the instantiation, so do so now.
7487 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
7488 if (SubStmt.isInvalid())
7489 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007490
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007491 // If we have resolved the name, just transform to the substatement.
7492 if (!Dependent)
7493 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00007494
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00007495 // The name is still dependent, so build a dependent expression again.
7496 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
7497 S->isIfExists(),
7498 QualifierLoc,
7499 NameInfo,
7500 SubStmt.get());
7501}
7502
7503template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00007504ExprResult
7505TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
7506 NestedNameSpecifierLoc QualifierLoc;
7507 if (E->getQualifierLoc()) {
7508 QualifierLoc
7509 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7510 if (!QualifierLoc)
7511 return ExprError();
7512 }
7513
7514 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
7515 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
7516 if (!PD)
7517 return ExprError();
7518
7519 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
7520 if (Base.isInvalid())
7521 return ExprError();
7522
7523 return new (SemaRef.getASTContext())
7524 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
7525 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
7526 QualifierLoc, E->getMemberLoc());
7527}
7528
David Majnemerfad8f482013-10-15 09:33:02 +00007529template <typename Derived>
Alexey Bataevf7630272015-11-25 12:01:00 +00007530ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
7531 MSPropertySubscriptExpr *E) {
7532 auto BaseRes = getDerived().TransformExpr(E->getBase());
7533 if (BaseRes.isInvalid())
7534 return ExprError();
7535 auto IdxRes = getDerived().TransformExpr(E->getIdx());
7536 if (IdxRes.isInvalid())
7537 return ExprError();
7538
7539 if (!getDerived().AlwaysRebuild() &&
7540 BaseRes.get() == E->getBase() &&
7541 IdxRes.get() == E->getIdx())
7542 return E;
7543
7544 return getDerived().RebuildArraySubscriptExpr(
7545 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
7546}
7547
7548template <typename Derived>
David Majnemerfad8f482013-10-15 09:33:02 +00007549StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007550 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007551 if (TryBlock.isInvalid())
7552 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007553
7554 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00007555 if (Handler.isInvalid())
7556 return StmtError();
7557
David Majnemerfad8f482013-10-15 09:33:02 +00007558 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
7559 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007560 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00007561
Warren Huntf6be4cb2014-07-25 20:52:51 +00007562 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
7563 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007564}
7565
David Majnemerfad8f482013-10-15 09:33:02 +00007566template <typename Derived>
7567StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00007568 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007569 if (Block.isInvalid())
7570 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007571
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007572 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007573}
7574
David Majnemerfad8f482013-10-15 09:33:02 +00007575template <typename Derived>
7576StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00007577 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00007578 if (FilterExpr.isInvalid())
7579 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007580
David Majnemer7e755502013-10-15 09:30:14 +00007581 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00007582 if (Block.isInvalid())
7583 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00007584
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007585 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
7586 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00007587}
7588
David Majnemerfad8f482013-10-15 09:33:02 +00007589template <typename Derived>
7590StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
7591 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00007592 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
7593 else
7594 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
7595}
7596
Nico Weber9b982072014-07-07 00:12:30 +00007597template<typename Derived>
7598StmtResult
7599TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
7600 return S;
7601}
7602
Alexander Musman64d33f12014-06-04 07:53:32 +00007603//===----------------------------------------------------------------------===//
7604// OpenMP directive transformation
7605//===----------------------------------------------------------------------===//
7606template <typename Derived>
7607StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
7608 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007609
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007610 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00007611 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007612 ArrayRef<OMPClause *> Clauses = D->clauses();
7613 TClauses.reserve(Clauses.size());
7614 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
7615 I != E; ++I) {
7616 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00007617 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007618 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00007619 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00007620 if (Clause)
7621 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00007622 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00007623 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007624 }
7625 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007626 StmtResult AssociatedStmt;
Alexey Bataeveb482352015-12-18 05:05:56 +00007627 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007628 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
7629 /*CurScope=*/nullptr);
7630 StmtResult Body;
7631 {
7632 Sema::CompoundScopeRAII CompoundScope(getSema());
Alexey Bataev475a7442018-01-12 19:39:11 +00007633 Stmt *CS = D->getInnermostCapturedStmt()->getCapturedStmt();
Arpith Chacko Jacob19b911c2017-01-18 18:18:53 +00007634 Body = getDerived().TransformStmt(CS);
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00007635 }
7636 AssociatedStmt =
7637 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00007638 if (AssociatedStmt.isInvalid()) {
7639 return StmtError();
7640 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00007641 }
Alexey Bataev68446b72014-07-18 07:47:19 +00007642 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007643 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00007644 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007645
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007646 // Transform directive name for 'omp critical' directive.
7647 DeclarationNameInfo DirName;
7648 if (D->getDirectiveKind() == OMPD_critical) {
7649 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
7650 DirName = getDerived().TransformDeclarationNameInfo(DirName);
7651 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007652 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
7653 if (D->getDirectiveKind() == OMPD_cancellation_point) {
7654 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00007655 } else if (D->getDirectiveKind() == OMPD_cancel) {
7656 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007657 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007658
Alexander Musman64d33f12014-06-04 07:53:32 +00007659 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007660 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
7661 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007662}
7663
Alexander Musman64d33f12014-06-04 07:53:32 +00007664template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007665StmtResult
7666TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
7667 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007668 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
7669 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007670 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7671 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7672 return Res;
7673}
7674
Alexander Musman64d33f12014-06-04 07:53:32 +00007675template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007676StmtResult
7677TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
7678 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007679 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
7680 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00007681 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7682 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007683 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007684}
7685
Alexey Bataevf29276e2014-06-18 04:14:57 +00007686template <typename Derived>
7687StmtResult
7688TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
7689 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007690 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
7691 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00007692 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7693 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7694 return Res;
7695}
7696
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007697template <typename Derived>
7698StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00007699TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
7700 DeclarationNameInfo DirName;
7701 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
7702 D->getLocStart());
7703 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7704 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7705 return Res;
7706}
7707
7708template <typename Derived>
7709StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007710TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
7711 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007712 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
7713 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00007714 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7715 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7716 return Res;
7717}
7718
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007719template <typename Derived>
7720StmtResult
7721TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
7722 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007723 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
7724 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00007725 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7726 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7727 return Res;
7728}
7729
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007730template <typename Derived>
7731StmtResult
7732TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7733 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007734 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7735 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007736 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7737 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7738 return Res;
7739}
7740
Alexey Bataev4acb8592014-07-07 13:01:15 +00007741template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007742StmtResult
7743TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7744 DeclarationNameInfo DirName;
7745 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7746 D->getLocStart());
7747 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7748 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7749 return Res;
7750}
7751
7752template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007753StmtResult
7754TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7755 getDerived().getSema().StartOpenMPDSABlock(
7756 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7757 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7758 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7759 return Res;
7760}
7761
7762template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007763StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7764 OMPParallelForDirective *D) {
7765 DeclarationNameInfo DirName;
7766 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7767 nullptr, D->getLocStart());
7768 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7769 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7770 return Res;
7771}
7772
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007773template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007774StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7775 OMPParallelForSimdDirective *D) {
7776 DeclarationNameInfo DirName;
7777 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7778 nullptr, D->getLocStart());
7779 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7780 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7781 return Res;
7782}
7783
7784template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007785StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7786 OMPParallelSectionsDirective *D) {
7787 DeclarationNameInfo DirName;
7788 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7789 nullptr, D->getLocStart());
7790 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7791 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7792 return Res;
7793}
7794
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007795template <typename Derived>
7796StmtResult
7797TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7798 DeclarationNameInfo DirName;
7799 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7800 D->getLocStart());
7801 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7802 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7803 return Res;
7804}
7805
Alexey Bataev68446b72014-07-18 07:47:19 +00007806template <typename Derived>
7807StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7808 OMPTaskyieldDirective *D) {
7809 DeclarationNameInfo DirName;
7810 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7811 D->getLocStart());
7812 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7813 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7814 return Res;
7815}
7816
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007817template <typename Derived>
7818StmtResult
7819TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7820 DeclarationNameInfo DirName;
7821 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7822 D->getLocStart());
7823 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7824 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7825 return Res;
7826}
7827
Alexey Bataev2df347a2014-07-18 10:17:07 +00007828template <typename Derived>
7829StmtResult
7830TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7831 DeclarationNameInfo DirName;
7832 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7833 D->getLocStart());
7834 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7835 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7836 return Res;
7837}
7838
Alexey Bataev6125da92014-07-21 11:26:11 +00007839template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007840StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7841 OMPTaskgroupDirective *D) {
7842 DeclarationNameInfo DirName;
7843 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7844 D->getLocStart());
7845 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7846 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7847 return Res;
7848}
7849
7850template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007851StmtResult
7852TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7853 DeclarationNameInfo DirName;
7854 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7855 D->getLocStart());
7856 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7857 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7858 return Res;
7859}
7860
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007861template <typename Derived>
7862StmtResult
7863TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7864 DeclarationNameInfo DirName;
7865 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7866 D->getLocStart());
7867 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7868 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7869 return Res;
7870}
7871
Alexey Bataev0162e452014-07-22 10:10:35 +00007872template <typename Derived>
7873StmtResult
7874TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7875 DeclarationNameInfo DirName;
7876 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7877 D->getLocStart());
7878 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7879 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7880 return Res;
7881}
7882
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007883template <typename Derived>
7884StmtResult
7885TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7886 DeclarationNameInfo DirName;
7887 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7888 D->getLocStart());
7889 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7890 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7891 return Res;
7892}
7893
Alexey Bataev13314bf2014-10-09 04:18:56 +00007894template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007895StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7896 OMPTargetDataDirective *D) {
7897 DeclarationNameInfo DirName;
7898 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7899 D->getLocStart());
7900 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7901 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7902 return Res;
7903}
7904
7905template <typename Derived>
Samuel Antaodf67fc42016-01-19 19:15:56 +00007906StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
7907 OMPTargetEnterDataDirective *D) {
7908 DeclarationNameInfo DirName;
7909 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
7910 nullptr, D->getLocStart());
7911 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7912 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7913 return Res;
7914}
7915
7916template <typename Derived>
Samuel Antao72590762016-01-19 20:04:50 +00007917StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
7918 OMPTargetExitDataDirective *D) {
7919 DeclarationNameInfo DirName;
7920 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
7921 nullptr, D->getLocStart());
7922 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7923 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7924 return Res;
7925}
7926
7927template <typename Derived>
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +00007928StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
7929 OMPTargetParallelDirective *D) {
7930 DeclarationNameInfo DirName;
7931 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
7932 nullptr, D->getLocStart());
7933 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7934 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7935 return Res;
7936}
7937
7938template <typename Derived>
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +00007939StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
7940 OMPTargetParallelForDirective *D) {
7941 DeclarationNameInfo DirName;
7942 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
7943 nullptr, D->getLocStart());
7944 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7945 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7946 return Res;
7947}
7948
7949template <typename Derived>
Samuel Antao686c70c2016-05-26 17:30:50 +00007950StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
7951 OMPTargetUpdateDirective *D) {
7952 DeclarationNameInfo DirName;
7953 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
7954 nullptr, D->getLocStart());
7955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7956 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7957 return Res;
7958}
7959
7960template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007961StmtResult
7962TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7963 DeclarationNameInfo DirName;
7964 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7965 D->getLocStart());
7966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7967 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7968 return Res;
7969}
7970
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007971template <typename Derived>
7972StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7973 OMPCancellationPointDirective *D) {
7974 DeclarationNameInfo DirName;
7975 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7976 nullptr, D->getLocStart());
7977 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7978 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7979 return Res;
7980}
7981
Alexey Bataev80909872015-07-02 11:25:17 +00007982template <typename Derived>
7983StmtResult
7984TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7985 DeclarationNameInfo DirName;
7986 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7987 D->getLocStart());
7988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7990 return Res;
7991}
7992
Alexey Bataev49f6e782015-12-01 04:18:41 +00007993template <typename Derived>
7994StmtResult
7995TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
7996 DeclarationNameInfo DirName;
7997 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
7998 D->getLocStart());
7999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8001 return Res;
8002}
8003
Alexey Bataev0a6ed842015-12-03 09:40:15 +00008004template <typename Derived>
8005StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
8006 OMPTaskLoopSimdDirective *D) {
8007 DeclarationNameInfo DirName;
8008 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
8009 nullptr, D->getLocStart());
8010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8012 return Res;
8013}
8014
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00008015template <typename Derived>
8016StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
8017 OMPDistributeDirective *D) {
8018 DeclarationNameInfo DirName;
8019 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
8020 D->getLocStart());
8021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8023 return Res;
8024}
8025
Carlo Bertolli9925f152016-06-27 14:55:37 +00008026template <typename Derived>
8027StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
8028 OMPDistributeParallelForDirective *D) {
8029 DeclarationNameInfo DirName;
8030 getDerived().getSema().StartOpenMPDSABlock(
8031 OMPD_distribute_parallel_for, DirName, nullptr, D->getLocStart());
8032 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8033 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8034 return Res;
8035}
8036
Kelvin Li4a39add2016-07-05 05:00:15 +00008037template <typename Derived>
8038StmtResult
8039TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
8040 OMPDistributeParallelForSimdDirective *D) {
8041 DeclarationNameInfo DirName;
8042 getDerived().getSema().StartOpenMPDSABlock(
8043 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8044 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8045 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8046 return Res;
8047}
8048
Kelvin Li787f3fc2016-07-06 04:45:38 +00008049template <typename Derived>
8050StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
8051 OMPDistributeSimdDirective *D) {
8052 DeclarationNameInfo DirName;
8053 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
8054 nullptr, D->getLocStart());
8055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8057 return Res;
8058}
8059
Kelvin Lia579b912016-07-14 02:54:56 +00008060template <typename Derived>
8061StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
8062 OMPTargetParallelForSimdDirective *D) {
8063 DeclarationNameInfo DirName;
8064 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for_simd,
8065 DirName, nullptr,
8066 D->getLocStart());
8067 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8068 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8069 return Res;
8070}
8071
Kelvin Li986330c2016-07-20 22:57:10 +00008072template <typename Derived>
8073StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
8074 OMPTargetSimdDirective *D) {
8075 DeclarationNameInfo DirName;
8076 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
8077 D->getLocStart());
8078 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8079 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8080 return Res;
8081}
8082
Kelvin Li02532872016-08-05 14:37:37 +00008083template <typename Derived>
8084StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
8085 OMPTeamsDistributeDirective *D) {
8086 DeclarationNameInfo DirName;
8087 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
8088 nullptr, D->getLocStart());
8089 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8090 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8091 return Res;
8092}
8093
Kelvin Li4e325f72016-10-25 12:50:55 +00008094template <typename Derived>
8095StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
8096 OMPTeamsDistributeSimdDirective *D) {
8097 DeclarationNameInfo DirName;
8098 getDerived().getSema().StartOpenMPDSABlock(
8099 OMPD_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8100 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8101 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8102 return Res;
8103}
8104
Kelvin Li579e41c2016-11-30 23:51:03 +00008105template <typename Derived>
8106StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
8107 OMPTeamsDistributeParallelForSimdDirective *D) {
8108 DeclarationNameInfo DirName;
8109 getDerived().getSema().StartOpenMPDSABlock(
8110 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, D->getLocStart());
8111 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8112 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8113 return Res;
8114}
8115
Kelvin Li7ade93f2016-12-09 03:24:30 +00008116template <typename Derived>
8117StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
8118 OMPTeamsDistributeParallelForDirective *D) {
8119 DeclarationNameInfo DirName;
8120 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute_parallel_for,
8121 DirName, nullptr, D->getLocStart());
8122 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
8123 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8124 return Res;
8125}
8126
Kelvin Libf594a52016-12-17 05:48:59 +00008127template <typename Derived>
8128StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
8129 OMPTargetTeamsDirective *D) {
8130 DeclarationNameInfo DirName;
8131 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
8132 nullptr, D->getLocStart());
8133 auto Res = getDerived().TransformOMPExecutableDirective(D);
8134 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8135 return Res;
8136}
Kelvin Li579e41c2016-11-30 23:51:03 +00008137
Kelvin Li83c451e2016-12-25 04:52:54 +00008138template <typename Derived>
8139StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
8140 OMPTargetTeamsDistributeDirective *D) {
8141 DeclarationNameInfo DirName;
8142 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_distribute,
8143 DirName, nullptr, D->getLocStart());
8144 auto Res = getDerived().TransformOMPExecutableDirective(D);
8145 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8146 return Res;
8147}
8148
Kelvin Li80e8f562016-12-29 22:16:30 +00008149template <typename Derived>
8150StmtResult
8151TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
8152 OMPTargetTeamsDistributeParallelForDirective *D) {
8153 DeclarationNameInfo DirName;
8154 getDerived().getSema().StartOpenMPDSABlock(
8155 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
8156 D->getLocStart());
8157 auto Res = getDerived().TransformOMPExecutableDirective(D);
8158 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8159 return Res;
8160}
8161
Kelvin Li1851df52017-01-03 05:23:48 +00008162template <typename Derived>
8163StmtResult TreeTransform<Derived>::
8164 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
8165 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
8166 DeclarationNameInfo DirName;
8167 getDerived().getSema().StartOpenMPDSABlock(
8168 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
8169 D->getLocStart());
8170 auto Res = getDerived().TransformOMPExecutableDirective(D);
8171 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8172 return Res;
8173}
8174
Kelvin Lida681182017-01-10 18:08:18 +00008175template <typename Derived>
8176StmtResult
8177TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
8178 OMPTargetTeamsDistributeSimdDirective *D) {
8179 DeclarationNameInfo DirName;
8180 getDerived().getSema().StartOpenMPDSABlock(
8181 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getLocStart());
8182 auto Res = getDerived().TransformOMPExecutableDirective(D);
8183 getDerived().getSema().EndOpenMPDSABlock(Res.get());
8184 return Res;
8185}
8186
Kelvin Li1851df52017-01-03 05:23:48 +00008187
Alexander Musman64d33f12014-06-04 07:53:32 +00008188//===----------------------------------------------------------------------===//
8189// OpenMP clause transformation
8190//===----------------------------------------------------------------------===//
8191template <typename Derived>
8192OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00008193 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8194 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008195 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00008196 return getDerived().RebuildOMPIfClause(
8197 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
8198 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008199}
8200
Alexander Musman64d33f12014-06-04 07:53:32 +00008201template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00008202OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
8203 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
8204 if (Cond.isInvalid())
8205 return nullptr;
8206 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
8207 C->getLParenLoc(), C->getLocEnd());
8208}
8209
8210template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00008211OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00008212TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
8213 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
8214 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008215 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00008216 return getDerived().RebuildOMPNumThreadsClause(
8217 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00008218}
8219
Alexey Bataev62c87d22014-03-21 04:51:18 +00008220template <typename Derived>
8221OMPClause *
8222TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
8223 ExprResult E = getDerived().TransformExpr(C->getSafelen());
8224 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008225 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00008226 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008227 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00008228}
8229
Alexander Musman8bd31e62014-05-27 15:12:19 +00008230template <typename Derived>
8231OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00008232TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
8233 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
8234 if (E.isInvalid())
8235 return nullptr;
8236 return getDerived().RebuildOMPSimdlenClause(
8237 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8238}
8239
8240template <typename Derived>
8241OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00008242TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
8243 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
8244 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00008245 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00008246 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008247 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00008248}
8249
Alexander Musman64d33f12014-06-04 07:53:32 +00008250template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00008251OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008252TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008253 return getDerived().RebuildOMPDefaultClause(
8254 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
8255 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008256}
8257
Alexander Musman64d33f12014-06-04 07:53:32 +00008258template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008259OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008260TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00008261 return getDerived().RebuildOMPProcBindClause(
8262 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
8263 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008264}
8265
Alexander Musman64d33f12014-06-04 07:53:32 +00008266template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00008267OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00008268TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
8269 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8270 if (E.isInvalid())
8271 return nullptr;
8272 return getDerived().RebuildOMPScheduleClause(
Alexey Bataev6402bca2015-12-28 07:25:51 +00008273 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008274 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
Alexey Bataev6402bca2015-12-28 07:25:51 +00008275 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
Alexey Bataev56dafe82014-06-20 07:16:17 +00008276 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8277}
8278
8279template <typename Derived>
8280OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008281TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00008282 ExprResult E;
8283 if (auto *Num = C->getNumForLoops()) {
8284 E = getDerived().TransformExpr(Num);
8285 if (E.isInvalid())
8286 return nullptr;
8287 }
8288 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
8289 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00008290}
8291
8292template <typename Derived>
8293OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00008294TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
8295 // No need to rebuild this clause, no template-dependent parameters.
8296 return C;
8297}
8298
8299template <typename Derived>
8300OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00008301TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
8302 // No need to rebuild this clause, no template-dependent parameters.
8303 return C;
8304}
8305
8306template <typename Derived>
8307OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008308TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
8309 // No need to rebuild this clause, no template-dependent parameters.
8310 return C;
8311}
8312
8313template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00008314OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
8315 // No need to rebuild this clause, no template-dependent parameters.
8316 return C;
8317}
8318
8319template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00008320OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
8321 // No need to rebuild this clause, no template-dependent parameters.
8322 return C;
8323}
8324
8325template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00008326OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00008327TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
8328 // No need to rebuild this clause, no template-dependent parameters.
8329 return C;
8330}
8331
8332template <typename Derived>
8333OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00008334TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
8335 // No need to rebuild this clause, no template-dependent parameters.
8336 return C;
8337}
8338
8339template <typename Derived>
8340OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00008341TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
8342 // No need to rebuild this clause, no template-dependent parameters.
8343 return C;
8344}
8345
8346template <typename Derived>
8347OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00008348TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
8349 // No need to rebuild this clause, no template-dependent parameters.
8350 return C;
8351}
8352
8353template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00008354OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
8355 // No need to rebuild this clause, no template-dependent parameters.
8356 return C;
8357}
8358
8359template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00008360OMPClause *
Alexey Bataevb825de12015-12-07 10:51:44 +00008361TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
8362 // No need to rebuild this clause, no template-dependent parameters.
8363 return C;
8364}
8365
8366template <typename Derived>
8367OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008368TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00008369 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008370 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008371 for (auto *VE : C->varlists()) {
8372 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008373 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008374 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008375 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008376 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008377 return getDerived().RebuildOMPPrivateClause(
8378 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00008379}
8380
Alexander Musman64d33f12014-06-04 07:53:32 +00008381template <typename Derived>
8382OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
8383 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008384 llvm::SmallVector<Expr *, 16> Vars;
8385 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008386 for (auto *VE : C->varlists()) {
8387 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008388 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008389 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008390 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008391 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008392 return getDerived().RebuildOMPFirstprivateClause(
8393 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008394}
8395
Alexander Musman64d33f12014-06-04 07:53:32 +00008396template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00008397OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00008398TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
8399 llvm::SmallVector<Expr *, 16> Vars;
8400 Vars.reserve(C->varlist_size());
8401 for (auto *VE : C->varlists()) {
8402 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8403 if (EVar.isInvalid())
8404 return nullptr;
8405 Vars.push_back(EVar.get());
8406 }
8407 return getDerived().RebuildOMPLastprivateClause(
8408 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8409}
8410
8411template <typename Derived>
8412OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00008413TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
8414 llvm::SmallVector<Expr *, 16> Vars;
8415 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008416 for (auto *VE : C->varlists()) {
8417 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00008418 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008419 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008420 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008421 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008422 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
8423 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00008424}
8425
Alexander Musman64d33f12014-06-04 07:53:32 +00008426template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008427OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00008428TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
8429 llvm::SmallVector<Expr *, 16> Vars;
8430 Vars.reserve(C->varlist_size());
8431 for (auto *VE : C->varlists()) {
8432 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8433 if (EVar.isInvalid())
8434 return nullptr;
8435 Vars.push_back(EVar.get());
8436 }
8437 CXXScopeSpec ReductionIdScopeSpec;
8438 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8439
8440 DeclarationNameInfo NameInfo = C->getNameInfo();
8441 if (NameInfo.getName()) {
8442 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8443 if (!NameInfo.getName())
8444 return nullptr;
8445 }
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008446 // Build a list of all UDR decls with the same names ranged by the Scopes.
8447 // The Scope boundary is a duplication of the previous decl.
8448 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8449 for (auto *E : C->reduction_ops()) {
8450 // Transform all the decls.
8451 if (E) {
8452 auto *ULE = cast<UnresolvedLookupExpr>(E);
8453 UnresolvedSet<8> Decls;
8454 for (auto *D : ULE->decls()) {
8455 NamedDecl *InstD =
8456 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8457 Decls.addDecl(InstD, InstD->getAccess());
8458 }
8459 UnresolvedReductions.push_back(
8460 UnresolvedLookupExpr::Create(
8461 SemaRef.Context, /*NamingClass=*/nullptr,
8462 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
8463 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
8464 Decls.begin(), Decls.end()));
8465 } else
8466 UnresolvedReductions.push_back(nullptr);
8467 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00008468 return getDerived().RebuildOMPReductionClause(
8469 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
Alexey Bataeva839ddd2016-03-17 10:19:46 +00008470 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
Alexey Bataevc5e02582014-06-16 07:08:35 +00008471}
8472
8473template <typename Derived>
Alexey Bataev169d96a2017-07-18 20:17:46 +00008474OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
8475 OMPTaskReductionClause *C) {
8476 llvm::SmallVector<Expr *, 16> Vars;
8477 Vars.reserve(C->varlist_size());
8478 for (auto *VE : C->varlists()) {
8479 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8480 if (EVar.isInvalid())
8481 return nullptr;
8482 Vars.push_back(EVar.get());
8483 }
8484 CXXScopeSpec ReductionIdScopeSpec;
8485 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8486
8487 DeclarationNameInfo NameInfo = C->getNameInfo();
8488 if (NameInfo.getName()) {
8489 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8490 if (!NameInfo.getName())
8491 return nullptr;
8492 }
8493 // Build a list of all UDR decls with the same names ranged by the Scopes.
8494 // The Scope boundary is a duplication of the previous decl.
8495 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8496 for (auto *E : C->reduction_ops()) {
8497 // Transform all the decls.
8498 if (E) {
8499 auto *ULE = cast<UnresolvedLookupExpr>(E);
8500 UnresolvedSet<8> Decls;
8501 for (auto *D : ULE->decls()) {
8502 NamedDecl *InstD =
8503 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8504 Decls.addDecl(InstD, InstD->getAccess());
8505 }
8506 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8507 SemaRef.Context, /*NamingClass=*/nullptr,
8508 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8509 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8510 } else
8511 UnresolvedReductions.push_back(nullptr);
8512 }
8513 return getDerived().RebuildOMPTaskReductionClause(
8514 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8515 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8516}
8517
8518template <typename Derived>
Alexey Bataevc5e02582014-06-16 07:08:35 +00008519OMPClause *
Alexey Bataevfa312f32017-07-21 18:48:21 +00008520TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
8521 llvm::SmallVector<Expr *, 16> Vars;
8522 Vars.reserve(C->varlist_size());
8523 for (auto *VE : C->varlists()) {
8524 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8525 if (EVar.isInvalid())
8526 return nullptr;
8527 Vars.push_back(EVar.get());
8528 }
8529 CXXScopeSpec ReductionIdScopeSpec;
8530 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
8531
8532 DeclarationNameInfo NameInfo = C->getNameInfo();
8533 if (NameInfo.getName()) {
8534 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8535 if (!NameInfo.getName())
8536 return nullptr;
8537 }
8538 // Build a list of all UDR decls with the same names ranged by the Scopes.
8539 // The Scope boundary is a duplication of the previous decl.
8540 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
8541 for (auto *E : C->reduction_ops()) {
8542 // Transform all the decls.
8543 if (E) {
8544 auto *ULE = cast<UnresolvedLookupExpr>(E);
8545 UnresolvedSet<8> Decls;
8546 for (auto *D : ULE->decls()) {
8547 NamedDecl *InstD =
8548 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
8549 Decls.addDecl(InstD, InstD->getAccess());
8550 }
8551 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
8552 SemaRef.Context, /*NamingClass=*/nullptr,
8553 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
8554 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
8555 } else
8556 UnresolvedReductions.push_back(nullptr);
8557 }
8558 return getDerived().RebuildOMPInReductionClause(
8559 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
8560 C->getLocEnd(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
8561}
8562
8563template <typename Derived>
8564OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00008565TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
8566 llvm::SmallVector<Expr *, 16> Vars;
8567 Vars.reserve(C->varlist_size());
8568 for (auto *VE : C->varlists()) {
8569 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8570 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008571 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008572 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00008573 }
8574 ExprResult Step = getDerived().TransformExpr(C->getStep());
8575 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008576 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00008577 return getDerived().RebuildOMPLinearClause(
8578 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
8579 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00008580}
8581
Alexander Musman64d33f12014-06-04 07:53:32 +00008582template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00008583OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008584TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
8585 llvm::SmallVector<Expr *, 16> Vars;
8586 Vars.reserve(C->varlist_size());
8587 for (auto *VE : C->varlists()) {
8588 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8589 if (EVar.isInvalid())
8590 return nullptr;
8591 Vars.push_back(EVar.get());
8592 }
8593 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
8594 if (Alignment.isInvalid())
8595 return nullptr;
8596 return getDerived().RebuildOMPAlignedClause(
8597 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
8598 C->getColonLoc(), C->getLocEnd());
8599}
8600
Alexander Musman64d33f12014-06-04 07:53:32 +00008601template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00008602OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008603TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
8604 llvm::SmallVector<Expr *, 16> Vars;
8605 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00008606 for (auto *VE : C->varlists()) {
8607 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008608 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00008609 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008610 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008611 }
Alexander Musman64d33f12014-06-04 07:53:32 +00008612 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
8613 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00008614}
8615
Alexey Bataevbae9a792014-06-27 10:37:06 +00008616template <typename Derived>
8617OMPClause *
8618TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
8619 llvm::SmallVector<Expr *, 16> Vars;
8620 Vars.reserve(C->varlist_size());
8621 for (auto *VE : C->varlists()) {
8622 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8623 if (EVar.isInvalid())
8624 return nullptr;
8625 Vars.push_back(EVar.get());
8626 }
8627 return getDerived().RebuildOMPCopyprivateClause(
8628 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8629}
8630
Alexey Bataev6125da92014-07-21 11:26:11 +00008631template <typename Derived>
8632OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
8633 llvm::SmallVector<Expr *, 16> Vars;
8634 Vars.reserve(C->varlist_size());
8635 for (auto *VE : C->varlists()) {
8636 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8637 if (EVar.isInvalid())
8638 return nullptr;
8639 Vars.push_back(EVar.get());
8640 }
8641 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
8642 C->getLParenLoc(), C->getLocEnd());
8643}
8644
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00008645template <typename Derived>
8646OMPClause *
8647TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
8648 llvm::SmallVector<Expr *, 16> Vars;
8649 Vars.reserve(C->varlist_size());
8650 for (auto *VE : C->varlists()) {
8651 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8652 if (EVar.isInvalid())
8653 return nullptr;
8654 Vars.push_back(EVar.get());
8655 }
8656 return getDerived().RebuildOMPDependClause(
8657 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
8658 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8659}
8660
Michael Wonge710d542015-08-07 16:16:36 +00008661template <typename Derived>
8662OMPClause *
8663TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
8664 ExprResult E = getDerived().TransformExpr(C->getDevice());
8665 if (E.isInvalid())
8666 return nullptr;
8667 return getDerived().RebuildOMPDeviceClause(
8668 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8669}
8670
Kelvin Li0bff7af2015-11-23 05:32:03 +00008671template <typename Derived>
8672OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
8673 llvm::SmallVector<Expr *, 16> Vars;
8674 Vars.reserve(C->varlist_size());
8675 for (auto *VE : C->varlists()) {
8676 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8677 if (EVar.isInvalid())
8678 return nullptr;
8679 Vars.push_back(EVar.get());
8680 }
8681 return getDerived().RebuildOMPMapClause(
Samuel Antao23abd722016-01-19 20:40:49 +00008682 C->getMapTypeModifier(), C->getMapType(), C->isImplicitMapType(),
8683 C->getMapLoc(), C->getColonLoc(), Vars, C->getLocStart(),
8684 C->getLParenLoc(), C->getLocEnd());
Kelvin Li0bff7af2015-11-23 05:32:03 +00008685}
8686
Kelvin Li099bb8c2015-11-24 20:50:12 +00008687template <typename Derived>
8688OMPClause *
8689TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
8690 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
8691 if (E.isInvalid())
8692 return nullptr;
8693 return getDerived().RebuildOMPNumTeamsClause(
8694 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8695}
8696
Kelvin Lia15fb1a2015-11-27 18:47:36 +00008697template <typename Derived>
8698OMPClause *
8699TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
8700 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
8701 if (E.isInvalid())
8702 return nullptr;
8703 return getDerived().RebuildOMPThreadLimitClause(
8704 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8705}
8706
Alexey Bataeva0569352015-12-01 10:17:31 +00008707template <typename Derived>
8708OMPClause *
8709TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
8710 ExprResult E = getDerived().TransformExpr(C->getPriority());
8711 if (E.isInvalid())
8712 return nullptr;
8713 return getDerived().RebuildOMPPriorityClause(
8714 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8715}
8716
Alexey Bataev1fd4aed2015-12-07 12:52:51 +00008717template <typename Derived>
8718OMPClause *
8719TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
8720 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
8721 if (E.isInvalid())
8722 return nullptr;
8723 return getDerived().RebuildOMPGrainsizeClause(
8724 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8725}
8726
Alexey Bataev382967a2015-12-08 12:06:20 +00008727template <typename Derived>
8728OMPClause *
8729TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
8730 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
8731 if (E.isInvalid())
8732 return nullptr;
8733 return getDerived().RebuildOMPNumTasksClause(
8734 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8735}
8736
Alexey Bataev28c75412015-12-15 08:19:24 +00008737template <typename Derived>
8738OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
8739 ExprResult E = getDerived().TransformExpr(C->getHint());
8740 if (E.isInvalid())
8741 return nullptr;
8742 return getDerived().RebuildOMPHintClause(E.get(), C->getLocStart(),
8743 C->getLParenLoc(), C->getLocEnd());
8744}
8745
Carlo Bertollib4adf552016-01-15 18:50:31 +00008746template <typename Derived>
8747OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
8748 OMPDistScheduleClause *C) {
8749 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
8750 if (E.isInvalid())
8751 return nullptr;
8752 return getDerived().RebuildOMPDistScheduleClause(
8753 C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
8754 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
8755}
8756
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00008757template <typename Derived>
8758OMPClause *
8759TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
8760 return C;
8761}
8762
Samuel Antao661c0902016-05-26 17:39:58 +00008763template <typename Derived>
8764OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
8765 llvm::SmallVector<Expr *, 16> Vars;
8766 Vars.reserve(C->varlist_size());
8767 for (auto *VE : C->varlists()) {
8768 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8769 if (EVar.isInvalid())
8770 return 0;
8771 Vars.push_back(EVar.get());
8772 }
8773 return getDerived().RebuildOMPToClause(Vars, C->getLocStart(),
8774 C->getLParenLoc(), C->getLocEnd());
8775}
8776
Samuel Antaoec172c62016-05-26 17:49:04 +00008777template <typename Derived>
8778OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
8779 llvm::SmallVector<Expr *, 16> Vars;
8780 Vars.reserve(C->varlist_size());
8781 for (auto *VE : C->varlists()) {
8782 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8783 if (EVar.isInvalid())
8784 return 0;
8785 Vars.push_back(EVar.get());
8786 }
8787 return getDerived().RebuildOMPFromClause(Vars, C->getLocStart(),
8788 C->getLParenLoc(), C->getLocEnd());
8789}
8790
Carlo Bertolli2404b172016-07-13 15:37:16 +00008791template <typename Derived>
8792OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
8793 OMPUseDevicePtrClause *C) {
8794 llvm::SmallVector<Expr *, 16> Vars;
8795 Vars.reserve(C->varlist_size());
8796 for (auto *VE : C->varlists()) {
8797 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8798 if (EVar.isInvalid())
8799 return nullptr;
8800 Vars.push_back(EVar.get());
8801 }
8802 return getDerived().RebuildOMPUseDevicePtrClause(
8803 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8804}
8805
Carlo Bertolli70594e92016-07-13 17:16:49 +00008806template <typename Derived>
8807OMPClause *
8808TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
8809 llvm::SmallVector<Expr *, 16> Vars;
8810 Vars.reserve(C->varlist_size());
8811 for (auto *VE : C->varlists()) {
8812 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
8813 if (EVar.isInvalid())
8814 return nullptr;
8815 Vars.push_back(EVar.get());
8816 }
8817 return getDerived().RebuildOMPIsDevicePtrClause(
8818 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
8819}
8820
Douglas Gregorebe10102009-08-20 07:17:43 +00008821//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00008822// Expression transformation
8823//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00008824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008826TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00008827 if (!E->isTypeDependent())
8828 return E;
8829
8830 return getDerived().RebuildPredefinedExpr(E->getLocation(),
8831 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008832}
Mike Stump11289f42009-09-09 15:08:12 +00008833
8834template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008835ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008836TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008837 NestedNameSpecifierLoc QualifierLoc;
8838 if (E->getQualifierLoc()) {
8839 QualifierLoc
8840 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8841 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008842 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008843 }
John McCallce546572009-12-08 09:08:17 +00008844
8845 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008846 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8847 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008848 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008849 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008850
John McCall815039a2010-08-17 21:27:17 +00008851 DeclarationNameInfo NameInfo = E->getNameInfo();
8852 if (NameInfo.getName()) {
8853 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8854 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00008855 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00008856 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008857
8858 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008859 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008860 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008861 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00008862 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008863
8864 // Mark it referenced in the new context regardless.
8865 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008866 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00008867
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008868 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00008869 }
John McCallce546572009-12-08 09:08:17 +00008870
Craig Topperc3ec1492014-05-26 06:22:03 +00008871 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00008872 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00008873 TemplateArgs = &TransArgs;
8874 TransArgs.setLAngleLoc(E->getLAngleLoc());
8875 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008876 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8877 E->getNumTemplateArgs(),
8878 TransArgs))
8879 return ExprError();
John McCallce546572009-12-08 09:08:17 +00008880 }
8881
Chad Rosier1dcde962012-08-08 18:46:20 +00008882 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00008883 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00008884}
Mike Stump11289f42009-09-09 15:08:12 +00008885
Douglas Gregora16548e2009-08-11 05:31:07 +00008886template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008887ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008888TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008889 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008890}
Mike Stump11289f42009-09-09 15:08:12 +00008891
Douglas Gregora16548e2009-08-11 05:31:07 +00008892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008893ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008894TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008895 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008896}
Mike Stump11289f42009-09-09 15:08:12 +00008897
Douglas Gregora16548e2009-08-11 05:31:07 +00008898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008899ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008900TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008901 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008902}
Mike Stump11289f42009-09-09 15:08:12 +00008903
Douglas Gregora16548e2009-08-11 05:31:07 +00008904template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008905ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008906TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008907 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008908}
Mike Stump11289f42009-09-09 15:08:12 +00008909
Douglas Gregora16548e2009-08-11 05:31:07 +00008910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008912TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008913 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008914}
8915
8916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008917ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00008918TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00008919 if (FunctionDecl *FD = E->getDirectCallee())
8920 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00008921 return SemaRef.MaybeBindToTemporary(E);
8922}
8923
8924template<typename Derived>
8925ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00008926TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
8927 ExprResult ControllingExpr =
8928 getDerived().TransformExpr(E->getControllingExpr());
8929 if (ControllingExpr.isInvalid())
8930 return ExprError();
8931
Chris Lattner01cf8db2011-07-20 06:58:45 +00008932 SmallVector<Expr *, 4> AssocExprs;
8933 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00008934 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
8935 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
8936 if (TS) {
8937 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
8938 if (!AssocType)
8939 return ExprError();
8940 AssocTypes.push_back(AssocType);
8941 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00008942 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00008943 }
8944
8945 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
8946 if (AssocExpr.isInvalid())
8947 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008948 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00008949 }
8950
8951 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
8952 E->getDefaultLoc(),
8953 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008954 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00008955 AssocTypes,
8956 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00008957}
8958
8959template<typename Derived>
8960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008961TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008962 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008963 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008964 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008965
Douglas Gregora16548e2009-08-11 05:31:07 +00008966 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008967 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008968
John McCallb268a282010-08-23 23:25:46 +00008969 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008970 E->getRParen());
8971}
8972
Richard Smithdb2630f2012-10-21 03:28:35 +00008973/// \brief The operand of a unary address-of operator has special rules: it's
8974/// allowed to refer to a non-static member of a class even if there's no 'this'
8975/// object available.
8976template<typename Derived>
8977ExprResult
8978TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
8979 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00008980 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00008981 else
8982 return getDerived().TransformExpr(E);
8983}
8984
Mike Stump11289f42009-09-09 15:08:12 +00008985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008987TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00008988 ExprResult SubExpr;
8989 if (E->getOpcode() == UO_AddrOf)
8990 SubExpr = TransformAddressOfOperand(E->getSubExpr());
8991 else
8992 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008993 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008995
Douglas Gregora16548e2009-08-11 05:31:07 +00008996 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008997 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008998
Douglas Gregora16548e2009-08-11 05:31:07 +00008999 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
9000 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009001 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009002}
Mike Stump11289f42009-09-09 15:08:12 +00009003
Douglas Gregora16548e2009-08-11 05:31:07 +00009004template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009005ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00009006TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
9007 // Transform the type.
9008 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
9009 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00009010 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009011
Douglas Gregor882211c2010-04-28 22:16:22 +00009012 // Transform all of the components into components similar to what the
9013 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00009014 // FIXME: It would be slightly more efficient in the non-dependent case to
9015 // just map FieldDecls, rather than requiring the rebuilder to look for
9016 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00009017 // template code that we don't care.
9018 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00009019 typedef Sema::OffsetOfComponent Component;
Chris Lattner01cf8db2011-07-20 06:58:45 +00009020 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00009021 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
James Y Knight7281c352015-12-29 22:31:18 +00009022 const OffsetOfNode &ON = E->getComponent(I);
Douglas Gregor882211c2010-04-28 22:16:22 +00009023 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00009024 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00009025 Comp.LocStart = ON.getSourceRange().getBegin();
9026 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00009027 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00009028 case OffsetOfNode::Array: {
Douglas Gregor882211c2010-04-28 22:16:22 +00009029 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00009030 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00009031 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009032 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009033
Douglas Gregor882211c2010-04-28 22:16:22 +00009034 ExprChanged = ExprChanged || Index.get() != FromIndex;
9035 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00009036 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00009037 break;
9038 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
James Y Knight7281c352015-12-29 22:31:18 +00009040 case OffsetOfNode::Field:
9041 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +00009042 Comp.isBrackets = false;
9043 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00009044 if (!Comp.U.IdentInfo)
9045 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009046
Douglas Gregor882211c2010-04-28 22:16:22 +00009047 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00009048
James Y Knight7281c352015-12-29 22:31:18 +00009049 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00009050 // Will be recomputed during the rebuild.
9051 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00009052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
Douglas Gregor882211c2010-04-28 22:16:22 +00009054 Components.push_back(Comp);
9055 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009056
Douglas Gregor882211c2010-04-28 22:16:22 +00009057 // If nothing changed, retain the existing expression.
9058 if (!getDerived().AlwaysRebuild() &&
9059 Type == E->getTypeSourceInfo() &&
9060 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009061 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00009062
Douglas Gregor882211c2010-04-28 22:16:22 +00009063 // Build a new offsetof expression.
9064 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00009065 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00009066}
9067
9068template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009069ExprResult
John McCall8d69a212010-11-15 23:31:06 +00009070TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00009071 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00009072 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009073 return E;
John McCall8d69a212010-11-15 23:31:06 +00009074}
9075
9076template<typename Derived>
9077ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00009078TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
9079 return E;
9080}
9081
9082template<typename Derived>
9083ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00009084TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00009085 // Rebuild the syntactic form. The original syntactic form has
9086 // opaque-value expressions in it, so strip those away and rebuild
9087 // the result. This is a really awful way of doing this, but the
9088 // better solution (rebuilding the semantic expressions and
9089 // rebinding OVEs as necessary) doesn't work; we'd need
9090 // TreeTransform to not strip away implicit conversions.
9091 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
9092 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00009093 if (result.isInvalid()) return ExprError();
9094
9095 // If that gives us a pseudo-object result back, the pseudo-object
9096 // expression must have been an lvalue-to-rvalue conversion which we
9097 // should reapply.
9098 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009099 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00009100
9101 return result;
9102}
9103
9104template<typename Derived>
9105ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00009106TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
9107 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009108 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00009109 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00009110
John McCallbcd03502009-12-07 02:54:59 +00009111 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00009112 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009113 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009114
John McCall4c98fd82009-11-04 07:28:41 +00009115 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009116 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009117
Peter Collingbournee190dee2011-03-11 19:24:49 +00009118 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
9119 E->getKind(),
9120 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009121 }
Mike Stump11289f42009-09-09 15:08:12 +00009122
Eli Friedmane4f22df2012-02-29 04:03:55 +00009123 // C++0x [expr.sizeof]p1:
9124 // The operand is either an expression, which is an unevaluated operand
9125 // [...]
Faisal Valid143a0c2017-04-01 21:30:49 +00009126 EnterExpressionEvaluationContext Unevaluated(
9127 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9128 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009129
Reid Kleckner32506ed2014-06-12 23:03:48 +00009130 // Try to recover if we have something like sizeof(T::X) where X is a type.
9131 // Notably, there must be *exactly* one set of parens if X is a type.
9132 TypeSourceInfo *RecoveryTSI = nullptr;
9133 ExprResult SubExpr;
9134 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
9135 if (auto *DRE =
9136 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
9137 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
9138 PE, DRE, false, &RecoveryTSI);
9139 else
9140 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
9141
9142 if (RecoveryTSI) {
9143 return getDerived().RebuildUnaryExprOrTypeTrait(
9144 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
9145 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00009146 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009147
Eli Friedmane4f22df2012-02-29 04:03:55 +00009148 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009149 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009150
Peter Collingbournee190dee2011-03-11 19:24:49 +00009151 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
9152 E->getOperatorLoc(),
9153 E->getKind(),
9154 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009155}
Mike Stump11289f42009-09-09 15:08:12 +00009156
Douglas Gregora16548e2009-08-11 05:31:07 +00009157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009158ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009159TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009160 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009161 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009162 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009163
John McCalldadc5752010-08-24 06:29:42 +00009164 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009165 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009166 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009167
9168
Douglas Gregora16548e2009-08-11 05:31:07 +00009169 if (!getDerived().AlwaysRebuild() &&
9170 LHS.get() == E->getLHS() &&
9171 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009172 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009173
John McCallb268a282010-08-23 23:25:46 +00009174 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009175 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009176 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009177 E->getRBracketLoc());
9178}
Mike Stump11289f42009-09-09 15:08:12 +00009179
Alexey Bataev1a3320e2015-08-25 14:24:04 +00009180template <typename Derived>
9181ExprResult
9182TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
9183 ExprResult Base = getDerived().TransformExpr(E->getBase());
9184 if (Base.isInvalid())
9185 return ExprError();
9186
9187 ExprResult LowerBound;
9188 if (E->getLowerBound()) {
9189 LowerBound = getDerived().TransformExpr(E->getLowerBound());
9190 if (LowerBound.isInvalid())
9191 return ExprError();
9192 }
9193
9194 ExprResult Length;
9195 if (E->getLength()) {
9196 Length = getDerived().TransformExpr(E->getLength());
9197 if (Length.isInvalid())
9198 return ExprError();
9199 }
9200
9201 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
9202 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
9203 return E;
9204
9205 return getDerived().RebuildOMPArraySectionExpr(
9206 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
9207 Length.get(), E->getRBracketLoc());
9208}
9209
Mike Stump11289f42009-09-09 15:08:12 +00009210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009212TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009213 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00009214 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009215 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009216 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009217
9218 // Transform arguments.
9219 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009220 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009221 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009222 &ArgChanged))
9223 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009224
Douglas Gregora16548e2009-08-11 05:31:07 +00009225 if (!getDerived().AlwaysRebuild() &&
9226 Callee.get() == E->getCallee() &&
9227 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00009228 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009229
Douglas Gregora16548e2009-08-11 05:31:07 +00009230 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00009231 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00009232 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00009233 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009234 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009235 E->getRParenLoc());
9236}
Mike Stump11289f42009-09-09 15:08:12 +00009237
9238template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009239ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009240TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009241 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009242 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009243 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009244
Douglas Gregorea972d32011-02-28 21:54:11 +00009245 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009246 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00009247 QualifierLoc
9248 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00009249
Douglas Gregorea972d32011-02-28 21:54:11 +00009250 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009251 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00009252 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00009253 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009254
Eli Friedman2cfcef62009-12-04 06:40:45 +00009255 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009256 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
9257 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009258 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00009259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009260
John McCall16df1e52010-03-30 21:47:33 +00009261 NamedDecl *FoundDecl = E->getFoundDecl();
9262 if (FoundDecl == E->getMemberDecl()) {
9263 FoundDecl = Member;
9264 } else {
9265 FoundDecl = cast_or_null<NamedDecl>(
9266 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
9267 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00009268 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00009269 }
9270
Douglas Gregora16548e2009-08-11 05:31:07 +00009271 if (!getDerived().AlwaysRebuild() &&
9272 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00009273 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009274 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00009275 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00009276 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009277
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009278 // Mark it referenced in the new context regardless.
9279 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00009280 SemaRef.MarkMemberReferenced(E);
9281
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009282 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00009283 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009284
John McCall6b51f282009-11-23 01:53:49 +00009285 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00009286 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00009287 TransArgs.setLAngleLoc(E->getLAngleLoc());
9288 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009289 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9290 E->getNumTemplateArgs(),
9291 TransArgs))
9292 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009293 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009294
Douglas Gregora16548e2009-08-11 05:31:07 +00009295 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00009296 SourceLocation FakeOperatorLoc =
9297 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00009298
John McCall38836f02010-01-15 08:34:02 +00009299 // FIXME: to do this check properly, we will need to preserve the
9300 // first-qualifier-in-scope here, just in case we had a dependent
9301 // base (and therefore couldn't do the check) and a
9302 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009303 NamedDecl *FirstQualifierInScope = nullptr;
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009304 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
9305 if (MemberNameInfo.getName()) {
9306 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
9307 if (!MemberNameInfo.getName())
9308 return ExprError();
9309 }
John McCall38836f02010-01-15 08:34:02 +00009310
John McCallb268a282010-08-23 23:25:46 +00009311 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009312 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00009313 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009314 TemplateKWLoc,
Akira Hatanaka59e3b432017-01-31 19:53:32 +00009315 MemberNameInfo,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00009316 Member,
John McCall16df1e52010-03-30 21:47:33 +00009317 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00009318 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009319 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00009320 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00009321}
Mike Stump11289f42009-09-09 15:08:12 +00009322
Douglas Gregora16548e2009-08-11 05:31:07 +00009323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009324ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009325TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009326 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009327 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009328 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009329
John McCalldadc5752010-08-24 06:29:42 +00009330 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009331 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009332 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009333
Douglas Gregora16548e2009-08-11 05:31:07 +00009334 if (!getDerived().AlwaysRebuild() &&
9335 LHS.get() == E->getLHS() &&
9336 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009337 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009338
Lang Hames5de91cc2012-10-02 04:45:10 +00009339 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009340 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009341
Douglas Gregora16548e2009-08-11 05:31:07 +00009342 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00009343 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009344}
9345
Mike Stump11289f42009-09-09 15:08:12 +00009346template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009347ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009348TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00009349 CompoundAssignOperator *E) {
9350 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009351}
Mike Stump11289f42009-09-09 15:08:12 +00009352
Douglas Gregora16548e2009-08-11 05:31:07 +00009353template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00009354ExprResult TreeTransform<Derived>::
9355TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
9356 // Just rebuild the common and RHS expressions and see whether we
9357 // get any changes.
9358
9359 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
9360 if (commonExpr.isInvalid())
9361 return ExprError();
9362
9363 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
9364 if (rhs.isInvalid())
9365 return ExprError();
9366
9367 if (!getDerived().AlwaysRebuild() &&
9368 commonExpr.get() == e->getCommon() &&
9369 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009370 return e;
John McCallc07a0c72011-02-17 10:25:35 +00009371
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009372 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00009373 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009374 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00009375 e->getColonLoc(),
9376 rhs.get());
9377}
9378
9379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009381TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00009382 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009383 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009384 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009385
John McCalldadc5752010-08-24 06:29:42 +00009386 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009387 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009388 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009389
John McCalldadc5752010-08-24 06:29:42 +00009390 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009391 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009393
Douglas Gregora16548e2009-08-11 05:31:07 +00009394 if (!getDerived().AlwaysRebuild() &&
9395 Cond.get() == E->getCond() &&
9396 LHS.get() == E->getLHS() &&
9397 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009398 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009399
John McCallb268a282010-08-23 23:25:46 +00009400 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009401 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00009402 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00009403 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009404 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009405}
Mike Stump11289f42009-09-09 15:08:12 +00009406
9407template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009408ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009409TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00009410 // Implicit casts are eliminated during transformation, since they
9411 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00009412 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009413}
Mike Stump11289f42009-09-09 15:08:12 +00009414
Douglas Gregora16548e2009-08-11 05:31:07 +00009415template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009416ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009417TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009418 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9419 if (!Type)
9420 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009421
John McCalldadc5752010-08-24 06:29:42 +00009422 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009423 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009424 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009426
Douglas Gregora16548e2009-08-11 05:31:07 +00009427 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009428 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009429 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009430 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009431
John McCall97513962010-01-15 18:39:57 +00009432 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009433 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00009434 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009435 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009436}
Mike Stump11289f42009-09-09 15:08:12 +00009437
Douglas Gregora16548e2009-08-11 05:31:07 +00009438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009440TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00009441 TypeSourceInfo *OldT = E->getTypeSourceInfo();
9442 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
9443 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00009444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009445
John McCalldadc5752010-08-24 06:29:42 +00009446 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00009447 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009449
Douglas Gregora16548e2009-08-11 05:31:07 +00009450 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00009451 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009452 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009453 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009454
John McCall5d7aa7f2010-01-19 22:33:45 +00009455 // Note: the expression type doesn't necessarily match the
9456 // type-as-written, but that's okay, because it should always be
9457 // derivable from the initializer.
9458
John McCalle15bbff2010-01-18 19:35:47 +00009459 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00009460 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00009461 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009462}
Mike Stump11289f42009-09-09 15:08:12 +00009463
Douglas Gregora16548e2009-08-11 05:31:07 +00009464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009466TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009467 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00009468 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009469 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009470
Douglas Gregora16548e2009-08-11 05:31:07 +00009471 if (!getDerived().AlwaysRebuild() &&
9472 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009473 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00009476 SourceLocation FakeOperatorLoc =
9477 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00009478 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00009479 E->getAccessorLoc(),
9480 E->getAccessor());
9481}
Mike Stump11289f42009-09-09 15:08:12 +00009482
Douglas Gregora16548e2009-08-11 05:31:07 +00009483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009484ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009485TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00009486 if (InitListExpr *Syntactic = E->getSyntacticForm())
9487 E = Syntactic;
9488
Douglas Gregora16548e2009-08-11 05:31:07 +00009489 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00009490
Benjamin Kramerf0623432012-08-23 22:51:59 +00009491 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00009492 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00009493 Inits, &InitChanged))
9494 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009495
Richard Smith520449d2015-02-05 06:15:50 +00009496 if (!getDerived().AlwaysRebuild() && !InitChanged) {
9497 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
9498 // in some cases. We can't reuse it in general, because the syntactic and
9499 // semantic forms are linked, and we can't know that semantic form will
9500 // match even if the syntactic form does.
9501 }
Mike Stump11289f42009-09-09 15:08:12 +00009502
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009503 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Richard Smithd1036122018-01-12 22:21:33 +00009504 E->getRBraceLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009505}
Mike Stump11289f42009-09-09 15:08:12 +00009506
Douglas Gregora16548e2009-08-11 05:31:07 +00009507template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009508ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009509TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009510 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00009511
Douglas Gregorebe10102009-08-20 07:17:43 +00009512 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00009513 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00009514 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009515 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009516
Douglas Gregorebe10102009-08-20 07:17:43 +00009517 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009518 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00009519 bool ExprChanged = false;
David Majnemerf7e36092016-06-23 00:15:04 +00009520 for (const DesignatedInitExpr::Designator &D : E->designators()) {
9521 if (D.isFieldDesignator()) {
9522 Desig.AddDesignator(Designator::getField(D.getFieldName(),
9523 D.getDotLoc(),
9524 D.getFieldLoc()));
Alex Lorenzcb642b92016-10-24 09:33:32 +00009525 if (D.getField()) {
9526 FieldDecl *Field = cast_or_null<FieldDecl>(
9527 getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
9528 if (Field != D.getField())
9529 // Rebuild the expression when the transformed FieldDecl is
9530 // different to the already assigned FieldDecl.
9531 ExprChanged = true;
9532 } else {
9533 // Ensure that the designator expression is rebuilt when there isn't
9534 // a resolved FieldDecl in the designator as we don't want to assign
9535 // a FieldDecl to a pattern designator that will be instantiated again.
9536 ExprChanged = true;
9537 }
Douglas Gregora16548e2009-08-11 05:31:07 +00009538 continue;
9539 }
Mike Stump11289f42009-09-09 15:08:12 +00009540
David Majnemerf7e36092016-06-23 00:15:04 +00009541 if (D.isArrayDesignator()) {
9542 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009543 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009544 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009545
David Majnemerf7e36092016-06-23 00:15:04 +00009546 Desig.AddDesignator(
9547 Designator::getArray(Index.get(), D.getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009548
David Majnemerf7e36092016-06-23 00:15:04 +00009549 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009550 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009551 continue;
9552 }
Mike Stump11289f42009-09-09 15:08:12 +00009553
David Majnemerf7e36092016-06-23 00:15:04 +00009554 assert(D.isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00009555 ExprResult Start
David Majnemerf7e36092016-06-23 00:15:04 +00009556 = getDerived().TransformExpr(E->getArrayRangeStart(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009557 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009559
David Majnemerf7e36092016-06-23 00:15:04 +00009560 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
Douglas Gregora16548e2009-08-11 05:31:07 +00009561 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009562 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009563
9564 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009565 End.get(),
David Majnemerf7e36092016-06-23 00:15:04 +00009566 D.getLBracketLoc(),
9567 D.getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00009568
David Majnemerf7e36092016-06-23 00:15:04 +00009569 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
9570 End.get() != E->getArrayRangeEnd(D);
Mike Stump11289f42009-09-09 15:08:12 +00009571
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009572 ArrayExprs.push_back(Start.get());
9573 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009574 }
Mike Stump11289f42009-09-09 15:08:12 +00009575
Douglas Gregora16548e2009-08-11 05:31:07 +00009576 if (!getDerived().AlwaysRebuild() &&
9577 Init.get() == E->getInit() &&
9578 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009579 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009580
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009581 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00009582 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00009583 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009584}
Mike Stump11289f42009-09-09 15:08:12 +00009585
Yunzhong Gaocb779302015-06-10 00:27:52 +00009586// Seems that if TransformInitListExpr() only works on the syntactic form of an
9587// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
9588template<typename Derived>
9589ExprResult
9590TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
9591 DesignatedInitUpdateExpr *E) {
9592 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
9593 "initializer");
9594 return ExprError();
9595}
9596
9597template<typename Derived>
9598ExprResult
9599TreeTransform<Derived>::TransformNoInitExpr(
9600 NoInitExpr *E) {
9601 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
9602 return ExprError();
9603}
9604
Douglas Gregora16548e2009-08-11 05:31:07 +00009605template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009606ExprResult
Richard Smith410306b2016-12-12 02:53:20 +00009607TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
9608 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
9609 return ExprError();
9610}
9611
9612template<typename Derived>
9613ExprResult
9614TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
9615 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
9616 return ExprError();
9617}
9618
9619template<typename Derived>
9620ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009621TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009622 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00009623 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00009624
Douglas Gregor3da3c062009-10-28 00:29:27 +00009625 // FIXME: Will we ever have proper type location here? Will we actually
9626 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00009627 QualType T = getDerived().TransformType(E->getType());
9628 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009629 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009630
Douglas Gregora16548e2009-08-11 05:31:07 +00009631 if (!getDerived().AlwaysRebuild() &&
9632 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009633 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009634
Douglas Gregora16548e2009-08-11 05:31:07 +00009635 return getDerived().RebuildImplicitValueInitExpr(T);
9636}
Mike Stump11289f42009-09-09 15:08:12 +00009637
Douglas Gregora16548e2009-08-11 05:31:07 +00009638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009640TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00009641 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
9642 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009644
John McCalldadc5752010-08-24 06:29:42 +00009645 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009646 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009648
Douglas Gregora16548e2009-08-11 05:31:07 +00009649 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00009650 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009651 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009653
John McCallb268a282010-08-23 23:25:46 +00009654 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00009655 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009656}
9657
9658template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009659ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009660TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009661 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009662 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00009663 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
9664 &ArgumentChanged))
9665 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009666
Douglas Gregora16548e2009-08-11 05:31:07 +00009667 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009668 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00009669 E->getRParenLoc());
9670}
Mike Stump11289f42009-09-09 15:08:12 +00009671
Douglas Gregora16548e2009-08-11 05:31:07 +00009672/// \brief Transform an address-of-label expression.
9673///
9674/// By default, the transformation of an address-of-label expression always
9675/// rebuilds the expression, so that the label identifier can be resolved to
9676/// the corresponding label statement by semantic analysis.
9677template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009678ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009679TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00009680 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
9681 E->getLabel());
9682 if (!LD)
9683 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009684
Douglas Gregora16548e2009-08-11 05:31:07 +00009685 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00009686 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00009687}
Mike Stump11289f42009-09-09 15:08:12 +00009688
9689template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00009690ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009691TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00009692 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00009693 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00009694 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00009695 if (SubStmt.isInvalid()) {
9696 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00009697 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00009698 }
Mike Stump11289f42009-09-09 15:08:12 +00009699
Douglas Gregora16548e2009-08-11 05:31:07 +00009700 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00009701 SubStmt.get() == E->getSubStmt()) {
9702 // Calling this an 'error' is unintuitive, but it does the right thing.
9703 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009704 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00009705 }
Mike Stump11289f42009-09-09 15:08:12 +00009706
9707 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009708 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009709 E->getRParenLoc());
9710}
Mike Stump11289f42009-09-09 15:08:12 +00009711
Douglas Gregora16548e2009-08-11 05:31:07 +00009712template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009714TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00009715 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00009716 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009718
John McCalldadc5752010-08-24 06:29:42 +00009719 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009720 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009722
John McCalldadc5752010-08-24 06:29:42 +00009723 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00009724 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009726
Douglas Gregora16548e2009-08-11 05:31:07 +00009727 if (!getDerived().AlwaysRebuild() &&
9728 Cond.get() == E->getCond() &&
9729 LHS.get() == E->getLHS() &&
9730 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009731 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009732
Douglas Gregora16548e2009-08-11 05:31:07 +00009733 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00009734 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009735 E->getRParenLoc());
9736}
Mike Stump11289f42009-09-09 15:08:12 +00009737
Douglas Gregora16548e2009-08-11 05:31:07 +00009738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009740TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009741 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00009742}
9743
9744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009745ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009746TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009747 switch (E->getOperator()) {
9748 case OO_New:
9749 case OO_Delete:
9750 case OO_Array_New:
9751 case OO_Array_Delete:
9752 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00009753
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009754 case OO_Call: {
9755 // This is a call to an object's operator().
9756 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
9757
9758 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00009759 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009760 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009761 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009762
9763 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00009764 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
9765 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009766
9767 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00009768 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009769 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00009770 Args))
9771 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009772
John McCallb268a282010-08-23 23:25:46 +00009773 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009774 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009775 E->getLocEnd());
9776 }
9777
9778#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
9779 case OO_##Name:
9780#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
9781#include "clang/Basic/OperatorKinds.def"
9782 case OO_Subscript:
9783 // Handled below.
9784 break;
9785
9786 case OO_Conditional:
9787 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009788
9789 case OO_None:
9790 case NUM_OVERLOADED_OPERATORS:
9791 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00009792 }
9793
John McCalldadc5752010-08-24 06:29:42 +00009794 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00009795 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009796 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009797
Richard Smithdb2630f2012-10-21 03:28:35 +00009798 ExprResult First;
9799 if (E->getOperator() == OO_Amp)
9800 First = getDerived().TransformAddressOfOperand(E->getArg(0));
9801 else
9802 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00009803 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009804 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009805
John McCalldadc5752010-08-24 06:29:42 +00009806 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00009807 if (E->getNumArgs() == 2) {
9808 Second = getDerived().TransformExpr(E->getArg(1));
9809 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009810 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009811 }
Mike Stump11289f42009-09-09 15:08:12 +00009812
Douglas Gregora16548e2009-08-11 05:31:07 +00009813 if (!getDerived().AlwaysRebuild() &&
9814 Callee.get() == E->getCallee() &&
9815 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00009816 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009817 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00009818
Lang Hames5de91cc2012-10-02 04:45:10 +00009819 Sema::FPContractStateRAII FPContractState(getSema());
Adam Nemet484aa452017-03-27 19:17:25 +00009820 getSema().FPFeatures = E->getFPFeatures();
Lang Hames5de91cc2012-10-02 04:45:10 +00009821
Douglas Gregora16548e2009-08-11 05:31:07 +00009822 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
9823 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00009824 Callee.get(),
9825 First.get(),
9826 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00009827}
Mike Stump11289f42009-09-09 15:08:12 +00009828
Douglas Gregora16548e2009-08-11 05:31:07 +00009829template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009830ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009831TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
9832 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009833}
Mike Stump11289f42009-09-09 15:08:12 +00009834
Douglas Gregora16548e2009-08-11 05:31:07 +00009835template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009836ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00009837TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
9838 // Transform the callee.
9839 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
9840 if (Callee.isInvalid())
9841 return ExprError();
9842
9843 // Transform exec config.
9844 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
9845 if (EC.isInvalid())
9846 return ExprError();
9847
9848 // Transform arguments.
9849 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009850 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009851 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009852 &ArgChanged))
9853 return ExprError();
9854
9855 if (!getDerived().AlwaysRebuild() &&
9856 Callee.get() == E->getCallee() &&
9857 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00009858 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00009859
9860 // FIXME: Wrong source location information for the '('.
9861 SourceLocation FakeLParenLoc
9862 = ((Expr *)Callee.get())->getSourceRange().getBegin();
9863 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009864 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00009865 E->getRParenLoc(), EC.get());
9866}
9867
9868template<typename Derived>
9869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009870TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009871 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
9872 if (!Type)
9873 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009874
John McCalldadc5752010-08-24 06:29:42 +00009875 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009876 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009877 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009879
Douglas Gregora16548e2009-08-11 05:31:07 +00009880 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009881 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009882 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009883 return E;
Nico Weberc153d242014-07-28 00:02:09 +00009884 return getDerived().RebuildCXXNamedCastExpr(
9885 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
9886 Type, E->getAngleBrackets().getEnd(),
9887 // FIXME. this should be '(' location
9888 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00009889}
Mike Stump11289f42009-09-09 15:08:12 +00009890
Douglas Gregora16548e2009-08-11 05:31:07 +00009891template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009892ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009893TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
9894 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009895}
Mike Stump11289f42009-09-09 15:08:12 +00009896
9897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009899TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
9900 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00009901}
9902
Douglas Gregora16548e2009-08-11 05:31:07 +00009903template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009904ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009905TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009906 CXXReinterpretCastExpr *E) {
9907 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009908}
Mike Stump11289f42009-09-09 15:08:12 +00009909
Douglas Gregora16548e2009-08-11 05:31:07 +00009910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009912TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
9913 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00009914}
Mike Stump11289f42009-09-09 15:08:12 +00009915
Douglas Gregora16548e2009-08-11 05:31:07 +00009916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009917ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009918TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009919 CXXFunctionalCastExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +00009920 TypeSourceInfo *Type =
9921 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009922 if (!Type)
9923 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009924
John McCalldadc5752010-08-24 06:29:42 +00009925 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00009926 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00009927 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009928 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009929
Douglas Gregora16548e2009-08-11 05:31:07 +00009930 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009931 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009932 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009933 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009934
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00009935 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00009936 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00009937 SubExpr.get(),
Vedant Kumara14a1f92018-01-17 18:53:51 +00009938 E->getRParenLoc(),
9939 E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +00009940}
Mike Stump11289f42009-09-09 15:08:12 +00009941
Douglas Gregora16548e2009-08-11 05:31:07 +00009942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009944TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009945 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00009946 TypeSourceInfo *TInfo
9947 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9948 if (!TInfo)
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() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00009952 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009953 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009954
Douglas Gregor9da64192010-04-26 22:37:10 +00009955 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9956 E->getLocStart(),
9957 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00009958 E->getLocEnd());
9959 }
Mike Stump11289f42009-09-09 15:08:12 +00009960
Eli Friedman456f0182012-01-20 01:26:23 +00009961 // We don't know whether the subexpression is potentially evaluated until
9962 // after we perform semantic analysis. We speculatively assume it is
9963 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00009964 // potentially evaluated.
Faisal Valid143a0c2017-04-01 21:30:49 +00009965 EnterExpressionEvaluationContext Unevaluated(
9966 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
9967 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00009968
John McCalldadc5752010-08-24 06:29:42 +00009969 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00009970 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009972
Douglas Gregora16548e2009-08-11 05:31:07 +00009973 if (!getDerived().AlwaysRebuild() &&
9974 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009975 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009976
Douglas Gregor9da64192010-04-26 22:37:10 +00009977 return getDerived().RebuildCXXTypeidExpr(E->getType(),
9978 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00009979 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00009980 E->getLocEnd());
9981}
9982
9983template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009984ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00009985TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
9986 if (E->isTypeOperand()) {
9987 TypeSourceInfo *TInfo
9988 = getDerived().TransformType(E->getTypeOperandSourceInfo());
9989 if (!TInfo)
9990 return ExprError();
9991
9992 if (!getDerived().AlwaysRebuild() &&
9993 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009994 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00009995
Douglas Gregor69735112011-03-06 17:40:41 +00009996 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00009997 E->getLocStart(),
9998 TInfo,
9999 E->getLocEnd());
10000 }
10001
Faisal Valid143a0c2017-04-01 21:30:49 +000010002 EnterExpressionEvaluationContext Unevaluated(
10003 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Francois Pichet9f4f2072010-09-08 12:20:18 +000010004
10005 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
10006 if (SubExpr.isInvalid())
10007 return ExprError();
10008
10009 if (!getDerived().AlwaysRebuild() &&
10010 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010011 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +000010012
10013 return getDerived().RebuildCXXUuidofExpr(E->getType(),
10014 E->getLocStart(),
10015 SubExpr.get(),
10016 E->getLocEnd());
10017}
10018
10019template<typename Derived>
10020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010021TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010022 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010023}
Mike Stump11289f42009-09-09 15:08:12 +000010024
Douglas Gregora16548e2009-08-11 05:31:07 +000010025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010026ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010027TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010028 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010029 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010030}
Mike Stump11289f42009-09-09 15:08:12 +000010031
Douglas Gregora16548e2009-08-11 05:31:07 +000010032template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010033ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010034TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +000010035 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +000010036
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010037 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
10038 // Make sure that we capture 'this'.
10039 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010040 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010041 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010042
Douglas Gregorb15af892010-01-07 23:12:05 +000010043 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +000010044}
Mike Stump11289f42009-09-09 15:08:12 +000010045
Douglas Gregora16548e2009-08-11 05:31:07 +000010046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010048TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010049 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010050 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010052
Douglas Gregora16548e2009-08-11 05:31:07 +000010053 if (!getDerived().AlwaysRebuild() &&
10054 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010055 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010056
Douglas Gregor53e191ed2011-07-06 22:04:06 +000010057 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
10058 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +000010059}
Mike Stump11289f42009-09-09 15:08:12 +000010060
Douglas Gregora16548e2009-08-11 05:31:07 +000010061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010063TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +000010064 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010065 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
10066 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010067 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +000010068 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010069
Chandler Carruth794da4c2010-02-08 06:42:49 +000010070 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010071 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010072 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010073
Douglas Gregor033f6752009-12-23 23:03:06 +000010074 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +000010075}
Mike Stump11289f42009-09-09 15:08:12 +000010076
Douglas Gregora16548e2009-08-11 05:31:07 +000010077template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010078ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +000010079TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
10080 FieldDecl *Field
10081 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
10082 E->getField()));
10083 if (!Field)
10084 return ExprError();
10085
10086 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010087 return E;
Richard Smith852c9db2013-04-20 22:23:05 +000010088
10089 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
10090}
10091
10092template<typename Derived>
10093ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +000010094TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
10095 CXXScalarValueInitExpr *E) {
10096 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
10097 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010098 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010099
Douglas Gregora16548e2009-08-11 05:31:07 +000010100 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010101 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010102 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010103
Chad Rosier1dcde962012-08-08 18:46:20 +000010104 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +000010105 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +000010106 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010107}
Mike Stump11289f42009-09-09 15:08:12 +000010108
Douglas Gregora16548e2009-08-11 05:31:07 +000010109template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010110ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010111TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010112 // Transform the type that we're allocating
Richard Smithee579842017-01-30 20:39:26 +000010113 TypeSourceInfo *AllocTypeInfo =
10114 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
Douglas Gregor0744ef62010-09-07 21:49:58 +000010115 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010116 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010117
Douglas Gregora16548e2009-08-11 05:31:07 +000010118 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +000010119 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +000010120 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010121 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010122
Douglas Gregora16548e2009-08-11 05:31:07 +000010123 // Transform the placement arguments (if any).
10124 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010125 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +000010126 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +000010127 E->getNumPlacementArgs(), true,
10128 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +000010129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010130
Sebastian Redl6047f072012-02-16 12:22:20 +000010131 // Transform the initializer (if any).
10132 Expr *OldInit = E->getInitializer();
10133 ExprResult NewInit;
10134 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +000010135 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +000010136 if (NewInit.isInvalid())
10137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010138
Sebastian Redl6047f072012-02-16 12:22:20 +000010139 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +000010140 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010141 if (E->getOperatorNew()) {
10142 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010143 getDerived().TransformDecl(E->getLocStart(),
10144 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010145 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +000010146 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010147 }
10148
Craig Topperc3ec1492014-05-26 06:22:03 +000010149 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010150 if (E->getOperatorDelete()) {
10151 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010152 getDerived().TransformDecl(E->getLocStart(),
10153 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010154 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010155 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010156 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010157
Douglas Gregora16548e2009-08-11 05:31:07 +000010158 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +000010159 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010160 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +000010161 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010162 OperatorNew == E->getOperatorNew() &&
10163 OperatorDelete == E->getOperatorDelete() &&
10164 !ArgumentChanged) {
10165 // Mark any declarations we need as referenced.
10166 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +000010167 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010168 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +000010169 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010170 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010171
Sebastian Redl6047f072012-02-16 12:22:20 +000010172 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +000010173 QualType ElementType
10174 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
10175 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
10176 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
10177 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +000010178 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +000010179 }
10180 }
10181 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010182
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010183 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010184 }
Mike Stump11289f42009-09-09 15:08:12 +000010185
Douglas Gregor0744ef62010-09-07 21:49:58 +000010186 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010187 if (!ArraySize.get()) {
10188 // If no array size was specified, but the new expression was
10189 // instantiated with an array type (e.g., "new T" where T is
10190 // instantiated with "int[4]"), extract the outer bound from the
10191 // array type as our array size. We do this with constant and
10192 // dependently-sized array types.
10193 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
10194 if (!ArrayT) {
10195 // Do nothing
10196 } else if (const ConstantArrayType *ConsArrayT
10197 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010198 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
10199 SemaRef.Context.getSizeType(),
10200 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010201 AllocType = ConsArrayT->getElementType();
10202 } else if (const DependentSizedArrayType *DepArrayT
10203 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
10204 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010205 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +000010206 AllocType = DepArrayT->getElementType();
10207 }
10208 }
10209 }
Sebastian Redl6047f072012-02-16 12:22:20 +000010210
Douglas Gregora16548e2009-08-11 05:31:07 +000010211 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
10212 E->isGlobalNew(),
10213 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010214 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010215 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +000010216 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +000010217 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +000010218 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +000010219 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +000010220 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +000010221 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010222}
Mike Stump11289f42009-09-09 15:08:12 +000010223
Douglas Gregora16548e2009-08-11 05:31:07 +000010224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010225ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010226TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010227 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +000010228 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010229 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010230
Douglas Gregord2d9da02010-02-26 00:38:10 +000010231 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +000010232 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010233 if (E->getOperatorDelete()) {
10234 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010235 getDerived().TransformDecl(E->getLocStart(),
10236 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +000010237 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +000010238 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +000010239 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010240
Douglas Gregora16548e2009-08-11 05:31:07 +000010241 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +000010242 Operand.get() == E->getArgument() &&
10243 OperatorDelete == E->getOperatorDelete()) {
10244 // Mark any declarations we need as referenced.
10245 // FIXME: instantiation-specific.
10246 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +000010247 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +000010248
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010249 if (!E->getArgument()->isTypeDependent()) {
10250 QualType Destroyed = SemaRef.Context.getBaseElementType(
10251 E->getDestroyedType());
10252 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
10253 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010254 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +000010255 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +000010256 }
10257 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010258
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010259 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +000010260 }
Mike Stump11289f42009-09-09 15:08:12 +000010261
Douglas Gregora16548e2009-08-11 05:31:07 +000010262 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
10263 E->isGlobalDelete(),
10264 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +000010265 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +000010266}
Mike Stump11289f42009-09-09 15:08:12 +000010267
Douglas Gregora16548e2009-08-11 05:31:07 +000010268template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010269ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +000010270TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010271 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +000010272 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +000010273 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010275
John McCallba7bf592010-08-24 05:47:05 +000010276 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +000010277 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000010278 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010279 E->getOperatorLoc(),
10280 E->isArrow()? tok::arrow : tok::period,
10281 ObjectTypePtr,
10282 MayBePseudoDestructor);
10283 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010284 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010285
John McCallba7bf592010-08-24 05:47:05 +000010286 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +000010287 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
10288 if (QualifierLoc) {
10289 QualifierLoc
10290 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
10291 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +000010292 return ExprError();
10293 }
Douglas Gregora6ce6082011-02-25 18:19:59 +000010294 CXXScopeSpec SS;
10295 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +000010296
Douglas Gregor678f90d2010-02-25 01:56:36 +000010297 PseudoDestructorTypeStorage Destroyed;
10298 if (E->getDestroyedTypeInfo()) {
10299 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +000010300 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010301 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +000010302 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010303 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +000010304 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +000010305 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +000010306 // We aren't likely to be able to resolve the identifier down to a type
10307 // now anyway, so just retain the identifier.
10308 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
10309 E->getDestroyedTypeLoc());
10310 } else {
10311 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +000010312 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010313 *E->getDestroyedTypeIdentifier(),
10314 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010315 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +000010316 SS, ObjectTypePtr,
10317 false);
10318 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010319 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010320
Douglas Gregor678f90d2010-02-25 01:56:36 +000010321 Destroyed
10322 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
10323 E->getDestroyedTypeLoc());
10324 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010325
Craig Topperc3ec1492014-05-26 06:22:03 +000010326 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010327 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +000010328 CXXScopeSpec EmptySS;
10329 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +000010330 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010331 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010332 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +000010333 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010334
John McCallb268a282010-08-23 23:25:46 +000010335 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +000010336 E->getOperatorLoc(),
10337 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +000010338 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000010339 ScopeTypeInfo,
10340 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +000010341 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +000010342 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +000010343}
Mike Stump11289f42009-09-09 15:08:12 +000010344
Richard Smith151c4562016-12-20 21:35:28 +000010345template <typename Derived>
10346bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
10347 bool RequiresADL,
10348 LookupResult &R) {
10349 // Transform all the decls.
10350 bool AllEmptyPacks = true;
10351 for (auto *OldD : Old->decls()) {
10352 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
10353 if (!InstD) {
10354 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
10355 // This can happen because of dependent hiding.
10356 if (isa<UsingShadowDecl>(OldD))
10357 continue;
10358 else {
10359 R.clear();
10360 return true;
10361 }
10362 }
10363
10364 // Expand using pack declarations.
10365 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
10366 ArrayRef<NamedDecl*> Decls = SingleDecl;
10367 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
10368 Decls = UPD->expansions();
10369
10370 // Expand using declarations.
10371 for (auto *D : Decls) {
10372 if (auto *UD = dyn_cast<UsingDecl>(D)) {
10373 for (auto *SD : UD->shadows())
10374 R.addDecl(SD);
10375 } else {
10376 R.addDecl(D);
10377 }
10378 }
10379
10380 AllEmptyPacks &= Decls.empty();
10381 };
10382
10383 // C++ [temp.res]/8.4.2:
10384 // The program is ill-formed, no diagnostic required, if [...] lookup for
10385 // a name in the template definition found a using-declaration, but the
10386 // lookup in the corresponding scope in the instantiation odoes not find
10387 // any declarations because the using-declaration was a pack expansion and
10388 // the corresponding pack is empty
10389 if (AllEmptyPacks && !RequiresADL) {
10390 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
10391 << isa<UnresolvedMemberExpr>(Old) << Old->getNameInfo().getName();
10392 return true;
10393 }
10394
10395 // Resolve a kind, but don't do any further analysis. If it's
10396 // ambiguous, the callee needs to deal with it.
10397 R.resolveKind();
10398 return false;
10399}
10400
Douglas Gregorad8a3362009-09-04 17:36:40 +000010401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010402ExprResult
John McCalld14a8642009-11-21 08:51:07 +000010403TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +000010404 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +000010405 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
10406 Sema::LookupOrdinaryName);
10407
Richard Smith151c4562016-12-20 21:35:28 +000010408 // Transform the declaration set.
10409 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
10410 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +000010411
10412 // Rebuild the nested-name qualifier, if present.
10413 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +000010414 if (Old->getQualifierLoc()) {
10415 NestedNameSpecifierLoc QualifierLoc
10416 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
10417 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010418 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010419
Douglas Gregor0da1d432011-02-28 20:01:57 +000010420 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +000010421 }
10422
Douglas Gregor9262f472010-04-27 18:19:34 +000010423 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +000010424 CXXRecordDecl *NamingClass
10425 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
10426 Old->getNameLoc(),
10427 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +000010428 if (!NamingClass) {
10429 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +000010430 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010431 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010432
Douglas Gregorda7be082010-04-27 16:10:10 +000010433 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +000010434 }
10435
Abramo Bagnara7945c982012-01-27 09:46:47 +000010436 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
10437
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010438 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +000010439 // it's a normal declaration name or member reference.
10440 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
10441 NamedDecl *D = R.getAsSingle<NamedDecl>();
10442 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
10443 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
10444 // give a good diagnostic.
10445 if (D && D->isCXXInstanceMember()) {
10446 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
10447 /*TemplateArgs=*/nullptr,
10448 /*Scope=*/nullptr);
10449 }
10450
John McCalle66edc12009-11-24 19:00:30 +000010451 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +000010452 }
John McCalle66edc12009-11-24 19:00:30 +000010453
10454 // If we have template arguments, rebuild them, then rebuild the
10455 // templateid expression.
10456 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +000010457 if (Old->hasExplicitTemplateArgs() &&
10458 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +000010459 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +000010460 TransArgs)) {
10461 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +000010462 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +000010463 }
John McCalle66edc12009-11-24 19:00:30 +000010464
Abramo Bagnara7945c982012-01-27 09:46:47 +000010465 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +000010466 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +000010467}
Mike Stump11289f42009-09-09 15:08:12 +000010468
Douglas Gregora16548e2009-08-11 05:31:07 +000010469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010470ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +000010471TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
10472 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010473 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010474 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
10475 TypeSourceInfo *From = E->getArg(I);
10476 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +000010477 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +000010478 TypeLocBuilder TLB;
10479 TLB.reserve(FromTL.getFullDataSize());
10480 QualType To = getDerived().TransformType(TLB, FromTL);
10481 if (To.isNull())
10482 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010483
Douglas Gregor29c42f22012-02-24 07:38:34 +000010484 if (To == From->getType())
10485 Args.push_back(From);
10486 else {
10487 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10488 ArgChanged = true;
10489 }
10490 continue;
10491 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010492
Douglas Gregor29c42f22012-02-24 07:38:34 +000010493 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010494
Douglas Gregor29c42f22012-02-24 07:38:34 +000010495 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +000010496 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +000010497 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
10498 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10499 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +000010500
Douglas Gregor29c42f22012-02-24 07:38:34 +000010501 // Determine whether the set of unexpanded parameter packs can and should
10502 // be expanded.
10503 bool Expand = true;
10504 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010505 Optional<unsigned> OrigNumExpansions =
10506 ExpansionTL.getTypePtr()->getNumExpansions();
10507 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010508 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
10509 PatternTL.getSourceRange(),
10510 Unexpanded,
10511 Expand, RetainExpansion,
10512 NumExpansions))
10513 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010514
Douglas Gregor29c42f22012-02-24 07:38:34 +000010515 if (!Expand) {
10516 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010517 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +000010518 // expansion.
10519 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +000010520
Douglas Gregor29c42f22012-02-24 07:38:34 +000010521 TypeLocBuilder TLB;
10522 TLB.reserve(From->getTypeLoc().getFullDataSize());
10523
10524 QualType To = getDerived().TransformType(TLB, PatternTL);
10525 if (To.isNull())
10526 return ExprError();
10527
Chad Rosier1dcde962012-08-08 18:46:20 +000010528 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010529 PatternTL.getSourceRange(),
10530 ExpansionTL.getEllipsisLoc(),
10531 NumExpansions);
10532 if (To.isNull())
10533 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010534
Douglas Gregor29c42f22012-02-24 07:38:34 +000010535 PackExpansionTypeLoc ToExpansionTL
10536 = TLB.push<PackExpansionTypeLoc>(To);
10537 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10538 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10539 continue;
10540 }
10541
10542 // Expand the pack expansion by substituting for each argument in the
10543 // pack(s).
10544 for (unsigned I = 0; I != *NumExpansions; ++I) {
10545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
10546 TypeLocBuilder TLB;
10547 TLB.reserve(PatternTL.getFullDataSize());
10548 QualType To = getDerived().TransformType(TLB, PatternTL);
10549 if (To.isNull())
10550 return ExprError();
10551
Eli Friedman5e05c4a2013-07-19 21:49:32 +000010552 if (To->containsUnexpandedParameterPack()) {
10553 To = getDerived().RebuildPackExpansionType(To,
10554 PatternTL.getSourceRange(),
10555 ExpansionTL.getEllipsisLoc(),
10556 NumExpansions);
10557 if (To.isNull())
10558 return ExprError();
10559
10560 PackExpansionTypeLoc ToExpansionTL
10561 = TLB.push<PackExpansionTypeLoc>(To);
10562 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10563 }
10564
Douglas Gregor29c42f22012-02-24 07:38:34 +000010565 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10566 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010567
Douglas Gregor29c42f22012-02-24 07:38:34 +000010568 if (!RetainExpansion)
10569 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000010570
Douglas Gregor29c42f22012-02-24 07:38:34 +000010571 // If we're supposed to retain a pack expansion, do so by temporarily
10572 // forgetting the partially-substituted parameter pack.
10573 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10574
10575 TypeLocBuilder TLB;
10576 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +000010577
Douglas Gregor29c42f22012-02-24 07:38:34 +000010578 QualType To = getDerived().TransformType(TLB, PatternTL);
10579 if (To.isNull())
10580 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010581
10582 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +000010583 PatternTL.getSourceRange(),
10584 ExpansionTL.getEllipsisLoc(),
10585 NumExpansions);
10586 if (To.isNull())
10587 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010588
Douglas Gregor29c42f22012-02-24 07:38:34 +000010589 PackExpansionTypeLoc ToExpansionTL
10590 = TLB.push<PackExpansionTypeLoc>(To);
10591 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
10592 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
10593 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010594
Douglas Gregor29c42f22012-02-24 07:38:34 +000010595 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010596 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +000010597
10598 return getDerived().RebuildTypeTrait(E->getTrait(),
10599 E->getLocStart(),
10600 Args,
10601 E->getLocEnd());
10602}
10603
10604template<typename Derived>
10605ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +000010606TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
10607 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
10608 if (!T)
10609 return ExprError();
10610
10611 if (!getDerived().AlwaysRebuild() &&
10612 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010613 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010614
10615 ExprResult SubExpr;
10616 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010617 EnterExpressionEvaluationContext Unevaluated(
10618 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegley6242b6a2011-04-28 00:16:57 +000010619 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
10620 if (SubExpr.isInvalid())
10621 return ExprError();
10622
10623 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010624 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +000010625 }
10626
10627 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
10628 E->getLocStart(),
10629 T,
10630 SubExpr.get(),
10631 E->getLocEnd());
10632}
10633
10634template<typename Derived>
10635ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +000010636TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
10637 ExprResult SubExpr;
10638 {
Faisal Valid143a0c2017-04-01 21:30:49 +000010639 EnterExpressionEvaluationContext Unevaluated(
10640 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
John Wiegleyf9f65842011-04-25 06:54:41 +000010641 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
10642 if (SubExpr.isInvalid())
10643 return ExprError();
10644
10645 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010646 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +000010647 }
10648
10649 return getDerived().RebuildExpressionTrait(
10650 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
10651}
10652
Reid Kleckner32506ed2014-06-12 23:03:48 +000010653template <typename Derived>
10654ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
10655 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
10656 TypeSourceInfo **RecoveryTSI) {
10657 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
10658 DRE, AddrTaken, RecoveryTSI);
10659
10660 // Propagate both errors and recovered types, which return ExprEmpty.
10661 if (!NewDRE.isUsable())
10662 return NewDRE;
10663
10664 // We got an expr, wrap it up in parens.
10665 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
10666 return PE;
10667 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
10668 PE->getRParen());
10669}
10670
10671template <typename Derived>
10672ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10673 DependentScopeDeclRefExpr *E) {
10674 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
10675 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +000010676}
10677
10678template<typename Derived>
10679ExprResult
10680TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
10681 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +000010682 bool IsAddressOfOperand,
10683 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +000010684 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010685 NestedNameSpecifierLoc QualifierLoc
10686 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
10687 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000010688 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +000010689 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +000010690
John McCall31f82722010-11-12 08:19:04 +000010691 // TODO: If this is a conversion-function-id, verify that the
10692 // destination type name (if present) resolves the same way after
10693 // instantiation as it did in the local scope.
10694
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010695 DeclarationNameInfo NameInfo
10696 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
10697 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000010698 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010699
John McCalle66edc12009-11-24 19:00:30 +000010700 if (!E->hasExplicitTemplateArgs()) {
10701 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +000010702 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000010703 // Note: it is sufficient to compare the Name component of NameInfo:
10704 // if name has not changed, DNLoc has not changed either.
10705 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010706 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010707
Reid Kleckner32506ed2014-06-12 23:03:48 +000010708 return getDerived().RebuildDependentScopeDeclRefExpr(
10709 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
10710 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +000010711 }
John McCall6b51f282009-11-23 01:53:49 +000010712
10713 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000010714 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
10715 E->getNumTemplateArgs(),
10716 TransArgs))
10717 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010718
Reid Kleckner32506ed2014-06-12 23:03:48 +000010719 return getDerived().RebuildDependentScopeDeclRefExpr(
10720 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
10721 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +000010722}
10723
10724template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010725ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010726TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +000010727 // CXXConstructExprs other than for list-initialization and
10728 // CXXTemporaryObjectExpr are always implicit, so when we have
10729 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +000010730 if ((E->getNumArgs() == 1 ||
10731 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +000010732 (!getDerived().DropCallArgument(E->getArg(0))) &&
10733 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +000010734 return getDerived().TransformExpr(E->getArg(0));
10735
Douglas Gregora16548e2009-08-11 05:31:07 +000010736 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
10737
10738 QualType T = getDerived().TransformType(E->getType());
10739 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +000010740 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +000010741
10742 CXXConstructorDecl *Constructor
10743 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010744 getDerived().TransformDecl(E->getLocStart(),
10745 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010746 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010748
Douglas Gregora16548e2009-08-11 05:31:07 +000010749 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010750 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +000010751 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010752 &ArgumentChanged))
10753 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010754
Douglas Gregora16548e2009-08-11 05:31:07 +000010755 if (!getDerived().AlwaysRebuild() &&
10756 T == E->getType() &&
10757 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +000010758 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +000010759 // Mark the constructor as referenced.
10760 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010761 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010762 return E;
Douglas Gregorde550352010-02-26 00:01:57 +000010763 }
Mike Stump11289f42009-09-09 15:08:12 +000010764
Douglas Gregordb121ba2009-12-14 16:27:04 +000010765 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
Richard Smithc83bf822016-06-10 00:58:19 +000010766 Constructor,
Richard Smithc2bebe92016-05-11 20:37:46 +000010767 E->isElidable(), Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +000010768 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +000010769 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +000010770 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +000010771 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +000010772 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +000010773 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +000010774}
Mike Stump11289f42009-09-09 15:08:12 +000010775
Richard Smith5179eb72016-06-28 19:03:57 +000010776template<typename Derived>
10777ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
10778 CXXInheritedCtorInitExpr *E) {
10779 QualType T = getDerived().TransformType(E->getType());
10780 if (T.isNull())
10781 return ExprError();
10782
10783 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
10784 getDerived().TransformDecl(E->getLocStart(), E->getConstructor()));
10785 if (!Constructor)
10786 return ExprError();
10787
10788 if (!getDerived().AlwaysRebuild() &&
10789 T == E->getType() &&
10790 Constructor == E->getConstructor()) {
10791 // Mark the constructor as referenced.
10792 // FIXME: Instantiation-specific
10793 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
10794 return E;
10795 }
10796
10797 return getDerived().RebuildCXXInheritedCtorInitExpr(
10798 T, E->getLocation(), Constructor,
10799 E->constructsVBase(), E->inheritedFromVBase());
10800}
10801
Douglas Gregora16548e2009-08-11 05:31:07 +000010802/// \brief Transform a C++ temporary-binding expression.
10803///
Douglas Gregor363b1512009-12-24 18:51:59 +000010804/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
10805/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010808TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010809 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010810}
Mike Stump11289f42009-09-09 15:08:12 +000010811
John McCall5d413782010-12-06 08:20:24 +000010812/// \brief Transform a C++ expression that contains cleanups that should
10813/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +000010814///
John McCall5d413782010-12-06 08:20:24 +000010815/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +000010816/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +000010817template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010818ExprResult
John McCall5d413782010-12-06 08:20:24 +000010819TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +000010820 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +000010821}
Mike Stump11289f42009-09-09 15:08:12 +000010822
Douglas Gregora16548e2009-08-11 05:31:07 +000010823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010824ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000010825TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +000010826 CXXTemporaryObjectExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000010827 TypeSourceInfo *T =
10828 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000010829 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000010830 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010831
Douglas Gregora16548e2009-08-11 05:31:07 +000010832 CXXConstructorDecl *Constructor
10833 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +000010834 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +000010835 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +000010836 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +000010837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010838
Douglas Gregora16548e2009-08-11 05:31:07 +000010839 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010840 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +000010841 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010842 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010843 &ArgumentChanged))
10844 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010845
Douglas Gregora16548e2009-08-11 05:31:07 +000010846 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000010847 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000010848 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010849 !ArgumentChanged) {
10850 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +000010851 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +000010852 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +000010853 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010854
Vedant Kumara14a1f92018-01-17 18:53:51 +000010855 // FIXME: We should just pass E->isListInitialization(), but we're not
10856 // prepared to handle list-initialization without a child InitListExpr.
10857 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
10858 return getDerived().RebuildCXXTemporaryObjectExpr(
10859 T, LParenLoc, Args, E->getLocEnd(),
10860 /*ListInitialization=*/LParenLoc.isInvalid());
Douglas Gregora16548e2009-08-11 05:31:07 +000010861}
Mike Stump11289f42009-09-09 15:08:12 +000010862
Douglas Gregora16548e2009-08-11 05:31:07 +000010863template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010864ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +000010865TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +000010866 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010867 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +000010868 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010869 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
10870 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +000010871 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010872 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +000010873 CEnd = E->capture_end();
10874 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +000010875 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010876 continue;
Faisal Valid143a0c2017-04-01 21:30:49 +000010877 EnterExpressionEvaluationContext EEEC(
10878 getSema(), Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010879 ExprResult NewExprInitResult = getDerived().TransformInitializer(
10880 C->getCapturedVar()->getInit(),
10881 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +000010882
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010883 if (NewExprInitResult.isInvalid())
10884 return ExprError();
10885 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +000010886
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010887 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +000010888 QualType NewInitCaptureType =
Richard Smith42b10572015-11-11 01:36:17 +000010889 getSema().buildLambdaInitCaptureInitialization(
10890 C->getLocation(), OldVD->getType()->isReferenceType(),
10891 OldVD->getIdentifier(),
10892 C->getCapturedVar()->getInitStyle() != VarDecl::CInit, NewExprInit);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010893 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010894 InitCaptureExprsAndTypes[C - E->capture_begin()] =
10895 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000010896 }
10897
Faisal Vali2cba1332013-10-23 06:44:28 +000010898 // Transform the template parameters, and add them to the current
10899 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +000010900 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +000010901 E->getTemplateParameterList());
10902
Richard Smith01014ce2014-11-20 23:53:14 +000010903 // Transform the type of the original lambda's call operator.
10904 // The transformation MUST be done in the CurrentInstantiationScope since
10905 // it introduces a mapping of the original to the newly created
10906 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +000010907 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +000010908 {
10909 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
10910 FunctionProtoTypeLoc OldCallOpFPTL =
10911 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +000010912
10913 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +000010914 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +000010915 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +000010916 QualType NewCallOpType = TransformFunctionProtoType(
10917 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +000010918 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
10919 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
10920 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +000010921 });
Reid Kleckneraac43c62014-12-15 21:07:16 +000010922 if (NewCallOpType.isNull())
10923 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +000010924 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
10925 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +000010926 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010927
Richard Smithc38498f2015-04-27 21:27:54 +000010928 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
10929 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
10930 LSI->GLTemplateParameterList = TPL;
10931
Eli Friedmand564afb2012-09-19 01:18:11 +000010932 // Create the local class that will describe the lambda.
10933 CXXRecordDecl *Class
10934 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +000010935 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +000010936 /*KnownDependent=*/false,
10937 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +000010938 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
10939
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010940 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +000010941 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
10942 Class, E->getIntroducerRange(), NewCallOpTSI,
10943 E->getCallOperator()->getLocEnd(),
Faisal Valia734ab92016-03-26 16:11:37 +000010944 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
10945 E->getCallOperator()->isConstexpr());
10946
Faisal Vali2cba1332013-10-23 06:44:28 +000010947 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +000010948
Akira Hatanaka402818462016-12-16 21:16:57 +000010949 for (unsigned I = 0, NumParams = NewCallOperator->getNumParams();
10950 I != NumParams; ++I) {
10951 auto *P = NewCallOperator->getParamDecl(I);
10952 if (P->hasUninstantiatedDefaultArg()) {
10953 EnterExpressionEvaluationContext Eval(
Faisal Valid143a0c2017-04-01 21:30:49 +000010954 getSema(),
10955 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, P);
Akira Hatanaka402818462016-12-16 21:16:57 +000010956 ExprResult R = getDerived().TransformExpr(
10957 E->getCallOperator()->getParamDecl(I)->getDefaultArg());
10958 P->setDefaultArg(R.get());
10959 }
10960 }
10961
Faisal Vali2cba1332013-10-23 06:44:28 +000010962 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +000010963 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +000010964
Douglas Gregorb4328232012-02-14 00:00:48 +000010965 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +000010966 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +000010967 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +000010968
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010969 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +000010970 getSema().buildLambdaScope(LSI, NewCallOperator,
10971 E->getIntroducerRange(),
10972 E->getCaptureDefault(),
10973 E->getCaptureDefaultLoc(),
10974 E->hasExplicitParameters(),
10975 E->hasExplicitResultType(),
10976 E->isMutable());
10977
10978 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010979
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010980 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010981 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010982 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010983 CEnd = E->capture_end();
10984 C != CEnd; ++C) {
10985 // When we hit the first implicit capture, tell Sema that we've finished
10986 // the list of explicit captures.
10987 if (!FinishedExplicitCaptures && C->isImplicit()) {
10988 getSema().finishLambdaExplicitCaptures(LSI);
10989 FinishedExplicitCaptures = true;
10990 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010991
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010992 // Capturing 'this' is trivial.
10993 if (C->capturesThis()) {
Faisal Validc6b5962016-03-21 09:25:37 +000010994 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
10995 /*BuildAndDiagnose*/ true, nullptr,
10996 C->getCaptureKind() == LCK_StarThis);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000010997 continue;
10998 }
Alexey Bataev39c81e22014-08-28 04:28:19 +000010999 // Captured expression will be recaptured during captured variables
11000 // rebuilding.
11001 if (C->capturesVLAType())
11002 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +000011003
Richard Smithba71c082013-05-16 06:20:58 +000011004 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +000011005 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011006 InitCaptureInfoTy InitExprTypePair =
11007 InitCaptureExprsAndTypes[C - E->capture_begin()];
11008 ExprResult Init = InitExprTypePair.first;
11009 QualType InitQualType = InitExprTypePair.second;
11010 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +000011011 Invalid = true;
11012 continue;
11013 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011014 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011015 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
Richard Smith42b10572015-11-11 01:36:17 +000011016 OldVD->getLocation(), InitExprTypePair.second, OldVD->getIdentifier(),
11017 OldVD->getInitStyle(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +000011018 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +000011019 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011020 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +000011021 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +000011022 }
Richard Smithbb13c9a2013-09-28 04:02:39 +000011023 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +000011024 continue;
11025 }
11026
11027 assert(C->capturesVariable() && "unexpected kind of lambda capture");
11028
Douglas Gregor3e308b12012-02-14 19:27:52 +000011029 // Determine the capture kind for Sema.
11030 Sema::TryCaptureKind Kind
11031 = C->isImplicit()? Sema::TryCapture_Implicit
11032 : C->getCaptureKind() == LCK_ByCopy
11033 ? Sema::TryCapture_ExplicitByVal
11034 : Sema::TryCapture_ExplicitByRef;
11035 SourceLocation EllipsisLoc;
11036 if (C->isPackExpansion()) {
11037 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
11038 bool ShouldExpand = false;
11039 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011040 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000011041 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
11042 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011043 Unexpanded,
11044 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +000011045 NumExpansions)) {
11046 Invalid = true;
11047 continue;
11048 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011049
Douglas Gregor3e308b12012-02-14 19:27:52 +000011050 if (ShouldExpand) {
11051 // The transform has determined that we should perform an expansion;
11052 // transform and capture each of the arguments.
11053 // expansion of the pattern. Do so.
11054 VarDecl *Pack = C->getCapturedVar();
11055 for (unsigned I = 0; I != *NumExpansions; ++I) {
11056 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11057 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011058 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +000011059 Pack));
11060 if (!CapturedVar) {
11061 Invalid = true;
11062 continue;
11063 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011064
Douglas Gregor3e308b12012-02-14 19:27:52 +000011065 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +000011066 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
11067 }
Richard Smith9467be42014-06-06 17:33:35 +000011068
11069 // FIXME: Retain a pack expansion if RetainExpansion is true.
11070
Douglas Gregor3e308b12012-02-14 19:27:52 +000011071 continue;
11072 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011073
Douglas Gregor3e308b12012-02-14 19:27:52 +000011074 EllipsisLoc = C->getEllipsisLoc();
11075 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011076
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011077 // Transform the captured variable.
11078 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +000011079 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011080 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +000011081 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011082 Invalid = true;
11083 continue;
11084 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011085
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011086 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +000011087 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
11088 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011089 }
11090 if (!FinishedExplicitCaptures)
11091 getSema().finishLambdaExplicitCaptures(LSI);
11092
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011093 // Enter a new evaluation context to insulate the lambda from any
11094 // cleanups from the enclosing full-expression.
Faisal Valid143a0c2017-04-01 21:30:49 +000011095 getSema().PushExpressionEvaluationContext(
11096 Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011097
Douglas Gregor0c46b2b2012-02-13 22:00:16 +000011098 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +000011099 StmtResult Body =
11100 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
11101
11102 // ActOnLambda* will pop the function scope for us.
11103 FuncScopeCleanup.disable();
11104
Douglas Gregorb4328232012-02-14 00:00:48 +000011105 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +000011106 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +000011107 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +000011108 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +000011109 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +000011110 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +000011111
Richard Smithc38498f2015-04-27 21:27:54 +000011112 // Copy the LSI before ActOnFinishFunctionBody removes it.
11113 // FIXME: This is dumb. Store the lambda information somewhere that outlives
11114 // the call operator.
11115 auto LSICopy = *LSI;
11116 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
11117 /*IsInstantiation*/ true);
11118 SavedContext.pop();
11119
11120 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
11121 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +000011122}
11123
11124template<typename Derived>
11125ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011126TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +000011127 CXXUnresolvedConstructExpr *E) {
Richard Smithee579842017-01-30 20:39:26 +000011128 TypeSourceInfo *T =
11129 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
Douglas Gregor2b88c112010-09-08 00:15:04 +000011130 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +000011131 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011132
Douglas Gregora16548e2009-08-11 05:31:07 +000011133 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011134 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011135 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +000011136 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011137 &ArgumentChanged))
11138 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011139
Douglas Gregora16548e2009-08-11 05:31:07 +000011140 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +000011141 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +000011142 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011143 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011144
Douglas Gregora16548e2009-08-11 05:31:07 +000011145 // FIXME: we're faking the locations of the commas
Vedant Kumara14a1f92018-01-17 18:53:51 +000011146 return getDerived().RebuildCXXUnresolvedConstructExpr(
11147 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
Douglas Gregora16548e2009-08-11 05:31:07 +000011148}
Mike Stump11289f42009-09-09 15:08:12 +000011149
Douglas Gregora16548e2009-08-11 05:31:07 +000011150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011151ExprResult
John McCall8cd78132009-11-19 22:55:06 +000011152TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011153 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011154 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011155 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011156 Expr *OldBase;
11157 QualType BaseType;
11158 QualType ObjectType;
11159 if (!E->isImplicitAccess()) {
11160 OldBase = E->getBase();
11161 Base = getDerived().TransformExpr(OldBase);
11162 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011164
John McCall2d74de92009-12-01 22:10:20 +000011165 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +000011166 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +000011167 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +000011168 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011169 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011170 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +000011171 ObjectTy,
11172 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +000011173 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011174 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +000011175
John McCallba7bf592010-08-24 05:47:05 +000011176 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +000011177 BaseType = ((Expr*) Base.get())->getType();
11178 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +000011179 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +000011180 BaseType = getDerived().TransformType(E->getBaseType());
11181 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
11182 }
Mike Stump11289f42009-09-09 15:08:12 +000011183
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011184 // Transform the first part of the nested-name-specifier that qualifies
11185 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +000011186 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +000011187 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +000011188 E->getFirstQualifierFoundInScope(),
11189 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +000011190
Douglas Gregore16af532011-02-28 18:50:33 +000011191 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011192 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +000011193 QualifierLoc
11194 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
11195 ObjectType,
11196 FirstQualifierInScope);
11197 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011198 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +000011199 }
Mike Stump11289f42009-09-09 15:08:12 +000011200
Abramo Bagnara7945c982012-01-27 09:46:47 +000011201 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11202
John McCall31f82722010-11-12 08:19:04 +000011203 // TODO: If this is a conversion-function-id, verify that the
11204 // destination type name (if present) resolves the same way after
11205 // instantiation as it did in the local scope.
11206
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011207 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +000011208 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011209 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +000011210 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011211
John McCall2d74de92009-12-01 22:10:20 +000011212 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +000011213 // This is a reference to a member without an explicitly-specified
11214 // template argument list. Optimize for this common case.
11215 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +000011216 Base.get() == OldBase &&
11217 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +000011218 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011219 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +000011220 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011221 return E;
Mike Stump11289f42009-09-09 15:08:12 +000011222
John McCallb268a282010-08-23 23:25:46 +000011223 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011224 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +000011225 E->isArrow(),
11226 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011227 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011228 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +000011229 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011230 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011231 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +000011232 }
11233
John McCall6b51f282009-11-23 01:53:49 +000011234 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011235 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11236 E->getNumTemplateArgs(),
11237 TransArgs))
11238 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011239
John McCallb268a282010-08-23 23:25:46 +000011240 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011241 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +000011242 E->isArrow(),
11243 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +000011244 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011245 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +000011246 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011247 NameInfo,
John McCall10eae182009-11-30 22:42:35 +000011248 &TransArgs);
11249}
11250
11251template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011252ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011253TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +000011254 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +000011255 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +000011256 QualType BaseType;
11257 if (!Old->isImplicitAccess()) {
11258 Base = getDerived().TransformExpr(Old->getBase());
11259 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011260 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011261 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +000011262 Old->isArrow());
11263 if (Base.isInvalid())
11264 return ExprError();
11265 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +000011266 } else {
11267 BaseType = getDerived().TransformType(Old->getBaseType());
11268 }
John McCall10eae182009-11-30 22:42:35 +000011269
Douglas Gregor0da1d432011-02-28 20:01:57 +000011270 NestedNameSpecifierLoc QualifierLoc;
11271 if (Old->getQualifierLoc()) {
11272 QualifierLoc
11273 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
11274 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +000011275 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011276 }
11277
Abramo Bagnara7945c982012-01-27 09:46:47 +000011278 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
11279
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011280 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +000011281 Sema::LookupOrdinaryName);
11282
Richard Smith151c4562016-12-20 21:35:28 +000011283 // Transform the declaration set.
11284 if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R))
11285 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011286
Douglas Gregor9262f472010-04-27 18:19:34 +000011287 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +000011288 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011289 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +000011290 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +000011291 Old->getMemberLoc(),
11292 Old->getNamingClass()));
11293 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +000011294 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011295
Douglas Gregorda7be082010-04-27 16:10:10 +000011296 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +000011297 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011298
John McCall10eae182009-11-30 22:42:35 +000011299 TemplateArgumentListInfo TransArgs;
11300 if (Old->hasExplicitTemplateArgs()) {
11301 TransArgs.setLAngleLoc(Old->getLAngleLoc());
11302 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +000011303 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
11304 Old->getNumTemplateArgs(),
11305 TransArgs))
11306 return ExprError();
John McCall10eae182009-11-30 22:42:35 +000011307 }
John McCall38836f02010-01-15 08:34:02 +000011308
11309 // FIXME: to do this check properly, we will need to preserve the
11310 // first-qualifier-in-scope here, just in case we had a dependent
11311 // base (and therefore couldn't do the check) and a
11312 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +000011313 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +000011314
John McCallb268a282010-08-23 23:25:46 +000011315 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +000011316 BaseType,
John McCall10eae182009-11-30 22:42:35 +000011317 Old->getOperatorLoc(),
11318 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +000011319 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011320 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +000011321 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +000011322 R,
11323 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +000011324 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +000011325}
11326
11327template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011328ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011329TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Faisal Valid143a0c2017-04-01 21:30:49 +000011330 EnterExpressionEvaluationContext Unevaluated(
11331 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011332 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
11333 if (SubExpr.isInvalid())
11334 return ExprError();
11335
11336 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011337 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000011338
11339 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
11340}
11341
11342template<typename Derived>
11343ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011344TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011345 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
11346 if (Pattern.isInvalid())
11347 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011348
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011349 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011350 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000011351
Douglas Gregorb8840002011-01-14 21:20:45 +000011352 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
11353 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011354}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011355
11356template<typename Derived>
11357ExprResult
11358TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
11359 // If E is not value-dependent, then nothing will change when we transform it.
11360 // Note: This is an instantiation-centric view.
11361 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011362 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011363
Faisal Valid143a0c2017-04-01 21:30:49 +000011364 EnterExpressionEvaluationContext Unevaluated(
11365 getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000011366
Richard Smithd784e682015-09-23 21:41:42 +000011367 ArrayRef<TemplateArgument> PackArgs;
11368 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000011369
Richard Smithd784e682015-09-23 21:41:42 +000011370 // Find the argument list to transform.
11371 if (E->isPartiallySubstituted()) {
11372 PackArgs = E->getPartialArguments();
11373 } else if (E->isValueDependent()) {
11374 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
11375 bool ShouldExpand = false;
11376 bool RetainExpansion = false;
11377 Optional<unsigned> NumExpansions;
11378 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
11379 Unexpanded,
11380 ShouldExpand, RetainExpansion,
11381 NumExpansions))
11382 return ExprError();
11383
11384 // If we need to expand the pack, build a template argument from it and
11385 // expand that.
11386 if (ShouldExpand) {
11387 auto *Pack = E->getPack();
11388 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
11389 ArgStorage = getSema().Context.getPackExpansionType(
11390 getSema().Context.getTypeDeclType(TTPD), None);
11391 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
11392 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
11393 } else {
11394 auto *VD = cast<ValueDecl>(Pack);
11395 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
11396 VK_RValue, E->getPackLoc());
11397 if (DRE.isInvalid())
11398 return ExprError();
11399 ArgStorage = new (getSema().Context) PackExpansionExpr(
11400 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
11401 }
11402 PackArgs = ArgStorage;
11403 }
11404 }
11405
11406 // If we're not expanding the pack, just transform the decl.
11407 if (!PackArgs.size()) {
11408 auto *Pack = cast_or_null<NamedDecl>(
11409 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011410 if (!Pack)
11411 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000011412 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
11413 E->getPackLoc(),
11414 E->getRParenLoc(), None, None);
11415 }
11416
Richard Smithc5452ed2016-10-19 22:18:42 +000011417 // Try to compute the result without performing a partial substitution.
11418 Optional<unsigned> Result = 0;
11419 for (const TemplateArgument &Arg : PackArgs) {
11420 if (!Arg.isPackExpansion()) {
11421 Result = *Result + 1;
11422 continue;
11423 }
11424
11425 TemplateArgumentLoc ArgLoc;
11426 InventTemplateArgumentLoc(Arg, ArgLoc);
11427
11428 // Find the pattern of the pack expansion.
11429 SourceLocation Ellipsis;
11430 Optional<unsigned> OrigNumExpansions;
11431 TemplateArgumentLoc Pattern =
11432 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
11433 OrigNumExpansions);
11434
11435 // Substitute under the pack expansion. Do not expand the pack (yet).
11436 TemplateArgumentLoc OutPattern;
11437 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11438 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
11439 /*Uneval*/ true))
11440 return true;
11441
11442 // See if we can determine the number of arguments from the result.
11443 Optional<unsigned> NumExpansions =
11444 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
11445 if (!NumExpansions) {
11446 // No: we must be in an alias template expansion, and we're going to need
11447 // to actually expand the packs.
11448 Result = None;
11449 break;
11450 }
11451
11452 Result = *Result + *NumExpansions;
11453 }
11454
11455 // Common case: we could determine the number of expansions without
11456 // substituting.
11457 if (Result)
11458 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11459 E->getPackLoc(),
11460 E->getRParenLoc(), *Result, None);
11461
Richard Smithd784e682015-09-23 21:41:42 +000011462 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
11463 E->getPackLoc());
11464 {
11465 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
11466 typedef TemplateArgumentLocInventIterator<
11467 Derived, const TemplateArgument*> PackLocIterator;
11468 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
11469 PackLocIterator(*this, PackArgs.end()),
11470 TransformedPackArgs, /*Uneval*/true))
11471 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000011472 }
11473
Richard Smithc5452ed2016-10-19 22:18:42 +000011474 // Check whether we managed to fully-expand the pack.
11475 // FIXME: Is it possible for us to do so and not hit the early exit path?
Richard Smithd784e682015-09-23 21:41:42 +000011476 SmallVector<TemplateArgument, 8> Args;
11477 bool PartialSubstitution = false;
11478 for (auto &Loc : TransformedPackArgs.arguments()) {
11479 Args.push_back(Loc.getArgument());
11480 if (Loc.getArgument().isPackExpansion())
11481 PartialSubstitution = true;
11482 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011483
Richard Smithd784e682015-09-23 21:41:42 +000011484 if (PartialSubstitution)
11485 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
11486 E->getPackLoc(),
11487 E->getRParenLoc(), None, Args);
11488
11489 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011490 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000011491 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000011492}
11493
Douglas Gregore8e9dd62011-01-03 17:17:50 +000011494template<typename Derived>
11495ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011496TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
11497 SubstNonTypeTemplateParmPackExpr *E) {
11498 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011499 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000011500}
11501
11502template<typename Derived>
11503ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000011504TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
11505 SubstNonTypeTemplateParmExpr *E) {
11506 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011507 return E;
John McCall7c454bb2011-07-15 05:09:51 +000011508}
11509
11510template<typename Derived>
11511ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000011512TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
11513 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011514 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000011515}
11516
11517template<typename Derived>
11518ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000011519TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
11520 MaterializeTemporaryExpr *E) {
11521 return getDerived().TransformExpr(E->GetTemporaryExpr());
11522}
Chad Rosier1dcde962012-08-08 18:46:20 +000011523
Douglas Gregorfe314812011-06-21 17:03:29 +000011524template<typename Derived>
11525ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000011526TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
11527 Expr *Pattern = E->getPattern();
11528
11529 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11530 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
11531 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11532
11533 // Determine whether the set of unexpanded parameter packs can and should
11534 // be expanded.
11535 bool Expand = true;
11536 bool RetainExpansion = false;
11537 Optional<unsigned> NumExpansions;
11538 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
11539 Pattern->getSourceRange(),
11540 Unexpanded,
11541 Expand, RetainExpansion,
11542 NumExpansions))
11543 return true;
11544
11545 if (!Expand) {
11546 // Do not expand any packs here, just transform and rebuild a fold
11547 // expression.
11548 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11549
11550 ExprResult LHS =
11551 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
11552 if (LHS.isInvalid())
11553 return true;
11554
11555 ExprResult RHS =
11556 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
11557 if (RHS.isInvalid())
11558 return true;
11559
11560 if (!getDerived().AlwaysRebuild() &&
11561 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
11562 return E;
11563
11564 return getDerived().RebuildCXXFoldExpr(
11565 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
11566 RHS.get(), E->getLocEnd());
11567 }
11568
11569 // The transform has determined that we should perform an elementwise
11570 // expansion of the pattern. Do so.
11571 ExprResult Result = getDerived().TransformExpr(E->getInit());
11572 if (Result.isInvalid())
11573 return true;
11574 bool LeftFold = E->isLeftFold();
11575
11576 // If we're retaining an expansion for a right fold, it is the innermost
11577 // component and takes the init (if any).
11578 if (!LeftFold && RetainExpansion) {
11579 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11580
11581 ExprResult Out = getDerived().TransformExpr(Pattern);
11582 if (Out.isInvalid())
11583 return true;
11584
11585 Result = getDerived().RebuildCXXFoldExpr(
11586 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
11587 Result.get(), E->getLocEnd());
11588 if (Result.isInvalid())
11589 return true;
11590 }
11591
11592 for (unsigned I = 0; I != *NumExpansions; ++I) {
11593 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
11594 getSema(), LeftFold ? I : *NumExpansions - I - 1);
11595 ExprResult Out = getDerived().TransformExpr(Pattern);
11596 if (Out.isInvalid())
11597 return true;
11598
11599 if (Out.get()->containsUnexpandedParameterPack()) {
11600 // We still have a pack; retain a pack expansion for this slice.
11601 Result = getDerived().RebuildCXXFoldExpr(
11602 E->getLocStart(),
11603 LeftFold ? Result.get() : Out.get(),
11604 E->getOperator(), E->getEllipsisLoc(),
11605 LeftFold ? Out.get() : Result.get(),
11606 E->getLocEnd());
11607 } else if (Result.isUsable()) {
11608 // We've got down to a single element; build a binary operator.
11609 Result = getDerived().RebuildBinaryOperator(
11610 E->getEllipsisLoc(), E->getOperator(),
11611 LeftFold ? Result.get() : Out.get(),
11612 LeftFold ? Out.get() : Result.get());
11613 } else
11614 Result = Out;
11615
11616 if (Result.isInvalid())
11617 return true;
11618 }
11619
11620 // If we're retaining an expansion for a left fold, it is the outermost
11621 // component and takes the complete expansion so far as its init (if any).
11622 if (LeftFold && RetainExpansion) {
11623 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
11624
11625 ExprResult Out = getDerived().TransformExpr(Pattern);
11626 if (Out.isInvalid())
11627 return true;
11628
11629 Result = getDerived().RebuildCXXFoldExpr(
11630 E->getLocStart(), Result.get(),
11631 E->getOperator(), E->getEllipsisLoc(),
11632 Out.get(), E->getLocEnd());
11633 if (Result.isInvalid())
11634 return true;
11635 }
11636
11637 // If we had no init and an empty pack, and we're not retaining an expansion,
11638 // then produce a fallback value or error.
11639 if (Result.isUnset())
11640 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
11641 E->getOperator());
11642
11643 return Result;
11644}
11645
11646template<typename Derived>
11647ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000011648TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
11649 CXXStdInitializerListExpr *E) {
11650 return getDerived().TransformExpr(E->getSubExpr());
11651}
11652
11653template<typename Derived>
11654ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011655TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011656 return SemaRef.MaybeBindToTemporary(E);
11657}
11658
11659template<typename Derived>
11660ExprResult
11661TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011662 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011663}
11664
11665template<typename Derived>
11666ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000011667TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
11668 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11669 if (SubExpr.isInvalid())
11670 return ExprError();
11671
11672 if (!getDerived().AlwaysRebuild() &&
11673 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011674 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000011675
11676 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000011677}
11678
11679template<typename Derived>
11680ExprResult
11681TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
11682 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011683 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011684 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000011685 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000011686 /*IsCall=*/false, Elements, &ArgChanged))
11687 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011688
Ted Kremeneke65b0862012-03-06 20:05:56 +000011689 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11690 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011691
Ted Kremeneke65b0862012-03-06 20:05:56 +000011692 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
11693 Elements.data(),
11694 Elements.size());
11695}
11696
11697template<typename Derived>
11698ExprResult
11699TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000011700 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011701 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000011702 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011703 bool ArgChanged = false;
11704 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
11705 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000011706
Ted Kremeneke65b0862012-03-06 20:05:56 +000011707 if (OrigElement.isPackExpansion()) {
11708 // This key/value element is a pack expansion.
11709 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
11710 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
11711 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
11712 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
11713
11714 // Determine whether the set of unexpanded parameter packs can
11715 // and should be expanded.
11716 bool Expand = true;
11717 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000011718 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
11719 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000011720 SourceRange PatternRange(OrigElement.Key->getLocStart(),
11721 OrigElement.Value->getLocEnd());
11722 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
11723 PatternRange,
11724 Unexpanded,
11725 Expand, RetainExpansion,
11726 NumExpansions))
11727 return ExprError();
11728
11729 if (!Expand) {
11730 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000011731 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000011732 // expansion.
11733 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
11734 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11735 if (Key.isInvalid())
11736 return ExprError();
11737
11738 if (Key.get() != OrigElement.Key)
11739 ArgChanged = true;
11740
11741 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11742 if (Value.isInvalid())
11743 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011744
Ted Kremeneke65b0862012-03-06 20:05:56 +000011745 if (Value.get() != OrigElement.Value)
11746 ArgChanged = true;
11747
Chad Rosier1dcde962012-08-08 18:46:20 +000011748 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011749 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
11750 };
11751 Elements.push_back(Expansion);
11752 continue;
11753 }
11754
11755 // Record right away that the argument was changed. This needs
11756 // to happen even if the array expands to nothing.
11757 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011758
Ted Kremeneke65b0862012-03-06 20:05:56 +000011759 // The transform has determined that we should perform an elementwise
11760 // expansion of the pattern. Do so.
11761 for (unsigned I = 0; I != *NumExpansions; ++I) {
11762 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
11763 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11764 if (Key.isInvalid())
11765 return ExprError();
11766
11767 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
11768 if (Value.isInvalid())
11769 return ExprError();
11770
Chad Rosier1dcde962012-08-08 18:46:20 +000011771 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000011772 Key.get(), Value.get(), SourceLocation(), NumExpansions
11773 };
11774
11775 // If any unexpanded parameter packs remain, we still have a
11776 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000011777 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000011778 if (Key.get()->containsUnexpandedParameterPack() ||
11779 Value.get()->containsUnexpandedParameterPack())
11780 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000011781
Ted Kremeneke65b0862012-03-06 20:05:56 +000011782 Elements.push_back(Element);
11783 }
11784
Richard Smith9467be42014-06-06 17:33:35 +000011785 // FIXME: Retain a pack expansion if RetainExpansion is true.
11786
Ted Kremeneke65b0862012-03-06 20:05:56 +000011787 // We've finished with this pack expansion.
11788 continue;
11789 }
11790
11791 // Transform and check key.
11792 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
11793 if (Key.isInvalid())
11794 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011795
Ted Kremeneke65b0862012-03-06 20:05:56 +000011796 if (Key.get() != OrigElement.Key)
11797 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011798
Ted Kremeneke65b0862012-03-06 20:05:56 +000011799 // Transform and check value.
11800 ExprResult Value
11801 = getDerived().TransformExpr(OrigElement.Value);
11802 if (Value.isInvalid())
11803 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011804
Ted Kremeneke65b0862012-03-06 20:05:56 +000011805 if (Value.get() != OrigElement.Value)
11806 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000011807
11808 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000011809 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000011810 };
11811 Elements.push_back(Element);
11812 }
Chad Rosier1dcde962012-08-08 18:46:20 +000011813
Ted Kremeneke65b0862012-03-06 20:05:56 +000011814 if (!getDerived().AlwaysRebuild() && !ArgChanged)
11815 return SemaRef.MaybeBindToTemporary(E);
11816
11817 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
Craig Topperd4336e02015-12-24 23:58:15 +000011818 Elements);
Douglas Gregora16548e2009-08-11 05:31:07 +000011819}
11820
Mike Stump11289f42009-09-09 15:08:12 +000011821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011823TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000011824 TypeSourceInfo *EncodedTypeInfo
11825 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
11826 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011828
Douglas Gregora16548e2009-08-11 05:31:07 +000011829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000011830 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011831 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011832
11833 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000011834 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000011835 E->getRParenLoc());
11836}
Mike Stump11289f42009-09-09 15:08:12 +000011837
Douglas Gregora16548e2009-08-11 05:31:07 +000011838template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000011839ExprResult TreeTransform<Derived>::
11840TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000011841 // This is a kind of implicit conversion, and it needs to get dropped
11842 // and recomputed for the same general reasons that ImplicitCastExprs
11843 // do, as well a more specific one: this expression is only valid when
11844 // it appears *immediately* as an argument expression.
11845 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000011846}
11847
11848template<typename Derived>
11849ExprResult TreeTransform<Derived>::
11850TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000011851 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000011852 = getDerived().TransformType(E->getTypeInfoAsWritten());
11853 if (!TSInfo)
11854 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011855
John McCall31168b02011-06-15 23:02:42 +000011856 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000011857 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000011858 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011859
John McCall31168b02011-06-15 23:02:42 +000011860 if (!getDerived().AlwaysRebuild() &&
11861 TSInfo == E->getTypeInfoAsWritten() &&
11862 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011863 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011864
John McCall31168b02011-06-15 23:02:42 +000011865 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000011866 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000011867 Result.get());
11868}
11869
Erik Pilkington29099de2016-07-16 00:35:23 +000011870template <typename Derived>
11871ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
11872 ObjCAvailabilityCheckExpr *E) {
11873 return E;
11874}
11875
John McCall31168b02011-06-15 23:02:42 +000011876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011878TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011879 // Transform arguments.
11880 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000011881 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000011882 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000011883 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000011884 &ArgChanged))
11885 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011886
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011887 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
11888 // Class message: transform the receiver type.
11889 TypeSourceInfo *ReceiverTypeInfo
11890 = getDerived().TransformType(E->getClassReceiverTypeInfo());
11891 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000011892 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011893
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011894 // If nothing changed, just retain the existing message send.
11895 if (!getDerived().AlwaysRebuild() &&
11896 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011897 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011898
11899 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011900 SmallVector<SourceLocation, 16> SelLocs;
11901 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011902 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
11903 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011904 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011905 E->getMethodDecl(),
11906 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011907 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011908 E->getRightLoc());
11909 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011910 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
11911 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
Bruno Cardoso Lopes25f02cf2016-08-22 21:50:22 +000011912 if (!E->getMethodDecl())
11913 return ExprError();
11914
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011915 // Build a new class message send to 'super'.
11916 SmallVector<SourceLocation, 16> SelLocs;
11917 E->getSelectorLocs(SelLocs);
11918 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
11919 E->getSelector(),
11920 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000011921 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000011922 E->getMethodDecl(),
11923 E->getLeftLoc(),
11924 Args,
11925 E->getRightLoc());
11926 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011927
11928 // Instance message: transform the receiver
11929 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
11930 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000011931 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011932 = getDerived().TransformExpr(E->getInstanceReceiver());
11933 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011934 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011935
11936 // If nothing changed, just retain the existing message send.
11937 if (!getDerived().AlwaysRebuild() &&
11938 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000011939 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000011940
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011941 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011942 SmallVector<SourceLocation, 16> SelLocs;
11943 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000011944 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011945 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000011946 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011947 E->getMethodDecl(),
11948 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011949 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000011950 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000011951}
11952
Mike Stump11289f42009-09-09 15:08:12 +000011953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011954ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011955TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011956 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011957}
11958
Mike Stump11289f42009-09-09 15:08:12 +000011959template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011960ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011961TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011962 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000011963}
11964
Mike Stump11289f42009-09-09 15:08:12 +000011965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011966ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011967TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000011968 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011969 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000011970 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011971 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000011972
11973 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011974
Douglas Gregord51d90d2010-04-26 20:11:03 +000011975 // If nothing changed, just retain the existing expression.
11976 if (!getDerived().AlwaysRebuild() &&
11977 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011978 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011979
John McCallb268a282010-08-23 23:25:46 +000011980 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000011981 E->getLocation(),
11982 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000011983}
11984
Mike Stump11289f42009-09-09 15:08:12 +000011985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000011987TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000011988 // 'super' and types never change. Property never changes. Just
11989 // retain the existing expression.
11990 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000011991 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000011992
Douglas Gregor9faee212010-04-26 20:47:02 +000011993 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000011994 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000011995 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011996 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000011997
Douglas Gregor9faee212010-04-26 20:47:02 +000011998 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000011999
Douglas Gregor9faee212010-04-26 20:47:02 +000012000 // If nothing changed, just retain the existing expression.
12001 if (!getDerived().AlwaysRebuild() &&
12002 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012003 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000012004
John McCallb7bd14f2010-12-02 01:19:52 +000012005 if (E->isExplicitProperty())
12006 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
12007 E->getExplicitProperty(),
12008 E->getLocation());
12009
12010 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000012011 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000012012 E->getImplicitPropertyGetter(),
12013 E->getImplicitPropertySetter(),
12014 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000012015}
12016
Mike Stump11289f42009-09-09 15:08:12 +000012017template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012018ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000012019TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
12020 // Transform the base expression.
12021 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
12022 if (Base.isInvalid())
12023 return ExprError();
12024
12025 // Transform the key expression.
12026 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
12027 if (Key.isInvalid())
12028 return ExprError();
12029
12030 // If nothing changed, just retain the existing expression.
12031 if (!getDerived().AlwaysRebuild() &&
12032 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012033 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000012034
Chad Rosier1dcde962012-08-08 18:46:20 +000012035 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000012036 Base.get(), Key.get(),
12037 E->getAtIndexMethodDecl(),
12038 E->setAtIndexMethodDecl());
12039}
12040
12041template<typename Derived>
12042ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012043TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000012044 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000012045 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000012046 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012047 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000012048
Douglas Gregord51d90d2010-04-26 20:11:03 +000012049 // If nothing changed, just retain the existing expression.
12050 if (!getDerived().AlwaysRebuild() &&
12051 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012052 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000012053
John McCallb268a282010-08-23 23:25:46 +000012054 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000012055 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000012056 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000012057}
12058
Mike Stump11289f42009-09-09 15:08:12 +000012059template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012060ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012061TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012062 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012063 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000012064 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000012065 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000012066 SubExprs, &ArgumentChanged))
12067 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012068
Douglas Gregora16548e2009-08-11 05:31:07 +000012069 if (!getDerived().AlwaysRebuild() &&
12070 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012071 return E;
Mike Stump11289f42009-09-09 15:08:12 +000012072
Douglas Gregora16548e2009-08-11 05:31:07 +000012073 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012074 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000012075 E->getRParenLoc());
12076}
12077
Mike Stump11289f42009-09-09 15:08:12 +000012078template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012079ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000012080TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
12081 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
12082 if (SrcExpr.isInvalid())
12083 return ExprError();
12084
12085 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12086 if (!Type)
12087 return ExprError();
12088
12089 if (!getDerived().AlwaysRebuild() &&
12090 Type == E->getTypeSourceInfo() &&
12091 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012092 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000012093
12094 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
12095 SrcExpr.get(), Type,
12096 E->getRParenLoc());
12097}
12098
12099template<typename Derived>
12100ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000012101TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000012102 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000012103
Craig Topperc3ec1492014-05-26 06:22:03 +000012104 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000012105 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
12106
12107 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000012108 blockScope->TheDecl->setBlockMissingReturnType(
12109 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000012110
Chris Lattner01cf8db2011-07-20 06:58:45 +000012111 SmallVector<ParmVarDecl*, 4> params;
12112 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000012113
John McCallc8e321d2016-03-01 02:09:25 +000012114 const FunctionProtoType *exprFunctionType = E->getFunctionType();
12115
Fariborz Jahanian1babe772010-07-09 18:44:02 +000012116 // Parameter substitution.
John McCallc8e321d2016-03-01 02:09:25 +000012117 Sema::ExtParameterInfoBuilder extParamInfos;
David Majnemer59f77922016-06-24 04:05:48 +000012118 if (getDerived().TransformFunctionTypeParams(
12119 E->getCaretLocation(), oldBlock->parameters(), nullptr,
12120 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
12121 extParamInfos)) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012122 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000012123 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012124 }
John McCall490112f2011-02-04 18:33:18 +000012125
Eli Friedman34b49062012-01-26 03:00:14 +000012126 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000012127 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000012128
John McCallc8e321d2016-03-01 02:09:25 +000012129 auto epi = exprFunctionType->getExtProtoInfo();
12130 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
12131
Jordan Rose5c382722013-03-08 21:51:21 +000012132 QualType functionType =
John McCallc8e321d2016-03-01 02:09:25 +000012133 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
John McCall490112f2011-02-04 18:33:18 +000012134 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000012135
12136 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000012137 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000012138 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000012139
12140 if (!oldBlock->blockMissingReturnType()) {
12141 blockScope->HasImplicitReturnType = false;
12142 blockScope->ReturnType = exprResultType;
12143 }
Chad Rosier1dcde962012-08-08 18:46:20 +000012144
John McCall3882ace2011-01-05 12:14:39 +000012145 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000012146 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012147 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012148 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000012149 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000012150 }
John McCall3882ace2011-01-05 12:14:39 +000012151
John McCall490112f2011-02-04 18:33:18 +000012152#ifndef NDEBUG
12153 // In builds with assertions, make sure that we captured everything we
12154 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012155 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000012156 for (const auto &I : oldBlock->captures()) {
12157 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000012158
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012159 // Ignore parameter packs.
12160 if (isa<ParmVarDecl>(oldCapture) &&
12161 cast<ParmVarDecl>(oldCapture)->isParameterPack())
12162 continue;
John McCall490112f2011-02-04 18:33:18 +000012163
Douglas Gregor4385d8b2011-05-20 15:32:55 +000012164 VarDecl *newCapture =
12165 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
12166 oldCapture));
12167 assert(blockScope->CaptureMap.count(newCapture));
12168 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000012169 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000012170 }
12171#endif
12172
12173 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000012174 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000012175}
12176
Mike Stump11289f42009-09-09 15:08:12 +000012177template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012178ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000012179TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000012180 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000012181}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012182
12183template<typename Derived>
12184ExprResult
12185TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012186 QualType RetTy = getDerived().TransformType(E->getType());
12187 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000012188 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012189 SubExprs.reserve(E->getNumSubExprs());
12190 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
12191 SubExprs, &ArgumentChanged))
12192 return ExprError();
12193
12194 if (!getDerived().AlwaysRebuild() &&
12195 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000012196 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012197
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012198 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000012199 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000012200}
Chad Rosier1dcde962012-08-08 18:46:20 +000012201
Douglas Gregora16548e2009-08-11 05:31:07 +000012202//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000012203// Type reconstruction
12204//===----------------------------------------------------------------------===//
12205
Mike Stump11289f42009-09-09 15:08:12 +000012206template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012207QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
12208 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012209 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012210 getDerived().getBaseEntity());
12211}
12212
Mike Stump11289f42009-09-09 15:08:12 +000012213template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000012214QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
12215 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000012216 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012217 getDerived().getBaseEntity());
12218}
12219
Mike Stump11289f42009-09-09 15:08:12 +000012220template<typename Derived>
12221QualType
John McCall70dd5f62009-10-30 00:06:24 +000012222TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
12223 bool WrittenAsLValue,
12224 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000012225 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000012226 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012227}
12228
12229template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012230QualType
John McCall70dd5f62009-10-30 00:06:24 +000012231TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
12232 QualType ClassType,
12233 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000012234 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
12235 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012236}
12237
12238template<typename Derived>
Manman Rene6be26c2016-09-13 17:25:08 +000012239QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
12240 const ObjCTypeParamDecl *Decl,
12241 SourceLocation ProtocolLAngleLoc,
12242 ArrayRef<ObjCProtocolDecl *> Protocols,
12243 ArrayRef<SourceLocation> ProtocolLocs,
12244 SourceLocation ProtocolRAngleLoc) {
12245 return SemaRef.BuildObjCTypeParamType(Decl,
12246 ProtocolLAngleLoc, Protocols,
12247 ProtocolLocs, ProtocolRAngleLoc,
12248 /*FailOnError=*/true);
12249}
12250
12251template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000012252QualType TreeTransform<Derived>::RebuildObjCObjectType(
12253 QualType BaseType,
12254 SourceLocation Loc,
12255 SourceLocation TypeArgsLAngleLoc,
12256 ArrayRef<TypeSourceInfo *> TypeArgs,
12257 SourceLocation TypeArgsRAngleLoc,
12258 SourceLocation ProtocolLAngleLoc,
12259 ArrayRef<ObjCProtocolDecl *> Protocols,
12260 ArrayRef<SourceLocation> ProtocolLocs,
12261 SourceLocation ProtocolRAngleLoc) {
12262 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
12263 TypeArgs, TypeArgsRAngleLoc,
12264 ProtocolLAngleLoc, Protocols, ProtocolLocs,
12265 ProtocolRAngleLoc,
12266 /*FailOnError=*/true);
12267}
12268
12269template<typename Derived>
12270QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
12271 QualType PointeeType,
12272 SourceLocation Star) {
12273 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
12274}
12275
12276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012277QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000012278TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
12279 ArrayType::ArraySizeModifier SizeMod,
12280 const llvm::APInt *Size,
12281 Expr *SizeExpr,
12282 unsigned IndexTypeQuals,
12283 SourceRange BracketsRange) {
12284 if (SizeExpr || !Size)
12285 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
12286 IndexTypeQuals, BracketsRange,
12287 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000012288
12289 QualType Types[] = {
12290 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
12291 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
12292 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000012293 };
Craig Toppere5ce8312013-07-15 03:38:40 +000012294 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012295 QualType SizeType;
12296 for (unsigned I = 0; I != NumTypes; ++I)
12297 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
12298 SizeType = Types[I];
12299 break;
12300 }
Mike Stump11289f42009-09-09 15:08:12 +000012301
Eli Friedman9562f392012-01-25 23:20:27 +000012302 // Note that we can return a VariableArrayType here in the case where
12303 // the element type was a dependent VariableArrayType.
12304 IntegerLiteral *ArraySize
12305 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
12306 /*FIXME*/BracketsRange.getBegin());
12307 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012308 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000012309 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000012310}
Mike Stump11289f42009-09-09 15:08:12 +000012311
Douglas Gregord6ff3322009-08-04 16:50:30 +000012312template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012313QualType
12314TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012315 ArrayType::ArraySizeModifier SizeMod,
12316 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000012317 unsigned IndexTypeQuals,
12318 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012319 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012320 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012321}
12322
12323template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012324QualType
Mike Stump11289f42009-09-09 15:08:12 +000012325TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012326 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000012327 unsigned IndexTypeQuals,
12328 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012329 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000012330 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012331}
Mike Stump11289f42009-09-09 15:08:12 +000012332
Douglas Gregord6ff3322009-08-04 16:50:30 +000012333template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012334QualType
12335TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012336 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012337 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012338 unsigned IndexTypeQuals,
12339 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012340 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012341 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012342 IndexTypeQuals, BracketsRange);
12343}
12344
12345template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012346QualType
12347TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012348 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000012349 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012350 unsigned IndexTypeQuals,
12351 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000012352 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000012353 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012354 IndexTypeQuals, BracketsRange);
12355}
12356
Andrew Gozillon572bbb02017-10-02 06:25:51 +000012357template <typename Derived>
12358QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
12359 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
12360 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
12361 AttributeLoc);
12362}
12363
12364template <typename Derived>
12365QualType
12366TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
12367 unsigned NumElements,
12368 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000012369 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000012370 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012371}
Mike Stump11289f42009-09-09 15:08:12 +000012372
Douglas Gregord6ff3322009-08-04 16:50:30 +000012373template<typename Derived>
12374QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
12375 unsigned NumElements,
12376 SourceLocation AttributeLoc) {
12377 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
12378 NumElements, true);
12379 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000012380 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
12381 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000012382 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012383}
Mike Stump11289f42009-09-09 15:08:12 +000012384
Douglas Gregord6ff3322009-08-04 16:50:30 +000012385template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012386QualType
12387TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000012388 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012389 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000012390 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012391}
Mike Stump11289f42009-09-09 15:08:12 +000012392
Douglas Gregord6ff3322009-08-04 16:50:30 +000012393template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000012394QualType TreeTransform<Derived>::RebuildFunctionProtoType(
12395 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000012396 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000012397 const FunctionProtoType::ExtProtoInfo &EPI) {
12398 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000012399 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000012400 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000012401 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012402}
Mike Stump11289f42009-09-09 15:08:12 +000012403
Douglas Gregord6ff3322009-08-04 16:50:30 +000012404template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000012405QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
12406 return SemaRef.Context.getFunctionNoProtoType(T);
12407}
12408
12409template<typename Derived>
Richard Smith151c4562016-12-20 21:35:28 +000012410QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
12411 Decl *D) {
John McCallb96ec562009-12-04 22:46:56 +000012412 assert(D && "no decl found");
12413 if (D->isInvalidDecl()) return QualType();
12414
Douglas Gregorc298ffc2010-04-22 16:44:27 +000012415 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000012416 TypeDecl *Ty;
Richard Smith151c4562016-12-20 21:35:28 +000012417 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
12418 // A valid resolved using typename pack expansion decl can have multiple
12419 // UsingDecls, but they must each have exactly one type, and it must be
12420 // the same type in every case. But we must have at least one expansion!
12421 if (UPD->expansions().empty()) {
12422 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
12423 << UPD->isCXXClassMember() << UPD;
12424 return QualType();
12425 }
12426
12427 // We might still have some unresolved types. Try to pick a resolved type
12428 // if we can. The final instantiation will check that the remaining
12429 // unresolved types instantiate to the type we pick.
12430 QualType FallbackT;
12431 QualType T;
12432 for (auto *E : UPD->expansions()) {
12433 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
12434 if (ThisT.isNull())
12435 continue;
12436 else if (ThisT->getAs<UnresolvedUsingType>())
12437 FallbackT = ThisT;
12438 else if (T.isNull())
12439 T = ThisT;
12440 else
12441 assert(getSema().Context.hasSameType(ThisT, T) &&
12442 "mismatched resolved types in using pack expansion");
12443 }
12444 return T.isNull() ? FallbackT : T;
12445 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000012446 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000012447 "UnresolvedUsingTypenameDecl transformed to non-typename using");
12448
12449 // A valid resolved using typename decl points to exactly one type decl.
12450 assert(++Using->shadow_begin() == Using->shadow_end());
12451 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
John McCallb96ec562009-12-04 22:46:56 +000012452 } else {
12453 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
12454 "UnresolvedUsingTypenameDecl transformed to non-using decl");
12455 Ty = cast<UnresolvedUsingTypenameDecl>(D);
12456 }
12457
12458 return SemaRef.Context.getTypeDeclType(Ty);
12459}
12460
12461template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012462QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
12463 SourceLocation Loc) {
12464 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012465}
12466
12467template<typename Derived>
12468QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
12469 return SemaRef.Context.getTypeOfType(Underlying);
12470}
12471
12472template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000012473QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
12474 SourceLocation Loc) {
12475 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012476}
12477
12478template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000012479QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
12480 UnaryTransformType::UTTKind UKind,
12481 SourceLocation Loc) {
12482 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
12483}
12484
12485template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000012486QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000012487 TemplateName Template,
12488 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000012489 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000012490 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000012491}
Mike Stump11289f42009-09-09 15:08:12 +000012492
Douglas Gregor1135c352009-08-06 05:28:30 +000012493template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000012494QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
12495 SourceLocation KWLoc) {
12496 return SemaRef.BuildAtomicType(ValueType, KWLoc);
12497}
12498
12499template<typename Derived>
Xiuli Pan9c14e282016-01-09 12:53:17 +000012500QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
Joey Gouly5788b782016-11-18 14:10:54 +000012501 SourceLocation KWLoc,
12502 bool isReadPipe) {
12503 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
12504 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
Xiuli Pan9c14e282016-01-09 12:53:17 +000012505}
12506
12507template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012508TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012509TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012510 bool TemplateKW,
12511 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012512 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000012513 Template);
12514}
12515
12516template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000012517TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012518TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
12519 const IdentifierInfo &Name,
12520 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000012521 QualType ObjectType,
Richard Smithfd3dae02017-01-20 00:20:39 +000012522 NamedDecl *FirstQualifierInScope,
12523 bool AllowInjectedClassName) {
Douglas Gregor9db53502011-03-02 18:07:45 +000012524 UnqualifiedId TemplateName;
12525 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000012526 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000012527 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000012528 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012529 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000012530 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012531 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012532 Template, AllowInjectedClassName);
John McCall31f82722010-11-12 08:19:04 +000012533 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000012534}
Mike Stump11289f42009-09-09 15:08:12 +000012535
Douglas Gregora16548e2009-08-11 05:31:07 +000012536template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000012537TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000012538TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000012539 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000012540 SourceLocation NameLoc,
Richard Smithfd3dae02017-01-20 00:20:39 +000012541 QualType ObjectType,
12542 bool AllowInjectedClassName) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000012543 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000012544 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000012545 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000012546 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000012547 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000012548 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000012549 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012550 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000012551 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000012552 /*EnteringContext=*/false,
Richard Smithfd3dae02017-01-20 00:20:39 +000012553 Template, AllowInjectedClassName);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000012554 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000012555}
Chad Rosier1dcde962012-08-08 18:46:20 +000012556
Douglas Gregor71395fa2009-11-04 00:56:37 +000012557template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000012558ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000012559TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
12560 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000012561 Expr *OrigCallee,
12562 Expr *First,
12563 Expr *Second) {
12564 Expr *Callee = OrigCallee->IgnoreParenCasts();
12565 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000012566
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000012567 if (First->getObjectKind() == OK_ObjCProperty) {
12568 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
12569 if (BinaryOperator::isAssignmentOp(Opc))
12570 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
12571 First, Second);
12572 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
12573 if (Result.isInvalid())
12574 return ExprError();
12575 First = Result.get();
12576 }
12577
12578 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
12579 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
12580 if (Result.isInvalid())
12581 return ExprError();
12582 Second = Result.get();
12583 }
12584
Douglas Gregora16548e2009-08-11 05:31:07 +000012585 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000012586 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000012587 if (!First->getType()->isOverloadableType() &&
12588 !Second->getType()->isOverloadableType())
12589 return getSema().CreateBuiltinArraySubscriptExpr(First,
12590 Callee->getLocStart(),
12591 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000012592 } else if (Op == OO_Arrow) {
12593 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000012594 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
12595 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000012596 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012597 // The argument is not of overloadable type, so try to create a
12598 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000012599 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012600 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000012601
John McCallb268a282010-08-23 23:25:46 +000012602 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000012603 }
12604 } else {
John McCallb268a282010-08-23 23:25:46 +000012605 if (!First->getType()->isOverloadableType() &&
12606 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000012607 // Neither of the arguments is an overloadable type, so try to
12608 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000012609 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000012610 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000012611 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000012612 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012613 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012614
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012615 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012616 }
12617 }
Mike Stump11289f42009-09-09 15:08:12 +000012618
12619 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000012620 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000012621 UnresolvedSet<16> Functions;
Richard Smith91fc7d82017-10-05 19:35:51 +000012622 bool RequiresADL;
Mike Stump11289f42009-09-09 15:08:12 +000012623
John McCallb268a282010-08-23 23:25:46 +000012624 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
Richard Smith100b24a2014-04-17 01:52:14 +000012625 Functions.append(ULE->decls_begin(), ULE->decls_end());
Richard Smith91fc7d82017-10-05 19:35:51 +000012626 // If the overload could not be resolved in the template definition
12627 // (because we had a dependent argument), ADL is performed as part of
12628 // template instantiation.
12629 RequiresADL = ULE->requiresADL();
John McCalld14a8642009-11-21 08:51:07 +000012630 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000012631 // If we've resolved this to a particular non-member function, just call
12632 // that function. If we resolved it to a member function,
12633 // CreateOverloaded* will find that function for us.
12634 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
12635 if (!isa<CXXMethodDecl>(ND))
12636 Functions.addDecl(ND);
Richard Smith91fc7d82017-10-05 19:35:51 +000012637 RequiresADL = false;
John McCalld14a8642009-11-21 08:51:07 +000012638 }
Mike Stump11289f42009-09-09 15:08:12 +000012639
Douglas Gregora16548e2009-08-11 05:31:07 +000012640 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000012641 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000012642 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000012643
Douglas Gregora16548e2009-08-11 05:31:07 +000012644 // Create the overloaded operator invocation for unary operators.
12645 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000012646 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000012647 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Richard Smith91fc7d82017-10-05 19:35:51 +000012648 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
12649 RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012650 }
Mike Stump11289f42009-09-09 15:08:12 +000012651
Douglas Gregore9d62932011-07-15 16:25:15 +000012652 if (Op == OO_Subscript) {
12653 SourceLocation LBrace;
12654 SourceLocation RBrace;
12655
12656 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000012657 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000012658 LBrace = SourceLocation::getFromRawEncoding(
12659 NameLoc.CXXOperatorName.BeginOpNameLoc);
12660 RBrace = SourceLocation::getFromRawEncoding(
12661 NameLoc.CXXOperatorName.EndOpNameLoc);
12662 } else {
12663 LBrace = Callee->getLocStart();
12664 RBrace = OpLoc;
12665 }
12666
12667 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
12668 First, Second);
12669 }
Sebastian Redladba46e2009-10-29 20:17:01 +000012670
Douglas Gregora16548e2009-08-11 05:31:07 +000012671 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000012672 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
Richard Smith91fc7d82017-10-05 19:35:51 +000012673 ExprResult Result = SemaRef.CreateOverloadedBinOp(
12674 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
Douglas Gregora16548e2009-08-11 05:31:07 +000012675 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000012676 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000012677
Benjamin Kramer62b95d82012-08-23 21:35:17 +000012678 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000012679}
Mike Stump11289f42009-09-09 15:08:12 +000012680
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012681template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000012682ExprResult
John McCallb268a282010-08-23 23:25:46 +000012683TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012684 SourceLocation OperatorLoc,
12685 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000012686 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012687 TypeSourceInfo *ScopeType,
12688 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000012689 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000012690 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000012691 QualType BaseType = Base->getType();
12692 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012693 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000012694 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000012695 !BaseType->getAs<PointerType>()->getPointeeType()
12696 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012697 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000012698 return SemaRef.BuildPseudoDestructorExpr(
12699 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
12700 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012701 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012702
Douglas Gregor678f90d2010-02-25 01:56:36 +000012703 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012704 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
12705 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
12706 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
12707 NameInfo.setNamedTypeInfo(DestroyedType);
12708
Richard Smith8e4a3862012-05-15 06:15:11 +000012709 // The scope type is now known to be a valid nested name specifier
12710 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000012711 if (ScopeType) {
12712 if (!ScopeType->getType()->getAs<TagType>()) {
12713 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
12714 diag::err_expected_class_or_namespace)
12715 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
12716 return ExprError();
12717 }
12718 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
12719 CCLoc);
12720 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012721
Abramo Bagnara7945c982012-01-27 09:46:47 +000012722 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000012723 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012724 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000012725 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000012726 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000012727 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000012728 /*TemplateArgs*/ nullptr,
12729 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000012730}
12731
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012732template<typename Derived>
12733StmtResult
12734TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000012735 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000012736 CapturedDecl *CD = S->getCapturedDecl();
12737 unsigned NumParams = CD->getNumParams();
12738 unsigned ContextParamPos = CD->getContextParamPosition();
12739 SmallVector<Sema::CapturedParamNameType, 4> Params;
12740 for (unsigned I = 0; I < NumParams; ++I) {
12741 if (I != ContextParamPos) {
12742 Params.push_back(
12743 std::make_pair(
12744 CD->getParam(I)->getName(),
12745 getDerived().TransformType(CD->getParam(I)->getType())));
12746 } else {
12747 Params.push_back(std::make_pair(StringRef(), QualType()));
12748 }
12749 }
Craig Topperc3ec1492014-05-26 06:22:03 +000012750 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000012751 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000012752 StmtResult Body;
12753 {
12754 Sema::CompoundScopeRAII CompoundScope(getSema());
12755 Body = getDerived().TransformStmt(S->getCapturedStmt());
12756 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000012757
12758 if (Body.isInvalid()) {
12759 getSema().ActOnCapturedRegionError();
12760 return StmtError();
12761 }
12762
Nikola Smiljanic01a75982014-05-29 10:55:11 +000012763 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000012764}
12765
Douglas Gregord6ff3322009-08-04 16:50:30 +000012766} // end namespace clang
12767
Hans Wennborg59dbe862015-09-29 20:56:43 +000012768#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H